Skip to content

Commit

Permalink
Changes for picking updated podmon image while running E2E tests (#253)
Browse files Browse the repository at this point in the history
* changes for picking updated podmon image

* function name change

---------

Co-authored-by: Adarsh Kumar Yadav <109620911+adarsh-dell@users.noreply.github.com>
  • Loading branch information
suryagupta4 and adarsh-dell committed May 26, 2023
1 parent 4898a89 commit 74e5cfc
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 14 deletions.
44 changes: 30 additions & 14 deletions pkg/modules/resiliency.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
drivers "github.com/dell/csm-operator/pkg/drivers"
"github.com/dell/csm-operator/pkg/logger"
utils "github.com/dell/csm-operator/pkg/utils"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
applyv1 "k8s.io/client-go/applyconfigurations/apps/v1"
acorev1 "k8s.io/client-go/applyconfigurations/core/v1"
Expand Down Expand Up @@ -129,16 +130,35 @@ func getResiliencyEnv(resiliencyModule csmv1.Module, driverType csmv1.DriverType
return ""
}

func getResiliencyArgs(m csmv1.Module, mode string) []string {
// Apply resiliency module from the manifest file to the podmon sidecar
func modifyPodmon(component csmv1.ContainerTemplate, container *acorev1.ContainerApplyConfiguration) {
if component.Image != "" {
image := string(component.Image)
if container.Image != nil {
*container.Image = image
}
container.Image = &image
}
if component.ImagePullPolicy != "" {
if container.ImagePullPolicy != nil {
*container.ImagePullPolicy = component.ImagePullPolicy
}
container.ImagePullPolicy = &component.ImagePullPolicy
}
emptyEnv := make([]corev1.EnvVar, 0)
container.Env = utils.ReplaceAllApplyCustomEnvs(container.Env, emptyEnv, component.Envs)
container.Args = utils.ReplaceAllArgs(container.Args, component.Args)
}

func setResiliencyArgs(m csmv1.Module, mode string, container *acorev1.ContainerApplyConfiguration) {
for _, component := range m.Components {
if component.Name == utils.PodmonControllerComponent && mode == "controller" {
return component.Args
modifyPodmon(component, container)
}
if component.Name == utils.PodmonNodeComponent && mode == "node" {
return component.Args
modifyPodmon(component, container)
}
}
return nil
}

func getPollRateFromArgs(args []string) string {
Expand All @@ -152,6 +172,7 @@ func getPollRateFromArgs(args []string) string {
}
return ""
}

func getResiliencyApplyCR(cr csmv1.ContainerStorageModule, op utils.OperatorConfig, driverType, mode string) (*csmv1.Module, *acorev1.ContainerApplyConfiguration, error) {
resiliencyModule := csmv1.Module{}
for _, m := range cr.Spec.Modules {
Expand All @@ -174,16 +195,13 @@ func getResiliencyApplyCR(cr csmv1.ContainerStorageModule, op utils.OperatorConf

YamlString := utils.ModifyCommonCR(string(buf), cr)

// read args from the respective components
args := getResiliencyArgs(resiliencyModule, mode)

var container acorev1.ContainerApplyConfiguration
err = yaml.Unmarshal([]byte(YamlString), &container)
if err != nil {
return nil, nil, err
}
// set arguments
container.Args = args
// read args from the respective components
setResiliencyArgs(resiliencyModule, mode, &container)
return &resiliencyModule, &container, nil
}

Expand All @@ -194,7 +212,6 @@ func ResiliencyInjectDeployment(dp applyv1.DeploymentApplyConfiguration, cr csmv
return nil, err
}
podmon := *podmonPtr
utils.UpdateSideCarApply(resiliencyModule.Components, &podmon)
// prepend podmon container in controller-pod
dp.Spec.Template.Spec.Containers = append([]acorev1.ContainerApplyConfiguration{podmon}, dp.Spec.Template.Spec.Containers...)

Expand Down Expand Up @@ -236,7 +253,6 @@ func ResiliencyInjectDaemonset(ds applyv1.DaemonSetApplyConfiguration, cr csmv1.
}

podmon := *podmonPtr
utils.UpdateSideCarApply(resiliencyModule.Components, &podmon)
// prepend podmon container in node-pod
ds.Spec.Template.Spec.Containers = append([]acorev1.ContainerApplyConfiguration{podmon}, ds.Spec.Template.Spec.Containers...)

Expand Down Expand Up @@ -268,10 +284,10 @@ func CheckApplyContainersResiliency(containers []acorev1.ContainerApplyConfigura

// fetch podmonAPIPort
podmonAPIPort := getResiliencyEnv(resiliencyModule, cr.Spec.Driver.CSIDriverType)

var container acorev1.ContainerApplyConfiguration
// fetch podmonArrayConnectivityPollRate
args := getResiliencyArgs(resiliencyModule, "node")
podmonArrayConnectivityPollRate := getPollRateFromArgs(args)
setResiliencyArgs(resiliencyModule, "node", &container)
podmonArrayConnectivityPollRate := getPollRateFromArgs(container.Args)

for _, cnt := range containers {
if *cnt.Name == utils.ResiliencySideCarName {
Expand Down
4 changes: 4 additions & 0 deletions pkg/modules/testdata/cr_powerstore_resiliency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ spec:
enabled: true
components:
- name: podmon-controller
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
args:
- "--csisock=unix:/var/run/csi/csi.sock"
- "--labelvalue=csi-powerstore"
Expand All @@ -30,6 +32,8 @@ spec:
- "--driverPodLabelValue=dell-storage"
- "--ignoreVolumelessPods=false"
- name: podmon-node
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
envs:
# podmonAPIPort: Defines the port to be used within the kubernetes cluster
# Allowed values: Any valid and free port (string)
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/testfiles/storage_csm_powerflex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ spec:
configVersion: v1.6.0
components:
- name: podmon-controller
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
args:
- "--csisock=unix:/var/run/csi/csi.sock"
- "--labelvalue=csi-vxflexos"
Expand All @@ -344,6 +346,8 @@ spec:
- "--driverPodLabelValue=dell-storage"
- "--ignoreVolumelessPods=false"
- name: podmon-node
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
envs:
# podmonAPIPort: Defines the port to be used within the kubernetes cluster
# Allowed values: Any valid and free port (string)
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/testfiles/storage_csm_powerflex_resiliency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ spec:
configVersion: v1.6.0
components:
- name: podmon-controller
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
args:
- "--csisock=unix:/var/run/csi/csi.sock"
- "--labelvalue=csi-vxflexos"
Expand All @@ -179,6 +181,8 @@ spec:
- "--driverPodLabelValue=dell-storage"
- "--ignoreVolumelessPods=false"
- name: podmon-node
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
envs:
# podmonAPIPort: Defines the port to be used within the kubernetes cluster
# Allowed values: Any valid and free port (string)
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/testfiles/storage_csm_powerscale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ spec:
configVersion: v1.6.0
components:
- name: podmon-controller
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
args:
- "--csisock=unix:/var/run/csi/csi.sock"
- "--labelvalue=csi-isilon"
Expand All @@ -444,6 +446,8 @@ spec:
- "--driverPodLabelValue=dell-storage"
- "--ignoreVolumelessPods=false"
- name: podmon-node
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
envs:
# podmonAPIPort: Defines the port to be used within the kubernetes cluster
# Allowed values: Any valid and free port (string)
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/testfiles/storage_csm_powerscale_resiliency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ spec:
configVersion: v1.6.0
components:
- name: podmon-controller
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
args:
- "--csisock=unix:/var/run/csi/csi.sock"
- "--labelvalue=csi-isilon"
Expand All @@ -279,6 +281,8 @@ spec:
- "--driverPodLabelValue=dell-storage"
- "--ignoreVolumelessPods=false"
- name: podmon-node
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
envs:
# podmonAPIPort: Defines the port to be used within the kubernetes cluster
# Allowed values: Any valid and free port (string)
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/testfiles/storage_csm_powerstore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ spec:
configVersion: v1.6.0
components:
- name: podmon-controller
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
args:
- "--csisock=unix:/var/run/csi/csi.sock"
- "--labelvalue=csi-powerstore"
Expand All @@ -162,6 +164,8 @@ spec:
- "--driverPodLabelValue=dell-storage"
- "--ignoreVolumelessPods=false"
- name: podmon-node
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
envs:
# podmonAPIPort: Defines the port to be used within the kubernetes cluster
# Allowed values: Any valid and free port (string)
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/testfiles/storage_csm_powerstore_resiliency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ spec:
configVersion: v1.6.0
components:
- name: podmon-controller
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
args:
- "--csisock=unix:/var/run/csi/csi.sock"
- "--labelvalue=csi-powerstore"
Expand All @@ -162,6 +164,8 @@ spec:
- "--driverPodLabelValue=dell-storage"
- "--ignoreVolumelessPods=false"
- name: podmon-node
image: dellemc/podmon:nightly
imagePullPolicy: IfNotPresent
envs:
# podmonAPIPort: Defines the port to be used within the kubernetes cluster
# Allowed values: Any valid and free port (string)
Expand Down

0 comments on commit 74e5cfc

Please sign in to comment.