From 609da95eb53bee48195811d920c5ffb5c8dc159a Mon Sep 17 00:00:00 2001 From: Nikita Bhatia Date: Thu, 1 Feb 2024 23:29:28 +0530 Subject: [PATCH 1/2] Mount volume to autopilot pod only if secret is created --- .../storage/portworx/component/autopilot.go | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/storage/portworx/component/autopilot.go b/drivers/storage/portworx/component/autopilot.go index cad28baf55..21f7efb8ac 100644 --- a/drivers/storage/portworx/component/autopilot.go +++ b/drivers/storage/portworx/component/autopilot.go @@ -691,7 +691,7 @@ func (c *autopilot) getDesiredVolumesAndMounts( ) ([]v1.Volume, []v1.VolumeMount) { volumeSpecs := make([]corev1.VolumeSpec, 0) - if c.isOCPUserWorkloadSupported() && !c.isVolumeMounted { + if c.isOCPUserWorkloadSupported() && !c.isVolumeMounted && c.isAutopilotSecretCreated(cluster.Namespace) { c.isVolumeMounted = true autopilotDeploymentVolumes = append(autopilotDeploymentVolumes, openshiftDeploymentVolume...) } @@ -712,6 +712,30 @@ func (c *autopilot) getDesiredVolumesAndMounts( return volumes, volumeMounts } +func (c *autopilot) isAutopilotSecretCreated(namespace string) bool { + secret := &v1.Secret{} + + err := c.k8sClient.Get( + context.TODO(), + types.NamespacedName{ + Name: AutopilotSecretName, + Namespace: namespace, + }, + secret, + ) + + if err == nil && secret.Name == AutopilotSecretName { + return true + } + + if err != nil && errors.IsNotFound(err) { + return false + } + + logrus.Errorf("error while fetching secret %s ", err) + return false +} + func (c *autopilot) getPrometheusTokenAndCert() (encodedToken, caCert string, err error) { secrets := &v1.SecretList{} err = c.k8sClient.List( From b59f8a42e1cec9936bbb95c2bcca2e303b03c965 Mon Sep 17 00:00:00 2001 From: Nikita Bhatia Date: Thu, 1 Feb 2024 23:47:54 +0530 Subject: [PATCH 2/2] remove name check for secret --- drivers/storage/portworx/component/autopilot.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/storage/portworx/component/autopilot.go b/drivers/storage/portworx/component/autopilot.go index 21f7efb8ac..4df05c114e 100644 --- a/drivers/storage/portworx/component/autopilot.go +++ b/drivers/storage/portworx/component/autopilot.go @@ -724,7 +724,7 @@ func (c *autopilot) isAutopilotSecretCreated(namespace string) bool { secret, ) - if err == nil && secret.Name == AutopilotSecretName { + if err == nil { return true }