Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.10] Create cabundle secret #2831

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading