Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 82 additions & 1 deletion bootstrap/kubeadm/webhooks/conversion/kubeadmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,91 @@ func ConvertKubeadmConfigHubToV1Beta1(ctx context.Context, src *bootstrapv1.Kube
dropEmptyStringsKubeadmConfigSpec(&dst.Spec)
dropEmptyStringsKubeadmConfigStatus(&dst.Status)

// Preserve Hub data on down-conversion except for metadata.
// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertKubeadmConfigV1Beta1ToHub to reduce memory usage.
src = &bootstrapv1.KubeadmConfig{
Spec: MinimalKubeadmConfigSpecForRestore(&src.Spec),
Status: bootstrapv1.KubeadmConfigStatus{
Initialization: src.Status.Initialization,
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}

// MinimalKubeadmConfigSpecForRestore returns a KubeadmConfigSpec that only contains the fields that
// are actually read back from the conversion annotation by RestoreBoolIntentKubeadmConfigSpec and
// RestoreKubeadmConfigSpec. This is used to reduce the amount of data stored in the conversion annotation.
func MinimalKubeadmConfigSpecForRestore(src *bootstrapv1.KubeadmConfigSpec) bootstrapv1.KubeadmConfigSpec {
return bootstrapv1.KubeadmConfigSpec{
ClusterConfiguration: bootstrapv1.ClusterConfiguration{
APIServer: bootstrapv1.APIServer{
ExtraVolumes: minimalHostPathMountsForRestore(src.ClusterConfiguration.APIServer.ExtraVolumes),
},
ControllerManager: bootstrapv1.ControllerManager{
ExtraVolumes: minimalHostPathMountsForRestore(src.ClusterConfiguration.ControllerManager.ExtraVolumes),
},
Scheduler: bootstrapv1.Scheduler{
ExtraVolumes: minimalHostPathMountsForRestore(src.ClusterConfiguration.Scheduler.ExtraVolumes),
},
},
InitConfiguration: bootstrapv1.InitConfiguration{
Timeouts: src.InitConfiguration.Timeouts,
},
JoinConfiguration: bootstrapv1.JoinConfiguration{
Timeouts: src.JoinConfiguration.Timeouts,
Discovery: bootstrapv1.Discovery{
BootstrapToken: bootstrapv1.BootstrapTokenDiscovery{
UnsafeSkipCAVerification: src.JoinConfiguration.Discovery.BootstrapToken.UnsafeSkipCAVerification,
},
File: bootstrapv1.FileDiscovery{
KubeConfig: bootstrapv1.FileDiscoveryKubeConfig{
Cluster: bootstrapv1.KubeConfigCluster{
InsecureSkipTLSVerify: src.JoinConfiguration.Discovery.File.KubeConfig.Cluster.InsecureSkipTLSVerify,
},
User: bootstrapv1.KubeConfigUser{
Exec: bootstrapv1.KubeConfigAuthExec{
ProvideClusterInfo: src.JoinConfiguration.Discovery.File.KubeConfig.User.Exec.ProvideClusterInfo,
},
},
},
},
},
},
Files: minimalFilesForRestore(src.Files),
Ignition: bootstrapv1.IgnitionSpec{
ContainerLinuxConfig: bootstrapv1.ContainerLinuxConfig{
Strict: src.Ignition.ContainerLinuxConfig.Strict,
},
},
}
}

// minimalHostPathMountsForRestore returns a slice of HostPathMount that only contains the fields
// needed to restore the ReadOnly bool intent (HostPath is used to find the matching entry).
func minimalHostPathMountsForRestore(volumes []bootstrapv1.HostPathMount) []bootstrapv1.HostPathMount {
if volumes == nil {
return nil
}
out := make([]bootstrapv1.HostPathMount, len(volumes))
for i, v := range volumes {
out[i] = bootstrapv1.HostPathMount{HostPath: v.HostPath, ReadOnly: v.ReadOnly}
}
return out
}

// minimalFilesForRestore returns a slice of File that only contains the fields needed to restore
// the Append bool intent (Path is used to find the matching entry).
func minimalFilesForRestore(files []bootstrapv1.File) []bootstrapv1.File {
if files == nil {
return nil
}
out := make([]bootstrapv1.File, len(files))
for i, f := range files {
out[i] = bootstrapv1.File{Path: f.Path, Append: f.Append}
}
return out
}

// ConvertKubeadmConfigSpecHubToV1Beta1 converts a hub KubeadmConfigSpec to a v1beta1 KubeadmConfigSpec.
func ConvertKubeadmConfigSpecHubToV1Beta1(_ context.Context, src *bootstrapv1.KubeadmConfigSpec, dst *bootstrapv1beta1.KubeadmConfigSpec) {
// Convert timeouts moved from one struct to another.
Expand Down
10 changes: 9 additions & 1 deletion bootstrap/kubeadm/webhooks/conversion/kubeadmconfigtemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ func ConvertKubeadmConfigTemplateHubToV1Beta1(ctx context.Context, src *bootstra

dropEmptyStringsKubeadmConfigSpec(&dst.Spec.Template.Spec)

// Preserve Hub data on down-conversion except for metadata.
// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertKubeadmConfigTemplateV1Beta1ToHub to reduce memory usage.
src = &bootstrapv1.KubeadmConfigTemplate{
Spec: bootstrapv1.KubeadmConfigTemplateSpec{
Template: bootstrapv1.KubeadmConfigTemplateResource{
Spec: MinimalKubeadmConfigSpecForRestore(&src.Spec.Template.Spec),
},
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}
14 changes: 13 additions & 1 deletion controlplane/kubeadm/webhooks/conversion/kubeadmcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,19 @@ func ConvertKubeadmControlPlaneHubToV1Beta1(ctx context.Context, src *controlpla
dropEmptyStringsKubeadmConfigSpec(&dst.Spec.KubeadmConfigSpec)
dropEmptyStringsKubeadmControlPlaneStatus(&dst.Status)

// Preserve Hub data on down-conversion except for metadata.
// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertKubeadmControlPlaneV1Beta1ToHub to reduce memory usage.
src = &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapconversion.MinimalKubeadmConfigSpecForRestore(&src.Spec.KubeadmConfigSpec),
Remediation: controlplanev1.KubeadmControlPlaneRemediationSpec{
RetryPeriodSeconds: src.Spec.Remediation.RetryPeriodSeconds,
},
},
Status: controlplanev1.KubeadmControlPlaneStatus{
Initialization: src.Status.Initialization,
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ func ConvertKubeadmControlPlaneTemplateHubToV1Beta1(ctx context.Context, src *co

dropEmptyStringsKubeadmConfigSpec(&dst.Spec.Template.Spec.KubeadmConfigSpec)

// Preserve Hub data on down-conversion except for metadata.
// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertKubeadmControlPlaneTemplateV1Beta1ToHub to reduce memory usage.
src = &controlplanev1.KubeadmControlPlaneTemplate{
Spec: controlplanev1.KubeadmControlPlaneTemplateSpec{
Template: controlplanev1.KubeadmControlPlaneTemplateResource{
Spec: controlplanev1.KubeadmControlPlaneTemplateResourceSpec{
KubeadmConfigSpec: bootstrapconversion.MinimalKubeadmConfigSpecForRestore(&src.Spec.Template.Spec.KubeadmConfigSpec),
Remediation: controlplanev1.KubeadmControlPlaneRemediationSpec{
RetryPeriodSeconds: src.Spec.Template.Spec.Remediation.RetryPeriodSeconds,
},
},
},
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}
10 changes: 10 additions & 0 deletions core/webhooks/conversion/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ func ConvertClusterHubToV1Beta1(ctx context.Context, src *clusterv1.Cluster, dst

dropEmptyStringsCluster(dst)

// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertClusterV1Beta1ToHub to reduce memory usage.
src = &clusterv1.Cluster{
Spec: clusterv1.ClusterSpec{
Paused: src.Spec.Paused,
},
Status: clusterv1.ClusterStatus{
Initialization: src.Status.Initialization,
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}

Expand Down
8 changes: 7 additions & 1 deletion core/webhooks/conversion/ipaddressclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ func ConvertIPAddressClaimHubToV1Alpha1(_ context.Context, src *ipamv1.IPAddress
dst.Labels[clusterv1.ClusterNameLabel] = src.Spec.ClusterName
}

// Preserve Hub data on down-conversion except for metadata
// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertIPAddressClaimV1Alpha1ToHub to reduce memory usage.
src = &ipamv1.IPAddressClaim{
Status: ipamv1.IPAddressClaimStatus{
Conditions: src.Status.Conditions,
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}

Expand Down
12 changes: 12 additions & 0 deletions core/webhooks/conversion/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,17 @@ func ConvertMachineHubToV1Beta1(ctx context.Context, src *clusterv1.Machine, dst

dropEmptyStringsMachineSpec(&dst.Spec)

// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertMachineV1Beta1ToHub to reduce memory usage.
src = &clusterv1.Machine{
Spec: clusterv1.MachineSpec{
MinReadySeconds: src.Spec.MinReadySeconds,
},
Status: clusterv1.MachineStatus{
Phase: src.Status.Phase,
FailureDomain: src.Status.FailureDomain,
Initialization: src.Status.Initialization,
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}
7 changes: 7 additions & 0 deletions core/webhooks/conversion/machinedeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,12 @@ func ConvertMachineDeploymentHubToV1Beta1(ctx context.Context, src *clusterv1.Ma

dropEmptyStringsMachineSpec(&dst.Spec.Template.Spec)

// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertMachineDeploymentV1Beta1ToHub to reduce memory usage.
src = &clusterv1.MachineDeployment{
Spec: clusterv1.MachineDeploymentSpec{
Paused: src.Spec.Paused,
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}
9 changes: 9 additions & 0 deletions core/webhooks/conversion/machinehealthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,14 @@ func ConvertMachineHealthCheckHubToV1Beta1(_ context.Context, src *clusterv1.Mac
dst.Spec.RemediationTemplate.Namespace = src.Namespace
}

// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertMachineHealthCheckV1Beta1ToHub to reduce memory usage.
src = &clusterv1.MachineHealthCheck{
Status: clusterv1.MachineHealthCheckStatus{
ExpectedMachines: src.Status.ExpectedMachines,
CurrentHealthy: src.Status.CurrentHealthy,
RemediationsAllowed: src.Status.RemediationsAllowed,
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}
7 changes: 7 additions & 0 deletions core/webhooks/conversion/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,12 @@ func ConvertMachinePoolHubToV1Beta1(ctx context.Context, src *clusterv1.MachineP

dropEmptyStringsMachineSpec(&dst.Spec.Template.Spec)

// Note: Only put the fields into the conversion annotation that are actually restored in
// ConvertMachinePoolV1Beta1ToHub to reduce memory usage.
src = &clusterv1.MachinePool{
Status: clusterv1.MachinePoolStatus{
Initialization: src.Status.Initialization,
},
}
return conversionutil.MarshalDataUnsafeNoCopy(src, dst)
}
Loading