Skip to content
Snippets Groups Projects
deployment.yaml 5.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • Andrea Michelotti's avatar
    Andrea Michelotti committed
    apiVersion: apps/v1
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
    kind: StatefulSet
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
    metadata:
      name: {{ include "jupyter-control-notebook-chart.fullname" . }}
      labels:
        {{- include "jupyter-control-notebook-chart.labels" . | nindent 4 }}
    spec:
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
      serviceName: "jupyter-notebook"
      replicas: {{ .Values.replicaCount }}
      selector:
        matchLabels:
          {{- include "jupyter-control-notebook-chart.selectorLabels" . | nindent 6 }}
      template:
        metadata:
          {{- with .Values.podAnnotations }}
          annotations:
            {{- toYaml . | nindent 8 }}
          {{- end }}
          labels:
            {{- include "jupyter-control-notebook-chart.selectorLabels" . | nindent 8 }}
        spec:
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          {{- if .Values.serviceAccountName }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          serviceAccountName: {{ .Values.serviceAccountName | quote }}
          {{- end }}
          securityContext:
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
            {{- toYaml .Values.securityContext | nindent 8 }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          {{- if .Values.securityContext.runAsUser }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          fsGroup: {{ .Values.securityContext.runAsUser }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          {{- end }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          initContainers:
          - name: fix-permissions
            image: baltig.infn.it:4567/epics-containers/container-init
            command: 
            - sh 
            - -c
            - |
    
              mountdir=/home/jovyan
              cd $mountdir
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              id=`id`
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              url="{{ .Values.gitRepoConfig.url }}"
    
              echo "ID: $id git $url"
              if [ -n "$url" ]; then
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
                clone_dir=$(basename "$url" .git)
                echo "* git directory $clone_dir"
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
                if [ -d $clone_dir ]; then
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
                  cd $clone_dir
                  git pull --recurse-submodules
                else 
                  if [ -n "{{ .Values.gitRepoConfig.branch }}" ]; then
                    git clone -b {{ .Values.gitRepoConfig.branch }} {{ .Values.gitRepoConfig.url }} --recurse-submodules 
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
                  else
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
                    git clone {{ .Values.gitRepoConfig.url }} --recurse-submodules 
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              fi
              ls -latr
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
            volumeMounts:
            - name: jupyter-data
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              mountPath: /home/jovyan
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
            resources:
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
    {{ toYaml .Values.resources | indent 12 }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
            securityContext:
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              {{- toYaml .Values.securityContext | nindent 8 }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          {{- with .Values.imagePullSecrets }}
          imagePullSecrets:
            {{- toYaml . | nindent 8 }}
          {{- end }}
          containers:
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          - name: {{ .Chart.Name }}
            image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
            imagePullPolicy: {{ .Values.image.pullPolicy }}
            volumeMounts:
            - name: jupyter-data
              mountPath: /home/jovyan/work
            {{- range .Values.nfsMounts }}
            - name: {{ .name }}
              mountPath: {{ .mountPath }}
            {{- end }}
            stdin: {{ .Values.image.stdinOpen }}
            tty: {{ .Values.image.tty }}
            {{- if .Values.epicsConfiguration.name }}
            envFrom:
            - configMapRef:
                name: {{ .Values.epicsConfiguration.name }}
            {{- end }}
            env:
            - name: NOTEBOOK_ARGS
              value: "--PasswordIdentityProvider.hashed_password={{ .Values.hashedpass }}"
            - name: JUPYTER_SERVER_URL
              value: "http://127.0.0.1:8888"
            {{- if .Values.epicsConfiguration.gateway }}
            - name: EPICS_CA_ADDR_LIST
              value: {{ .Values.epicsConfiguration.gateway | quote }}
            - name: EPICS_CA_AUTO_ADDR_LIST
              value: "NO"
            {{- end }}
            {{- range .Values.nfsMounts }}
            - name: {{ .name | upper }}_SERVER
              value: {{ .server | quote }}
            - name: {{ .name | upper }}_SERVER_PATH
              value: {{ .path | quote }}
            - name: {{ .name | upper }}_DIR
              value: {{ .mountPath | quote }}
            {{- end }}
            ports:
            - name: http
              containerPort: 8888
              protocol: TCP
            command: 
            - sh 
            - -c
            - |
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              {{- range .Values.nfsMounts }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              mkdir -p {{ .mountPath }}/{{ include "jupyter-control-notebook-chart.fullname" . }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              {{- end }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
              echo "Starting Notebook"
              {{- range .Values.pip }}
              echo "installing {{.}}"
              pip install {{.}}
              {{- end }}
              tini -g -- start.sh /usr/local/bin/start-notebook.py
            resources:
              {{- toYaml .Values.resources | nindent 10 }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          {{- with .Values.nodeSelector }}
          nodeSelector:
            {{- toYaml . | nindent 8 }}
          {{- end }}
          {{- with .Values.affinity }}
          affinity:
            {{- toYaml . | nindent 8 }}
          {{- end }}
          {{- with .Values.tolerations }}
          tolerations:
            {{- toYaml . | nindent 8 }}
          {{- end }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          {{- if .Values.dataVolume.claim }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          volumes:
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          {{- range .Values.nfsMounts }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          - name: {{ .name }}
            nfs:
              server: {{ .server }}
              path: {{ .path }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          {{- end }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
          - name: jupyter-data
            persistentVolumeClaim:
              claimName: {{ .Values.dataVolume.claim }}
    
          {{- end }}
    
    Andrea Michelotti's avatar
    Andrea Michelotti committed
      {{- if not .Values.dataVolume.claim }}
      volumeClaimTemplates:
      - metadata:
          name: jupyter-data
        spec:
          accessModes: [ "ReadWriteOnce" ]
          resources:
            requests:
              storage: {{ .Values.dataVolume.size }}
      {{- end }}