artifactory-node-statefulset.yaml 17.7 KB
Newer Older
Joe Mayer's avatar
Joe Mayer committed
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
  name: {{ template "artifactory-ha.node.name" . }}
  labels:
    app: {{ template "artifactory-ha.name" . }}
    chart: {{ template "artifactory-ha.chart" . }}
    component: {{ .Values.artifactory.name }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
spec:
  serviceName: {{ template "artifactory-ha.node.name" . }}
  replicas: {{ .Values.artifactory.node.replicaCount }}
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: {{ template "artifactory-ha.name" . }}
      role: {{ template "artifactory-ha.node.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "artifactory-ha.name" . }}
        role: {{ template "artifactory-ha.node.name" . }}
        component: {{ .Values.artifactory.name }}
        release: {{ .Release.Name }}
      annotations:
        checksum/binarystore: {{ include (print $.Template.BasePath "/artifactory-binarystore.yaml") . | sha256sum }}
      {{- range $key, $value := .Values.artifactory.annotations }}
        {{ $key }}: {{ $value | quote }}
      {{- end }}
    spec:
      serviceAccountName: {{ template "artifactory-ha.serviceAccountName" . }}
      terminationGracePeriodSeconds: {{ .Values.artifactory.terminationGracePeriodSeconds}}
    {{- if .Values.imagePullSecrets }}
      imagePullSecrets:
      - name: {{ .Values.imagePullSecrets }}
    {{- end }}
      securityContext:
        runAsUser: {{ .Values.artifactory.uid }}
        fsGroup: {{ .Values.artifactory.uid }}
      initContainers:
    {{- if eq .Values.artifactory.persistence.type "file-system" }}
      {{- if .Values.artifactory.persistence.fileSystem.existingSharedClaim.enabled }}
      - name: "create-artifactory-data-dir"
        image: "{{ .Values.initContainerImage }}"
        imagePullPolicy: {{ .Values.artifactory.image.pullPolicy }}
        command:
        - 'sh'
        - '-c'
        - >
          mkdir {{ .Values.artifactory.persistence.fileSystem.existingSharedClaim.dataDir }}
        volumeMounts:
        - mountPath: {{ .Values.artifactory.persistence.mountPath | quote }}
          name: volume
      {{- end }}          
    {{- end }}          
      - name: "remove-lost-found"
        image: "{{ .Values.initContainerImage }}"
        imagePullPolicy: {{ .Values.artifactory.image.pullPolicy }}
        command:
        - 'sh'
        - '-c'
        - >
          if [ -d {{ .Values.artifactory.persistence.mountPath }}/lost+found ]; then
            rm -rfv {{ .Values.artifactory.persistence.mountPath }}/lost+found
          fi
        volumeMounts:
        - mountPath: {{ .Values.artifactory.persistence.mountPath | quote }}
          name: volume
      - name: "wait-for-db"
        image: "{{ .Values.initContainerImage }}"
        command:
        - 'sh'
        - '-c'
        - >
      {{- if .Values.postgresql.enabled }}
          until nc -z -w 2 {{ .Release.Name }}-postgresql {{ .Values.postgresql.service.port }} && echo database ok; do
      {{- else }}
        {{- if and .Values.database.host .Values.database.port }}
          until nc -z -w 2 {{ .Values.database.host }} {{ .Values.database.port }} && echo database ok; do
        {{- else }}
          until true; do
        {{- end }}
      {{- end }}
            sleep 2;
          done;
    {{- if .Values.artifactory.customInitContainers }}
{{ tpl .Values.artifactory.customInitContainers . | indent 6 }}
    {{- end }}
      containers:
      - name: {{ .Values.artifactory.name }}
        image: '{{ .Values.artifactory.image.repository }}:{{ default .Chart.AppVersion .Values.artifactory.image.version }}'
        imagePullPolicy: {{ .Values.artifactory.image.pullPolicy }}
        securityContext:
          allowPrivilegeEscalation: false
      {{- if .Values.artifactory.preStartCommand }}
        command:
        - '/bin/sh'
        - '-c'
        - >
          {{- if .Values.artifactory.userPluginSecrets }}
          echo "Copying plugins";
          cp -Lrf /tmp/plugin/*/* /tmp/plugins;
          {{- end }}
          echo "Running custom preStartCommand command";
          {{ .Values.artifactory.preStartCommand }};
          /entrypoint-artifactory.sh
      {{- end }}
      {{- if .Values.artifactory.postStartCommand }}
        lifecycle:
          postStart:
            exec:
              command:
              - '/bin/sh'
              - '-c'
              - >
                echo;
                {{ .Values.artifactory.postStartCommand }}
      {{- end }}
        env:
      {{- if .Values.postgresql.enabled }}
        - name: DB_TYPE
          value: 'postgresql'
        - name: DB_HOST
          value: '{{ .Release.Name }}-postgresql'
        - name: DB_PORT
          value: '{{ .Values.postgresql.service.port }}'
        - name: DB_USER
          value: '{{ .Values.postgresql.postgresUser }}'
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ .Release.Name }}-postgresql
              key: postgres-password
      {{- else }}
        - name: DB_TYPE
          value: '{{ required "Must set database.type when not using the PostgreSQL sub-chart (postgresql.enabled=false) " .Values.database.type }}'
        {{- if or .Values.database.url .Values.database.secrets.url }}
        - name: DB_URL
        {{- if .Values.database.url }}
          value: '{{.Values.database.url }}'
        {{- else }}
          valueFrom:
            secretKeyRef:
              name: {{ .Values.database.secrets.url.name }}
              key: {{ .Values.database.secrets.url.key }}
        {{- end }}
        {{- else }}
        - name: DB_HOST
          value: '{{ .Values.database.host }}'
        - name: DB_PORT
          value: '{{ .Values.database.port }}'
        {{- end }}
        {{- if .Values.database.secrets.user }}
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: {{ .Values.database.secrets.user.name }}
              key: {{ .Values.database.secrets.user.key }}
        {{- end }}
        {{- if .Values.database.secrets.password }}
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ .Values.database.secrets.password.name }}
              key: {{ .Values.database.secrets.password.key }}
        {{- else }}
        {{- if and .Values.database.type .Values.database.user }}
        - name: DB_USER
          value: '{{ .Values.database.user }}'
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "artifactory-ha.fullname" . }}
              key: db-password
        {{- end }}
        {{- end }}
      {{- end }}
        - name: EXTRA_JAVA_OPTIONS
          value: "
      {{- if .Values.artifactory.node.javaOpts.xms }}
          -Xms{{ .Values.artifactory.node.javaOpts.xms }}
      {{- end}}
      {{- if .Values.artifactory.node.javaOpts.xmx }}
          -Xmx{{ .Values.artifactory.node.javaOpts.xmx }}
      {{- end}}
      {{- if .Values.artifactory.javaOpts.other }}
          {{ .Values.artifactory.javaOpts.other }}
      {{- end}}
      {{- if .Values.artifactory.node.javaOpts.other }}
          {{ .Values.artifactory.node.javaOpts.other }}
      {{- end}}
      {{- if .Values.artifactory.replicator.enabled }}
          -Dartifactory.releasebundle.feature.enabled=true
      {{- end }}
            "
        {{- if .Values.artifactory.replicator.enabled }}
        - name: START_LOCAL_REPLICATOR
          value: "true"
        {{- end }}
        - name: ARTIFACTORY_MASTER_KEY
          valueFrom:
            secretKeyRef:
              name: "{{ .Values.artifactory.masterKeySecretName | default (include "artifactory-ha.fullname" .) }}"
              key: master-key
        - name: HA_IS_PRIMARY
          value: "false"
        - name: HA_MEMBERSHIP_PORT
          value: "{{ .Values.artifactory.membershipPort }}"
        - name: HA_NODE_ID
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: ART_PRIMARY_BASE_URL
          value: 'http://{{ template "artifactory-ha.primary.name" . }}:8081/artifactory'
      {{- if eq .Values.artifactory.persistence.type "file-system" }}
        {{- if .Values.artifactory.persistence.fileSystem.existingSharedClaim.enabled }}
        - name: HA_DATA_DIR
          value: "{{ .Values.artifactory.persistence.fileSystem.existingSharedClaim.dataDir }}"
        - name: HA_BACKUP_DIR
          value: "{{ .Values.artifactory.persistence.fileSystem.existingSharedClaim.backupDir }}"
        {{- end }}
      {{- end }}
      {{- if eq .Values.artifactory.persistence.type "nfs" }}
        - name: HA_DATA_DIR
          value: "{{ .Values.artifactory.persistence.nfs.dataDir }}"
        - name: HA_BACKUP_DIR
          value: "{{ .Values.artifactory.persistence.nfs.backupDir }}"
      {{- end }}
      {{- range .Values.artifactory.extraEnvironmentVariables }}
        - name: {{ .name }}
          value: '{{ tpl .value $ }}'
      {{- end }}
        ports:
        - containerPort: {{ .Values.artifactory.internalPort }}
        volumeMounts:
      {{- if .Values.artifactory.userPluginSecrets }}
        - name: tmp-plugins
          mountPath: "/tmp/plugins/"
      {{- range .Values.artifactory.userPluginSecrets }}
        - name: {{ tpl . $ }}
          mountPath: "/tmp/plugin/{{ tpl . $ }}"
      {{- end }}
      {{- end }}
        - name: volume
          mountPath: "{{ .Values.artifactory.persistence.mountPath }}"
      {{- if eq .Values.artifactory.persistence.type "file-system" }}
        {{- if .Values.artifactory.persistence.fileSystem.existingSharedClaim.enabled }}
          {{- range $sharedClaimNumber, $e := until (.Values.artifactory.persistence.fileSystem.existingSharedClaim.numberOfExistingClaims|int) }}
        - name: artifactory-ha-data-{{ $sharedClaimNumber }}
          mountPath: "{{ $.Values.artifactory.persistence.fileSystem.existingSharedClaim.dataDir }}/filestore{{ $sharedClaimNumber }}"
          {{- end }}
        - name: artifactory-ha-backup
          mountPath: "{{ $.Values.artifactory.persistence.fileSystem.existingSharedClaim.backupDir }}"
        {{- end }}
      {{- end }}
      {{- if eq .Values.artifactory.persistence.type "nfs" }}
        - name: artifactory-ha-data
          mountPath: "{{ .Values.artifactory.persistence.nfs.dataDir }}"
        - name: artifactory-ha-backup
          mountPath: "{{ .Values.artifactory.persistence.nfs.backupDir }}"
      {{- else }}
        - name: binarystore-xml
          mountPath: "/artifactory_extra_conf/binarystore.xml"
          subPath: binarystore.xml
      {{- end }}
      {{- if .Values.artifactory.replicator.enabled }}
        - name: replicator-config
          mountPath: "/replicator_extra_conf/replicator.yaml"
          subPath: replicator.yaml
      {{- end }}
        - name: installer-info
          mountPath: "/artifactory_extra_conf/info/installer-info.json"
          subPath: installer-info.json
        resources:
{{ toYaml .Values.artifactory.node.resources | indent 10 }}
        {{- if .Values.artifactory.readinessProbe.enabled }}
        readinessProbe:
          httpGet:
            path: {{ .Values.artifactory.readinessProbe.path }}
            port: 8040
          initialDelaySeconds: {{ .Values.artifactory.readinessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.artifactory.readinessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.artifactory.readinessProbe.timeoutSeconds }}
          failureThreshold: {{ .Values.artifactory.readinessProbe.failureThreshold }}
          successThreshold: {{ .Values.artifactory.readinessProbe.successThreshold }}
        {{- end }}
        {{- if .Values.artifactory.livenessProbe.enabled }}
        livenessProbe:
          httpGet:
            path: {{ .Values.artifactory.livenessProbe.path }}
            port: 8040
          initialDelaySeconds: {{ .Values.artifactory.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.artifactory.livenessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.artifactory.livenessProbe.timeoutSeconds }}
          failureThreshold: {{ .Values.artifactory.livenessProbe.failureThreshold }}
          successThreshold: {{ .Values.artifactory.livenessProbe.successThreshold }}
        {{- end }}
      {{- $image := .Values.logger.image.repository }}
      {{- $tag := .Values.logger.image.tag }}
      {{- $mountPath := .Values.artifactory.persistence.mountPath }}
      {{- range .Values.artifactory.loggers }}
      - name: {{ . | replace "_" "-" | replace "." "-" }}
        image: {{ $image }}
        tag: {{ $tag }}
        command:
        - tail
        args:
        - "-F"
        - "{{ $mountPath }}/logs/{{ . }}"
        volumeMounts:
        - name: volume
          mountPath: {{ $mountPath }}
      {{- end }}
      {{ if .Values.artifactory.catalinaLoggers }}
      {{- range .Values.artifactory.catalinaLoggers }}
      - name: {{ . | replace "_" "-" | replace "." "-" }}
        image: {{ $image }}
        tag: {{ $tag }}
        command:
        - 'sh'
        - '-c'
        - 'sh /scripts/tail-log.sh {{ $mountPath }}/logs/catalina {{ . }}'
        volumeMounts:
        - name: volume
          mountPath: {{ $mountPath }}
        - name: catalina-logger
          mountPath: /scripts/tail-log.sh
          subPath: tail-log.sh
      {{- end }}
      {{- end }}
    {{- if .Values.artifactory.customSidecarContainers }}
{{ tpl .Values.artifactory.customSidecarContainers . | indent 6 }}
    {{- end }}
    {{- with .Values.artifactory.node.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- if .Values.artifactory.node.affinity }}
    {{- with .Values.artifactory.node.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- else if eq .Values.artifactory.node.podAntiAffinity.type "soft" }}
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              topologyKey: {{ .Values.artifactory.node.podAntiAffinity.topologyKey }}
              labelSelector:
                matchLabels:
                  app: {{ template "artifactory-ha.name" . }}
                  release: {{ .Release.Name }}
                  {{- if eq .Values.artifactory.service.pool "members" }}
                  role: {{ template "artifactory-ha.node.name" . }}
                  {{- end }}
    {{- else if eq .Values.artifactory.node.podAntiAffinity.type "hard" }}
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - topologyKey: {{ .Values.artifactory.node.podAntiAffinity.topologyKey }}
            labelSelector:
              matchLabels:
                app: {{ template "artifactory-ha.name" . }}
                release: {{ .Release.Name }}
                {{- if eq .Values.artifactory.service.pool "members" }}
                role: {{ template "artifactory-ha.node.name" . }}
                {{- end }}
    {{- end }}
    {{- with .Values.artifactory.node.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
      volumes:
      - name: binarystore-xml
        configMap:
          name: {{ template "artifactory-ha.fullname" . }}-bs
      - name: installer-info
        configMap:
          name: {{ template "artifactory-ha.fullname" . }}-installer-info
      {{- if .Values.artifactory.userPluginSecrets }}
      - name: tmp-plugins
        emptyDir: {}
      {{- range .Values.artifactory.userPluginSecrets }}
      - name: {{ tpl . $ }}
        secret:
          secretName: {{ tpl . $ }}
      {{- end }}
      {{- end }}
      {{- if .Values.artifactory.replicator.enabled }}
      - name: replicator-config
        configMap:
          name: {{ template "artifactory-ha.fullname" . }}-replicator-config
      {{- end }}
      {{- if .Values.artifactory.catalinaLoggers }}
      - name: catalina-logger
        configMap:
          name: {{ template "artifactory-ha.fullname" . }}-catalina-logger
      {{- end }}
      {{- if eq .Values.artifactory.persistence.type "file-system" }}
        {{- if .Values.artifactory.persistence.fileSystem.existingSharedClaim.enabled }}
          {{- range $sharedClaimNumber, $e := until (.Values.artifactory.persistence.fileSystem.existingSharedClaim.numberOfExistingClaims|int) }}
      - name: artifactory-ha-data-{{ $sharedClaimNumber }}
        persistentVolumeClaim:
          claimName: {{ template "artifactory-ha.fullname" $ }}-data-pvc-{{ $sharedClaimNumber }}
          {{- end }}
      - name: artifactory-ha-backup
        persistentVolumeClaim:
          claimName: {{ template "artifactory-ha.fullname" $ }}-backup-pvc
        {{- end }}
      {{- end }}
      {{- if eq .Values.artifactory.persistence.type "nfs" }}
      - name: artifactory-ha-data
        persistentVolumeClaim:
          claimName: {{ template "artifactory-ha.fullname" . }}-data-pvc
      - name: artifactory-ha-backup
        persistentVolumeClaim:
          claimName: {{ template "artifactory-ha.fullname" . }}-backup-pvc
      {{- end }}
      {{- if .Values.artifactory.customVolumes }}
{{ tpl .Values.artifactory.customVolumes . | indent 6 }}
      {{- end }}
      {{- if not .Values.artifactory.persistence.enabled }}
      - name: volume
        emptyDir:
          sizeLimit: {{ .Values.artifactory.persistence.size }}
      {{- else }}
  volumeClaimTemplates:
  - metadata:
      name: volume
    {{- if not .Values.artifactory.node.persistence.existingClaim }}
    spec:
      {{- if .Values.artifactory.persistence.storageClass }}
      {{- if (eq "-" .Values.artifactory.persistence.storageClass) }}
      storageClassName: ""
      {{- else }}
      storageClassName: "{{ .Values.artifactory.persistence.storageClass }}"
      {{- end }}
      {{- end }}
      accessModes: [ "{{ .Values.artifactory.persistence.accessMode }}" ]
      resources:
        requests:
          storage: {{ .Values.artifactory.persistence.size }}
    {{- end }}
  {{- end }}