Skip to content

Commit

Permalink
[ACM-8576] Updated MCE status response for resource applying (#585)
Browse files Browse the repository at this point in the history
* updated MCE status response for resource applying

Signed-off-by: Disaiah Bennett <[email protected]>

* fixed conditional statement

Signed-off-by: Disaiah Bennett <[email protected]>

* removed additional invalid status

Signed-off-by: Disaiah Bennett <[email protected]>

* updated MCE status condition

Signed-off-by: Disaiah Bennett <[email protected]>

* updated controller

Signed-off-by: Disaiah Bennett <[email protected]>

* added test cases for condition status

Signed-off-by: Disaiah Bennett <[email protected]>

---------

Signed-off-by: Disaiah Bennett <[email protected]>
  • Loading branch information
dislbenn authored Feb 6, 2024
1 parent b4fc526 commit 7f155b4
Show file tree
Hide file tree
Showing 5 changed files with 405 additions and 10 deletions.
30 changes: 21 additions & 9 deletions api/v1/multiclusterengine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,35 @@ const (
MultiClusterEnginePhaseUninstalling PhaseType = "Uninstalling"
MultiClusterEnginePhaseError PhaseType = "Error"
MultiClusterEnginePhaseUnimplemented PhaseType = "Unimplemented"
MultiClusterEnginePhaseUpdating PhaseType = "Updating"
)

type MultiClusterEngineConditionType string

// These are valid conditions of the multiclusterengine.
const (
// Available means the deployment is available, ie. at least the minimum available
// replicas required are up and running for at least minReadySeconds.
/*
Available means the deployment is available, ie. at least the minimum available
replicas required are up and running for at least minReadySeconds.
*/
MultiClusterEngineAvailable MultiClusterEngineConditionType = "Available"
// Progressing means the deployment is progressing. Progress for a deployment is
// considered when a new replica set is created or adopted, and when new pods scale
// up or old pods scale down. Progress is not estimated for paused deployments or
// when progressDeadlineSeconds is not specified.
/*
Progressing means the deployment is progressing. Progress for a deployment is
considered when a new replica set is created or adopted, and when new pods scale
up or old pods scale down. Progress is not estimated for paused deployments or
when progressDeadlineSeconds is not specified.
*/
MultiClusterEngineProgressing MultiClusterEngineConditionType = "Progressing"
// Failure is added in a deployment when one of its pods fails to be created
// or deleted.
MultiClusterEngineFailure MultiClusterEngineConditionType = "MultiClusterEngineFailure"
/*
ComponentFailure is added in a deployment when one of its pods fails to be created
or deleted.
*/
MultiClusterEngineComponentFailure MultiClusterEngineConditionType = "ComponentFailure"
/*
Failure is added in a deployment when one of its pods fails to be created
or deleted.
*/
MultiClusterEngineFailure MultiClusterEngineConditionType = "Failure"
)

type MultiClusterEngineCondition struct {
Expand Down
18 changes: 17 additions & 1 deletion controllers/backplaneconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ func (r *MultiClusterEngineReconciler) Reconcile(ctx context.Context, req ctrl.R
return ctrl.Result{}, nil
}

// reset the status conditions for failures that has occurred in previous iterations.
backplaneConfig.Status.Conditions = status.FilterOutConditionWithSubString(backplaneConfig.Status.Conditions,
backplanev1.MultiClusterEngineComponentFailure)

// reset status manager
r.StatusManager.Reset("")
for _, c := range backplaneConfig.Status.Conditions {
Expand Down Expand Up @@ -982,7 +986,19 @@ func (r *MultiClusterEngineReconciler) applyTemplate(ctx context.Context, backpl
force := true
err := r.Client.Patch(ctx, template, client.Apply, &client.PatchOptions{Force: &force, FieldManager: "backplane-operator"})
if err != nil {
return ctrl.Result{}, fmt.Errorf("error applying object Name: %s Kind: %s Error: %w", template.GetName(), template.GetKind(), err)
errMessage := fmt.Errorf(
"error applying object Name: %s Kind: %s Error: %w", template.GetName(), template.GetKind(), err)

condType := fmt.Sprintf("%v: %v (Kind:%v)", backplanev1.MultiClusterEngineComponentFailure,
template.GetName(), template.GetKind())

r.StatusManager.AddCondition(
status.NewCondition(
backplanev1.MultiClusterEngineConditionType(condType), metav1.ConditionTrue,
status.ApplyFailedReason, errMessage.Error()),
)

return ctrl.Result{}, errMessage
}
}
return ctrl.Result{}, nil
Expand Down
29 changes: 29 additions & 0 deletions pkg/status/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
package status

import (
"strings"

v1 "github.com/stolostron/backplane-operator/api/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// ApplyFailedReason is added when the hub fails to apply a resource
ApplyFailedReason = "FailedApplyingComponent"
// ComponentsAvailableReason is when all desired components are running successfully
ComponentsAvailableReason = "ComponentsAvailable"
// ComponentsUnavailableReason is when one or more components are in an unready state
Expand Down Expand Up @@ -88,3 +92,28 @@ func filterOutCondition(conditions []v1.MultiClusterEngineCondition, condType v1
}
return newConditions
}

// FilterOutConditionWithSubString returns a new slice of hub conditions without conditions with the provided type.
func FilterOutConditionWithSubString(conditions []v1.MultiClusterEngineCondition, condType v1.MultiClusterEngineConditionType) []v1.MultiClusterEngineCondition {
var newConditions []v1.MultiClusterEngineCondition
for _, c := range conditions {
if strings.Contains(string(c.Type), string(condType)) {
continue
}
newConditions = append(newConditions, c)
}
return newConditions
}

/*
ConditionPresentWithSubstring returns true or false if a MultiClusterEngineCondition is
present with a target substring.
*/
func ConditionPresentWithSubstring(conditions []v1.MultiClusterEngineCondition, substring string) bool {
for _, c := range conditions {
if strings.Contains(string(c.Type), substring) {
return true
}
}
return false
}
Loading

0 comments on commit 7f155b4

Please sign in to comment.