Skip to content

Commit

Permalink
tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuvaraj Kakaraparthi committed May 23, 2023
1 parent 342a80e commit e2d70bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
34 changes: 20 additions & 14 deletions internal/controllers/topology/cluster/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,6 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP
// Add ClusterTopologyMachineDeploymentLabel to the generated InfrastructureMachine template
infraMachineTemplateLabels[clusterv1.ClusterTopologyMachineDeploymentNameLabel] = machineDeploymentTopology.Name
desiredMachineDeployment.InfrastructureMachineTemplate.SetLabels(infraMachineTemplateLabels)
version, err := computeMachineDeploymentVersion(s, machineDeploymentTopology, desiredControlPlaneState, currentMachineDeployment)
if err != nil {
return nil, errors.Wrapf(err, "failed to compute version for %s", machineDeploymentTopology.Name)
}

// Compute values that can be set both in the MachineDeploymentClass and in the MachineDeploymentTopology
minReadySeconds := machineDeploymentClass.MinReadySeconds
Expand Down Expand Up @@ -688,7 +684,6 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP
Template: clusterv1.MachineTemplateSpec{
Spec: clusterv1.MachineSpec{
ClusterName: s.Current.Cluster.Name,
Version: pointer.String(version),
Bootstrap: clusterv1.Bootstrap{ConfigRef: desiredBootstrapTemplateRef},
InfrastructureRef: *desiredInfraMachineTemplateRef,
FailureDomain: failureDomain,
Expand All @@ -706,6 +701,12 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP
desiredMachineDeploymentObj.SetName(currentMachineDeployment.Object.Name)
}

version, err := computeMachineDeploymentVersion(s, desiredMachineDeploymentObj.Name, machineDeploymentTopology, desiredControlPlaneState, currentMachineDeployment)
if err != nil {
return nil, errors.Wrapf(err, "failed to compute version for %s", machineDeploymentTopology.Name)
}
desiredMachineDeploymentObj.Spec.Template.Spec.Version = pointer.String(version)

// Apply annotations
machineDeploymentAnnotations := util.MergeMap(machineDeploymentTopology.Metadata.Annotations, machineDeploymentBlueprint.Metadata.Annotations)
// Ensure the annotations used to control the upgrade sequence are never propagated.
Expand Down Expand Up @@ -762,7 +763,7 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP
// Nb: No MachineDeployment upgrades will be triggered while any MachineDeployment is in the middle
// of an upgrade. Even if the number of MachineDeployments that are being upgraded is less
// than the number of allowed concurrent upgrades.
func computeMachineDeploymentVersion(s *scope.Scope, machineDeploymentTopology clusterv1.MachineDeploymentTopology, desiredControlPlaneState *scope.ControlPlaneState, currentMDState *scope.MachineDeploymentState) (string, error) {
func computeMachineDeploymentVersion(s *scope.Scope, desiredMDName string, machineDeploymentTopology clusterv1.MachineDeploymentTopology, desiredControlPlaneState *scope.ControlPlaneState, currentMDState *scope.MachineDeploymentState) (string, error) {
desiredVersion := s.Blueprint.Topology.Version
// If creating a new machine deployment, we can pick up the desired version
// Note: We are not blocking the creation of new machine deployments when
Expand All @@ -782,13 +783,13 @@ func computeMachineDeploymentVersion(s *scope.Scope, machineDeploymentTopology c

// Return early if the upgrade for the MachineDeployment is deferred.
if isMachineDeploymentDeferred(s.Blueprint.Topology, machineDeploymentTopology) {
s.UpgradeTracker.MachineDeployments.MarkDeferredUpgrade(currentMDState.Object.Name)
s.UpgradeTracker.MachineDeployments.MarkDeferredUpgrade(desiredMDName)
return currentVersion, nil
}

// Return early if we are not allowed to upgrade the machine deployment.
if !s.UpgradeTracker.MachineDeployments.AllowUpgrade() {
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(currentMDState.Object.Name)
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(desiredMDName)
return currentVersion, nil
}

Expand All @@ -798,7 +799,8 @@ func computeMachineDeploymentVersion(s *scope.Scope, machineDeploymentTopology c
// NOTE: this case should never happen (upgrading a MachineDeployment) before creating a CP,
// but we are implementing this check for extra safety.
if s.Current.ControlPlane == nil || s.Current.ControlPlane.Object == nil {
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(currentMDState.Object.Name)
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(desiredMDName)
// TODO(ykakarap): Hold out creating new MD.
return currentVersion, nil
}

Expand All @@ -810,7 +812,8 @@ func computeMachineDeploymentVersion(s *scope.Scope, machineDeploymentTopology c
return "", errors.Wrap(err, "failed to check if control plane is upgrading")
}
if cpUpgrading {
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(currentMDState.Object.Name)
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(desiredMDName)
// TODO(ykakarap): Hold out creating new MD.
return currentVersion, nil
}

Expand All @@ -824,7 +827,8 @@ func computeMachineDeploymentVersion(s *scope.Scope, machineDeploymentTopology c
return "", errors.Wrap(err, "failed to check if the control plane is scaling")
}
if cpScaling {
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(currentMDState.Object.Name)
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(desiredMDName)
// TODO(ykakarap): Hold out creating new MD.
return currentVersion, nil
}
}
Expand All @@ -843,19 +847,21 @@ func computeMachineDeploymentVersion(s *scope.Scope, machineDeploymentTopology c
if *currentCPVersion != *desiredCPVersion {
// The versions of the current and desired control planes do no match,
// implies we are about to upgrade the control plane.
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(currentMDState.Object.Name)
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(desiredMDName)
// TODO(ykakarap): Hold out creating new MD.
return currentVersion, nil
}

// If the ControlPlane is pending picking up an upgrade then do not pick up the new version yet.
if s.UpgradeTracker.ControlPlane.PendingUpgrade {
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(currentMDState.Object.Name)
s.UpgradeTracker.MachineDeployments.MarkPendingUpgrade(desiredMDName)
// TODO(ykakarap): Hold out creating new MD.
return currentVersion, nil
}

// Control plane and machine deployments are stable.
// Ready to pick up the topology version.
s.UpgradeTracker.MachineDeployments.MarkUpgradingAndRollingOut(currentMDState.Object.Name)
s.UpgradeTracker.MachineDeployments.MarkUpgradingAndRollingOut(desiredMDName)
return desiredVersion, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/topology/cluster/reconcile_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func (r *Reconciler) reconcileMachineDeployments(ctx context.Context, s *scope.S
// Create MachineDeployments.
for _, mdTopologyName := range diff.toCreate {
md := s.Desired.MachineDeployments[mdTopologyName]
if s.UpgradeTracker.ControlPlane.PendingUpgrade {
if s.UpgradeTracker.ControlPlane.PendingUpgrade || s.UpgradeTracker.ControlPlane.IsUpgrading {
// If the control plane is pending an upgrade then do not create a new MachineDeployment.
// We cannot create the new MD with the new Kubernetes version as the ControlPlane is still at the old version and
// creating a new MD would not be safe.
Expand Down

0 comments on commit e2d70bd

Please sign in to comment.