Skip to content

Commit

Permalink
[v0.10] Create cabundle secret (#2831)
Browse files Browse the repository at this point in the history
This ensures that the gitOps controller creates the necessary secret
specified by `caBundle`.
---------

Co-authored-by: sebastienmusso <[email protected]>
Co-authored-by: Mario Manno <[email protected]>
  • Loading branch information
3 people authored Sep 11, 2024
1 parent 668edfc commit 23f0047
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/cmd/controller/gitops/reconciler/gitjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -393,6 +396,28 @@ func (r *GitJobReconciler) createTargetsConfigMap(ctx context.Context, gitrepo *
return err
}

func (r *GitJobReconciler) createCABundleSecret(ctx context.Context, gitrepo *v1alpha1.GitRepo) error {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: gitrepo.ObjectMeta.Namespace,
Name: caBundleName(gitrepo),
},
Data: map[string][]byte{
bundleCAFile: 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 {
Expand Down

0 comments on commit 23f0047

Please sign in to comment.