Skip to content

Commit

Permalink
Add CSMNamespaceLabel 2 deployment and daemonset (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajendraindukuri authored Jan 10, 2025
1 parent 90e72d6 commit 4f2abf7
Show file tree
Hide file tree
Showing 89 changed files with 254 additions and 79 deletions.
145 changes: 72 additions & 73 deletions controllers/csm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,34 +416,34 @@ func (r *ContainerStorageModuleReconciler) handleDeploymentUpdate(oldObj interfa
log.Infow("deployment", "deployment name", d.Name, "numberUnavailable", numberUnavailable)

ns := d.Spec.Template.Labels[constants.CsmNamespaceLabel]
if ns == "" {
ns = d.Namespace
}
log.Debugw("csm being modified in handledeployment", "namespace", ns, "name", name)
namespacedName := t1.NamespacedName{
Name: name,
Namespace: ns,
}

csm := new(csmv1.ContainerStorageModule)
err := r.Client.Get(ctx, namespacedName, csm)
if err != nil {
log.Error("deployment get csm", "error", err.Error())
}
if ns != "" {
log.Debugw("csm being modified in handledeployment", "namespace", ns, "name", name)
namespacedName := t1.NamespacedName{
Name: name,
Namespace: ns,
}

newStatus := csm.GetCSMStatus()
csm := new(csmv1.ContainerStorageModule)
err := r.Client.Get(ctx, namespacedName, csm)
if err != nil {
log.Error("deployment get csm", "error", err.Error())
}

// Updating controller status manually as controller runtime API is not updating csm object with latest data
// TODO: Can remove this once the controller runtime repo has a fix for updating the object passed
newStatus.ControllerStatus.Available = strconv.Itoa(int(available))
newStatus.ControllerStatus.Desired = strconv.Itoa(int(desired))
newStatus.ControllerStatus.Failed = strconv.Itoa(int(numberUnavailable))
newStatus := csm.GetCSMStatus()

err = utils.UpdateStatus(ctx, csm, r, newStatus)
if err != nil {
log.Debugw("deployment status ", "pods", err.Error())
} else {
r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "Driver deployment running OK")
// Updating controller status manually as controller runtime API is not updating csm object with latest data
// TODO: Can remove this once the controller runtime repo has a fix for updating the object passed
newStatus.ControllerStatus.Available = strconv.Itoa(int(available))
newStatus.ControllerStatus.Desired = strconv.Itoa(int(desired))
newStatus.ControllerStatus.Failed = strconv.Itoa(int(numberUnavailable))

err = utils.UpdateStatus(ctx, csm, r, newStatus)
if err != nil {
log.Debugw("deployment status ", "pods", err.Error())
} else {
r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "Driver deployment running OK")
}
}
}

Expand All @@ -455,39 +455,38 @@ func (r *ContainerStorageModuleReconciler) handlePodsUpdate(_ interface{}, obj i
name := p.GetLabels()[constants.CsmLabel]
// if this pod is an obs. pod, namespace might not match csm namespace
ns := p.GetLabels()[constants.CsmNamespaceLabel]
if ns == "" {
ns = p.Namespace
}

key := name + "-" + fmt.Sprintf("%d", r.GetUpdateCount())
ctx, log := logger.GetNewContextWithLogger(key)
if ns != "" {
key := name + "-" + fmt.Sprintf("%d", r.GetUpdateCount())
ctx, log := logger.GetNewContextWithLogger(key)

if !p.ObjectMeta.DeletionTimestamp.IsZero() {
log.Debugw("driver delete invoked", "stopping pod with name", p.Name)
return
}
log.Infow("pod modified for driver", "name", p.Name)
if !p.ObjectMeta.DeletionTimestamp.IsZero() {
log.Debugw("driver delete invoked", "stopping pod with name", p.Name)
return
}
log.Infow("pod modified for driver", "name", p.Name)

namespacedName := t1.NamespacedName{
Name: name,
Namespace: ns,
}
csm := new(csmv1.ContainerStorageModule)
err := r.Client.Get(ctx, namespacedName, csm)
if err != nil {
r.Log.Errorw("daemonset get csm", "error", err.Error())
}
log.Infow("csm prev status ", "state", csm.Status)
newStatus := csm.GetCSMStatus()
namespacedName := t1.NamespacedName{
Name: name,
Namespace: ns,
}
csm := new(csmv1.ContainerStorageModule)
err := r.Client.Get(ctx, namespacedName, csm)
if err != nil {
r.Log.Errorw("daemonset get csm", "error", err.Error())
}
log.Infow("csm prev status ", "state", csm.Status)
newStatus := csm.GetCSMStatus()

err = utils.UpdateStatus(ctx, csm, r, newStatus)
state := csm.GetCSMStatus().State
stamp := fmt.Sprintf("at %d", time.Now().UnixNano())
if state != "0" && err != nil {
log.Infow("pod status ", "state", err.Error())
r.EventRecorder.Eventf(csm, corev1.EventTypeWarning, csmv1.EventUpdated, "%s Pod error details %s", stamp, err.Error())
} else {
r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "%s Driver pods running OK", stamp)
err = utils.UpdateStatus(ctx, csm, r, newStatus)
state := csm.GetCSMStatus().State
stamp := fmt.Sprintf("at %d", time.Now().UnixNano())
if state != "0" && err != nil {
log.Infow("pod status ", "state", err.Error())
r.EventRecorder.Eventf(csm, corev1.EventTypeWarning, csmv1.EventUpdated, "%s Pod error details %s", stamp, err.Error())
} else {
r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "%s Driver pods running OK", stamp)
}
}
}

Expand Down Expand Up @@ -516,28 +515,28 @@ func (r *ContainerStorageModuleReconciler) handleDaemonsetUpdate(oldObj interfac
log.Infow("daemonset ", "numberUnavailable", numberUnavailable)

ns := d.Spec.Template.Labels[constants.CsmNamespaceLabel]
if ns == "" {
ns = d.Namespace
}
r.Log.Debugw("daemonset ", "ns", ns, "name", name)
namespacedName := t1.NamespacedName{
Name: name,
Namespace: ns,
}

csm := new(csmv1.ContainerStorageModule)
err := r.Client.Get(ctx, namespacedName, csm)
if err != nil {
r.Log.Error("daemonset get csm", "error", err.Error())
}
if ns != "" {
r.Log.Debugw("daemonset ", "ns", ns, "name", name)
namespacedName := t1.NamespacedName{
Name: name,
Namespace: ns,
}

log.Infow("csm prev status ", "state", csm.Status)
newStatus := csm.GetCSMStatus()
err = utils.UpdateStatus(ctx, csm, r, newStatus)
if err != nil {
log.Debugw("daemonset status ", "pods", err.Error())
} else {
r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "Driver daemonset running OK")
csm := new(csmv1.ContainerStorageModule)
err := r.Client.Get(ctx, namespacedName, csm)
if err != nil {
r.Log.Error("daemonset get csm", "error", err.Error())
}

log.Infow("csm prev status ", "state", csm.Status)
newStatus := csm.GetCSMStatus()
err = utils.UpdateStatus(ctx, csm, r, newStatus)
if err != nil {
log.Debugw("daemonset status ", "pods", err.Error())
} else {
r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "Driver daemonset running OK")
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/csm_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ func (suite *CSMControllerTestSuite) handleDaemonsetTest(r *ContainerStorageModu
daemonset := &appsv1.DaemonSet{}
err := suite.fakeClient.Get(ctx, client.ObjectKey{Namespace: suite.namespace, Name: name}, daemonset)
assert.Nil(suite.T(), err)
daemonset.Spec.Template.Labels = map[string]string{"csm": "csm"}
daemonset.Spec.Template.Labels = map[string]string{"csm": "csm", "csmNamespace": suite.namespace}

r.handleDaemonsetUpdate(daemonset, daemonset)

Expand Down Expand Up @@ -1465,7 +1465,7 @@ func (suite *CSMControllerTestSuite) handleDeploymentTest(r *ContainerStorageMod
deployment := &appsv1.Deployment{}
err := suite.fakeClient.Get(ctx, client.ObjectKey{Namespace: suite.namespace, Name: name}, deployment)
assert.Nil(suite.T(), err)
deployment.Spec.Template.Labels = map[string]string{"csm": "csm"}
deployment.Spec.Template.Labels = map[string]string{"csm": "csm", "csmNamespace": suite.namespace}

r.handleDeploymentUpdate(deployment, deployment)

Expand Down Expand Up @@ -1493,7 +1493,7 @@ func (suite *CSMControllerTestSuite) handleDaemonsetTestFake(r *ContainerStorage
daemonset := &appsv1.DaemonSet{}
err := suite.fakeClient.Get(ctx, client.ObjectKey{Namespace: suite.namespace, Name: name}, daemonset)
assert.Error(suite.T(), err)
daemonset.Spec.Template.Labels = map[string]string{"csm": "csm"}
daemonset.Spec.Template.Labels = map[string]string{"csm": "csm", "csmNamespace": suite.namespace}

r.handleDaemonsetUpdate(daemonset, daemonset)

Expand Down Expand Up @@ -1521,7 +1521,7 @@ func (suite *CSMControllerTestSuite) handleDeploymentTestFake(r *ContainerStorag
deployment := &appsv1.Deployment{}
err := suite.fakeClient.Get(ctx, client.ObjectKey{Namespace: suite.namespace, Name: name}, deployment)
assert.Error(suite.T(), err)
deployment.Spec.Template.Labels = map[string]string{"csm": "csm"}
deployment.Spec.Template.Labels = map[string]string{"csm": "csm", "csmNamespace": suite.namespace}

r.handleDeploymentUpdate(deployment, deployment)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ spec:
metadata:
labels:
name: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powerflex/v2.11.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ spec:
labels:
app: <DriverDefaultReleaseName>-node
driver.dellemc.com: dell-storage
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ spec:
metadata:
labels:
name: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powerflex/v2.12.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ spec:
labels:
app: <DriverDefaultReleaseName>-node
driver.dellemc.com: dell-storage
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ spec:
metadata:
labels:
name: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powerflex/v2.13.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ spec:
labels:
app: <DriverDefaultReleaseName>-node
driver.dellemc.com: dell-storage
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powermax/v2.11.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-node
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powermax/v2.12.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-node
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powermax/v2.13.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-node
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powerscale/v2.11.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-node
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powerscale/v2.12.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-node
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powerscale/v2.13.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
metadata:
labels:
app: <DriverDefaultReleaseName>-node
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ spec:
metadata:
labels:
name: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powerstore/v2.11.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ spec:
labels:
app: <DriverDefaultReleaseName>-node
driver.dellemc.com: dell-storage
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ spec:
metadata:
labels:
name: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
1 change: 1 addition & 0 deletions operatorconfig/driverconfig/powerstore/v2.12.0/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ spec:
labels:
app: <DriverDefaultReleaseName>-node
driver.dellemc.com: dell-storage
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ spec:
metadata:
labels:
name: <DriverDefaultReleaseName>-controller
csmNamespace: <CSM_NAMESPACE>
annotations:
kubectl.kubernetes.io/default-container: driver
spec:
Expand Down
Loading

0 comments on commit 4f2abf7

Please sign in to comment.