Repository: scylladb/scylla-operator
Pull request #464 (2021-03-04 18:09:58)

Revert "cluster: fix source of rack version and members in cluster status"
Reverts scylladb/scylla-operator#462


Patch:
diff --git a/pkg/controllers/cluster/status.go b/pkg/controllers/cluster/status.go
index 9c24c9471..f44477c0c 100644
--- a/pkg/controllers/cluster/status.go
+++ b/pkg/controllers/cluster/status.go
@@ -68,7 +68,7 @@ func (cc *ClusterReconciler) updateStatus(ctx context.Context, cluster *scyllav1
 		}
 
 		// Update Members
-		rackStatus.Members = sts.Status.Replicas
+		rackStatus.Members = *sts.Spec.Replicas
 		// Update ReadyMembers
 		rackStatus.ReadyMembers = sts.Status.ReadyReplicas
 
@@ -82,7 +82,7 @@ func (cc *ClusterReconciler) updateStatus(ctx context.Context, cluster *scyllav1
 			if err != nil {
 				return errors.WithStack(err)
 			}
-			rackStatus.Version, err = naming.ScyllaVersion(firstRackMember.Spec.Containers)
+			rackStatus.Version, err = naming.ScyllaVersion(sts.Spec.Template.Spec.Containers)
 			if err != nil {
 				return errors.WithStack(err)
 			}


Test patch:
diff --git a/pkg/controllers/cluster/status_test.go b/pkg/controllers/cluster/status_test.go
index b9183f774..713ed17b7 100644
--- a/pkg/controllers/cluster/status_test.go
+++ b/pkg/controllers/cluster/status_test.go
@@ -4,15 +4,9 @@ package cluster
 
 import (
 	"context"
-	"fmt"
 	"testing"
 
-	"github.com/scylladb/scylla-operator/pkg/controllers/cluster/resource"
-	"github.com/scylladb/scylla-operator/pkg/naming"
 	"github.com/scylladb/scylla-operator/pkg/test/unit"
-	appsv1 "k8s.io/api/apps/v1"
-	corev1 "k8s.io/api/core/v1"
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime"
 	clientgoscheme "k8s.io/client-go/kubernetes/scheme"
 	"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -38,56 +32,3 @@ func TestClusterStatus_RackStatusIsRemovedWhenStatefulSetNoLongerExists(t *testi
 		t.Errorf("expected rack status to be cleared, got %v", v)
 	}
 }
-
-func TestClusterStatus_SourceOfRackStatus(t *testing.T) {
-	const (
-		scyllaVersion = "1.2.3"
-	)
-	cluster := unit.NewSingleRackCluster(1)
-	rack := cluster.Spec.Datacenter.Racks[0]
-
-	scheme := runtime.NewScheme()
-	if err := clientgoscheme.AddToScheme(scheme); err != nil {
-		t.Fatal(err)
-	}
-
-	rackFirstPodName := fmt.Sprintf("%s-0", naming.StatefulSetNameForRack(rack, cluster))
-	rackFirstPod := &corev1.Pod{
-		ObjectMeta: metav1.ObjectMeta{
-			Name:      rackFirstPodName,
-			Namespace: cluster.Namespace,
-		},
-		Spec: corev1.PodSpec{
-			Containers: []corev1.Container{
-				{
-					Name:  naming.ScyllaContainerName,
-					Image: fmt.Sprintf("scylladb/scylla:%s", scyllaVersion),
-				},
-			},
-		},
-	}
-
-	rackSts := resource.StatefulSetForRack(rack, cluster, "image")
-	rackSts.Status = appsv1.StatefulSetStatus{
-		Replicas:      2,
-		ReadyReplicas: 1,
-	}
-	cc := &ClusterReconciler{
-		Client: fake.NewFakeClientWithScheme(scheme, []runtime.Object{rackSts, rackFirstPod}...),
-	}
-
-	if err := cc.updateStatus(context.Background(), cluster); err != nil {
-		t.Errorf("expected nil, got %s", err)
-	}
-
-	rackStatus := cluster.Status.Racks[rack.Name]
-	if rackStatus.Version != scyllaVersion {
-		t.Errorf("expected rack version to be taken from container spec from first pod, got %s", rackStatus.Version)
-	}
-	if rackStatus.ReadyMembers != rackSts.Status.ReadyReplicas {
-		t.Errorf("expected ready replicas to be taken from rack stateful status, got %d", rackStatus.ReadyMembers)
-	}
-	if rackStatus.Members != rackSts.Status.Replicas {
-		t.Errorf("expected replicas to be taken from rack stateful status, got %d", rackStatus.Members)
-	}
-}