Skip to content

Commit

Permalink
Inject ReverseProxy directly into the deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshaySainiDell committed Dec 11, 2024
1 parent e9e6a63 commit 9c4fa54
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 70 deletions.
32 changes: 25 additions & 7 deletions controllers/csm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,25 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1
node := driverConfig.Node
controller := driverConfig.Controller

if cr.GetDriverType() == csmv1.PowerMax {
if !modules.IsReverseProxySidecar() {
log.Infof("DeployAsSidar is false...csi-reverseproxy should be present as deployement\n")
log.Infof("adding proxy service name...\n")
modules.AddReverseProxyServiceName(&controller.Deployment)
} else {
log.Info("Starting CSI ReverseProxy Service")
if err := modules.ReverseProxyStartService(ctx, false, operatorConfig, cr, ctrlClient); err != nil {
return fmt.Errorf("unable to reconcile reverse-proxy service: %v", err)
}
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)
}
controller.Deployment = *dp
}
}

replicationEnabled, clusterClients, err := utils.GetDefaultClusters(ctx, cr, r)
if err != nil {
return err
Expand Down Expand Up @@ -827,13 +846,6 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1
}

controller.Rbac.ClusterRole = *clusterRole
case csmv1.ReverseProxy:
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)
}
controller.Deployment = *dp
}
}
}
Expand Down Expand Up @@ -1260,6 +1272,12 @@ func (r *ContainerStorageModuleReconciler) removeDriver(ctx context.Context, ins
return err
}
for _, cluster := range clusterClients {
if instance.GetDriverType() == csmv1.PowerMax && modules.IsReverseProxySidecar() {
log.Info("Removing CSI ReverseProxy Service")
if err := modules.ReverseProxyStartService(ctx, true, operatorConfig, instance, cluster.ClusterCTRLClient); err != nil {
return fmt.Errorf("unable to reconcile reverse-proxy service: %v", err)
}
}
if err = removeDriverReplicaCluster(ctx, cluster, driverConfig); err != nil {
return err
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/drivers/powermax.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,13 @@ func PrecheckPowerMax(ctx context.Context, cr *csmv1.ContainerStorageModule, ope
}
}

foundRevProxy := false
for i, mod := range cr.Spec.Modules {
if mod.Name == csmv1.ReverseProxy {
foundRevProxy = true
cr.Spec.Modules[i].Enabled = true
cr.Spec.Modules[i].ForceRemoveModule = true
break
}
}
if !foundRevProxy {
// if we are here then it's minimal yaml
log.Infof("Reverse proxy module not found adding it")
cr.Spec.Modules = append(cr.Spec.Modules, csmv1.Module{
Name: csmv1.ReverseProxy,
Enabled: true,
})
}

log.Debugw("preCheck", "secrets", cred)
return nil
Expand Down
88 changes: 35 additions & 53 deletions pkg/modules/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ const (

// var used in deploying reverseproxy
var (
deployAsSidecar = true
CSIPmaxRevProxyServiceName = "X_CSI_POWERMAX_PROXY_SERVICE_NAME"
CSIPmaxRevProxyPort = "X_CSI_POWERMAX_SIDECAR_PROXY_PORT"
RevProxyDefaultPort = "2222"
RevProxyServiceName = "csipowermax-reverseproxy"
RevProxyConfigMapVolName = "configmap-volume"
RevProxyTLSSecretVolName = "tls-secret"
deployAsSidecar = true
CSIPmaxRevProxyServiceName = "X_CSI_POWERMAX_PROXY_SERVICE_NAME"
CSIPmaxRevProxyPort = "X_CSI_POWERMAX_SIDECAR_PROXY_PORT"
RevProxyDefaultPort = "2222"
RevProxyServiceName = "csipowermax-reverseproxy"
RevProxyConfigMapVolName = "configmap-volume"
RevProxyConfigMapDeafultName = "powermax-reverseproxy-config"
RevProxyTLSSecretVolName = "tls-secret"
RevProxyTLSSecretDefaultName = "csirevproxy-tls-secret"
)

// ReverseproxySupportedDrivers is a map containing the CSI Drivers supported by CSM Reverseproxy. The key is driver name and the value is the driver plugin identifier
Expand Down Expand Up @@ -152,10 +154,7 @@ func ReverseProxyServer(ctx context.Context, isDeleting bool, op utils.OperatorC
// ReverseProxyStartService starts reverseproxy service for node to connect to revserseproxy sidecar
func ReverseProxyStartService(ctx context.Context, isDeleting bool, op utils.OperatorConfig, cr csmv1.ContainerStorageModule, ctrlClient crclient.Client) error {
log := logger.GetLogger(ctx)
if !deployAsSidecar {
log.Infof("DeployAsSidar is false...csi-reverseproxy service is part of deployement already\n")
return nil
}

YamlString, err := getReverseProxyService(op, cr)
if err != nil {
return err
Expand Down Expand Up @@ -193,9 +192,10 @@ func getReverseProxyModule(cr csmv1.ContainerStorageModule) (csmv1.Module, error
// getReverseProxyService - gets the reverseproxy service manifest
func getReverseProxyService(op utils.OperatorConfig, cr csmv1.ContainerStorageModule) (string, error) {
yamlString := ""
revProxy, err := getReverseProxyModule(cr)
if err != nil {
return yamlString, err
revProxy := cr.GetModule(csmv1.ReverseProxy)
// This is necessary for the minimal manifest, where the reverse proxy will not be included in the CSM CR.
if len(revProxy.Name) == 0 {
revProxy.Name = csmv1.ReverseProxy
}

buf, err := readConfigFile(revProxy, cr, op, ReverseProxyService)
Expand Down Expand Up @@ -300,45 +300,11 @@ func getReverseProxyDeployment(op utils.OperatorConfig, cr csmv1.ContainerStorag

// ReverseProxyInjectDeployment injects reverseproxy container as sidecar into controller
func ReverseProxyInjectDeployment(dp v1.DeploymentApplyConfiguration, cr csmv1.ContainerStorageModule, op utils.OperatorConfig) (*v1.DeploymentApplyConfiguration, error) {
log := logger.GetLogger(context.Background())

if !deployAsSidecar {
log.Infof("DeployAsSidar is false...csi-reverseproxy should be present as deployement\n")
log.Infof("adding proxy service name...\n")
for i, cnt := range dp.Spec.Template.Spec.Containers {
if *cnt.Name == "driver" {
dp.Spec.Template.Spec.Containers[i].Env = append(dp.Spec.Template.Spec.Containers[i].Env,
acorev1.EnvVarApplyConfiguration{Name: &CSIPmaxRevProxyServiceName, Value: &RevProxyServiceName},
)
break
}
}
return &dp, nil
}

revProxyModule, containerPtr, err := getRevproxyApplyCR(cr, op)
if err != nil {
return nil, err
}
if revProxyModule.Components == nil {
revProxyModule = &csmv1.Module{
Name: csmv1.ReverseProxy,
ForceRemoveModule: true,
Enabled: true,
Components: []csmv1.ContainerTemplate{
{
Image: csmv1.ImageType(op.K8sVersion.Images.CSIRevProxy),
Name: "csipowermax-reverseproxy",
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"},
},
},
},
}
}

container := *containerPtr
// update the image
for _, side := range revProxyModule.Components {
Expand Down Expand Up @@ -382,7 +348,7 @@ func getRevProxyPort(revProxyModule csmv1.Module) string {
}

func getRevProxyVolumeComp(revProxyModule csmv1.Module) []acorev1.VolumeApplyConfiguration {
var revProxyConfigMap, revProxyTLSSecret string
var revProxyConfigMap, revProxyTLSSecret = RevProxyConfigMapDeafultName, RevProxyTLSSecretDefaultName
for _, component := range revProxyModule.Components {
if component.Name == ReverseProxyServerComponent {
for _, env := range component.Envs {
Expand Down Expand Up @@ -422,9 +388,10 @@ func getRevProxyVolumeComp(revProxyModule csmv1.Module) []acorev1.VolumeApplyCon
// returns revproxy module and container
func getRevproxyApplyCR(cr csmv1.ContainerStorageModule, op utils.OperatorConfig) (*csmv1.Module, *acorev1.ContainerApplyConfiguration, error) {
var err error
revProxyModule, err := getReverseProxyModule(cr)
if err != nil {
return nil, nil, err
revProxyModule := cr.GetModule(csmv1.ReverseProxy)
// This is necessary for the minimal manifest, where the reverse proxy will not be included in the CSM CR.
if len(revProxyModule.Name) == 0 {
revProxyModule.Name = csmv1.ReverseProxy
}

buf, err := readConfigFile(revProxyModule, cr, op, ReverseProxySidecar)
Expand All @@ -440,3 +407,18 @@ func getRevproxyApplyCR(cr csmv1.ContainerStorageModule, op utils.OperatorConfig
}
return &revProxyModule, &container, nil
}

func AddReverseProxyServiceName(dp *v1.DeploymentApplyConfiguration) {
for i, cnt := range dp.Spec.Template.Spec.Containers {
if *cnt.Name == "driver" {
dp.Spec.Template.Spec.Containers[i].Env = append(dp.Spec.Template.Spec.Containers[i].Env,
acorev1.EnvVarApplyConfiguration{Name: &CSIPmaxRevProxyServiceName, Value: &RevProxyServiceName},
)
break
}
}
}

func IsReverseProxySidecar() bool {
return deployAsSidecar
}

0 comments on commit 9c4fa54

Please sign in to comment.