Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auth v2 e2e tests using PowerMax mount credentials #892

Draft
wants to merge 9 commits into
base: usr/spark/mount-credentials
Choose a base branch
from
24 changes: 22 additions & 2 deletions controllers/csm_controller.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 - 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
// Copyright © 2021 - 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -769,6 +769,12 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1
log.Infof("DeployAsSidar is false...csi-reverseproxy should be present as deployement\n")
log.Infof("adding proxy service name...\n")
modules.AddReverseProxyServiceName(&controller.Deployment)

// Set the secret mount for powermax controller.
err := drivers.DynamicallyMountPowermaxContent(&controller.Deployment, cr)
if err != nil {
return err
}
} else {
log.Info("Starting CSI ReverseProxy Service")
if err := modules.ReverseProxyStartService(ctx, false, operatorConfig, cr, ctrlClient); err != nil {
Expand All @@ -777,10 +783,20 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1
log.Info("Injecting CSI ReverseProxy")
dp, err := modules.ReverseProxyInjectDeployment(controller.Deployment, cr, operatorConfig)
if err != nil {
return fmt.Errorf("injecting replication into deployment: %v", err)
return fmt.Errorf("unable to inject ReverseProxy into deployment: %v", err)
}

controller.Deployment = *dp
}

// Set the secret mount for powermax node.
err := drivers.DynamicallyMountPowermaxContent(&node.DaemonSetApplyConfig, cr)
if err != nil {
return err
}

// Dynamically update the drivers config param.
modules.UpdatePowerMaxConfigMap(configMap, cr)
}

replicationEnabled, clusterClients, err := utils.GetDefaultClusters(ctx, cr, r)
Expand Down Expand Up @@ -1370,6 +1386,10 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs
if err != nil {
return fmt.Errorf("failed powermax validation: %v", err)
}

// To ensure that we are handling minimal manifests correctly and consistent, we must reset DeployAsSidecar to the original value.
// This variable will be set correctly if the reverseproxy is found in the manifests.
modules.ResetDeployAsSidecar()
default:
// Go to checkUpgrade if it is standalone module i.e. app mobility or authorizatio proxy server
if cr.HasModule(csmv1.ApplicationMobility) || cr.HasModule(csmv1.AuthorizationServer) {
Expand Down
67 changes: 64 additions & 3 deletions controllers/csm_controller_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 - 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
// Copyright © 2022 - 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -273,6 +273,17 @@ func (suite *CSMControllerTestSuite) TestReverseProxyReconcile() {
suite.runFakeCSMManager("", true)
}

func (suite *CSMControllerTestSuite) TestReverseProxyWithSecretReconcile() {
csm := suite.buildFakeRevProxyCSM(csmName, suite.namespace, true, getReverseProxyModuleWithSecret(), string(v1.PowerMax))
csm.Spec.Driver.Common.Envs = append(csm.Spec.Driver.Common.Envs, corev1.EnvVar{Name: "X_CSI_REVPROXY_USE_SECRET", Value: "true"})
err := suite.fakeClient.Create(ctx, &csm)
assert.Nil(suite.T(), err)

suite.runFakeCSMManager("", false)
suite.deleteCSM(csmName)
suite.runFakeCSMManager("", true)
}

func (suite *CSMControllerTestSuite) TestReverseProxySidecarReconcile() {
revProxy := getReverseProxyModule()
deploAsSidecar := corev1.EnvVar{Name: "DeployAsSidecar", Value: "true"}
Expand Down Expand Up @@ -815,6 +826,10 @@ func (suite *CSMControllerTestSuite) TestSyncCSM() {
reverseProxyServerCSM.Spec.Modules = getReverseProxyModule()
modules.IsReverseProxySidecar = func() bool { return false }

reverseProxyWithSecret := shared.MakeCSM(csmName, suite.namespace, configVersion)
reverseProxyWithSecret.Spec.Modules = getReverseProxyModuleWithSecret()
reverseProxyServerCSM.Spec.Driver.CSIDriverType = csmv1.PowerMax

syncCSMTests := []struct {
name string
csm csmv1.ContainerStorageModule
Expand All @@ -827,6 +842,7 @@ func (suite *CSMControllerTestSuite) TestSyncCSM() {
{"reverse proxy server bad op conf", reverseProxyServerCSM, badOperatorConfig, "failed to deploy reverseproxy proxy server"},
{"getDriverConfig bad op config", csm, badOperatorConfig, ""},
{"getDriverConfig error", csmBadType, badOperatorConfig, "no such file or directory"},
{"success: deployAsSidecar with secret", reverseProxyWithSecret, operatorConfig, ""},
}

for _, tt := range syncCSMTests {
Expand Down Expand Up @@ -1844,6 +1860,45 @@ func getReverseProxyModule() []csmv1.Module {
}
}

func getReverseProxyModuleWithSecret() []csmv1.Module {
return []csmv1.Module{
{
Name: csmv1.ReverseProxy,
Enabled: true,
ConfigVersion: "v2.13.0",
Components: []csmv1.ContainerTemplate{
{
Name: string(csmv1.ReverseProxyServer),
Enabled: &[]bool{true}[0],
Envs: []corev1.EnvVar{
{
Name: "X_CSI_REVPROXY_TLS_SECRET",
Value: "csirevproxy-tls-secret",
},
{
Name: "X_CSI_REVPROXY_PORT",
Value: "2222",
},
{
Name: "X_CSI_CONFIG_MAP_NAME",
Value: "powermax-reverseproxy-config",
},
{
Name: "DeployAsSidecar",
Value: "true",
},
{
Name: "X_CSI_REVPROXY_USE_SECRET",
Value: "true",
},
},
},
},
ForceRemoveModule: true,
},
}
}

func (suite *CSMControllerTestSuite) TestDeleteErrorReconcile() {
suite.makeFakeCSM(csmName, suite.namespace, true, append(getAuthModule(), getObservabilityModule()...))
suite.runFakeCSMManager("", false)
Expand Down Expand Up @@ -2353,7 +2408,7 @@ func (suite *CSMControllerTestSuite) ShouldFail(method string, obj runtime.Objec
return nil
}

func (suite *CSMControllerTestSuite) makeFakeRevProxyCSM(name string, ns string, withFinalizer bool, modules []v1.Module, driverType string) {
func (suite *CSMControllerTestSuite) buildFakeRevProxyCSM(name string, ns string, withFinalizer bool, modules []v1.Module, driverType string) v1.ContainerStorageModule {
// Create secrets and config map for Reconcile
sec := shared.MakeSecret("csirevproxy-tls-secret", ns, configVersion)
err := suite.fakeClient.Create(ctx, sec)
Expand Down Expand Up @@ -2395,7 +2450,13 @@ func (suite *CSMControllerTestSuite) makeFakeRevProxyCSM(name string, ns string,
out, _ := json.Marshal(&csm)
csm.Annotations[previouslyAppliedCustomResource] = string(out)

err = suite.fakeClient.Create(ctx, &csm)
return csm
}

func (suite *CSMControllerTestSuite) makeFakeRevProxyCSM(name string, ns string, withFinalizer bool, modules []v1.Module, driverType string) {
csm := suite.buildFakeRevProxyCSM(name, ns, withFinalizer, modules, driverType)

err := suite.fakeClient.Create(ctx, &csm)
assert.Nil(suite.T(), err)
}

Expand Down
Loading
Loading