summaryrefslogtreecommitdiffstats
path: root/kubernetes/portal/charts/portal-sdk/templates/deployment.yaml
blob: 1c94c78bb42a2acae0b97aea7a99148d0297317d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Copyright © 2017 Amdocs, Bell Canada
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ include "common.fullname" . }}
  namespace: {{ include "common.namespace" . }}
  labels:
    app: {{ include "common.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        app: {{ include "common.name" . }}
        release: {{ .Release.Name }}
    spec:
      initContainers:
      - name: {{ include "common.name" . }}-readiness
        image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
        imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
        command:
        - /root/ready.py
        args:
        - --container-name
        - {{ .Values.mariadb.chart.name }}
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
      containers:
      - name: {{ include "common.name" . }}
        image: "{{ .Values.global.repository | default .Values.repository }}/{{ .Values.image }}"
        imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
        command:
          - /start-apache-tomcat.sh
        ports:
        - containerPort: {{ .Values.service.internalPort }}
        {{- if eq .Values.liveness.enabled true }}
        livenessProbe:
          tcpSocket:
            port: {{ .Values.service.internalPort }}
          initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
          periodSeconds: {{ .Values.liveness.periodSeconds }}
        {{ end -}}
        readinessProbe:
          tcpSocket:
            port: {{ .Values.service.internalPort }}
          initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
          periodSeconds: {{ .Values.readiness.periodSeconds }}
        volumeMounts:
        - mountPath: /etc/localtime
          name: localtime
          readOnly: true
        - name: properties-onapportalsdk
          mountPath: "{{ .Values.global.env.tomcatDir }}/webapps/ONAPPORTALSDK/WEB-INF/fusion/conf/fusion.properties"
          subPath: fusion.properties
        - name: properties-onapportalsdk
          mountPath: "{{ .Values.global.env.tomcatDir }}/webapps/ONAPPORTALSDK/WEB-INF/conf/system.properties"
          subPath: system.properties
        - name: properties-onapportalsdk
          mountPath: "{{ .Values.global.env.tomcatDir }}/webapps/ONAPPORTALSDK/WEB-INF/classes/portal.properties"
          subPath: portal.properties
        - name: properties-onapportalsdk
          mountPath: "{{ .Values.global.env.tomcatDir }}/webapps/ONAPPORTALSDK/WEB-INF/classes/music.properties"
          subPath: music.properties
        - name: properties-onapportalsdk
          mountPath: "{{ .Values.global.env.tomcatDir }}/webapps/ONAPPORTALSDK/WEB-INF/classes/logback.xml"
          subPath: logback.xml
        - name: portal-tomcat-logs
          mountPath: "{{ .Values.global.env.tomcatDir }}/logs"
        - name: var-log-onap
          mountPath: /var/log/onap
        resources:
{{ toYaml .Values.resources | indent 12 }}
      {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 10 }}
      {{- end -}}
      {{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 10 }}
      {{- end }}
      - name: filebeat-onap
        image: "{{ .Values.global.loggingRepository }}/{{ .Values.global.loggingImage }}"
        imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
        volumeMounts:
        - mountPath: /usr/share/filebeat/filebeat.yml
          name: filebeat-conf
          subPath: filebeat.yml
        - name: portal-data-filebeat
          mountPath: /usr/share/filebeat/data
        - name: var-log-onap
          mountPath: /var/log/onap
      volumes:
        - name: localtime
          hostPath:
            path: /etc/localtime
        - name: properties-onapportalsdk
          configMap:
            name: {{ include "common.fullname" . }}-onapportalsdk
            defaultMode: 0755
        - name: filebeat-conf
          configMap:
            name: portal-filebeat
        - name: var-log-onap
          emptyDir: {}
        - name: portal-data-filebeat
          emptyDir: {}
        - name: portal-tomcat-logs
          emptyDir: {}
      imagePullSecrets:
      - name: "{{ include "common.namespace" . }}-docker-registry-key"
s="k">range src { // If the key doesn't exist already, then just set the key to that value if _, exists := dest[k]; !exists { dest[k] = v continue } nextMap, ok := v.(map[string]interface{}) // If it isn't another map, overwrite the value if !ok { dest[k] = v continue } // Edge case: If the key exists in the destination, but isn't a map destMap, isMap := dest[k].(map[string]interface{}) // If the source map has a map for this key, prefer it if !isMap { dest[k] = v continue } // If we got to this point, it is a map in both, so merge them dest[k] = h.mergeValues(destMap, nextMap) } return dest } // GenerateKubernetesArtifacts a mapping of type to fully evaluated helm template func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFiles []string, values []string) ([]KubernetesResourceTemplate, error) { var outputDir, chartPath, namespace, releaseName string var retData []KubernetesResourceTemplate releaseName = h.releaseName namespace = h.kubeNameSpace // verify chart path exists if _, err := os.Stat(inputPath); err == nil { if chartPath, err = filepath.Abs(inputPath); err != nil { return retData, err } } else { return retData, err } //Create a temp directory in the system temp folder outputDir, err := ioutil.TempDir("", "helm-tmpl-") if err != nil { return retData, pkgerrors.Wrap(err, "Got error creating temp dir") } logger.Info(":: The o/p dir:: ", logger.Fields{"OutPutDirectory ":outputDir}) if namespace == "" { namespace = "default" } // get combined values and create config rawVals, err := h.processValues(valueFiles, values) if err != nil { return retData, err } config := &chart.Config{Raw: string(rawVals), Values: map[string]*chart.Value{}} if msgs := validation.IsDNS1123Label(releaseName); releaseName != "" && len(msgs) > 0 { return retData, fmt.Errorf("release name %s is not a valid DNS label: %s", releaseName, strings.Join(msgs, ";")) } // Check chart requirements to make sure all dependencies are present in /charts c, err := chartutil.Load(chartPath) if err != nil { return retData, pkgerrors.Errorf("Got error: %s", err.Error()) } renderOpts := renderutil.Options{ ReleaseOptions: chartutil.ReleaseOptions{ Name: releaseName, IsInstall: true, IsUpgrade: false, Time: timeconv.Now(), Namespace: namespace, }, KubeVersion: h.kubeVersion, } renderedTemplates, err := renderutil.Render(c, config, renderOpts) if err != nil { return retData, err } newRenderedTemplates := make(map[string]string) //Some manifests can contain multiple yaml documents //This step is splitting them up into multiple files //Each file contains only a single k8s kind for k, v := range renderedTemplates { //Splits into manifest-0, manifest-1 etc if filepath.Base(k) == "NOTES.txt" { continue } rmap := releaseutil.SplitManifests(v) count := 0 for _, v1 := range rmap { key := fmt.Sprintf("%s-%d", k, count) newRenderedTemplates[key] = v1 count = count + 1 } } listManifests := manifest.SplitManifests(newRenderedTemplates) var manifestsToRender []manifest.Manifest //render all manifests in the chart manifestsToRender = listManifests for _, m := range tiller.SortByKind(manifestsToRender) { data := m.Content b := filepath.Base(m.Name) if b == "NOTES.txt" { continue } if strings.HasPrefix(b, "_") { continue } // blank template after execution if h.whitespaceRegex.MatchString(data) { continue } mfilePath := filepath.Join(outputDir, m.Name) utils.EnsureDirectory(mfilePath) err = ioutil.WriteFile(mfilePath, []byte(data), 0666) if err != nil { return retData, err } gvk, err := getGroupVersionKind(data) if err != nil { return retData, err } kres := KubernetesResourceTemplate{ GVK: gvk, FilePath: mfilePath, } retData = append(retData, kres) } return retData, nil } func getGroupVersionKind(data string) (schema.GroupVersionKind, error) { out, err := k8syaml.ToJSON([]byte(data)) if err != nil { return schema.GroupVersionKind{}, pkgerrors.Wrap(err, "Converting yaml to json") } simpleMeta := json.SimpleMetaFactory{} gvk, err := simpleMeta.Interpret(out) if err != nil { return schema.GroupVersionKind{}, pkgerrors.Wrap(err, "Parsing apiversion and kind") } return *gvk, nil } // Resolver is an interface exposes the helm related functionalities type Resolver interface { Resolve(appContent, appProfileContent []byte, overrideValuesOfAppStr []string, appName string) ([]KubernetesResourceTemplate, error) } // Resolve function func (h *TemplateClient) Resolve(appContent []byte, appProfileContent []byte, overrideValuesOfAppStr []string, appName string) ([]KubernetesResourceTemplate, error) { var sortedTemplates []KubernetesResourceTemplate //chartBasePath is the tmp path where the appContent(rawHelmCharts) is extracted. chartBasePath, err := utils.ExtractTarBall(bytes.NewBuffer(appContent)) if err != nil { return sortedTemplates, pkgerrors.Wrap(err, "Extracting appContent") } logger.Info("The chartBasePath ::", logger.Fields{"chartBasePath":chartBasePath}) //prPath is the tmp path where the appProfileContent is extracted. prPath, err := utils.ExtractTarBall(bytes.NewBuffer(appProfileContent)) if err != nil { return sortedTemplates, pkgerrors.Wrap(err, "Extracting Profile Content") } logger.Info("The profile path:: ", logger.Fields{"Profile Path":prPath}) prYamlClient, err := ProcessProfileYaml(prPath, h.manifestName) if err != nil { return sortedTemplates, pkgerrors.Wrap(err, "Processing Profile Manifest") } logger.Info("Got the profileYamlClient..", logger.Fields{}) err = prYamlClient.CopyConfigurationOverrides(chartBasePath) if err != nil { return sortedTemplates, pkgerrors.Wrap(err, "Copying configresources to chart") } chartPath := filepath.Join(chartBasePath, appName) sortedTemplates, err = h.GenerateKubernetesArtifacts(chartPath, []string{prYamlClient.GetValues()}, overrideValuesOfAppStr) if err != nil { return sortedTemplates, pkgerrors.Wrap(err, "Generate final k8s yaml") } return sortedTemplates, nil }