Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit b00dcc2

Browse files
committed
Have the pilotcontroller copy cluster type, name and noepool name from the controlling pod and add those generic labels to the pod template and pod pilot selectors
1 parent 27d821c commit b00dcc2

File tree

6 files changed

+31
-13
lines changed

6 files changed

+31
-13
lines changed

pkg/apis/navigator/v1alpha1/types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ const (
1515
ElasticsearchNodePoolVersionAnnotation = "navigator.jetstack.io/elasticsearch-version"
1616
ElasticsearchRoleLabelPrefix = "navigator.jetstack.io/elasticsearch-role-"
1717

18-
CassandraClusterNameLabel = "navigator.jetstack.io/cassandra-cluster-name"
19-
CassandraNodePoolNameLabel = "navigator.jetstack.io/cassandra-node-pool-name"
20-
PilotLabel = "navigator.jetstack.io/has-pilot"
18+
ClusterTypeLabel = "navigator.jetstack.io/cluster-type"
19+
ClusterNameLabel = "navigator.jetstack.io/cluster-name"
20+
NodePoolNameLabel = "navigator.jetstack.io/node-pool-name"
21+
PilotLabel = "navigator.jetstack.io/has-pilot"
2122
)
2223

2324
// +genclient

pkg/controllers/cassandra/nodepool/nodepool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (e *defaultCassandraClusterNodepoolControl) updateStatus(cluster *v1alpha1.
4545
}
4646
// Create a NodePoolStatus for each statefulset that is controlled by this cluster.
4747
for _, ss := range sets {
48-
npName := ss.Labels[v1alpha1.CassandraNodePoolNameLabel]
48+
npName := ss.Labels[v1alpha1.NodePoolNameLabel]
4949
nps := cluster.Status.NodePools[npName]
5050
nps.ReadyReplicas = ss.Status.ReadyReplicas
5151
cluster.Status.NodePools[npName] = nps

pkg/controllers/cassandra/pilot/pilot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (c *pilotControl) updateDiscoveredVersions(cluster *v1alpha1.CassandraClust
5656
glog.V(4).Infof("No pilots found matching selector: %s", selector)
5757
}
5858
for _, pilot := range pilots {
59-
nodePoolNameForPilot, nodePoolNameFound := pilot.Labels[v1alpha1.CassandraNodePoolNameLabel]
59+
nodePoolNameForPilot, nodePoolNameFound := pilot.Labels[v1alpha1.NodePoolNameLabel]
6060
if !nodePoolNameFound {
6161
glog.Warningf("Skipping pilot without NodePoolNameLabelKey: %s", pilot.Name)
6262
continue
@@ -129,7 +129,7 @@ func (pb *PilotBuilder) ForNodePool(np *v1alpha1.CassandraClusterNodePool) *Pilo
129129
UpdateLabels(
130130
pb.pilot,
131131
map[string]string{
132-
v1alpha1.CassandraNodePoolNameLabel: np.Name,
132+
v1alpha1.NodePoolNameLabel: np.Name,
133133
},
134134
)
135135
return pb

pkg/controllers/cassandra/util/util.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,37 @@ func PilotRBACRoleName(c *v1alpha1.CassandraCluster) string {
5050
func ClusterLabels(c metav1.Object) map[string]string {
5151
return map[string]string{
5252
"app": "cassandracluster",
53-
v1alpha1.CassandraClusterNameLabel: c.GetName(),
53+
v1alpha1.ClusterTypeLabel: kindName,
54+
v1alpha1.ClusterNameLabel: c.GetName(),
5455
}
5556
}
5657

5758
func SelectorForCluster(c *v1alpha1.CassandraCluster) (labels.Selector, error) {
59+
clusterTypeReq, err := labels.NewRequirement(
60+
v1alpha1.ClusterTypeLabel,
61+
selection.Equals,
62+
[]string{kindName},
63+
)
64+
if err != nil {
65+
return nil, err
66+
}
5867
clusterNameReq, err := labels.NewRequirement(
59-
v1alpha1.CassandraClusterNameLabel,
68+
v1alpha1.ClusterNameLabel,
6069
selection.Equals,
6170
[]string{c.Name},
6271
)
6372
if err != nil {
6473
return nil, err
6574
}
66-
return labels.NewSelector().Add(*clusterNameReq), nil
75+
return labels.NewSelector().Add(*clusterTypeReq, *clusterNameReq), nil
6776
}
6877

6978
func NodePoolLabels(
7079
c *v1alpha1.CassandraCluster,
7180
poolName string,
7281
) map[string]string {
7382
labels := ClusterLabels(c)
74-
labels[v1alpha1.CassandraNodePoolNameLabel] = poolName
83+
labels[v1alpha1.NodePoolNameLabel] = poolName
7584
return labels
7685
}
7786

pkg/controllers/pilotcontroller/pilot.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ func PilotForPod(pod *v1.Pod) *v1alpha1.Pilot {
230230
},
231231
),
232232
},
233+
Labels: map[string]string{
234+
v1alpha1.ClusterTypeLabel: pod.Labels[v1alpha1.ClusterTypeLabel],
235+
v1alpha1.ClusterNameLabel: pod.Labels[v1alpha1.ClusterNameLabel],
236+
v1alpha1.NodePoolNameLabel: pod.Labels[v1alpha1.NodePoolNameLabel],
237+
},
233238
},
234239
}
235240
}

pkg/controllers/pilotcontroller/pilot_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestPilotControllerIntegration(t *testing.T) {
130130
Kind: "StatefulSet",
131131
},
132132
ObjectMeta: metav1.ObjectMeta{
133-
Name: "ss1",
133+
Name: "np1",
134134
Namespace: "ns1",
135135
OwnerReferences: []metav1.OwnerReference{
136136
*metav1.NewControllerRef(cc1, cc1.GroupVersionKind()),
@@ -140,10 +140,13 @@ func TestPilotControllerIntegration(t *testing.T) {
140140

141141
pod1 := &v1.Pod{
142142
ObjectMeta: metav1.ObjectMeta{
143-
Name: "p1",
143+
Name: "np1-0",
144144
Namespace: "ns1",
145145
Labels: map[string]string{
146-
v1alpha1.PilotLabel: "",
146+
v1alpha1.ClusterTypeLabel: "CassandraCluster",
147+
v1alpha1.ClusterNameLabel: "cc1",
148+
v1alpha1.NodePoolNameLabel: "np1",
149+
v1alpha1.PilotLabel: "",
147150
},
148151
OwnerReferences: []metav1.OwnerReference{
149152
*metav1.NewControllerRef(ss1, ss1.GroupVersionKind()),

0 commit comments

Comments
 (0)