diff --git a/pkg/operator/bootstrapteardown/waitforceo.go b/pkg/operator/bootstrapteardown/waitforceo.go index f2c4a5f037..a39922dff5 100644 --- a/pkg/operator/bootstrapteardown/waitforceo.go +++ b/pkg/operator/bootstrapteardown/waitforceo.go @@ -62,10 +62,13 @@ func waitForEtcdBootstrap(ctx context.Context, operatorRestClient rest.Interface } func done(etcd *operatorv1.Etcd) (bool, error) { - if operatorv1helpers.IsOperatorConditionTrue(etcd.Status.Conditions, "EtcdRunningInCluster") { + etcdRunningInCluster := operatorv1helpers.IsOperatorConditionTrue(etcd.Status.Conditions, "EtcdRunningInCluster") + bootstrapMemberRemoved := operatorv1helpers.IsOperatorConditionTrue(etcd.Status.Conditions, "EtcdBootstrapMemberRemoved") + + if etcdRunningInCluster && bootstrapMemberRemoved { klog.Info("Cluster etcd operator bootstrapped successfully") return true, nil } - klog.Infof("waiting on condition %s in etcd CR %s/%s to be True.", "EtcdRunningInCluster", etcd.Namespace, etcd.Name) + klog.Infof("waiting for etcd bootstrap to complete: EtcdRunningInCluster=%v, EtcdBootstrapMemberRemoved=%v", etcdRunningInCluster, bootstrapMemberRemoved) return false, nil } diff --git a/pkg/operator/bootstrapteardown/waitforceo_test.go b/pkg/operator/bootstrapteardown/waitforceo_test.go new file mode 100644 index 0000000000..e593691541 --- /dev/null +++ b/pkg/operator/bootstrapteardown/waitforceo_test.go @@ -0,0 +1,83 @@ +package bootstrapteardown + +import ( + "testing" + + operatorv1 "github.com/openshift/api/operator/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestDone(t *testing.T) { + tests := map[string]struct { + conditions []operatorv1.OperatorCondition + expectDone bool + }{ + "both conditions true": { + conditions: []operatorv1.OperatorCondition{ + {Type: "EtcdRunningInCluster", Status: operatorv1.ConditionTrue}, + {Type: "EtcdBootstrapMemberRemoved", Status: operatorv1.ConditionTrue}, + }, + expectDone: true, + }, + "only EtcdRunningInCluster true": { + conditions: []operatorv1.OperatorCondition{ + {Type: "EtcdRunningInCluster", Status: operatorv1.ConditionTrue}, + }, + expectDone: false, + }, + "only EtcdBootstrapMemberRemoved true": { + conditions: []operatorv1.OperatorCondition{ + {Type: "EtcdBootstrapMemberRemoved", Status: operatorv1.ConditionTrue}, + }, + expectDone: false, + }, + "neither condition set": { + conditions: nil, + expectDone: false, + }, + "EtcdRunningInCluster true but EtcdBootstrapMemberRemoved false": { + conditions: []operatorv1.OperatorCondition{ + {Type: "EtcdRunningInCluster", Status: operatorv1.ConditionTrue}, + {Type: "EtcdBootstrapMemberRemoved", Status: operatorv1.ConditionFalse}, + }, + expectDone: false, + }, + "EtcdRunningInCluster false but EtcdBootstrapMemberRemoved true": { + conditions: []operatorv1.OperatorCondition{ + {Type: "EtcdRunningInCluster", Status: operatorv1.ConditionFalse}, + {Type: "EtcdBootstrapMemberRemoved", Status: operatorv1.ConditionTrue}, + }, + expectDone: false, + }, + "both conditions false": { + conditions: []operatorv1.OperatorCondition{ + {Type: "EtcdRunningInCluster", Status: operatorv1.ConditionFalse}, + {Type: "EtcdBootstrapMemberRemoved", Status: operatorv1.ConditionFalse}, + }, + expectDone: false, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + etcd := &operatorv1.Etcd{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, + Status: operatorv1.EtcdStatus{ + StaticPodOperatorStatus: operatorv1.StaticPodOperatorStatus{ + OperatorStatus: operatorv1.OperatorStatus{ + Conditions: test.conditions, + }, + }, + }, + } + + result, err := done(etcd) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if result != test.expectDone { + t.Errorf("expected done=%v, got %v", test.expectDone, result) + } + }) + } +}