feat: add runtime icons on OpenShift (#1116)

Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
This commit is contained in:
Zbynek Roubalik 2022-07-18 18:18:59 +02:00 committed by GitHub
parent 7a760fbf57
commit a7671e45a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 6 deletions

View File

@ -311,6 +311,10 @@ func generateNewService(f fn.Function, decorator DeployDecorator) (*v1.Service,
Spec: v1.ServiceSpec{
ConfigurationSpec: v1.ConfigurationSpec{
Template: v1.RevisionTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
Annotations: annotations,
},
Spec: v1.RevisionSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{
@ -346,6 +350,7 @@ func updateService(f fn.Function, newEnv []corev1.EnvVar, newEnvFrom []corev1.En
for k, v := range f.Annotations {
service.ObjectMeta.Annotations[k] = v
service.Spec.Template.ObjectMeta.Annotations[k] = v
}
// I hate that we have to do this. Users should not see these values.
// It is an implementation detail. These health endpoints should not be
@ -372,6 +377,7 @@ func updateService(f fn.Function, newEnv []corev1.EnvVar, newEnvFrom []corev1.En
return service, err
}
service.ObjectMeta.Labels = labels
service.Spec.Template.ObjectMeta.Labels = labels
err = flags.UpdateImage(&service.Spec.Template.Spec.PodSpec, f.ImageWithDigest())
if err != nil {

View File

@ -5,12 +5,21 @@ import (
)
const (
AnnotationOpenShiftVcsUri = "app.openshift.io/vcs-uri"
AnnotationOpenShiftVcsRef = "app.openshift.io/vcs-ref"
annotationOpenShiftVcsUri = "app.openshift.io/vcs-uri"
annotationOpenShiftVcsRef = "app.openshift.io/vcs-ref"
LabelAppK8sInstance = "app.kubernetes.io/instance"
labelAppK8sInstance = "app.kubernetes.io/instance"
labelOpenShiftRuntime = "app.openshift.io/runtime"
)
var iconValuesForRuntimes = map[string]string{
"go": "golang",
"node": "nodejs",
"python": "python",
"quarkus": "quarkus",
"springboot": "spring-boot",
}
type OpenshiftMetadataDecorator struct{}
func (o OpenshiftMetadataDecorator) UpdateAnnotations(f fn.Function, annotations map[string]string) map[string]string {
@ -18,10 +27,10 @@ func (o OpenshiftMetadataDecorator) UpdateAnnotations(f fn.Function, annotations
annotations = map[string]string{}
}
if f.Git.URL != nil {
annotations[AnnotationOpenShiftVcsUri] = *f.Git.URL
annotations[annotationOpenShiftVcsUri] = *f.Git.URL
}
if f.Git.Revision != nil {
annotations[AnnotationOpenShiftVcsRef] = *f.Git.Revision
annotations[annotationOpenShiftVcsRef] = *f.Git.Revision
}
return annotations
@ -32,7 +41,14 @@ func (o OpenshiftMetadataDecorator) UpdateLabels(f fn.Function, labels map[strin
labels = map[string]string{}
}
labels[LabelAppK8sInstance] = f.Name
// this label is used for referencing a Tekton Pipeline and deployed KService
labels[labelAppK8sInstance] = f.Name
// if supported, set the label representing a runtime icon in Developer Console
iconValue, ok := iconValuesForRuntimes[f.Runtime]
if ok {
labels[labelOpenShiftRuntime] = iconValue
}
return labels
}