mgr: addressing review comments
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
This commit is contained in:
3 files changed
+20
-23
No files matched your search
@@ -236,16 +236,18 @@ func (c *Cluster) reconcileServices() error {
|
||||
}
|
||||
}
|
||||
|
||||
return c.updateServiceSelectors()
|
||||
c.updateServiceSelectors()
|
||||
return nil
|
||||
}
|
||||
|
||||
// For the upgrade scenario: remove any selector DaemonIDLabel from the all
|
||||
// the services since new mgr HA doesn't rely on this label anymore.
|
||||
func (c *Cluster) updateServiceSelectors() error {
|
||||
func (c *Cluster) updateServiceSelectors() {
|
||||
selector := metav1.ListOptions{LabelSelector: "app=rook-ceph-mgr"}
|
||||
services, err := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).List(c.clusterInfo.Context, selector)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to query mgr services to update")
|
||||
logger.Errorf("failed to query mgr services to update: %v", err)
|
||||
return
|
||||
}
|
||||
for i, service := range services.Items {
|
||||
if service.Spec.Selector == nil {
|
||||
@@ -264,7 +266,6 @@ func (c *Cluster) updateServiceSelectors() error {
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) configureModules(daemonIDs []string) {
|
||||
|
||||
@@ -131,9 +131,7 @@ func validateStart(t *testing.T, c *Cluster) {
|
||||
assert.Equal(t, map[string]string{"my": "annotation"}, d.Spec.Template.Annotations)
|
||||
assert.Contains(t, d.Spec.Template.Labels, "my-label-key")
|
||||
assert.Equal(t, "my-priority-class", d.Spec.Template.Spec.PriorityClassName)
|
||||
if c.spec.Mgr.Count == 1 {
|
||||
assert.Equal(t, 1, len(d.Spec.Template.Spec.Containers))
|
||||
}
|
||||
assert.Equal(t, 1, len(d.Spec.Template.Spec.Containers))
|
||||
}
|
||||
|
||||
// verify we have exactly the expected number of deployments and not extra
|
||||
@@ -180,9 +178,9 @@ func TestUpdateServiceSelectors(t *testing.T) {
|
||||
// Make sure we remove the daemon_id label from the selector
|
||||
// of all services with a label "app=rook-ceph-mgr"
|
||||
t.Run("remove daemon_id from mgr services", func(t *testing.T) {
|
||||
svc_1 := corev1.Service{
|
||||
svc1 := corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "svc_1",
|
||||
Name: "svc1",
|
||||
Labels: map[string]string{
|
||||
"app": "rook-ceph-mgr",
|
||||
"svc": "rook-ceph-mgr",
|
||||
@@ -195,31 +193,30 @@ func TestUpdateServiceSelectors(t *testing.T) {
|
||||
controller.DaemonIDLabel: "a",
|
||||
}},
|
||||
}
|
||||
svc_2 := corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "svc_2"},
|
||||
svc2 := corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "svc2"},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Selector: map[string]string{
|
||||
"app": "rook-ceph-mgr",
|
||||
controller.DaemonIDLabel: "a",
|
||||
}},
|
||||
}
|
||||
_, err := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Create(clusterInfo.Context, &svc_1, metav1.CreateOptions{})
|
||||
_, err := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Create(clusterInfo.Context, &svc1, metav1.CreateOptions{})
|
||||
assert.NoError(t, err)
|
||||
_, err_2 := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Create(clusterInfo.Context, &svc_2, metav1.CreateOptions{})
|
||||
assert.NoError(t, err_2)
|
||||
_, err2 := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Create(clusterInfo.Context, &svc2, metav1.CreateOptions{})
|
||||
assert.NoError(t, err2)
|
||||
|
||||
// Check the the label has been only removed from svc_1
|
||||
err = c.updateServiceSelectors()
|
||||
assert.NoError(t, err)
|
||||
// Check the the label has been only removed from svc1
|
||||
c.updateServiceSelectors()
|
||||
|
||||
updated_svc_1, err := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Get(clusterInfo.Context, "svc_1", metav1.GetOptions{})
|
||||
updatedService1, err := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Get(clusterInfo.Context, "svc1", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
_, hasDaemonLabel := updated_svc_1.Spec.Selector[controller.DaemonIDLabel]
|
||||
_, hasDaemonLabel := updatedService1.Spec.Selector[controller.DaemonIDLabel]
|
||||
assert.Equal(t, hasDaemonLabel, false)
|
||||
|
||||
updated_svc_2, err := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Get(clusterInfo.Context, "svc_2", metav1.GetOptions{})
|
||||
updatedService2, err := c.context.Clientset.CoreV1().Services(c.clusterInfo.Namespace).Get(clusterInfo.Context, "svc2", metav1.GetOptions{})
|
||||
assert.NoError(t, err)
|
||||
_, hasDaemonLabel = updated_svc_2.Spec.Selector[controller.DaemonIDLabel]
|
||||
_, hasDaemonLabel = updatedService2.Spec.Selector[controller.DaemonIDLabel]
|
||||
assert.Equal(t, hasDaemonLabel, true)
|
||||
|
||||
})
|
||||
|
||||
@@ -324,6 +324,5 @@ func (c *Cluster) cephMgrOrchestratorModuleEnvs() []v1.EnvVar {
|
||||
}
|
||||
|
||||
func (c *Cluster) selectorLabels() map[string]string {
|
||||
labels := controller.AppLabels(AppName, c.clusterInfo.Namespace)
|
||||
return labels
|
||||
return controller.AppLabels(AppName, c.clusterInfo.Namespace)
|
||||
}
|
||||
Reference in new issue
Block a user