Unverified Commit 410691dc authored by Xavier Chang's avatar Xavier Chang Committed by GitHub
Browse files

fix: fix missing update DynamoComponentReady condition (#5051)


Signed-off-by: default avatarXavier Chang <xuzhengc@nvidia.com>
parent d00f9607
...@@ -460,14 +460,31 @@ func (r *DynamoComponentDeploymentReconciler) reconcileLeaderWorkerSetResources( ...@@ -460,14 +460,31 @@ func (r *DynamoComponentDeploymentReconciler) reconcileLeaderWorkerSetResources(
} }
func (r *DynamoComponentDeploymentReconciler) setStatusConditionAndServiceReplicaStatus(ctx context.Context, dynamoComponentDeployment *v1alpha1.DynamoComponentDeployment, componentReconcileResult ComponentReconcileResult) error { func (r *DynamoComponentDeploymentReconciler) setStatusConditionAndServiceReplicaStatus(ctx context.Context, dynamoComponentDeployment *v1alpha1.DynamoComponentDeployment, componentReconcileResult ComponentReconcileResult) error {
condition := metav1.Condition{ availableCondition := metav1.Condition{
Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable, Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
Status: componentReconcileResult.status, Status: componentReconcileResult.status,
Reason: componentReconcileResult.reason, Reason: componentReconcileResult.reason,
Message: componentReconcileResult.message, Message: componentReconcileResult.message,
} }
meta.SetStatusCondition(&dynamoComponentDeployment.Status.Conditions, condition) var componentReadyReason, componentReadyMessage string
if componentReconcileResult.status == metav1.ConditionTrue {
componentReadyReason = "ComponentReady"
componentReadyMessage = "DynamoComponent is ready"
} else {
componentReadyReason = "ComponentNotReady"
componentReadyMessage = "DynamoComponent is not ready"
}
componentReadyCondition := metav1.Condition{
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
Status: componentReconcileResult.status,
Reason: componentReadyReason,
Message: componentReadyMessage,
}
meta.SetStatusCondition(&dynamoComponentDeployment.Status.Conditions, availableCondition)
meta.SetStatusCondition(&dynamoComponentDeployment.Status.Conditions, componentReadyCondition)
dynamoComponentDeployment.Status.Service = componentReconcileResult.serviceReplicaStatus dynamoComponentDeployment.Status.Service = componentReconcileResult.serviceReplicaStatus
dynamoComponentDeployment.Status.ObservedGeneration = dynamoComponentDeployment.Generation dynamoComponentDeployment.Status.ObservedGeneration = dynamoComponentDeployment.Generation
......
...@@ -1876,9 +1876,7 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) { ...@@ -1876,9 +1876,7 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
componentReconcileResult ComponentReconcileResult componentReconcileResult ComponentReconcileResult
wantConditionStatus metav1.ConditionStatus wantConditions []metav1.Condition
wantConditionReason string
wantConditionMessage string
wantServiceReplicaStatus *v1alpha1.ServiceReplicaStatus wantServiceReplicaStatus *v1alpha1.ServiceReplicaStatus
wantObservedGeneration int64 wantObservedGeneration int64
}{ }{
...@@ -1898,9 +1896,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) { ...@@ -1898,9 +1896,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
AvailableReplicas: ptr.To(int32(0)), AvailableReplicas: ptr.To(int32(0)),
}, },
}, },
wantConditionStatus: metav1.ConditionFalse, wantConditions: []metav1.Condition{
wantConditionReason: "DeploymentNotReady", {
wantConditionMessage: "Deployment is not ready", Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
Status: metav1.ConditionFalse,
Reason: "DeploymentNotReady",
Message: "Deployment is not ready",
},
{
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
Status: metav1.ConditionFalse,
Reason: "ComponentNotReady",
Message: "DynamoComponent is not ready",
},
},
wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{ wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{
ComponentKind: v1alpha1.ComponentKindDeployment, ComponentKind: v1alpha1.ComponentKindDeployment,
ComponentName: "test-component", ComponentName: "test-component",
...@@ -1926,9 +1935,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) { ...@@ -1926,9 +1935,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
AvailableReplicas: ptr.To(int32(2)), AvailableReplicas: ptr.To(int32(2)),
}, },
}, },
wantConditionStatus: metav1.ConditionTrue, wantConditions: []metav1.Condition{
wantConditionReason: "DeploymentReady", {
wantConditionMessage: "Deployment is ready", Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
Status: metav1.ConditionTrue,
Reason: "DeploymentReady",
Message: "Deployment is ready",
},
{
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
Status: metav1.ConditionTrue,
Reason: "ComponentReady",
Message: "DynamoComponent is ready",
},
},
wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{ wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{
ComponentKind: v1alpha1.ComponentKindDeployment, ComponentKind: v1alpha1.ComponentKindDeployment,
ComponentName: "test-component", ComponentName: "test-component",
...@@ -1953,9 +1973,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) { ...@@ -1953,9 +1973,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
ReadyReplicas: ptr.To(int32(2)), ReadyReplicas: ptr.To(int32(2)),
}, },
}, },
wantConditionStatus: metav1.ConditionFalse, wantConditions: []metav1.Condition{
wantConditionReason: "SomeLeaderWorkerSetsNotReady", {
wantConditionMessage: "Some LeaderWorkerSets are not ready", Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
Status: metav1.ConditionFalse,
Reason: "SomeLeaderWorkerSetsNotReady",
Message: "Some LeaderWorkerSets are not ready",
},
{
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
Status: metav1.ConditionFalse,
Reason: "ComponentNotReady",
Message: "DynamoComponent is not ready",
},
},
wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{ wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{
ComponentKind: v1alpha1.ComponentKindLeaderWorkerSet, ComponentKind: v1alpha1.ComponentKindLeaderWorkerSet,
ComponentName: "test-component-0", ComponentName: "test-component-0",
...@@ -1979,9 +2010,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) { ...@@ -1979,9 +2010,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
ReadyReplicas: ptr.To(int32(3)), ReadyReplicas: ptr.To(int32(3)),
}, },
}, },
wantConditionStatus: metav1.ConditionTrue, wantConditions: []metav1.Condition{
wantConditionReason: "AllLeaderWorkerSetsReady", {
wantConditionMessage: "All LeaderWorkerSets are ready", Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
Status: metav1.ConditionTrue,
Reason: "AllLeaderWorkerSetsReady",
Message: "All LeaderWorkerSets are ready",
},
{
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
Status: metav1.ConditionTrue,
Reason: "ComponentReady",
Message: "DynamoComponent is ready",
},
},
wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{ wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{
ComponentKind: v1alpha1.ComponentKindLeaderWorkerSet, ComponentKind: v1alpha1.ComponentKindLeaderWorkerSet,
ComponentName: "test-component-0", ComponentName: "test-component-0",
...@@ -2049,14 +2091,17 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) { ...@@ -2049,14 +2091,17 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
err = fakeKubeClient.Get(ctx, req.NamespacedName, updatedDCD) err = fakeKubeClient.Get(ctx, req.NamespacedName, updatedDCD)
g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(err).NotTo(gomega.HaveOccurred())
// Assert the status condition // Assert the status conditions
g.Expect(updatedDCD.Status.Conditions).To(gomega.HaveLen(1)) g.Expect(updatedDCD.Status.Conditions).To(gomega.HaveLen(len(tt.wantConditions)))
condition := updatedDCD.Status.Conditions[0]
g.Expect(condition.Type).To(gomega.Equal(v1alpha1.DynamoGraphDeploymentConditionTypeAvailable)) // Clear LastTransitionTime from actual conditions for comparison
g.Expect(condition.Status).To(gomega.Equal(tt.wantConditionStatus)) actualConditions := make([]metav1.Condition, len(updatedDCD.Status.Conditions))
g.Expect(condition.Reason).To(gomega.Equal(tt.wantConditionReason)) for i, cond := range updatedDCD.Status.Conditions {
g.Expect(condition.Message).To(gomega.Equal(tt.wantConditionMessage)) cond.LastTransitionTime = metav1.Time{}
actualConditions[i] = cond
}
g.Expect(actualConditions).To(gomega.ConsistOf(tt.wantConditions))
// Assert the service replica status // Assert the service replica status
g.Expect(updatedDCD.Status.Service).To(gomega.Equal(tt.wantServiceReplicaStatus)) g.Expect(updatedDCD.Status.Service).To(gomega.Equal(tt.wantServiceReplicaStatus))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment