Skip to content

Commit

Permalink
Merge pull request #54 from application-stacks/vcs
Browse files Browse the repository at this point in the history
Adding OpenShift specific annotations
  • Loading branch information
navidsh authored Mar 18, 2020
2 parents e1e068f + 6c57491 commit cd13d98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
15 changes: 6 additions & 9 deletions pkg/controller/runtimecomponent/runtimecomponent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
})

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 19 additions & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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] == ""
Expand Down

0 comments on commit cd13d98

Please sign in to comment.