Mohammed Naser | b8eccd2 | 2023-02-10 05:55:56 +0000 | [diff] [blame] | 1 | {{- if .Values.toolbox.enabled }} |
| 2 | --- |
| 3 | apiVersion: apps/v1 |
| 4 | kind: Deployment |
| 5 | metadata: |
| 6 | name: rook-ceph-tools |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 7 | namespace: {{ .Release.Namespace }} # namespace:cluster |
Mohammed Naser | b8eccd2 | 2023-02-10 05:55:56 +0000 | [diff] [blame] | 8 | labels: |
| 9 | app: rook-ceph-tools |
| 10 | spec: |
| 11 | replicas: 1 |
| 12 | selector: |
| 13 | matchLabels: |
| 14 | app: rook-ceph-tools |
| 15 | template: |
| 16 | metadata: |
| 17 | labels: |
| 18 | app: rook-ceph-tools |
| 19 | spec: |
| 20 | dnsPolicy: ClusterFirstWithHostNet |
| 21 | {{- $network := .Values.cephClusterSpec.network | default dict -}} |
| 22 | {{- if ($network.provider | default "") | eq "host" }} |
| 23 | hostNetwork: true |
| 24 | {{- end }} |
| 25 | {{- if .Values.toolbox.priorityClassName }} |
| 26 | priorityClassName: {{ .Values.toolbox.priorityClassName }} |
| 27 | {{- end }} |
| 28 | containers: |
| 29 | - name: rook-ceph-tools |
| 30 | image: {{ default .Values.cephClusterSpec.cephVersion.image .Values.toolbox.image }} |
| 31 | command: |
| 32 | - /bin/bash |
| 33 | - -c |
| 34 | - | |
| 35 | # Replicate the script from toolbox.sh inline so the ceph image |
| 36 | # can be run directly, instead of requiring the rook toolbox |
| 37 | CEPH_CONFIG="/etc/ceph/ceph.conf" |
| 38 | MON_CONFIG="/etc/rook/mon-endpoints" |
| 39 | KEYRING_FILE="/etc/ceph/keyring" |
| 40 | |
| 41 | # create a ceph config file in its default location so ceph/rados tools can be used |
| 42 | # without specifying any arguments |
| 43 | write_endpoints() { |
| 44 | endpoints=$(cat ${MON_CONFIG}) |
| 45 | |
| 46 | # filter out the mon names |
| 47 | # external cluster can have numbers or hyphens in mon names, handling them in regex |
| 48 | # shellcheck disable=SC2001 |
| 49 | mon_endpoints=$(echo "${endpoints}"| sed 's/[a-z0-9_-]\+=//g') |
| 50 | |
| 51 | DATE=$(date) |
| 52 | echo "$DATE writing mon endpoints to ${CEPH_CONFIG}: ${endpoints}" |
| 53 | cat <<EOF > ${CEPH_CONFIG} |
| 54 | [global] |
| 55 | mon_host = ${mon_endpoints} |
| 56 | |
| 57 | [client.admin] |
| 58 | keyring = ${KEYRING_FILE} |
| 59 | EOF |
| 60 | } |
| 61 | |
| 62 | # watch the endpoints config file and update if the mon endpoints ever change |
| 63 | watch_endpoints() { |
| 64 | # get the timestamp for the target of the soft link |
| 65 | real_path=$(realpath ${MON_CONFIG}) |
| 66 | initial_time=$(stat -c %Z "${real_path}") |
| 67 | while true; do |
| 68 | real_path=$(realpath ${MON_CONFIG}) |
| 69 | latest_time=$(stat -c %Z "${real_path}") |
| 70 | |
| 71 | if [[ "${latest_time}" != "${initial_time}" ]]; then |
| 72 | write_endpoints |
| 73 | initial_time=${latest_time} |
| 74 | fi |
| 75 | |
| 76 | sleep 10 |
| 77 | done |
| 78 | } |
| 79 | |
| 80 | # read the secret from an env var (for backward compatibility), or from the secret file |
| 81 | ceph_secret=${ROOK_CEPH_SECRET} |
| 82 | if [[ "$ceph_secret" == "" ]]; then |
| 83 | ceph_secret=$(cat /var/lib/rook-ceph-mon/secret.keyring) |
| 84 | fi |
| 85 | |
| 86 | # create the keyring file |
| 87 | cat <<EOF > ${KEYRING_FILE} |
| 88 | [${ROOK_CEPH_USERNAME}] |
Mohammed Naser | b8eccd2 | 2023-02-10 05:55:56 +0000 | [diff] [blame] | 89 | key = ${ceph_secret} |
| 90 | EOF |
| 91 | |
| 92 | # write the initial config file |
| 93 | write_endpoints |
| 94 | |
| 95 | # continuously update the mon endpoints if they fail over |
| 96 | watch_endpoints |
| 97 | imagePullPolicy: IfNotPresent |
| 98 | tty: true |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 99 | securityContext: {{- .Values.toolbox.containerSecurityContext | toYaml | nindent 12 }} |
Mohammed Naser | b8eccd2 | 2023-02-10 05:55:56 +0000 | [diff] [blame] | 100 | env: |
| 101 | - name: ROOK_CEPH_USERNAME |
| 102 | valueFrom: |
| 103 | secretKeyRef: |
| 104 | name: rook-ceph-mon |
| 105 | key: ceph-username |
| 106 | {{- if .Values.toolbox.resources }} |
| 107 | resources: |
| 108 | {{- toYaml .Values.toolbox.resources | nindent 12 }} |
| 109 | {{- end }} |
| 110 | volumeMounts: |
| 111 | - mountPath: /etc/ceph |
| 112 | name: ceph-config |
| 113 | - name: mon-endpoint-volume |
| 114 | mountPath: /etc/rook |
| 115 | - name: ceph-admin-secret |
| 116 | mountPath: /var/lib/rook-ceph-mon |
| 117 | volumes: |
| 118 | - name: ceph-admin-secret |
| 119 | secret: |
| 120 | secretName: rook-ceph-mon |
| 121 | optional: false |
| 122 | items: |
| 123 | - key: ceph-secret |
| 124 | path: secret.keyring |
| 125 | - name: mon-endpoint-volume |
| 126 | configMap: |
| 127 | name: rook-ceph-mon-endpoints |
| 128 | items: |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 129 | - key: data |
| 130 | path: mon-endpoints |
Mohammed Naser | b8eccd2 | 2023-02-10 05:55:56 +0000 | [diff] [blame] | 131 | - name: ceph-config |
| 132 | emptyDir: {} |
| 133 | tolerations: |
| 134 | - key: "node.kubernetes.io/unreachable" |
| 135 | operator: "Exists" |
| 136 | effect: "NoExecute" |
| 137 | tolerationSeconds: 5 |
| 138 | {{- if .Values.toolbox.tolerations }} |
| 139 | {{ toYaml .Values.toolbox.tolerations | indent 8 }} |
| 140 | {{- end }} |
| 141 | {{- if .Values.toolbox.affinity }} |
| 142 | affinity: |
| 143 | {{ toYaml .Values.toolbox.affinity | indent 8 }} |
| 144 | {{- end }} |
| 145 | {{- end }} |