|
| 1 | +// Copyright (c) 2021 Gitpod GmbH. All rights reserved. |
| 2 | +// Licensed under the GNU Affero General Public License (AGPL). |
| 3 | +// See License.AGPL.txt in the project root for license information. |
| 4 | + |
| 5 | +package openfga |
| 6 | + |
| 7 | +import ( |
| 8 | + "github.com/gitpod-io/gitpod/installer/pkg/cluster" |
| 9 | + "github.com/gitpod-io/gitpod/installer/pkg/common" |
| 10 | + |
| 11 | + appsv1 "k8s.io/api/apps/v1" |
| 12 | + corev1 "k8s.io/api/core/v1" |
| 13 | + "k8s.io/apimachinery/pkg/api/resource" |
| 14 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 15 | + "k8s.io/apimachinery/pkg/runtime" |
| 16 | + "k8s.io/apimachinery/pkg/util/intstr" |
| 17 | + "k8s.io/utils/pointer" |
| 18 | +) |
| 19 | + |
| 20 | +func deployment(ctx *common.RenderContext) ([]runtime.Object, error) { |
| 21 | + labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment) |
| 22 | + |
| 23 | + return []runtime.Object{ |
| 24 | + &appsv1.Deployment{ |
| 25 | + TypeMeta: common.TypeMetaDeployment, |
| 26 | + ObjectMeta: metav1.ObjectMeta{ |
| 27 | + Name: Component, |
| 28 | + Namespace: ctx.Namespace, |
| 29 | + Labels: labels, |
| 30 | + Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment), |
| 31 | + }, |
| 32 | + Spec: appsv1.DeploymentSpec{ |
| 33 | + Selector: &metav1.LabelSelector{MatchLabels: common.DefaultLabels(Component)}, |
| 34 | + Replicas: common.Replicas(ctx, Component), |
| 35 | + Strategy: common.DeploymentStrategy, |
| 36 | + Template: corev1.PodTemplateSpec{ |
| 37 | + ObjectMeta: metav1.ObjectMeta{ |
| 38 | + Name: Component, |
| 39 | + Namespace: ctx.Namespace, |
| 40 | + Labels: labels, |
| 41 | + Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment), |
| 42 | + }, |
| 43 | + Spec: corev1.PodSpec{ |
| 44 | + Affinity: common.NodeAffinity(cluster.AffinityLabelMeta), |
| 45 | + PriorityClassName: common.SystemNodeCritical, |
| 46 | + ServiceAccountName: Component, |
| 47 | + EnableServiceLinks: pointer.Bool(false), |
| 48 | + DNSPolicy: "ClusterFirst", |
| 49 | + RestartPolicy: "Always", |
| 50 | + TerminationGracePeriodSeconds: pointer.Int64(30), |
| 51 | + SecurityContext: &corev1.PodSecurityContext{ |
| 52 | + RunAsNonRoot: pointer.Bool(false), |
| 53 | + }, |
| 54 | + Containers: []corev1.Container{{ |
| 55 | + Name: ContainerName, |
| 56 | + Image: ctx.ImageName(common.ThirdPartyContainerRepo(ctx.Config.Repository, RegistryRepo), RegistryImage, ImageTag), |
| 57 | + ImagePullPolicy: corev1.PullIfNotPresent, |
| 58 | + Args: []string{ |
| 59 | + "run", |
| 60 | + "--log-format=json", |
| 61 | + }, |
| 62 | + Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv( |
| 63 | + common.DefaultEnv(&ctx.Config), |
| 64 | + )), |
| 65 | + Ports: []corev1.ContainerPort{ |
| 66 | + { |
| 67 | + ContainerPort: ContainerGRPCPort, |
| 68 | + Name: ContainerGRPCName, |
| 69 | + Protocol: *common.TCPProtocol, |
| 70 | + }, |
| 71 | + { |
| 72 | + ContainerPort: ContainerHTTPPort, |
| 73 | + Name: ContainerHTTPName, |
| 74 | + Protocol: *common.TCPProtocol, |
| 75 | + }, |
| 76 | + { |
| 77 | + ContainerPort: ContainerPlaygroundPort, |
| 78 | + Name: ContainerPlaygroundName, |
| 79 | + Protocol: *common.TCPProtocol, |
| 80 | + }, |
| 81 | + }, |
| 82 | + Resources: common.ResourceRequirements(ctx, Component, ContainerName, corev1.ResourceRequirements{ |
| 83 | + Requests: corev1.ResourceList{ |
| 84 | + "cpu": resource.MustParse("1m"), |
| 85 | + "memory": resource.MustParse("30Mi"), |
| 86 | + }, |
| 87 | + }), |
| 88 | + SecurityContext: &corev1.SecurityContext{ |
| 89 | + RunAsGroup: pointer.Int64(65532), |
| 90 | + RunAsNonRoot: pointer.Bool(true), |
| 91 | + RunAsUser: pointer.Int64(65532), |
| 92 | + }, |
| 93 | + LivenessProbe: &corev1.Probe{ |
| 94 | + ProbeHandler: corev1.ProbeHandler{ |
| 95 | + HTTPGet: &corev1.HTTPGetAction{ |
| 96 | + Path: "/healthz", |
| 97 | + Port: intstr.IntOrString{IntVal: ContainerHTTPPort}, |
| 98 | + Scheme: corev1.URISchemeHTTP, |
| 99 | + }, |
| 100 | + }, |
| 101 | + FailureThreshold: 3, |
| 102 | + SuccessThreshold: 1, |
| 103 | + TimeoutSeconds: 1, |
| 104 | + }, |
| 105 | + ReadinessProbe: &corev1.Probe{ |
| 106 | + ProbeHandler: corev1.ProbeHandler{ |
| 107 | + HTTPGet: &corev1.HTTPGetAction{ |
| 108 | + Path: "/healthz", |
| 109 | + Port: intstr.IntOrString{IntVal: ContainerHTTPPort}, |
| 110 | + Scheme: corev1.URISchemeHTTP, |
| 111 | + }, |
| 112 | + }, |
| 113 | + FailureThreshold: 3, |
| 114 | + SuccessThreshold: 1, |
| 115 | + TimeoutSeconds: 1, |
| 116 | + }, |
| 117 | + }}, |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, nil |
| 123 | +} |
0 commit comments