Skip to content

Commit 88b384a

Browse files
authored
chore: return error from gitSyncEnvs instead of logging the error (#1578)
1 parent 694c8f2 commit 88b384a

File tree

5 files changed

+312
-147
lines changed

5 files changed

+312
-147
lines changed

pkg/reconcilermanager/controllers/gitsync_env.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"time"
2222

2323
corev1 "k8s.io/api/core/v1"
24-
"k8s.io/klog/v2"
2524
"kpt.dev/configsync/pkg/api/configsync"
2625
)
2726

@@ -242,7 +241,7 @@ func useCACert(caCertSecretRef string) bool {
242241
return caCertSecretRef != ""
243242
}
244243

245-
func gitSyncEnvs(_ context.Context, opts options) []corev1.EnvVar {
244+
func gitSyncEnvs(_ context.Context, opts options) ([]corev1.EnvVar, error) {
246245
var result []corev1.EnvVar
247246
result = append(result, corev1.EnvVar{
248247
Name: GitSyncRepo,
@@ -350,8 +349,7 @@ func gitSyncEnvs(_ context.Context, opts options) []corev1.EnvVar {
350349
})
351350
}
352351
default:
353-
// TODO b/168553377 Return error while setting up gitSyncData.
354-
klog.Errorf("Unrecognized secret type %s", opts.secretType)
352+
return nil, fmt.Errorf("Unrecognized secret type %q", opts.secretType)
355353
}
356-
return result
354+
return result, nil
357355
}

pkg/reconcilermanager/controllers/reposync_controller.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ func (r *RepoSyncReconciler) upsertManagedObjects(ctx context.Context, reconcile
275275
return fmt.Errorf("upserting helm config maps: %w", err)
276276
}
277277

278-
containerEnvs := r.populateContainerEnvs(ctx, rs, reconcilerRef.Name)
278+
containerEnvs, err := r.populateContainerEnvs(ctx, rs, reconcilerRef.Name)
279+
if err != nil {
280+
return fmt.Errorf("populating container environment variables: %w", err)
281+
}
279282
mut := r.mutationsFor(ctx, rs, containerEnvs)
280283

281284
// Upsert Namespace reconciler deployment.
@@ -881,7 +884,7 @@ func (r *RepoSyncReconciler) mapObjectToRepoSync(ctx context.Context, obj client
881884
return requests
882885
}
883886

884-
func (r *RepoSyncReconciler) populateContainerEnvs(ctx context.Context, rs *v1beta1.RepoSync, reconcilerName string) map[string][]corev1.EnvVar {
887+
func (r *RepoSyncReconciler) populateContainerEnvs(ctx context.Context, rs *v1beta1.RepoSync, reconcilerName string) (map[string][]corev1.EnvVar, error) {
885888
result := map[string][]corev1.EnvVar{
886889
reconcilermanager.HydrationController: hydrationEnvs(hydrationOptions{
887890
sourceType: rs.Spec.SourceType,
@@ -911,9 +914,12 @@ func (r *RepoSyncReconciler) populateContainerEnvs(ctx context.Context, rs *v1be
911914
webhookEnabled: r.webhookEnabled,
912915
}),
913916
}
917+
918+
var err error
919+
914920
switch rs.Spec.SourceType {
915921
case configsync.GitSource:
916-
result[reconcilermanager.GitSync] = gitSyncEnvs(ctx, options{
922+
result[reconcilermanager.GitSync], err = gitSyncEnvs(ctx, options{
917923
ref: rs.Spec.Git.Revision,
918924
branch: rs.Spec.Git.Branch,
919925
repo: rs.Spec.Git.Repo,
@@ -925,6 +931,9 @@ func (r *RepoSyncReconciler) populateContainerEnvs(ctx context.Context, rs *v1be
925931
caCertSecretRef: v1beta1.GetSecretName(rs.Spec.Git.CACertSecretRef),
926932
knownHost: r.isKnownHostsEnabled(rs.Spec.Git.Auth),
927933
})
934+
if err != nil {
935+
return nil, err
936+
}
928937
if EnableAskpassSidecar(rs.Spec.SourceType, rs.Spec.Git.Auth) {
929938
result[reconcilermanager.GCENodeAskpassSidecar] = gceNodeAskPassSidecarEnvs(rs.Spec.GCPServiceAccountEmail)
930939
}
@@ -944,7 +953,7 @@ func (r *RepoSyncReconciler) populateContainerEnvs(ctx context.Context, rs *v1be
944953
caCertSecretRef: v1beta1.GetSecretName(rs.Spec.Helm.CACertSecretRef),
945954
})
946955
}
947-
return result
956+
return result, nil
948957
}
949958

950959
// This check surfaces the RepoSync NN length constraint earlier as a validation error.

0 commit comments

Comments
 (0)