From a1f310e8d0a4c3d768cbdd7fd225e7556d5ffa1b Mon Sep 17 00:00:00 2001 From: sebastienmusso Date: Tue, 10 Sep 2024 15:51:46 +0200 Subject: [PATCH 1/3] CreateCABundle Secret from gitrepo spec --- .../gitops/reconciler/gitjob_controller.go | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go index e0fff3016c..cfda509754 100644 --- a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go +++ b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go @@ -273,6 +273,9 @@ func (r *GitJobReconciler) manageGitJob(ctx context.Context, logger logr.Logger, if err := r.createTargetsConfigMap(ctx, gitrepo); err != nil { return result(repoPolled, gitrepo), fmt.Errorf("failed to create targets config map for git job: %w", err) } + if err := r.createCABundleSecret(ctx, gitrepo); err != nil { + return result(repoPolled, gitrepo), fmt.Errorf("failed to create cabundle secret for git job: %w", err) + } if err := r.createJob(ctx, gitrepo); err != nil { return result(repoPolled, gitrepo), fmt.Errorf("error creating git job: %w", err) } @@ -393,6 +396,29 @@ func (r *GitJobReconciler) createTargetsConfigMap(ctx context.Context, gitrepo * return err } +func (r *GitJobReconciler) createCABundleSecret(ctx context.Context, gitrepo *v1alpha1.GitRepo) error { + fmt.Println("TEST INDA createCABundleSecret") + secret := &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: gitrepo.ObjectMeta.Namespace, + Name: caBundleName(gitrepo), + }, + Data: map[string][]byte{ + "additional-ca.crt": gitrepo.Spec.CABundle, + }, + } + if err := controllerutil.SetControllerReference(gitrepo, secret, r.Scheme); err != nil { + return err + } + data := secret.StringData + _, err := controllerutil.CreateOrUpdate(ctx, r.Client, secret, func() error { + secret.StringData = data + return nil + }) + + return err +} + func (r *GitJobReconciler) validateExternalSecretExist(ctx context.Context, gitrepo *v1alpha1.GitRepo) error { if gitrepo.Spec.HelmSecretNameForPaths != "" { if err := r.Get(ctx, types.NamespacedName{Namespace: gitrepo.Namespace, Name: gitrepo.Spec.HelmSecretNameForPaths}, &corev1.Secret{}); err != nil { From 4edb376a04067553012420a0cc3179edea77b99b Mon Sep 17 00:00:00 2001 From: sebastienmusso Date: Tue, 10 Sep 2024 15:59:43 +0200 Subject: [PATCH 2/3] Update gitjob_controller.go --- internal/cmd/controller/gitops/reconciler/gitjob_controller.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go index cfda509754..381219a0c6 100644 --- a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go +++ b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go @@ -397,7 +397,6 @@ func (r *GitJobReconciler) createTargetsConfigMap(ctx context.Context, gitrepo * } func (r *GitJobReconciler) createCABundleSecret(ctx context.Context, gitrepo *v1alpha1.GitRepo) error { - fmt.Println("TEST INDA createCABundleSecret") secret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: gitrepo.ObjectMeta.Namespace, From 65d88f0f538259307aab87f0d8679dbccfaf0353 Mon Sep 17 00:00:00 2001 From: Mario Manno Date: Wed, 11 Sep 2024 12:16:22 +0200 Subject: [PATCH 3/3] Update internal/cmd/controller/gitops/reconciler/gitjob_controller.go --- internal/cmd/controller/gitops/reconciler/gitjob_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go index 381219a0c6..3f6336dfce 100644 --- a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go +++ b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go @@ -403,7 +403,7 @@ func (r *GitJobReconciler) createCABundleSecret(ctx context.Context, gitrepo *v1 Name: caBundleName(gitrepo), }, Data: map[string][]byte{ - "additional-ca.crt": gitrepo.Spec.CABundle, + bundleCAFile: gitrepo.Spec.CABundle, }, } if err := controllerutil.SetControllerReference(gitrepo, secret, r.Scheme); err != nil {