internal/helm: return callback on empty TLS config

...and no-op on empty valuesFile string.
This commit is contained in:
Hidde Beydals 2020-09-21 23:27:38 +02:00
parent 4da80b65e5
commit 969a46f4d6
4 changed files with 7 additions and 13 deletions

View File

@ -296,9 +296,7 @@ func (r *HelmChartReconciler) reconcileFromHelmRepository(ctx context.Context,
err = fmt.Errorf("auth options error: %w", err) err = fmt.Errorf("auth options error: %w", err)
return sourcev1.HelmChartNotReady(chart, sourcev1.AuthenticationFailedReason, err.Error()), err return sourcev1.HelmChartNotReady(chart, sourcev1.AuthenticationFailedReason, err.Error()), err
} }
if cleanup != nil { defer cleanup()
defer cleanup()
}
clientOpts = opts clientOpts = opts
} }
@ -435,11 +433,9 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
return chart, nil return chart, nil
} }
// Overwrite default values if instructed to // Overwrite default values if configured
if chart.Spec.ValuesFile != "" { if err := helm.OverwriteChartDefaultValues(chartPath, chart.Spec.ValuesFile); err != nil {
if err := helm.OverwriteChartDefaultValues(chartPath, chart.Spec.ValuesFile); err != nil { return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPackageFailedReason, err.Error()), err
return sourcev1.HelmChartNotReady(chart, sourcev1.ChartPackageFailedReason, err.Error()), err
}
} }
// Ensure artifact directory exists // Ensure artifact directory exists

View File

@ -195,9 +195,7 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
err = fmt.Errorf("auth options error: %w", err) err = fmt.Errorf("auth options error: %w", err)
return sourcev1.HelmRepositoryNotReady(repository, sourcev1.AuthenticationFailedReason, err.Error()), err return sourcev1.HelmRepositoryNotReady(repository, sourcev1.AuthenticationFailedReason, err.Error()), err
} }
if cleanup != nil { defer cleanup()
defer cleanup()
}
clientOpts = opts clientOpts = opts
} }

View File

@ -28,7 +28,7 @@ import (
// OverwriteChartDefaultValues overwrites the chart default values file in the // OverwriteChartDefaultValues overwrites the chart default values file in the
// given chartPath with the contents of the given valuesFile. // given chartPath with the contents of the given valuesFile.
func OverwriteChartDefaultValues(chartPath, valuesFile string) error { func OverwriteChartDefaultValues(chartPath, valuesFile string) error {
if valuesFile == chartutil.ValuesfileName { if valuesFile == "" || valuesFile == chartutil.ValuesfileName {
return nil return nil
} }
srcPath := path.Join(chartPath, valuesFile) srcPath := path.Join(chartPath, valuesFile)

View File

@ -60,7 +60,7 @@ func TLSClientConfigFromSecret(secret corev1.Secret) (getter.Option, func(), err
certBytes, keyBytes, caBytes := secret.Data["certFile"], secret.Data["keyFile"], secret.Data["caFile"] certBytes, keyBytes, caBytes := secret.Data["certFile"], secret.Data["keyFile"], secret.Data["caFile"]
switch { switch {
case len(certBytes)+len(keyBytes)+len(caBytes) == 0: case len(certBytes)+len(keyBytes)+len(caBytes) == 0:
return nil, nil, nil return nil, func() {}, nil
case (len(certBytes) > 0 && len(keyBytes) == 0) || (len(keyBytes) > 0 && len(certBytes) == 0): case (len(certBytes) > 0 && len(keyBytes) == 0) || (len(keyBytes) > 0 && len(certBytes) == 0):
return nil, nil, fmt.Errorf("invalid '%s' secret data: fields 'certFile' and 'keyFile' require each other's presence", return nil, nil, fmt.Errorf("invalid '%s' secret data: fields 'certFile' and 'keyFile' require each other's presence",
secret.Name) secret.Name)