@@ -23,6 +23,7 @@ import (
2323 "net/url"
2424 "os"
2525 "path"
26+ "regexp"
2627 "strings"
2728 "time"
2829
@@ -187,7 +188,8 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
187188 }
188189
189190 // Emit an event if we did not have an artifact before, or the revision has changed
190- if chart .Status .Artifact == nil || reconciledChart .Status .Artifact .Revision != chart .Status .Artifact .Revision {
191+ if (chart .Status .Artifact == nil && reconciledChart .Status .Artifact != nil ) ||
192+ reconciledChart .Status .Artifact .Revision != chart .Status .Artifact .Revision {
191193 r .event (reconciledChart , events .EventSeverityInfo , sourcev1 .HelmChartReadyMessage (reconciledChart ))
192194 }
193195 r .recordReadiness (reconciledChart )
@@ -275,6 +277,12 @@ func (r *HelmChartReconciler) getSource(ctx context.Context, chart sourcev1.Helm
275277
276278func (r * HelmChartReconciler ) reconcileFromHelmRepository (ctx context.Context ,
277279 repository sourcev1.HelmRepository , chart sourcev1.HelmChart , force bool ) (sourcev1.HelmChart , error ) {
280+ // TODO: move this to a validation webhook once the discussion around
281+ // certificates has settled: https://github.com/fluxcd/image-reflector-controller/issues/69
282+ if err := validHelmChartName (chart .Spec .Chart ); err != nil {
283+ return sourcev1 .HelmChartNotReady (chart , sourcev1 .ChartPullFailedReason , err .Error ()), nil
284+ }
285+
278286 // Configure ChartRepository getter options
279287 var clientOpts []getter.Option
280288 if secret , err := r .getHelmRepositorySecret (ctx , & repository ); err != nil {
@@ -877,3 +885,15 @@ func (r *HelmChartReconciler) requestsForBucketChange(obj handler.MapObject) []r
877885 }
878886 return reqs
879887}
888+
889+ // validHelmChartName returns an error if the given string is not a
890+ // valid Helm chart name; a valid name must be lower case letters
891+ // and numbers, words may be separated with dashes (-).
892+ // Ref: https://helm.sh/docs/chart_best_practices/conventions/#chart-names
893+ func validHelmChartName (s string ) error {
894+ chartFmt := regexp .MustCompile ("^([-a-z0-9]*)$" )
895+ if ! chartFmt .MatchString (s ) {
896+ return fmt .Errorf ("invalid chart name %q, a valid name must be lower case letters and numbers and MAY be seperated with dashes (-)" , s )
897+ }
898+ return nil
899+ }
0 commit comments