Skip to content

Commit

Permalink
Increase coverage of reverseproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshaySainiDell committed Dec 18, 2024
1 parent b3b5a9d commit 252d2ea
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 0 deletions.
111 changes: 111 additions & 0 deletions pkg/modules/reverseproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package modules

import (
"context"
"strings"
"testing"

"github.com/dell/csm-operator/pkg/drivers"
Expand Down Expand Up @@ -366,3 +367,113 @@ func TestReverseProxyStartService(t *testing.T) {
})
}
}

func TestAddReverseProxyServiceName(t *testing.T) {
tests := map[string]func(t *testing.T) applyv1.DeploymentApplyConfiguration{
"Add env var to driver container": func(*testing.T) applyv1.DeploymentApplyConfiguration {
customResource, err := getCustomResource("./testdata/cr_powermax_reverseproxy.yaml")
if err != nil {
panic(err)
}
controllerYAML, err := drivers.GetController(ctx, customResource, operatorConfig, csmv1.PowerMax)
if err != nil {
panic(err)
}
deployAsSidecar = true
return controllerYAML.Deployment
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
dp := tc(t)
AddReverseProxyServiceName(&dp)
isEnvFound := false
for i, cnt := range dp.Spec.Template.Spec.Containers {
if *cnt.Name == "driver" {
for _, env := range dp.Spec.Template.Spec.Containers[i].Env {
if strings.EqualFold(*env.Name, CSIPmaxRevProxyServiceName) && strings.EqualFold(*env.Value, RevProxyServiceName) {
isEnvFound = true
}

}
}
}
if !isEnvFound {
t.Errorf("Expected env vars: %v with value %v, but not found", CSIPmaxRevProxyServiceName, RevProxyServiceName)
}
})
}
}

func TestIsReverseProxySidecar(t *testing.T) {
type fakeControllerRuntimeClientWrapper func(clusterConfigData []byte) (ctrlClient.Client, error)

tests := map[string]func(t *testing.T) (bool, csmv1.Module, csmv1.ContainerStorageModule, ctrlClient.Client, fakeControllerRuntimeClientWrapper){
"Reverse proxy is configured as sidecar": func(*testing.T) (bool, csmv1.Module, csmv1.ContainerStorageModule, ctrlClient.Client, fakeControllerRuntimeClientWrapper) {
customResource, err := getCustomResource("./testdata/cr_powermax_reverseproxy_sidecar.yaml")
if err != nil {
panic(err)
}

proxySecret := getSecret(customResource.Namespace, "csirevproxy-tls-secret")
proxyConfigMap := getConfigMap(customResource.Namespace, "powermax-reverseproxy-config")

tmpCR := customResource
reverseProxy := tmpCR.Spec.Modules[0]

sourceClient := ctrlClientFake.NewClientBuilder().WithObjects(proxySecret, proxyConfigMap).Build()
fakeControllerRuntimeClient := func(_ []byte) (ctrlClient.Client, error) {
clusterClient := ctrlClientFake.NewClientBuilder().WithObjects(proxySecret, proxyConfigMap).Build()
return clusterClient, nil
}

return true, reverseProxy, tmpCR, sourceClient, fakeControllerRuntimeClient
},
"Reverse proxy is not configured as sidecar": func(*testing.T) (bool, csmv1.Module, csmv1.ContainerStorageModule, ctrlClient.Client, fakeControllerRuntimeClientWrapper) {
customResource, err := getCustomResource("./testdata/cr_powermax_reverseproxy.yaml")
if err != nil {
panic(err)
}

proxySecret := getSecret(customResource.Namespace, "csirevproxy-tls-secret")
proxyConfigMap := getConfigMap(customResource.Namespace, "powermax-reverseproxy-config")

tmpCR := customResource
reverseProxy := tmpCR.Spec.Modules[0]

sourceClient := ctrlClientFake.NewClientBuilder().WithObjects(proxySecret, proxyConfigMap).Build()
fakeControllerRuntimeClient := func(_ []byte) (ctrlClient.Client, error) {
clusterClient := ctrlClientFake.NewClientBuilder().WithObjects(proxySecret, proxyConfigMap).Build()
return clusterClient, nil
}

return false, reverseProxy, tmpCR, sourceClient, fakeControllerRuntimeClient
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
oldNewControllerRuntimeClientWrapper := utils.NewControllerRuntimeClientWrapper
oldNewK8sClientWrapper := utils.NewK8sClientWrapper
defer func() {
utils.NewControllerRuntimeClientWrapper = oldNewControllerRuntimeClientWrapper
utils.NewK8sClientWrapper = oldNewK8sClientWrapper
}()

isSideCar, reverseProxy, tmpCR, sourceClient, fakeControllerRuntimeClient := tc(t)
utils.NewControllerRuntimeClientWrapper = fakeControllerRuntimeClient
utils.NewK8sClientWrapper = func(_ []byte) (*kubernetes.Clientset, error) {
return nil, nil
}

fakeReconcile := utils.FakeReconcileCSM{
Client: sourceClient,
K8sClient: fake.NewSimpleClientset(),
}

ReverseProxyPrecheck(ctx, operatorConfig, reverseProxy, tmpCR, &fakeReconcile)
if isSideCar != IsReverseProxySidecar() {
t.Errorf("Expected %v but got %v", isSideCar, IsReverseProxySidecar())
}
})
}
}
63 changes: 63 additions & 0 deletions pkg/modules/testdata/cr_powermax_reverseproxy_sidecar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright © 2024 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.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: storage.dell.com/v1
kind: ContainerStorageModule
metadata:
name: test-powermax
namespace: powermax
spec:
driver:
csiDriverType: "powermax"
configVersion: v2.13.0
authSecret: powermax-creds
replicas: 1
common:
image: "quay.io/dell/container-storage-modules/csi-powermax:v2.13.0"
imagePullPolicy: IfNotPresent
modules:
# CSI Powermax Reverseproxy is a mandatory module
- name: "csireverseproxy"
# enabled: Always set to true
enabled: true
configVersion: v2.12.0
components:
- name: csipowermax-reverseproxy
# image: Define the container images used for the reverse proxy
# Default value: None
image: quay.io/dell/container-storage-modules/csipowermax-reverseproxy:v2.12.0
envs:
# "tlsSecret" defines the TLS secret that is created with certificate
# and its associated key
# Default value: None
# Example: "tls-secret"
- 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: authorization
# enable: Enable/Disable csm-authorization
enabled: false
components:
- name: karavi-authorization-proxy
image: quay.io/dell/container-storage-modules/csm-authorization-sidecar:v2.1.0
envs:
# proxyHost: hostname of the csm-authorization server
- name: "PROXY_HOST"
value: "testing-proxy-host"
# skipCertificateValidation: Enable/Disable certificate validation of the csm-authorization server
- name: "SKIP_CERTIFICATE_VALIDATION"
value: "true"

0 comments on commit 252d2ea

Please sign in to comment.