[SO] update cnf-adapter
[oom.git] / kubernetes / aai / components / aai-graphadmin / templates / deployment.yaml
index 033cfa0..4f3b44f 100644 (file)
 */}}
 apiVersion: apps/v1
 kind: Deployment
-metadata:
-  name: {{ include "common.fullname" . }}
-  namespace: {{ include "common.namespace" . }}
-  labels:
-    app: {{ include "common.name" . }}
-    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
-    release: {{ include "common.release" . }}
-    heritage: {{ .Release.Service }}
+metadata: {{- include "common.resourceMetadata" (dict "annotations" .Values.annotations "dot" .) | nindent 2 }}
 spec:
+  {{- if .Values.config.debug.enabled }}
+  replicas: 1
+  {{- else }}
   replicas: {{ .Values.replicaCount }}
+  {{- end }}
+  revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
   minReadySeconds: {{ .Values.minReadySeconds }}
   strategy:
     type: {{ .Values.updateStrategy.type }}
@@ -43,97 +41,141 @@ spec:
     matchLabels:
       app: {{ include "common.name" . }}
   template:
-    metadata:
-      labels:
-        app: {{ include "common.name" . }}
-        release: {{ include "common.release" . }}
-      name: {{ include "common.name" . }}
-      annotations:
-        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
+    metadata: {{- include "common.templateMetadata" . | nindent 6 }}
     spec:
       hostname: aai-graphadmin
       terminationGracePeriodSeconds: {{ .Values.service.terminationGracePeriodSeconds }}
-    {{ if .Values.global.initContainers.enabled }}
+      {{- if .Values.global.initContainers.enabled }}
       initContainers:
-      - command:
-      {{ if .Values.global.jobs.migration.enabled }}
-        - /app/ready.py
-        args:
-        - --job-name
-        - {{ include "common.release" . }}-aai-graphadmin-migration
-      {{  else if .Values.global.jobs.createSchema.enabled  }}
-        - /app/ready.py
-        args:
-        - --job-name
-        - {{ include "common.release" . }}-aai-graphadmin-create-db-schema
-      {{  else }}
-        - /app/ready.py
-        args:
-        - --container-name
-        {{- if .Values.global.cassandra.localCluster }}
-        - aai-cassandra
-        {{- else }}
-        - cassandra
+        {{ include "common.readinessCheck.waitFor" (dict "dot" . "wait_for" .Values.readinessCheck.waitForCassandraService ) | indent 8 | trim }}
+        {{- if not .Values.createDbSchemaViaJob.enabled }}
+        {{- include "aai.waitForSchemaService" . | nindent 8 }}
+        - name: {{ include "common.name" . }}-create-db-schema
+          image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          {{ include "common.containerSecurityContext" . | nindent 10 | trim }}
+          command:
+          - sh
+          args:
+          - -c
+          - |
+            {{- if include "common.onServiceMesh" . }}
+            echo "waiting 15s for istio side cars to be up"; sleep 15s;{{- end }}
+            sh docker-entrypoint.sh createDBSchema.sh;
+            {{ include "common.serviceMesh.killSidecar" . | indent 11 | trim }}
+          env:
+          {{- if .Values.config.debug.enabled }}
+          - name: JVM_OPTS
+            value: {{ .Values.config.debug.args | quote }}
+          {{- end }}
+          {{- if .Values.config.env }}
+          {{- range $key,$value := .Values.config.env }}
+          - name: {{ $key | upper | quote}}
+            value: {{ $value | quote}}
+          {{- end }}
+          {{- end }}
+          - name: BOOTSTRAP_SERVERS
+            value: {{ include "common.release" . }}-strimzi-kafka-bootstrap:9092
+          - name: JAAS_CONFIG
+            valueFrom:
+              secretKeyRef:
+                name: {{ include "common.release" . }}-{{ .Values.global.aaiGraphKafkaUser }}
+                key: sasl.jaas.config
+          {{- if .Values.config.debug.enabled }}
+          ports:
+          - containerPort: {{ .Values.service.debugPort }}
+            name: {{ .Values.service.debugPortName }}
+          {{- end }}
+          volumeMounts:
+          - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-realtime.properties
+            name: config
+            subPath: janusgraph-realtime.properties
+          - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/aaiconfig.properties
+            name: properties
+            subPath: aaiconfig.properties
+          - mountPath: /opt/aai/logroot/AAI-GA
+            name: logs
+          - mountPath: /opt/app/aai-graphadmin/resources/logback.xml
+            name: config
+            subPath: logback.xml
+          - mountPath: /opt/app/aai-graphadmin/resources/localhost-access-logback.xml
+            name: config
+            subPath: localhost-access-logback.xml
+          - mountPath: /opt/app/aai-graphadmin/resources/application.properties
+            name: properties
+            subPath: application.properties
+          resources: {{ include "common.resources" . | nindent 12 }}
         {{- end }}
-        - --container-name
-        - aai-schema-service
-      {{  end  }}
-        env:
-        - name: NAMESPACE
-          valueFrom:
-            fieldRef:
-              apiVersion: v1
-              fieldPath: metadata.namespace
-        image: {{ include "repositoryGenerator.image.readiness" . }}
-        imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
-        name: {{ include "common.name" . }}-readiness
-      {{  end  }}
+      {{- end }}
+      {{ include "common.podSecurityContext" . | indent 6 | trim }}
       containers:
       - name: {{ include "common.name" . }}
         image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
         imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+        {{ include "common.containerSecurityContext" . | indent 8 | trim }}
         env:
-        - name: LOCAL_USER_ID
-          value: {{ .Values.securityContext.user_id | quote }}
-        - name: LOCAL_GROUP_ID
-          value: {{ .Values.securityContext.group_id | quote }}
+        {{- if .Values.config.env }}
+        {{- range $key,$value := .Values.config.env }}
+        - name: {{ $key | upper | quote}}
+          value: {{ $value | quote}}
+        {{- end }}
+        {{- end }}
         - name: INTERNAL_PORT_1
-          value: {{ .Values.service.internalPort | quote }}
+          value: {{ .Values.service.appPort | quote }}
         - name: INTERNAL_PORT_2
-          value: {{ .Values.service.internalPort2 | quote }}
+          value: {{ .Values.service.debugPort | quote }}
         - name: INTERNAL_PORT_3
-          value: {{ .Values.service.internalPort3 | quote }}
+          value: {{ .Values.service.actuatorPort | quote }}
+        - name: BOOTSTRAP_SERVERS
+          value: {{ include "common.release" . }}-strimzi-kafka-bootstrap:9092
+        - name: JAAS_CONFIG
+          valueFrom:
+            secretKeyRef:
+              name: {{ include "common.release" . }}-{{ .Values.global.aaiGraphKafkaUser }}
+              key: sasl.jaas.config
+        {{- if .Values.config.profiling.enabled }}
+        - name: PRE_JVM_ARGS
+          value: '{{ join " " .Values.config.profiling.args }}'
+        {{- end }}
+        {{- if .Values.config.debug.enabled }}
+        - name: POST_JVM_ARGS
+          value: {{ .Values.config.debug.args | quote }}
+        {{- end }}
         volumeMounts:
-        - mountPath: /etc/localtime
-          name: localtime
-          readOnly: true
         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-realtime.properties
           name: config
           subPath: janusgraph-realtime.properties
-        - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/janusgraph-cached.properties
-          name: config
-          subPath: janusgraph-cached.properties
         - mountPath: /opt/app/aai-graphadmin/resources/etc/appprops/aaiconfig.properties
           name: properties
           subPath: aaiconfig.properties
         - mountPath: /opt/aai/logroot/AAI-RES
           name: logs
+        - mountPath: /opt/app/aai-graphadmin/logs
+          name: script-logs
         - mountPath: /opt/app/aai-graphadmin/resources/logback.xml
           name: config
           subPath: logback.xml
         - mountPath: /opt/app/aai-graphadmin/resources/localhost-access-logback.xml
           name: config
           subPath: localhost-access-logback.xml
-        - mountPath: /opt/app/aai-graphadmin/resources/etc/auth/realm.properties
-          name: config
-          subPath: realm.properties
         - mountPath: /opt/app/aai-graphadmin/resources/application.properties
           name: properties
           subPath: application.properties
+        - mountPath: /tmp
+          name: tmp-volume
         ports:
-        - containerPort: {{ .Values.service.internalPort }}
-        - containerPort: {{ .Values.service.internalPort2 }}
-        - containerPort: {{ .Values.service.internalPort3 }}
+        - containerPort: {{ .Values.service.appPort }}
+          name: {{ .Values.service.appPortName }}
+        {{- if .Values.config.debug.enabled }}
+        - containerPort: {{ .Values.service.debugPort }}
+          name: {{ .Values.service.debugPortName }}
+        {{- end }}
+        {{- if .Values.config.profiling.enabled }}
+        - containerPort: {{ .Values.service.profilingPort }}
+          name: {{ .Values.service.profilingPortName }}
+        {{- end }}
+        - containerPort: {{ .Values.service.actuatorPort }}
+          name: {{ .Values.service.actuatorPortName }}
         lifecycle:
           # wait for active requests (long-running tasks) to be finished
           # Before the SIGTERM is invoked, Kubernetes exposes a preStop hook in the Pod.
@@ -143,42 +185,58 @@ spec:
                 - sh
                 - -c
                 - |
-                  while (netstat -an | grep ESTABLISHED | grep -e $INTERNAL_PORT_1 -e $INTERNAL_PORT_2)
-                  do sleep 10
+                  while (netstat -an | grep ESTABLISHED | grep -e $INTERNAL_PORT_1 -e $INTERNAL_PORT_2) do
+                    echo "Still active connections. Waiting for active requests to be finished"
+                    sleep 3
                   done
-        # disable liveness probe when breakpoints set in debugger
-        # so K8s doesn't restart unresponsive container
-        {{ if .Values.liveness.enabled }}
+        # disable liveness probe when
+        # debugging.enabled=true or profiling.enabled=true
+        {{- if and .Values.liveness.enabled (not (or .Values.config.debug.enabled .Values.config.profiling.enabled)) }}
         livenessProbe:
-          tcpSocket:
-            port: {{ .Values.service.internalPort }}
+          httpGet:
+            port: {{ .Values.service.actuatorPort }}
+            path: {{ .Values.liveness.path }}
+          {{- if .Values.liveness.initialDelaySeconds }}
           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
+          {{- end }}
           periodSeconds: {{ .Values.liveness.periodSeconds }}
-        {{ end }}
+        {{- end }}
         readinessProbe:
-          tcpSocket:
-            port: {{ .Values.service.internalPort }}
+          httpGet:
+            port: {{ .Values.service.actuatorPort }}
+            path: {{ .Values.readiness.path }}
+          {{- if .Values.readiness.initialDelaySeconds }}
           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
+          {{- end }}
           periodSeconds: {{ .Values.readiness.periodSeconds }}
+        startupProbe:
+          httpGet:
+            port: {{ .Values.service.actuatorPort }}
+            path: {{ .Values.startup.path }}
+          failureThreshold: {{ .Values.startup.failureThreshold }}
+          periodSeconds: {{ .Values.startup.periodSeconds }}
         resources: {{ include "common.resources" . | nindent 10 }}
       {{- if .Values.nodeSelector }}
       nodeSelector:
-{{ toYaml .Values.nodeSelector | indent 8 }}
+      {{ toYaml .Values.nodeSelector | indent 8 }}
       {{- end -}}
       {{- if .Values.affinity }}
       affinity:
-{{ toYaml .Values.affinity | indent 8 }}
+      {{ toYaml .Values.affinity | indent 8 }}
       {{- end }}
-
       # side car containers
       {{ include "common.log.sidecar" . | nindent 6 }}
       serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
       volumes:
-      - name: localtime
-        hostPath:
-          path: /etc/localtime
+      - name: tmp-volume
+        emptyDir:
+          sizeLimit: {{ .Values.volumes.tmpSizeLimit }}
       - name: logs
-        emptyDir: {}
+        emptyDir:
+          sizeLimit: {{ .Values.volumes.logSizeLimit }}
+      - name: script-logs
+        emptyDir:
+          sizeLimit: {{ .Values.volumes.scriptlogSizeLimit }}
       {{ include "common.log.volumes" (dict "dot" . "configMapNamePrefix" (tpl .Values.logConfigMapNamePrefix .)) | nindent 6 }}
       - name: config
         configMap:
@@ -187,5 +245,4 @@ spec:
         configMap:
           name: {{ include "common.fullname" . }}-properties
       restartPolicy: {{ .Values.restartPolicy }}
-      imagePullSecrets:
-      - name: {{ include "common.namespace" . }}-docker-registry-key
+      {{- include "common.imagePullSecrets" . | nindent 6 }}