From 270454eb92092c3f13dc5cb8712434c7beea5c82 Mon Sep 17 00:00:00 2001 From: rchikatw Date: Fri, 12 Jan 2024 19:04:01 +0530 Subject: [PATCH] fixed re trigger job issue when public key deleted Signed-off-by: rchikatw --- controllers/storagecluster/provider_server.go | 2 ++ controllers/util/util.go | 4 ++++ .../manifests/onboarding-secret-generator-role.yaml | 1 + onboarding/main.go | 5 +++++ rbac/onboarding-secret-generator-role.yaml | 1 + tools/csv-merger/csv-merger.go | 6 ++---- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/controllers/storagecluster/provider_server.go b/controllers/storagecluster/provider_server.go index f405a5d3b0..c7580615e2 100644 --- a/controllers/storagecluster/provider_server.go +++ b/controllers/storagecluster/provider_server.go @@ -454,6 +454,8 @@ func getOnboardingJobObject(instance *ocsv1.StorageCluster) *batchv1.Job { Namespace: instance.Namespace, }, Spec: batchv1.JobSpec{ + // Eligible to delete automatically when job finishes + TTLSecondsAfterFinished: util.ToPointer[int32](0), Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ RestartPolicy: corev1.RestartPolicyOnFailure, diff --git a/controllers/util/util.go b/controllers/util/util.go index f0d1ad6b93..8e0d9ea140 100644 --- a/controllers/util/util.go +++ b/controllers/util/util.go @@ -22,3 +22,7 @@ func DetectDuplicateInStringSlice(slice []string) bool { } return false } + +func ToPointer[T any](value T) *T { + return &value +} diff --git a/deploy/ocs-operator/manifests/onboarding-secret-generator-role.yaml b/deploy/ocs-operator/manifests/onboarding-secret-generator-role.yaml index cae160c88c..e572b48cc2 100644 --- a/deploy/ocs-operator/manifests/onboarding-secret-generator-role.yaml +++ b/deploy/ocs-operator/manifests/onboarding-secret-generator-role.yaml @@ -11,3 +11,4 @@ rules: - get - list - create + - update diff --git a/onboarding/main.go b/onboarding/main.go index 170feb4e46..cc3d62845f 100644 --- a/onboarding/main.go +++ b/onboarding/main.go @@ -72,10 +72,15 @@ func main() { _, err = clientset.CoreV1().Secrets(operatorNamespace).Create(context.Background(), privateSecret, metav1.CreateOptions{}) + if err != nil && kerrors.IsAlreadyExists(err) { + _, err = clientset.CoreV1().Secrets(operatorNamespace).Update(context.Background(), privateSecret, metav1.UpdateOptions{}) + } + if err != nil { klog.Error(err, "Failed to create private secret.") os.Exit(1) } + publicSecret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: onboardingTicketPublicKeySecretName, diff --git a/rbac/onboarding-secret-generator-role.yaml b/rbac/onboarding-secret-generator-role.yaml index cae160c88c..e572b48cc2 100644 --- a/rbac/onboarding-secret-generator-role.yaml +++ b/rbac/onboarding-secret-generator-role.yaml @@ -11,3 +11,4 @@ rules: - get - list - create + - update diff --git a/tools/csv-merger/csv-merger.go b/tools/csv-merger/csv-merger.go index 21c715c4bd..dfcaf41448 100644 --- a/tools/csv-merger/csv-merger.go +++ b/tools/csv-merger/csv-merger.go @@ -925,10 +925,8 @@ func copyManifests() { } func getUXBackendServerDeployment() appsv1.DeploymentSpec { - replica := int32(1) - ptrToTrue := true deployment := appsv1.DeploymentSpec{ - Replicas: &replica, + Replicas: util.ToPointer[int32](1), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "app.kubernetes.io/component": "ux-backend-server", @@ -1019,7 +1017,7 @@ func getUXBackendServerDeployment() appsv1.DeploymentSpec { VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ SecretName: "onboarding-private-key", - Optional: &ptrToTrue, + Optional: util.ToPointer[bool](true), }, }, },