Skip to content

Commit

Permalink
Merge pull request #335 from fmount/obs_gen
Browse files Browse the repository at this point in the history
Check Deployment ObservedGeneration to set ReadyCondition
  • Loading branch information
openshift-merge-bot[bot] authored Apr 16, 2024
2 parents 1bc90c7 + b7d6102 commit 051151b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
48 changes: 26 additions & 22 deletions controllers/neutronapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,34 +1009,38 @@ func (r *NeutronAPIReconciler) reconcileNormal(ctx context.Context, instance *ne
return ctrlResult, nil
}

instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
if depl.GetDeployment().Generation <= depl.GetDeployment().Status.ObservedGeneration {
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas

// verify if network attachment matches expectations
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
if err != nil {
return ctrl.Result{}, err
}
// verify if network attachment matches expectations
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
if err != nil {
return ctrl.Result{}, err
}

instance.Status.NetworkAttachments = networkAttachmentStatus
if networkReady {
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
} else {
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.NetworkAttachmentsReadyErrorMessage,
err.Error()))
instance.Status.NetworkAttachments = networkAttachmentStatus
if networkReady {
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
} else {
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.NetworkAttachmentsReadyErrorMessage,
err.Error()))

return ctrl.Result{}, err
}
return ctrl.Result{}, err
}

if instance.Status.ReadyCount > 0 {
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
if instance.Status.ReadyCount == *instance.Spec.Replicas {
instance.Status.Conditions.MarkTrue(
condition.DeploymentReadyCondition,
condition.DeploymentReadyMessage,
)
}
}
// create Deployment - end

if instance.Status.ReadyCount > 0 {
// remove finalizers from unused MariaDBAccount records
err = mariadbv1.DeleteUnusedMariaDBAccountFinalizers(
Expand Down
1 change: 1 addition & 0 deletions test/functional/neutronapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ var _ = Describe("NeutronAPI controller", func() {
Name: "neutron",
}
depl := th.GetDeployment(deplName)
th.SimulateDeploymentReadyWithPods(deplName, map[string][]string{})

expectedAnnotation, err := json.Marshal(
[]networkv1.NetworkSelectionElement{
Expand Down

0 comments on commit 051151b

Please sign in to comment.