diff --git a/pkg/controller/runtimecomponent/runtimecomponent_controller.go b/pkg/controller/runtimecomponent/runtimecomponent_controller.go index 34400bea0..b0fc38af7 100644 --- a/pkg/controller/runtimecomponent/runtimecomponent_controller.go +++ b/pkg/controller/runtimecomponent/runtimecomponent_controller.go @@ -334,6 +334,12 @@ func (r *ReconcileRuntimeComponent) Reconcile(request reconcile.Request) (reconc reqLogger.V(1).Info(fmt.Sprintf("%s is not supported on the cluster", applicationsv1beta1.SchemeGroupVersion.String())) } + if r.IsOpenShift() { + // The order of items passed to the MergeMaps matters here! Annotations from GetOpenShiftAnnotations have higher importance. Otherwise, + // it is not possible to override converted annotations. + instance.Annotations = appstacksutils.MergeMaps(instance.Annotations, appstacksutils.GetOpenShiftAnnotations(instance)) + } + currentGen := instance.Generation err = r.GetClient().Update(context.TODO(), instance) if err != nil { @@ -440,9 +446,6 @@ func (r *ReconcileRuntimeComponent) Reconcile(request reconcile.Request) (reconc ksvc := &servingv1alpha1.Service{ObjectMeta: defaultMeta} err = r.CreateOrUpdate(ksvc, instance, func() error { appstacksutils.CustomizeKnativeService(ksvc, instance) - if r.IsOpenShift() { - ksvc.Spec.Template.ObjectMeta.Annotations = appstacksutils.MergeMaps(appstacksutils.GetConnectToAnnotation(instance), ksvc.Spec.Template.ObjectMeta.Annotations) - } return nil }) @@ -510,9 +513,6 @@ func (r *ReconcileRuntimeComponent) Reconcile(request reconcile.Request) (reconc appstacksutils.CustomizeStatefulSet(statefulSet, instance) appstacksutils.CustomizePodSpec(&statefulSet.Spec.Template, instance) appstacksutils.CustomizePersistence(statefulSet, instance) - if r.IsOpenShift() { - statefulSet.Annotations = appstacksutils.MergeMaps(appstacksutils.GetConnectToAnnotation(instance), statefulSet.Annotations) - } return nil }) if err != nil { @@ -541,9 +541,6 @@ func (r *ReconcileRuntimeComponent) Reconcile(request reconcile.Request) (reconc err = r.CreateOrUpdate(deploy, instance, func() error { appstacksutils.CustomizeDeployment(deploy, instance) appstacksutils.CustomizePodSpec(&deploy.Spec.Template, instance) - if r.IsOpenShift() { - deploy.Annotations = appstacksutils.MergeMaps(appstacksutils.GetConnectToAnnotation(instance), deploy.Annotations) - } return nil }) if err != nil { diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 4b65a8db6..549695637 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -233,7 +233,6 @@ func CustomizePodSpec(pts *corev1.PodTemplateSpec, ba common.BaseComponent) { appContainer.Ports[0].ContainerPort = ba.GetService().GetPort() } - appContainer.Image = ba.GetStatus().GetImageReference() if ba.GetService().GetPortName() != "" { appContainer.Ports[0].Name = ba.GetService().GetPortName() @@ -672,6 +671,7 @@ func GetWatchNamespaces() ([]string, error) { // MergeMaps returns a map containing the union of al the key-value pairs from the input maps. The order of the maps passed into the // func, defines the importance. e.g. if (keyA, value1) is in map1, and (keyA, value2) is in map2, mergeMaps(map1, map2) would contain (keyA, value2). +// If the input map is nil, it is treated as empty map. func MergeMaps(maps ...map[string]string) map[string]string { dest := make(map[string]string) @@ -787,6 +787,24 @@ func GetConnectToAnnotation(ba common.BaseComponent) map[string]string { return anno } +// GetOpenShiftAnnotations returns OpenShift specific annotations +func GetOpenShiftAnnotations(ba common.BaseComponent) map[string]string { + // Conversion table between the pseudo Open Container Initiative <-> OpenShift annotations + conversionMap := map[string]string{ + "image.opencontainers.org/source": "app.openshift.io/vcs-uri", + "image.opencontainers.org/revision": "app.openshift.io/vcs-ref", + } + + annos := map[string]string{} + for from, to := range conversionMap { + if annoVal, ok := ba.GetAnnotations()[from]; ok { + annos[to] = annoVal + } + } + + return MergeMaps(annos, GetConnectToAnnotation(ba)) +} + // IsClusterWide returns true if watchNamespaces is set to [""] func IsClusterWide(watchNamespaces []string) bool { return len(watchNamespaces) == 1 && watchNamespaces[0] == ""