Skip to content

[installer]: add customization functions to components #10857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions install/installer/pkg/common/customize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the MIT License. See License-MIT.txt in the project root for license information.

package common

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func CustomizeAnnotation(ctx *RenderContext, component string, typeMeta metav1.TypeMeta, existingAnnotations ...func() map[string]string) map[string]string {
annotations := make(map[string]string, 0)

for _, e := range existingAnnotations {
for k, v := range e() {
annotations[k] = v
}
}

return annotations
}

func CustomizeEnvvar(ctx *RenderContext, component string, existingEnvvars []corev1.EnvVar) []corev1.EnvVar {
return existingEnvvars
}

func CustomizeLabel(ctx *RenderContext, component string, typeMeta metav1.TypeMeta, existingLabels ...func() map[string]string) map[string]string {
labels := DefaultLabels(component)

for _, e := range existingLabels {
for k, v := range e() {
labels[k] = v
}
}

return labels
}
7 changes: 4 additions & 3 deletions install/installer/pkg/components/agent-smith/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
&corev1.ConfigMap{
TypeMeta: common.TypeMetaConfigmap,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: common.DefaultLabels(Component),
Name: Component,
Namespace: ctx.Namespace,
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
},
Data: map[string]string{
"config.json": string(fc),
Expand Down
19 changes: 11 additions & 8 deletions install/installer/pkg/components/agent-smith/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func daemonset(ctx *common.RenderContext) ([]runtime.Object, error) {
labels := common.DefaultLabels(Component)
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDaemonset)

configHash, err := common.ObjectHash(configmap(ctx))
if err != nil {
Expand All @@ -30,16 +30,19 @@ func daemonset(ctx *common.RenderContext) ([]runtime.Object, error) {
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: map[string]string{
common.AnnotationConfigChecksum: configHash,
},
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDaemonset, func() map[string]string {
return map[string]string{
common.AnnotationConfigChecksum: configHash,
}
}),
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{MatchLabels: labels},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Labels: labels,
Name: Component,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDaemonset),
},
Spec: corev1.PodSpec{
Affinity: common.NodeAffinity(cluster.AffinityLabelWorkspacesRegular, cluster.AffinityLabelWorkspacesHeadless),
Expand All @@ -64,7 +67,7 @@ func daemonset(ctx *common.RenderContext) ([]runtime.Object, error) {
Name: "config",
MountPath: "/config",
}},
Env: common.MergeEnv(
Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.WorkspaceTracingEnv(ctx),
[]corev1.EnvVar{{
Expand All @@ -73,7 +76,7 @@ func daemonset(ctx *common.RenderContext) ([]runtime.Object, error) {
FieldRef: &corev1.ObjectFieldSelector{FieldPath: "spec.nodeName"},
},
}},
),
)),
SecurityContext: &corev1.SecurityContext{
Privileged: pointer.Bool(true),
ProcMount: func() *corev1.ProcMountType { r := corev1.DefaultProcMount; return &r }(),
Expand Down
7 changes: 4 additions & 3 deletions install/installer/pkg/components/blobserve/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
&corev1.ConfigMap{
TypeMeta: common.TypeMetaConfigmap,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: common.DefaultLabels(Component),
Name: Component,
Namespace: ctx.Namespace,
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
},
Data: map[string]string{
"config.json": string(fc),
Expand Down
21 changes: 12 additions & 9 deletions install/installer/pkg/components/blobserve/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
labels := common.DefaultLabels(Component)
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment)

volumeName := "pull-secret"
var secretName string
Expand Down Expand Up @@ -54,9 +54,10 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
&appsv1.Deployment{
TypeMeta: common.TypeMetaDeployment,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{MatchLabels: labels},
Expand All @@ -67,9 +68,11 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: map[string]string{
common.AnnotationConfigChecksum: configHash,
},
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment, func() map[string]string {
return map[string]string{
common.AnnotationConfigChecksum: configHash,
}
}),
},
Spec: corev1.PodSpec{
Affinity: common.NodeAffinity(cluster.AffinityLabelWorkspaceServices),
Expand Down Expand Up @@ -110,10 +113,10 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
Privileged: pointer.Bool(false),
RunAsUser: pointer.Int64(1000),
},
Env: common.MergeEnv(
Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.WorkspaceTracingEnv(ctx),
),
)),
VolumeMounts: []corev1.VolumeMount{{
Name: "config",
MountPath: "/mnt/config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package content_service

import (
"fmt"

"github.com/gitpod-io/gitpod/common-go/baseserver"

"github.com/gitpod-io/gitpod/content-service/api/config"
Expand All @@ -32,9 +33,10 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
return []runtime.Object{&corev1.ConfigMap{
TypeMeta: common.TypeMetaConfigmap,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: common.DefaultLabels(Component),
Name: Component,
Namespace: ctx.Namespace,
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
},
Data: map[string]string{
"config.json": string(fc),
Expand Down
21 changes: 12 additions & 9 deletions install/installer/pkg/components/content-service/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
labels := common.DefaultLabels(Component)
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment)

configHash, err := common.ObjectHash(configmap(ctx))
if err != nil {
Expand Down Expand Up @@ -65,14 +65,14 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
Privileged: pointer.Bool(false),
RunAsUser: pointer.Int64(1000),
},
Env: common.MergeEnv(
Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
common.DefaultEnv(&ctx.Config),
common.WorkspaceTracingEnv(ctx),
[]corev1.EnvVar{{
Name: "GRPC_GO_RETRY",
Value: "on",
}},
),
)),
VolumeMounts: []corev1.VolumeMount{{
Name: "config",
MountPath: "/config",
Expand All @@ -90,9 +90,10 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
&v1.Deployment{
TypeMeta: common.TypeMetaDeployment,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
},
Spec: v1.DeploymentSpec{
Selector: &metav1.LabelSelector{MatchLabels: labels},
Expand All @@ -103,9 +104,11 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: map[string]string{
common.AnnotationConfigChecksum: configHash,
},
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment, func() map[string]string {
return map[string]string{
common.AnnotationConfigChecksum: configHash,
}
}),
},
Spec: podSpec,
},
Expand Down
20 changes: 11 additions & 9 deletions install/installer/pkg/components/dashboard/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ import (
)

func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
labels := common.DefaultLabels(Component)
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment)

return []runtime.Object{
&appsv1.Deployment{
TypeMeta: common.TypeMetaDeployment,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{MatchLabels: labels},
Replicas: common.Replicas(ctx, Component),
Strategy: common.DeploymentStrategy,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
},
Spec: corev1.PodSpec{
Affinity: common.NodeAffinity(cluster.AffinityLabelMeta),
Expand All @@ -62,9 +64,9 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
SecurityContext: &corev1.SecurityContext{
Privileged: pointer.Bool(false),
},
Env: common.MergeEnv(
Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
common.DefaultEnv(&ctx.Config),
),
)),
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Expand Down
18 changes: 11 additions & 7 deletions install/installer/pkg/components/database/cloudsql/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cloudsql

import (
"fmt"

"github.com/gitpod-io/gitpod/installer/pkg/cluster"
"github.com/gitpod-io/gitpod/installer/pkg/common"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -17,15 +18,16 @@ import (
)

func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
labels := common.DefaultLabels(Component)
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment)

return []runtime.Object{
&appsv1.Deployment{
TypeMeta: common.TypeMetaDeployment,
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-cloud-sql-proxy", Component),
Namespace: ctx.Namespace,
Labels: labels,
Name: fmt.Sprintf("%s-cloud-sql-proxy", Component),
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
},
Spec: appsv1.DeploymentSpec{
Strategy: appsv1.DeploymentStrategy{
Expand All @@ -39,9 +41,10 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
Replicas: common.Replicas(ctx, Component),
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
},
Spec: corev1.PodSpec{
Affinity: &corev1.Affinity{
Expand Down Expand Up @@ -84,6 +87,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
MountPath: "/credentials",
Name: "gcloud-sql-token",
}},
Env: common.CustomizeEnvvar(ctx, Component, []corev1.EnvVar{}),
}},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
&corev1.ConfigMap{
TypeMeta: common.TypeMetaConfigmap,
ObjectMeta: metav1.ObjectMeta{
Name: SQLInitScripts,
Namespace: ctx.Namespace,
Labels: common.DefaultLabels(Component),
Name: SQLInitScripts,
Namespace: ctx.Namespace,
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
},
Data: map[string]string{
"init.sql": initScriptData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
// service this doesn't use the common.GenerateService function
// because it's more complex than this caters for
func service(ctx *common.RenderContext) ([]runtime.Object, error) {
labels := common.DefaultLabels(Component)
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaService)

return []runtime.Object{&corev1.Service{
TypeMeta: common.TypeMetaService,
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaService),
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Expand Down
7 changes: 4 additions & 3 deletions install/installer/pkg/components/database/init/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
&corev1.ConfigMap{
TypeMeta: common.TypeMetaConfigmap,
ObjectMeta: metav1.ObjectMeta{
Name: sqlInitScripts,
Namespace: ctx.Namespace,
Labels: common.DefaultLabels(Component),
Name: sqlInitScripts,
Namespace: ctx.Namespace,
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
},
Data: map[string]string{
"init.sql": initScriptData,
Expand Down
Loading