Skip to content

Commit 410691d

Browse files
authored
fix: fix missing update DynamoComponentReady condition (ai-dynamo#5051)
Signed-off-by: Xavier Chang <xuzhengc@nvidia.com>
1 parent d00f960 commit 410691d

2 files changed

Lines changed: 86 additions & 24 deletions

File tree

deploy/operator/internal/controller/dynamocomponentdeployment_controller.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,31 @@ func (r *DynamoComponentDeploymentReconciler) reconcileLeaderWorkerSetResources(
460460
}
461461

462462
func (r *DynamoComponentDeploymentReconciler) setStatusConditionAndServiceReplicaStatus(ctx context.Context, dynamoComponentDeployment *v1alpha1.DynamoComponentDeployment, componentReconcileResult ComponentReconcileResult) error {
463-
condition := metav1.Condition{
463+
availableCondition := metav1.Condition{
464464
Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
465465
Status: componentReconcileResult.status,
466466
Reason: componentReconcileResult.reason,
467467
Message: componentReconcileResult.message,
468468
}
469469

470-
meta.SetStatusCondition(&dynamoComponentDeployment.Status.Conditions, condition)
470+
var componentReadyReason, componentReadyMessage string
471+
if componentReconcileResult.status == metav1.ConditionTrue {
472+
componentReadyReason = "ComponentReady"
473+
componentReadyMessage = "DynamoComponent is ready"
474+
} else {
475+
componentReadyReason = "ComponentNotReady"
476+
componentReadyMessage = "DynamoComponent is not ready"
477+
}
478+
479+
componentReadyCondition := metav1.Condition{
480+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
481+
Status: componentReconcileResult.status,
482+
Reason: componentReadyReason,
483+
Message: componentReadyMessage,
484+
}
485+
486+
meta.SetStatusCondition(&dynamoComponentDeployment.Status.Conditions, availableCondition)
487+
meta.SetStatusCondition(&dynamoComponentDeployment.Status.Conditions, componentReadyCondition)
471488
dynamoComponentDeployment.Status.Service = componentReconcileResult.serviceReplicaStatus
472489
dynamoComponentDeployment.Status.ObservedGeneration = dynamoComponentDeployment.Generation
473490

deploy/operator/internal/controller/dynamocomponentdeployment_controller_test.go

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,9 +1876,7 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
18761876
tests := []struct {
18771877
name string
18781878
componentReconcileResult ComponentReconcileResult
1879-
wantConditionStatus metav1.ConditionStatus
1880-
wantConditionReason string
1881-
wantConditionMessage string
1879+
wantConditions []metav1.Condition
18821880
wantServiceReplicaStatus *v1alpha1.ServiceReplicaStatus
18831881
wantObservedGeneration int64
18841882
}{
@@ -1898,9 +1896,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
18981896
AvailableReplicas: ptr.To(int32(0)),
18991897
},
19001898
},
1901-
wantConditionStatus: metav1.ConditionFalse,
1902-
wantConditionReason: "DeploymentNotReady",
1903-
wantConditionMessage: "Deployment is not ready",
1899+
wantConditions: []metav1.Condition{
1900+
{
1901+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
1902+
Status: metav1.ConditionFalse,
1903+
Reason: "DeploymentNotReady",
1904+
Message: "Deployment is not ready",
1905+
},
1906+
{
1907+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
1908+
Status: metav1.ConditionFalse,
1909+
Reason: "ComponentNotReady",
1910+
Message: "DynamoComponent is not ready",
1911+
},
1912+
},
19041913
wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{
19051914
ComponentKind: v1alpha1.ComponentKindDeployment,
19061915
ComponentName: "test-component",
@@ -1926,9 +1935,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
19261935
AvailableReplicas: ptr.To(int32(2)),
19271936
},
19281937
},
1929-
wantConditionStatus: metav1.ConditionTrue,
1930-
wantConditionReason: "DeploymentReady",
1931-
wantConditionMessage: "Deployment is ready",
1938+
wantConditions: []metav1.Condition{
1939+
{
1940+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
1941+
Status: metav1.ConditionTrue,
1942+
Reason: "DeploymentReady",
1943+
Message: "Deployment is ready",
1944+
},
1945+
{
1946+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
1947+
Status: metav1.ConditionTrue,
1948+
Reason: "ComponentReady",
1949+
Message: "DynamoComponent is ready",
1950+
},
1951+
},
19321952
wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{
19331953
ComponentKind: v1alpha1.ComponentKindDeployment,
19341954
ComponentName: "test-component",
@@ -1953,9 +1973,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
19531973
ReadyReplicas: ptr.To(int32(2)),
19541974
},
19551975
},
1956-
wantConditionStatus: metav1.ConditionFalse,
1957-
wantConditionReason: "SomeLeaderWorkerSetsNotReady",
1958-
wantConditionMessage: "Some LeaderWorkerSets are not ready",
1976+
wantConditions: []metav1.Condition{
1977+
{
1978+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
1979+
Status: metav1.ConditionFalse,
1980+
Reason: "SomeLeaderWorkerSetsNotReady",
1981+
Message: "Some LeaderWorkerSets are not ready",
1982+
},
1983+
{
1984+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
1985+
Status: metav1.ConditionFalse,
1986+
Reason: "ComponentNotReady",
1987+
Message: "DynamoComponent is not ready",
1988+
},
1989+
},
19591990
wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{
19601991
ComponentKind: v1alpha1.ComponentKindLeaderWorkerSet,
19611992
ComponentName: "test-component-0",
@@ -1979,9 +2010,20 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
19792010
ReadyReplicas: ptr.To(int32(3)),
19802011
},
19812012
},
1982-
wantConditionStatus: metav1.ConditionTrue,
1983-
wantConditionReason: "AllLeaderWorkerSetsReady",
1984-
wantConditionMessage: "All LeaderWorkerSets are ready",
2013+
wantConditions: []metav1.Condition{
2014+
{
2015+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeAvailable,
2016+
Status: metav1.ConditionTrue,
2017+
Reason: "AllLeaderWorkerSetsReady",
2018+
Message: "All LeaderWorkerSets are ready",
2019+
},
2020+
{
2021+
Type: v1alpha1.DynamoGraphDeploymentConditionTypeDynamoComponentReady,
2022+
Status: metav1.ConditionTrue,
2023+
Reason: "ComponentReady",
2024+
Message: "DynamoComponent is ready",
2025+
},
2026+
},
19852027
wantServiceReplicaStatus: &v1alpha1.ServiceReplicaStatus{
19862028
ComponentKind: v1alpha1.ComponentKindLeaderWorkerSet,
19872029
ComponentName: "test-component-0",
@@ -2049,14 +2091,17 @@ func Test_setStatusConditionAndServiceReplicaStatus(t *testing.T) {
20492091
err = fakeKubeClient.Get(ctx, req.NamespacedName, updatedDCD)
20502092
g.Expect(err).NotTo(gomega.HaveOccurred())
20512093

2052-
// Assert the status condition
2053-
g.Expect(updatedDCD.Status.Conditions).To(gomega.HaveLen(1))
2054-
condition := updatedDCD.Status.Conditions[0]
2055-
g.Expect(condition.Type).To(gomega.Equal(v1alpha1.DynamoGraphDeploymentConditionTypeAvailable))
2056-
g.Expect(condition.Status).To(gomega.Equal(tt.wantConditionStatus))
2057-
g.Expect(condition.Reason).To(gomega.Equal(tt.wantConditionReason))
2058-
g.Expect(condition.Message).To(gomega.Equal(tt.wantConditionMessage))
2094+
// Assert the status conditions
2095+
g.Expect(updatedDCD.Status.Conditions).To(gomega.HaveLen(len(tt.wantConditions)))
2096+
2097+
// Clear LastTransitionTime from actual conditions for comparison
2098+
actualConditions := make([]metav1.Condition, len(updatedDCD.Status.Conditions))
2099+
for i, cond := range updatedDCD.Status.Conditions {
2100+
cond.LastTransitionTime = metav1.Time{}
2101+
actualConditions[i] = cond
2102+
}
20592103

2104+
g.Expect(actualConditions).To(gomega.ConsistOf(tt.wantConditions))
20602105
// Assert the service replica status
20612106
g.Expect(updatedDCD.Status.Service).To(gomega.Equal(tt.wantServiceReplicaStatus))
20622107

0 commit comments

Comments
 (0)