Skip to content
Open
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
13 changes: 13 additions & 0 deletions api/orchestration/v1alpha1/roleset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ const (
RoleSetProgressing ConditionType = "Progressing"
)

const (
// Ready
RoleSetReasonRolesReady = "RolesReady"
RoleSetReasonRolesNotReady = "RolesNotReady"

// Progressing
RoleSetReasonRolesProgressing = "RolesProgressing"
RoleSetReasonProgressingComplete = "ProgressingCompleted"

// ReplicaFailure
RoleSetReasonReconcileError = "ReconcileError"
)

type RoleStatus struct {
Name string `json:"name,omitempty"`

Expand Down
51 changes: 48 additions & 3 deletions pkg/controller/roleset/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func (r *RoleSetReconciler) calculateStatus(ctx context.Context, rs *orchestrati
newStatus := rs.Status.DeepCopy()
newStatus.Roles = nil
var notReadyRoles []string
var progressingRoles []string
isProgressing := false
for _, role := range rs.Spec.Roles {
if roleStatus, err := r.calculateStatusForRole(ctx, rs, &role); err != nil {
// TODO: add into condition
Expand All @@ -105,20 +107,63 @@ func (r *RoleSetReconciler) calculateStatus(ctx context.Context, rs *orchestrati
if roleStatus.ReadyReplicas < *role.Replicas {
notReadyRoles = append(notReadyRoles, role.Name)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current Progressing logic is as here 🤔

if roleStatus.ReadyReplicas < *role.Replicas ||
roleStatus.UpdatedReadyReplicas < roleStatus.UpdatedReplicas ||
(roleStatus.UpdatedReplicas > 0 && roleStatus.UpdatedReadyReplicas < roleStatus.UpdatedReplicas) {
progressingRoles = append(progressingRoles, role.Name)
isProgressing = true
}
Comment on lines +110 to +115
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition to check if a role is progressing is partially redundant. The third part of the || condition, (roleStatus.UpdatedReplicas > 0 && roleStatus.UpdatedReadyReplicas < roleStatus.UpdatedReplicas), is already covered by the second part, roleStatus.UpdatedReadyReplicas < roleStatus.UpdatedReplicas.

If UpdatedReadyReplicas is less than UpdatedReplicas, it implies UpdatedReplicas must be greater than 0 (since replica counts are non-negative). This redundancy can be removed to simplify the code and improve clarity.

            if roleStatus.ReadyReplicas < *role.Replicas ||
					roleStatus.UpdatedReadyReplicas < roleStatus.UpdatedReplicas {
				progressingRoles = append(progressingRoles, role.Name)
				isProgressing = true
			}

}
}

if len(notReadyRoles) > 0 {
notReadyCondition := utils.NewCondition(orchestrationv1alpha1.RoleSetReady, v1.ConditionFalse, "roleset is not ready", fmt.Sprintf("role %s is not ready", strings.Join(notReadyRoles, ",")))
notReadyCondition := utils.NewCondition(
orchestrationv1alpha1.RoleSetReady,
v1.ConditionFalse,
orchestrationv1alpha1.RoleSetReasonRolesNotReady,
fmt.Sprintf("Roles %s are not ready", strings.Join(notReadyRoles, ",")),
)
SetRoleSetCondition(newStatus, *notReadyCondition)
} else {
readyCondition := utils.NewCondition(orchestrationv1alpha1.RoleSetReady, v1.ConditionTrue, "roleset is ready", "")
readyCondition := utils.NewCondition(
orchestrationv1alpha1.RoleSetReady,
v1.ConditionTrue,
orchestrationv1alpha1.RoleSetReasonRolesReady,
"All roles are ready",
)
SetRoleSetCondition(newStatus, *readyCondition)
}

if isProgressing {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is Progressing, add condition.
If it is not Progressing, then if the Progressing condition exists, it means it has been completed. If not, it means it is not Progressing.

cond := utils.NewCondition(
orchestrationv1alpha1.RoleSetProgressing,
v1.ConditionTrue,
orchestrationv1alpha1.RoleSetReasonRolesProgressing,
fmt.Sprintf("Roles %s are progressing", strings.Join(progressingRoles, ", ")),
)
SetRoleSetCondition(newStatus, *cond)
} else {
// If all roles are ready, set the Progressing condition to complete.
currentProgressingCond := utils.GetCondition(rs.Status.Conditions, orchestrationv1alpha1.RoleSetProgressing)
if currentProgressingCond != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic sets the Progressing condition to False if it existed in the previous status, regardless of its previous state (True or False). To be more precise and avoid unnecessary status updates, it's better to only set the condition to False if it was previously True. This more clearly indicates a completed transition from a progressing state.

		if currentProgressingCond != nil && currentProgressingCond.Status == v1.ConditionTrue {

cond := utils.NewCondition(
orchestrationv1alpha1.RoleSetProgressing,
v1.ConditionFalse,
orchestrationv1alpha1.RoleSetReasonProgressingComplete,
"All roles have completed progressing",
)
SetRoleSetCondition(newStatus, *cond)
}
}

failureCond := utils.GetCondition(rs.Status.Conditions, orchestrationv1alpha1.RoleSetReplicaFailure)
if len(managedErrors) != 0 && failureCond == nil {
cond := utils.NewCondition(orchestrationv1alpha1.RoleSetReplicaFailure, v1.ConditionTrue, "reconcile roleset error", fmt.Sprintf("%+v", managedErrors))
cond := utils.NewCondition(
orchestrationv1alpha1.RoleSetReplicaFailure,
v1.ConditionTrue,
orchestrationv1alpha1.RoleSetReasonReconcileError,
fmt.Sprintf("%+v", managedErrors),
)
SetRoleSetCondition(newStatus, *cond)
} else if len(managedErrors) == 0 && failureCond != nil {
RemoveRoleSetCondition(newStatus, orchestrationv1alpha1.RoleSetReplicaFailure)
Expand Down