Skip to content
Merged
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
11 changes: 1 addition & 10 deletions api/bootstrap/kubeadm/v1beta2/kubeadm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,7 @@ type ClusterConfiguration struct {
CertificatesDir string `json:"certificatesDir,omitempty"`

// imageRepository sets the container registry to pull images from.
// * If not set, the default registry of kubeadm will be used, i.e.
// * registry.k8s.io (new registry): >= v1.22.17, >= v1.23.15, >= v1.24.9, >= v1.25.0
// * k8s.gcr.io (old registry): all older versions
// Please note that when imageRepository is not set we don't allow upgrades to
// versions >= v1.22.0 which use the old registry (k8s.gcr.io). Please use
// a newer patch version with the new registry instead (i.e. >= v1.22.17,
// >= v1.23.15, >= v1.24.9, >= v1.25.0).
// * If the version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/k8s-staging-ci-images` will be used as a default for control plane components
// and for kube-proxy, while `registry.k8s.io` will be used for all the other images.
// If not set, the default registry of kubeadm will be used (registry.k8s.io).
// +optional
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=512
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,6 @@ type KubeadmControlPlaneSpec struct {
Replicas *int32 `json:"replicas,omitempty"`

// version defines the desired Kubernetes version.
// Please note that if kubeadmConfigSpec.ClusterConfiguration.imageRepository is not set
// we don't allow upgrades to versions >= v1.22.0 for which kubeadm uses the old registry (k8s.gcr.io).
// Please use a newer patch version with the new registry instead. The default registries of kubeadm are:
// * registry.k8s.io (new registry): >= v1.22.17, >= v1.23.15, >= v1.24.9, >= v1.25.0
// * k8s.gcr.io (old registry): all older versions
// +required
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=256
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 29 additions & 33 deletions controlplane/kubeadm/internal/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ type ControlPlane struct {
Machines collections.Machines
machinesPatchHelpers map[string]*patch.Helper

machinesNotUptoDate collections.Machines
machinesNotUptoDateLogMessages map[string][]string
machinesNotUptoDateConditionMessages map[string][]string
machinesNotUptoDate collections.Machines
machinesNotUpToDateResults map[string]NotUpToDateResult

// reconciliationTime is the time of the current reconciliation, and should be used for all "now" calculations
reconciliationTime metav1.Time
Expand Down Expand Up @@ -98,7 +97,7 @@ type PreflightCheckResults struct {

// NewControlPlane returns an instantiated ControlPlane.
func NewControlPlane(ctx context.Context, managementCluster ManagementCluster, client client.Client, cluster *clusterv1.Cluster, kcp *controlplanev1.KubeadmControlPlane, ownedMachines collections.Machines) (*ControlPlane, error) {
infraObjects, err := getInfraResources(ctx, client, ownedMachines)
infraMachines, err := getInfraMachines(ctx, client, ownedMachines)
if err != nil {
return nil, err
}
Expand All @@ -118,32 +117,29 @@ func NewControlPlane(ctx context.Context, managementCluster ManagementCluster, c
// Select machines that should be rolled out because of an outdated configuration or because rolloutAfter/Before expired.
reconciliationTime := metav1.Now()
machinesNotUptoDate := make(collections.Machines, len(ownedMachines))
machinesNotUptoDateLogMessages := map[string][]string{}
machinesNotUptoDateConditionMessages := map[string][]string{}
machinesNotUpToDateResults := map[string]NotUpToDateResult{}
for _, m := range ownedMachines {
upToDate, logMessages, conditionMessages, err := UpToDate(m, kcp, &reconciliationTime, infraObjects, kubeadmConfigs)
upToDate, notUpToDateResult, err := UpToDate(m, kcp, &reconciliationTime, infraMachines, kubeadmConfigs)
if err != nil {
return nil, err
}
if !upToDate {
machinesNotUptoDate.Insert(m)
machinesNotUptoDateLogMessages[m.Name] = logMessages
machinesNotUptoDateConditionMessages[m.Name] = conditionMessages
machinesNotUpToDateResults[m.Name] = *notUpToDateResult
}
}

return &ControlPlane{
KCP: kcp,
Cluster: cluster,
Machines: ownedMachines,
machinesPatchHelpers: patchHelpers,
machinesNotUptoDate: machinesNotUptoDate,
machinesNotUptoDateLogMessages: machinesNotUptoDateLogMessages,
machinesNotUptoDateConditionMessages: machinesNotUptoDateConditionMessages,
KubeadmConfigs: kubeadmConfigs,
InfraResources: infraObjects,
reconciliationTime: reconciliationTime,
managementCluster: managementCluster,
KCP: kcp,
Cluster: cluster,
Machines: ownedMachines,
machinesPatchHelpers: patchHelpers,
machinesNotUptoDate: machinesNotUptoDate,
machinesNotUpToDateResults: machinesNotUpToDateResults,
KubeadmConfigs: kubeadmConfigs,
InfraResources: infraMachines,
reconciliationTime: reconciliationTime,
managementCluster: managementCluster,
}, nil
}

Expand Down Expand Up @@ -256,15 +252,15 @@ func (c *ControlPlane) GetKubeadmConfig(machineName string) (*bootstrapv1.Kubead
}

// MachinesNeedingRollout return a list of machines that need to be rolled out.
func (c *ControlPlane) MachinesNeedingRollout() (collections.Machines, map[string][]string) {
func (c *ControlPlane) MachinesNeedingRollout() (collections.Machines, map[string]NotUpToDateResult) {
// Note: Machines already deleted are dropped because they will be replaced by new machines after deletion completes.
return c.machinesNotUptoDate.Filter(collections.Not(collections.HasDeletionTimestamp)), c.machinesNotUptoDateLogMessages
return c.machinesNotUptoDate.Filter(collections.Not(collections.HasDeletionTimestamp)), c.machinesNotUpToDateResults
}

// NotUpToDateMachines return a list of machines that are not up to date with the control
// plane's configuration.
func (c *ControlPlane) NotUpToDateMachines() (collections.Machines, map[string][]string) {
return c.machinesNotUptoDate, c.machinesNotUptoDateConditionMessages
func (c *ControlPlane) NotUpToDateMachines() (collections.Machines, map[string]NotUpToDateResult) {
return c.machinesNotUptoDate, c.machinesNotUpToDateResults
}

// UpToDateMachines returns the machines that are up to date with the control
Expand All @@ -273,18 +269,18 @@ func (c *ControlPlane) UpToDateMachines() collections.Machines {
return c.Machines.Difference(c.machinesNotUptoDate)
}

// getInfraResources fetches the external infrastructure resource for each machine in the collection and returns a map of machine.Name -> infraResource.
func getInfraResources(ctx context.Context, cl client.Client, machines collections.Machines) (map[string]*unstructured.Unstructured, error) {
// getInfraMachines fetches the InfraMachine for each machine in the collection and returns a map of machine.Name -> InfraMachine.
func getInfraMachines(ctx context.Context, cl client.Client, machines collections.Machines) (map[string]*unstructured.Unstructured, error) {
result := map[string]*unstructured.Unstructured{}
for _, m := range machines {
infraObj, err := external.GetObjectFromContractVersionedRef(ctx, cl, m.Spec.InfrastructureRef, m.Namespace)
infraMachine, err := external.GetObjectFromContractVersionedRef(ctx, cl, m.Spec.InfrastructureRef, m.Namespace)
if err != nil {
if apierrors.IsNotFound(errors.Cause(err)) {
continue
}
return nil, errors.Wrapf(err, "failed to retrieve infra obj for machine %q", m.Name)
return nil, errors.Wrapf(err, "failed to retrieve InfraMachine for Machine %s", m.Name)
}
result[m.Name] = infraObj
result[m.Name] = infraMachine
}
return result, nil
}
Expand All @@ -297,14 +293,14 @@ func getKubeadmConfigs(ctx context.Context, cl client.Client, machines collectio
if !bootstrapRef.IsDefined() {
continue
}
machineConfig := &bootstrapv1.KubeadmConfig{}
if err := cl.Get(ctx, client.ObjectKey{Name: bootstrapRef.Name, Namespace: m.Namespace}, machineConfig); err != nil {
kubeadmConfig := &bootstrapv1.KubeadmConfig{}
if err := cl.Get(ctx, client.ObjectKey{Name: bootstrapRef.Name, Namespace: m.Namespace}, kubeadmConfig); err != nil {
if apierrors.IsNotFound(errors.Cause(err)) {
continue
}
return nil, errors.Wrapf(err, "failed to retrieve bootstrap config for machine %q", m.Name)
return nil, errors.Wrapf(err, "failed to retrieve KubeadmConfig for Machine %s", m.Name)
}
result[m.Name] = machineConfig
result[m.Name] = kubeadmConfig
}
return result, nil
}
Expand Down
16 changes: 8 additions & 8 deletions controlplane/kubeadm/internal/control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ func TestControlPlane(t *testing.T) {

g.Expect(controlPlane.Machines).To(HaveLen(5))

machinesNotUptoDate, machinesNotUptoDateConditionMessages := controlPlane.NotUpToDateMachines()
machinesNotUptoDate, machinesNotUpToDateResults := controlPlane.NotUpToDateMachines()
g.Expect(machinesNotUptoDate.Names()).To(ConsistOf("m2", "m3"))
g.Expect(machinesNotUptoDateConditionMessages).To(HaveLen(2))
g.Expect(machinesNotUptoDateConditionMessages).To(HaveKeyWithValue("m2", []string{"Version v1.29.0, v1.31.0 required"}))
g.Expect(machinesNotUptoDateConditionMessages).To(HaveKeyWithValue("m3", []string{"Version v1.29.3, v1.31.0 required"}))
g.Expect(machinesNotUpToDateResults).To(HaveLen(2))
g.Expect(machinesNotUpToDateResults["m2"].ConditionMessages).To(Equal([]string{"Version v1.29.0, v1.31.0 required"}))
g.Expect(machinesNotUpToDateResults["m3"].ConditionMessages).To(Equal([]string{"Version v1.29.3, v1.31.0 required"}))

machinesNeedingRollout, machinesNotUptoDateLogMessages := controlPlane.MachinesNeedingRollout()
machinesNeedingRollout, machinesNotUpToDateResults := controlPlane.MachinesNeedingRollout()
g.Expect(machinesNeedingRollout.Names()).To(ConsistOf("m2"))
g.Expect(machinesNotUptoDateLogMessages).To(HaveLen(2))
g.Expect(machinesNotUptoDateLogMessages).To(HaveKeyWithValue("m2", []string{"Machine version \"v1.29.0\" is not equal to KCP version \"v1.31.0\""}))
g.Expect(machinesNotUptoDateLogMessages).To(HaveKeyWithValue("m3", []string{"Machine version \"v1.29.3\" is not equal to KCP version \"v1.31.0\""}))
g.Expect(machinesNotUpToDateResults).To(HaveLen(2))
g.Expect(machinesNotUpToDateResults["m2"].LogMessages).To(Equal([]string{"Machine version \"v1.29.0\" is not equal to KCP version \"v1.31.0\""}))
g.Expect(machinesNotUpToDateResults["m3"].LogMessages).To(Equal([]string{"Machine version \"v1.29.3\" is not equal to KCP version \"v1.31.0\""}))

upToDateMachines := controlPlane.UpToDateMachines()
g.Expect(upToDateMachines).To(HaveLen(3))
Expand Down
Loading