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

Commit

Permalink
Have the pilotcontroller copy cluster type, name and noepool name fro…
Browse files Browse the repository at this point in the history
…m the controlling pod and add those generic labels to the pod template and pod pilot selectors
  • Loading branch information
wallrj committed Jun 7, 2018
1 parent 27d821c commit b00dcc2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
7 changes: 4 additions & 3 deletions pkg/apis/navigator/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const (
ElasticsearchNodePoolVersionAnnotation = "navigator.jetstack.io/elasticsearch-version"
ElasticsearchRoleLabelPrefix = "navigator.jetstack.io/elasticsearch-role-"

CassandraClusterNameLabel = "navigator.jetstack.io/cassandra-cluster-name"
CassandraNodePoolNameLabel = "navigator.jetstack.io/cassandra-node-pool-name"
PilotLabel = "navigator.jetstack.io/has-pilot"
ClusterTypeLabel = "navigator.jetstack.io/cluster-type"
ClusterNameLabel = "navigator.jetstack.io/cluster-name"
NodePoolNameLabel = "navigator.jetstack.io/node-pool-name"
PilotLabel = "navigator.jetstack.io/has-pilot"
)

// +genclient
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/cassandra/nodepool/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (e *defaultCassandraClusterNodepoolControl) updateStatus(cluster *v1alpha1.
}
// Create a NodePoolStatus for each statefulset that is controlled by this cluster.
for _, ss := range sets {
npName := ss.Labels[v1alpha1.CassandraNodePoolNameLabel]
npName := ss.Labels[v1alpha1.NodePoolNameLabel]
nps := cluster.Status.NodePools[npName]
nps.ReadyReplicas = ss.Status.ReadyReplicas
cluster.Status.NodePools[npName] = nps
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/cassandra/pilot/pilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *pilotControl) updateDiscoveredVersions(cluster *v1alpha1.CassandraClust
glog.V(4).Infof("No pilots found matching selector: %s", selector)
}
for _, pilot := range pilots {
nodePoolNameForPilot, nodePoolNameFound := pilot.Labels[v1alpha1.CassandraNodePoolNameLabel]
nodePoolNameForPilot, nodePoolNameFound := pilot.Labels[v1alpha1.NodePoolNameLabel]
if !nodePoolNameFound {
glog.Warningf("Skipping pilot without NodePoolNameLabelKey: %s", pilot.Name)
continue
Expand Down Expand Up @@ -129,7 +129,7 @@ func (pb *PilotBuilder) ForNodePool(np *v1alpha1.CassandraClusterNodePool) *Pilo
UpdateLabels(
pb.pilot,
map[string]string{
v1alpha1.CassandraNodePoolNameLabel: np.Name,
v1alpha1.NodePoolNameLabel: np.Name,
},
)
return pb
Expand Down
17 changes: 13 additions & 4 deletions pkg/controllers/cassandra/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,37 @@ func PilotRBACRoleName(c *v1alpha1.CassandraCluster) string {
func ClusterLabels(c metav1.Object) map[string]string {
return map[string]string{
"app": "cassandracluster",
v1alpha1.CassandraClusterNameLabel: c.GetName(),
v1alpha1.ClusterTypeLabel: kindName,
v1alpha1.ClusterNameLabel: c.GetName(),
}
}

func SelectorForCluster(c *v1alpha1.CassandraCluster) (labels.Selector, error) {
clusterTypeReq, err := labels.NewRequirement(
v1alpha1.ClusterTypeLabel,
selection.Equals,
[]string{kindName},
)
if err != nil {
return nil, err
}
clusterNameReq, err := labels.NewRequirement(
v1alpha1.CassandraClusterNameLabel,
v1alpha1.ClusterNameLabel,
selection.Equals,
[]string{c.Name},
)
if err != nil {
return nil, err
}
return labels.NewSelector().Add(*clusterNameReq), nil
return labels.NewSelector().Add(*clusterTypeReq, *clusterNameReq), nil
}

func NodePoolLabels(
c *v1alpha1.CassandraCluster,
poolName string,
) map[string]string {
labels := ClusterLabels(c)
labels[v1alpha1.CassandraNodePoolNameLabel] = poolName
labels[v1alpha1.NodePoolNameLabel] = poolName
return labels
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/controllers/pilotcontroller/pilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ func PilotForPod(pod *v1.Pod) *v1alpha1.Pilot {
},
),
},
Labels: map[string]string{
v1alpha1.ClusterTypeLabel: pod.Labels[v1alpha1.ClusterTypeLabel],
v1alpha1.ClusterNameLabel: pod.Labels[v1alpha1.ClusterNameLabel],
v1alpha1.NodePoolNameLabel: pod.Labels[v1alpha1.NodePoolNameLabel],
},
},
}
}
9 changes: 6 additions & 3 deletions pkg/controllers/pilotcontroller/pilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestPilotControllerIntegration(t *testing.T) {
Kind: "StatefulSet",
},
ObjectMeta: metav1.ObjectMeta{
Name: "ss1",
Name: "np1",
Namespace: "ns1",
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(cc1, cc1.GroupVersionKind()),
Expand All @@ -140,10 +140,13 @@ func TestPilotControllerIntegration(t *testing.T) {

pod1 := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "p1",
Name: "np1-0",
Namespace: "ns1",
Labels: map[string]string{
v1alpha1.PilotLabel: "",
v1alpha1.ClusterTypeLabel: "CassandraCluster",
v1alpha1.ClusterNameLabel: "cc1",
v1alpha1.NodePoolNameLabel: "np1",
v1alpha1.PilotLabel: "",
},
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(ss1, ss1.GroupVersionKind()),
Expand Down

0 comments on commit b00dcc2

Please sign in to comment.