@@ -38,18 +38,21 @@ import (
3838)
3939
4040const (
41- Label = "helmcharts.helm.cattle.io/chart"
42- Annotation = "helmcharts.helm.cattle.io/configHash"
43- Unmanaged = "helmcharts.helm.cattle.io/unmanaged"
4441 SecretType = "helmcharts.helm.cattle.io/values"
45- ManagedBy = "helmcharts.cattle.io/managed-by"
4642 CRDName = "helmcharts.helm.cattle.io"
4743 ConfigCRDName = "helmchartconfigs.helm.cattle.io"
4844
4945 TaintExternalCloudProvider = "node.cloudprovider.kubernetes.io/uninitialized"
50- LabelNodeRolePrefix = "node-role.kubernetes.io/"
51- LabelControlPlaneSuffix = "control-plane"
52- LabelEtcdSuffix = "etcd"
46+
47+ AnnotationChartURL = "helm.cattle.io/chart-url"
48+ AnnotationConfigHash = "helmcharts.helm.cattle.io/configHash"
49+ AnnotationManagedBy = "helmcharts.cattle.io/managed-by"
50+ AnnotationUnmanaged = "helmcharts.helm.cattle.io/unmanaged"
51+
52+ LabelChartName = "helmcharts.helm.cattle.io/chart"
53+ LabelNodeRolePrefix = "node-role.kubernetes.io/"
54+ LabelControlPlaneSuffix = "control-plane"
55+ LabelEtcdSuffix = "etcd"
5356
5457 FailurePolicyReinstall = "reinstall"
5558 FailurePolicyAbort = "abort"
@@ -320,7 +323,8 @@ func (c *Controller) OnChange(chart *v1.HelmChart, chartStatus v1.HelmChartStatu
320323 }
321324
322325 // emit an event to indicate that this Helm chart is being applied
323- c .recorder .Eventf (chart , corev1 .EventTypeNormal , "ApplyJob" , "Applying HelmChart using Job %s/%s" , job .Namespace , job .Name )
326+ annotations := map [string ]string {AnnotationConfigHash : job .Spec .Template .ObjectMeta .Annotations [AnnotationConfigHash ]}
327+ c .recorder .AnnotatedEventf (chart , annotations , corev1 .EventTypeNormal , "ApplyJob" , "Applying HelmChart from %s using Job %s/%s " , chartSource (chart ), job .Namespace , job .Name )
324328
325329 return append (objs , job ), chartStatus , nil
326330}
@@ -430,10 +434,10 @@ func (c *Controller) shouldManage(chart *v1.HelmChart) (bool, error) {
430434 return false , nil
431435 }
432436 if chart .Annotations != nil {
433- if _ , ok := chart .Annotations [Unmanaged ]; ok {
437+ if _ , ok := chart .Annotations [AnnotationUnmanaged ]; ok {
434438 return false , nil
435439 }
436- managedBy , ok := chart .Annotations [ManagedBy ]
440+ managedBy , ok := chart .Annotations [AnnotationManagedBy ]
437441 if ok {
438442 // if the label exists, only handle this if the managedBy label matches that of this controller
439443 return managedBy == c .managedBy , nil
@@ -444,10 +448,10 @@ func (c *Controller) shouldManage(chart *v1.HelmChart) (bool, error) {
444448 chartCopy := chart .DeepCopy ()
445449 if chartCopy .Annotations == nil {
446450 chartCopy .SetAnnotations (map [string ]string {
447- ManagedBy : c .managedBy ,
451+ AnnotationManagedBy : c .managedBy ,
448452 })
449453 } else {
450- chartCopy .Annotations [ManagedBy ] = c .managedBy
454+ chartCopy .Annotations [AnnotationManagedBy ] = c .managedBy
451455 }
452456 _ , err := c .helms .Update (chartCopy )
453457 return false , err
@@ -573,15 +577,15 @@ func job(chart *v1.HelmChart, apiServerPort string) (*batch.Job, *corev1.Secret,
573577 Name : fmt .Sprintf ("helm-%s-%s" , action , chart .Name ),
574578 Namespace : chart .Namespace ,
575579 Labels : map [string ]string {
576- Label : chart .Name ,
580+ LabelChartName : chart .Name ,
577581 },
578582 },
579583 Spec : batch.JobSpec {
580584 Template : corev1.PodTemplateSpec {
581585 ObjectMeta : metav1.ObjectMeta {
582586 Annotations : map [string ]string {},
583587 Labels : map [string ]string {
584- Label : chart .Name ,
588+ LabelChartName : chart .Name ,
585589 },
586590 },
587591 Spec : corev1.PodSpec {
@@ -1174,7 +1178,7 @@ func hashObjects(job *batch.Job, objs ...metav1.Object) {
11741178 }
11751179 }
11761180
1177- job .Spec .Template .ObjectMeta .Annotations [Annotation ] = fmt .Sprintf ("SHA256=%X" , hash .Sum (nil ))
1181+ job .Spec .Template .ObjectMeta .Annotations [AnnotationConfigHash ] = fmt .Sprintf ("SHA256=%X" , hash .Sum (nil ))
11781182}
11791183
11801184func setBackOffLimit (job * batch.Job , backOffLimit * int32 ) {
@@ -1190,3 +1194,35 @@ func setSecurityContext(job *batch.Job, chart *v1.HelmChart) {
11901194 job .Spec .Template .Spec .Containers [0 ].SecurityContext = chart .Spec .SecurityContext
11911195 }
11921196}
1197+
1198+ // chartSource returns a string describing the source of the chart:
1199+ // chartContent, chart URL, or repo+version
1200+ func chartSource (chart * v1.HelmChart ) string {
1201+ if chart == nil {
1202+ return "<unknown>"
1203+ }
1204+
1205+ if chart .Spec .ChartContent != "" {
1206+ if url := chart .Annotations [AnnotationChartURL ]; url != "" {
1207+ return fmt .Sprintf ("inline spec.chartContent from %s" , url )
1208+ }
1209+ return "inline spec.chartContent"
1210+ }
1211+
1212+ if strings .HasPrefix (chart .Spec .Chart , "oci://" ) {
1213+ if chart .Spec .Version != "" {
1214+ return fmt .Sprintf ("version %s from OCI registry %s" , chart .Spec .Version , chart .Spec .Chart )
1215+ }
1216+ return fmt .Sprintf ("latest stable version from OCI registry %s" , chart .Spec .Chart )
1217+ }
1218+
1219+ if strings .Contains (chart .Spec .Chart , "://" ) {
1220+ return chart .Spec .Chart
1221+ }
1222+
1223+ if chart .Spec .Version != "" {
1224+ return fmt .Sprintf ("%s version %s from chart repository %s" , chart .Spec .Chart , chart .Spec .Version , chart .Spec .Repo )
1225+ }
1226+
1227+ return fmt .Sprintf ("latest stable version of %s from chart repository %s" , chart .Spec .Chart , chart .Spec .Repo )
1228+ }
0 commit comments