Skip to content

Commit

Permalink
[installer]: add customization functions to components
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Emms authored and roboquat committed Jun 24, 2022
1 parent 090c32c commit 8fad588
Show file tree
Hide file tree
Showing 38 changed files with 280 additions and 210 deletions.
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
8 changes: 5 additions & 3 deletions install/installer/pkg/components/content-service/configmap.go
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
7 changes: 4 additions & 3 deletions install/installer/pkg/components/database/init/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func job(ctx *common.RenderContext) ([]runtime.Object, error) {
}

objectMeta := metav1.ObjectMeta{
Name: fmt.Sprintf("%s-session", Component),
Namespace: ctx.Namespace,
Labels: common.DefaultLabels(Component),
Name: fmt.Sprintf("%s-session", Component),
Namespace: ctx.Namespace,
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaBatchJob),
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaBatchJob),
}

return []runtime.Object{&batchv1.Job{
Expand Down
Loading

0 comments on commit 8fad588

Please sign in to comment.