Skip to content

Commit

Permalink
Merge pull request #5222 from Patryk-Stefanski/OCPBUGS-45322
Browse files Browse the repository at this point in the history
 OCPBUGS-45322: consolidating upgradingConfig/Version nodepool status update from CAPI controller to Conditions controller
  • Loading branch information
openshift-merge-bot[bot] authored Dec 12, 2024
2 parents 2610e5c + be403e4 commit dc7bd65
Show file tree
Hide file tree
Showing 3 changed files with 482 additions and 65 deletions.
59 changes: 0 additions & 59 deletions hypershift-operator/controllers/nodepool/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,65 +1056,6 @@ func (c *CAPI) reconcileMachineSet(ctx context.Context,
}
}

// Bubble up upgrading NodePoolUpdatingVersionConditionType.
var status corev1.ConditionStatus
reason := ""
message := ""
status = "unknown"
removeStatusCondition(&nodePool.Status.Conditions, hyperv1.NodePoolUpdatingVersionConditionType)

if _, ok := machineSet.Annotations[nodePoolAnnotationUpgradeInProgressTrue]; ok {
status = corev1.ConditionTrue
reason = hyperv1.AsExpectedReason
}

if _, ok := machineSet.Annotations[nodePoolAnnotationUpgradeInProgressFalse]; ok {
status = corev1.ConditionFalse
reason = hyperv1.NodePoolInplaceUpgradeFailedReason
}

// Check if config needs to be updated.
isUpdatingConfig := isUpdatingConfig(nodePool, targetConfigHash)

// Check if version needs to be updated.
isUpdatingVersion := isUpdatingVersion(nodePool, targetVersion)

if isUpdatingVersion {
message = fmt.Sprintf("Updating Version, Target: %v", machineSet.Annotations[nodePoolAnnotationTargetConfigVersion])
SetStatusCondition(&nodePool.Status.Conditions, hyperv1.NodePoolCondition{
Type: hyperv1.NodePoolUpdatingVersionConditionType,
Status: status,
ObservedGeneration: nodePool.Generation,
Message: message,
Reason: reason,
})
} else {
SetStatusCondition(&nodePool.Status.Conditions, hyperv1.NodePoolCondition{
Type: hyperv1.NodePoolUpdatingVersionConditionType,
Status: corev1.ConditionFalse,
ObservedGeneration: nodePool.Generation,
Reason: hyperv1.AsExpectedReason,
})
}

if isUpdatingConfig {
message = fmt.Sprintf("Updating Config, Target: %v", machineSet.Annotations[nodePoolAnnotationTargetConfigVersion])
SetStatusCondition(&nodePool.Status.Conditions, hyperv1.NodePoolCondition{
Type: hyperv1.NodePoolUpdatingConfigConditionType,
Status: status,
ObservedGeneration: nodePool.Generation,
Message: message,
Reason: reason,
})
} else {
SetStatusCondition(&nodePool.Status.Conditions, hyperv1.NodePoolCondition{
Type: hyperv1.NodePoolUpdatingConfigConditionType,
Status: corev1.ConditionFalse,
ObservedGeneration: nodePool.Generation,
Reason: hyperv1.AsExpectedReason,
})
}

// Bubble up AvailableReplicas and Ready condition from MachineSet.
nodePool.Status.Replicas = machineSet.Status.AvailableReplicas
for _, c := range machineSet.Status.Conditions {
Expand Down
79 changes: 73 additions & 6 deletions hypershift-operator/controllers/nodepool/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,42 @@ func (r *NodePoolReconciler) updatingConfigCondition(ctx context.Context, nodePo
targetConfigHash := token.HashWithoutVersion()
isUpdatingConfig := isUpdatingConfig(nodePool, targetConfigHash)
if isUpdatingConfig {
reason := hyperv1.AsExpectedReason
message := fmt.Sprintf("Updating config in progress. Target config: %s", targetConfigHash)
status := corev1.ConditionTrue

if nodePool.Spec.Management.UpgradeType == hyperv1.UpgradeTypeInPlace {
capi, err := newCAPI(token, hcluster.Spec.InfraID)
if err != nil {
return &ctrl.Result{}, fmt.Errorf("error getting capi client: %w", err)
}

machineSet := capi.machineSet()
err = r.Get(ctx, client.ObjectKeyFromObject(machineSet), machineSet)
if err != nil {
if !apierrors.IsNotFound(err) {
return &ctrl.Result{}, fmt.Errorf("failed to get MachineSet: %w", err)
}
} else {
if _, ok := machineSet.Annotations[nodePoolAnnotationUpgradeInProgressTrue]; ok {
status = corev1.ConditionTrue
reason = hyperv1.AsExpectedReason
message = machineSet.Annotations[nodePoolAnnotationUpgradeInProgressTrue]
}

if _, ok := machineSet.Annotations[nodePoolAnnotationUpgradeInProgressFalse]; ok {
status = corev1.ConditionFalse
reason = hyperv1.NodePoolInplaceUpgradeFailedReason
message = machineSet.Annotations[nodePoolAnnotationUpgradeInProgressFalse]
}
}
}

SetStatusCondition(&nodePool.Status.Conditions, hyperv1.NodePoolCondition{
Type: hyperv1.NodePoolUpdatingConfigConditionType,
Status: corev1.ConditionTrue,
Reason: hyperv1.AsExpectedReason,
Message: fmt.Sprintf("Updating config in progress. Target config: %s", targetConfigHash),
Status: status,
Reason: reason,
Message: message,
ObservedGeneration: nodePool.Generation,
})
log.Info("NodePool config is updating",
Expand All @@ -378,11 +409,47 @@ func (r *NodePoolReconciler) updatingVersionCondition(ctx context.Context, nodeP
targetVersion := releaseImage.Version()
isUpdatingVersion := isUpdatingVersion(nodePool, targetVersion)
if isUpdatingVersion {
reason := hyperv1.AsExpectedReason
message := fmt.Sprintf("Updating version in progress. Target version: %s", targetVersion)
status := corev1.ConditionTrue

if nodePool.Spec.Management.UpgradeType == hyperv1.UpgradeTypeInPlace {
token, err := r.token(ctx, hcluster, nodePool)
if err != nil {
return &ctrl.Result{}, fmt.Errorf("error getting token: %w", err)
}

capi, err := newCAPI(token, hcluster.Spec.InfraID)
if err != nil {
return &ctrl.Result{}, fmt.Errorf("error getting capi client: %w", err)
}

machineSet := capi.machineSet()
err = r.Get(ctx, client.ObjectKeyFromObject(machineSet), machineSet)
if err != nil {
if !apierrors.IsNotFound(err) {
return &ctrl.Result{}, fmt.Errorf("failed to get MachineSet: %w", err)
}
} else {
if _, ok := machineSet.Annotations[nodePoolAnnotationUpgradeInProgressTrue]; ok {
status = corev1.ConditionTrue
reason = hyperv1.AsExpectedReason
message = machineSet.Annotations[nodePoolAnnotationUpgradeInProgressTrue]
}

if _, ok := machineSet.Annotations[nodePoolAnnotationUpgradeInProgressFalse]; ok {
status = corev1.ConditionFalse
reason = hyperv1.NodePoolInplaceUpgradeFailedReason
message = machineSet.Annotations[nodePoolAnnotationUpgradeInProgressFalse]
}
}
}

SetStatusCondition(&nodePool.Status.Conditions, hyperv1.NodePoolCondition{
Type: hyperv1.NodePoolUpdatingVersionConditionType,
Status: corev1.ConditionTrue,
Reason: hyperv1.AsExpectedReason,
Message: fmt.Sprintf("Updating version in progress. Target version: %s", targetVersion),
Status: status,
Reason: reason,
Message: message,
ObservedGeneration: nodePool.Generation,
})
log.Info("NodePool version is updating",
Expand Down
Loading

0 comments on commit dc7bd65

Please sign in to comment.