Skip to content

Commit

Permalink
feat: global pull secret
Browse files Browse the repository at this point in the history
  • Loading branch information
Maurice Faber committed Jul 12, 2021
1 parent e1e5486 commit ab4d832
Show file tree
Hide file tree
Showing 80 changed files with 514 additions and 667 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Expand Up @@ -14,7 +14,7 @@ RUN if [ "$SKIP_TESTS" = 'false' ]; then \
npm install cspell && npm run spellcheck; fi

#-----------------------------
FROM otomi/tools:v1.4.16 as test
FROM otomi/tools:v1.4.17 as test

ENV APP_HOME=/home/app/stack
RUN mkdir -p $APP_HOME
Expand All @@ -28,7 +28,7 @@ COPY --chown=app . .
RUN if [ "$SKIP_TESTS" = 'false' ]; then bin/ci-tests.sh; fi

#-----------------------------
FROM otomi/tools:v1.4.16 as prod
FROM otomi/tools:v1.4.17 as prod

ENV APP_HOME=/home/app/stack
RUN mkdir -p $APP_HOME
Expand Down
70 changes: 34 additions & 36 deletions bin/gen-drone.sh
Expand Up @@ -8,42 +8,40 @@ readonly enabled=$(yqr charts.drone.enabled || echo false)

crypt

readonly raw_receiver=$(yqr alerts.drone)
readonly receiver=${raw_receiver:-'slack'}
readonly template_path=$PWD/tpl/.drone.yml.gotmpl
readonly target_path=$ENV_DIR/.drone.yml
readonly branch=$(yqr charts.otomi-api.git.branch || echo 'main')
readonly template_path=$PWD/tpl/.drone.tpl.$receiver.yml
readonly customer_name=$(customer_name)

if [ "$receiver" = 'slack' ]; then
key="url"
channel=$(yqr alerts.$receiver.channel | echo dev-mon)
else
key="lowPrio"
readonly cluster="$(yqr cluster.name)"
readonly customer=$(customer_name)
readonly global_pull_secret=$(yqr otomi.globalPullSecret)
readonly image_tag="$(otomi_image_tag)"
readonly provider=$(yqr alerts.drone)

pull_policy="always"
[ "${image_tag:0:1}" = "v" ] && pull_policy='if-not-exists'
target=$target_path
[ -n "$DRY_RUN" ] && target="/dev/stdout"

if [ "$provider" != '' ]; then
if [ "$provider" = 'slack' ]; then
key="url"
channel=$(yqr alerts.$provider.channel | echo dev-mon)
else
key="lowPrio"
fi
readonly webhook=$(yqr alerts.$provider.$key)
fi

readonly webhook=$(yqr alerts.$receiver.$key)

function template_drone_config() {
local target_path="$ENV_DIR/.drone.yml"
local image_tag="$(otomi_image_tag)"
local cluster="$(yqr cluster.name)"
local pullPolicy="always"
[ "${image_tag:0:1}" = "v" ] && pullPolicy='if-not-exists'

printf "${COLOR_LIGHT_PURPLE}Creating $target_path ${COLOR_NC}\n"

local target=$target_path
[ "${DRY_RUN-'false'}" = 'false' ] && target="/dev/stdout"

cat $template_path | sed \
-e "s/__CLUSTER/$cluster/g" \
-e "s/__IMAGE_TAG/$image_tag/g" \
-e "s|__WEBHOOK|$webhook|g" \
-e "s/__CUSTOMER/$customer_name/g" \
-e "s/__BRANCH/$branch/g" \
-e "s/__CHANNEL/$channel/g" \
-e "s/__PULL_POLICY/$pullPolicy/g" \
>$target
}

template_drone_config
printf "${COLOR_LIGHT_PURPLE}Creating $target_path ${COLOR_NC}\n"

cat $template_path | gucci \
-s imageTag="$image_tag" \
-s branch="$branch" \
-s cluster="$cluster" \
-s channel="$channel" \
-s customer="$customer" \
-s globalPullSecret="$global_pull_secret" \
-s provider="$provider" \
-s webhook="$webhook" \
-s pullPolicy="$pull_policy" \
>$target
30 changes: 13 additions & 17 deletions bin/gen-sops.sh
Expand Up @@ -2,32 +2,28 @@
. bin/common.sh
. bin/colors.sh

readonly target_path="$ENV_DIR/.sops.yaml"

declare -A map=(["aws"]="kms" ["azure"]="azure_keyvault" ["google"]="gcp_kms" ["vault"]="hc_vault_transit_uri")

settings_file=$ENV_DIR/env/settings.yaml
[ -f $settings_file ] && provider=$(cat $settings_file | yq r - kms.sops.provider)
[ "$provider" = '' ] && echo "No sops information given. Assuming no sops enc/decryption needed." && exit

readonly template_path="$PWD/tpl/.sops.yaml"
readonly kmsProvider="${map[$provider]}"
readonly kmsKeys=$(cat $settings_file | yq r - kms.sops.$provider.keys)
readonly template_path="$PWD/tpl/.sops.yaml.gotmpl"
readonly target_path="$ENV_DIR/.sops.yaml"
readonly sops_provider="${map[$provider]}"
readonly keys=$(cat $settings_file | yq r - kms.sops.$provider.keys)

target=$target_path
[ -n "$DRY_RUN" ] && target="/dev/stdout"

echo "Creating sops file for provider $provider"
function create_from_template() {
printf "${COLOR_LIGHT_PURPLE}Creating $target_path ${COLOR_NC}\n"
local target=$target_path
[ "${DRY_RUN-'false'}" = 'false' ] && target="/dev/stdout"
cat "$template_path" | sed \
-e "s@__PROVIDER@${kmsProvider}@g" \
-e "s@__KEYS@${kmsKeys}@g" \
>$target
}
create_from_template
printf "${COLOR_LIGHT_PURPLE}Creating sops file for provider $provider${COLOR_NC}\n"
cat "$template_path" | gucci \
-s provider="$sops_provider" \
-s keys="$keys" \
>$target

if [ -z "$CI" ]; then
# we know we are in dev/ops mode and need to read the credentials for SOPS. We provide a location to
# we know we are in dev/ops mode and need to read the credentials for SOPS. We know the location to
# provide those to this context: $ENV_DIR/.secrets (gitignored)
[ ! -f $ENV_DIR/.secrets ] && err "Expecting $ENV_DIR/.secrets to exist and hold credentials for SOPS." && exit 1
. $ENV_DIR/.secrets
Expand Down
1 change: 1 addition & 0 deletions bin/otomi
Expand Up @@ -195,6 +195,7 @@ function drun() {
-e DEBUG="$DEBUG" \
-e KEEP_DEBUGGING="$KEEP_DEBUGGING" \
-e TRACE="$TRACE" \
-e DRY_RUN="$DRY_RUN" \
-e CI="$CI" \
-w $stack_dir \
$cmd_image \
Expand Down
1 change: 1 addition & 0 deletions chart/otomi/localtest.sh
@@ -1,6 +1,7 @@
# Usage:
# ENV_OUT=$PWD/../ENV_OUT VALUES_DIR=$PWD/../ chart/otomi/localtest.sh
# With VALUES_DIR holding a file named values.yaml holding the initial chart values
set -e

function run_core() {
image=$1
Expand Down
3 changes: 2 additions & 1 deletion chart/otomi/scripts/bootstrap-values.sh
Expand Up @@ -66,7 +66,8 @@ popd

bin/bootstrap.sh

crypt dec
# decrypt before merging if we can
[ -f $ENV_DIR/.sops.yaml ] && crypt dec

# lastly copy the schema file
cp values-schema.yaml $ENV_DIR/
Expand Down
6 changes: 6 additions & 0 deletions charts/aws-alb-ingress-controller/templates/deployment.yaml
Expand Up @@ -26,6 +26,12 @@ spec:
{{ toYaml .Values.podAnnotations | indent 8}}
{{- end }}
spec:
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
{{- range . }}
- name: {{ . }}
{{- end }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: "{{ .Values.priorityClassName }}"
{{- end }}
Expand Down
5 changes: 2 additions & 3 deletions charts/cluster-overprovisioner/templates/deployments.yaml
Expand Up @@ -11,7 +11,6 @@
{{- $repository := .Values.image.repository }}
{{- $imageTag := .Values.image.tag }}
{{- $pullPolicy := .Values.image.pullPolicy }}
{{- $imagePullSecrets := .Values.image.pullSecrets }}

{{ range .Values.deployments }}
apiVersion: apps/v1
Expand Down Expand Up @@ -51,9 +50,9 @@ spec:
imagePullPolicy: {{ $pullPolicy }}
resources:
{{- toYaml .resources | nindent 12 }}
{{- if $imagePullSecrets }}
{{- with $.Values.image.pullSecrets }}
imagePullSecrets:
{{- range $imagePullSecrets }}
{{- range . }}
- name: {{ . }}
{{- end }}
{{- end }}
Expand Down
9 changes: 7 additions & 2 deletions charts/demo-tlspass/templates/deployment.yaml
Expand Up @@ -20,8 +20,13 @@ spec:
spec:
automountServiceAccountToken: true
serviceAccountName: {{ include "demo-tlspass.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
{{- range . }}
- name: {{ . }}
{{- end }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down
6 changes: 6 additions & 0 deletions charts/drone-admit-members/templates/deployment.yaml
Expand Up @@ -18,6 +18,12 @@ spec:
labels:
{{- include "drone-admit-members.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.image.pullSecrets }}
imagePullSecrets:
{{- range . }}
- name: {{ . }}
{{- end }}
{{- end }}
serviceAccountName: {{ include "drone-admit-members.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
Expand Down
3 changes: 3 additions & 0 deletions charts/drone/templates/deployment-agent.yaml
Expand Up @@ -28,6 +28,9 @@ spec:
release: "{{ .Release.Name }}"
component: agent
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets: {{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.kubernetes.securityContext }}
securityContext:
{{- toYaml .Values.kubernetes.securityContext | nindent 8 }}
Expand Down
3 changes: 3 additions & 0 deletions charts/drone/templates/deployment-server.yaml
Expand Up @@ -34,6 +34,9 @@ spec:
release: "{{ .Release.Name }}"
component: server
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets: {{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.server.securityContext }}
securityContext:
{{- toYaml .Values.server.securityContext | nindent 8 }}
Expand Down
3 changes: 2 additions & 1 deletion charts/drone/values.yaml
Expand Up @@ -403,4 +403,5 @@ serviceAccount:
## imagePullSecrets:
## - dockerconfig

extraRootCA: ''
extraRootCA: ''
imagePullSecrets: []
4 changes: 4 additions & 0 deletions charts/ingress-azure/templates/deployment.yaml
Expand Up @@ -31,6 +31,10 @@ spec:
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.kubernetes.securityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
Expand Down
4 changes: 4 additions & 0 deletions charts/ingress-merge/templates/02_deployment.yaml
Expand Up @@ -21,6 +21,10 @@ spec:
app: {{ include "ingress-merge.name" . }}
release: {{ .Release.Name }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ if .Values.rbac.create }}{{ include "ingress-merge.fullname" . }}{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }}
containers:
- name: {{ .Chart.Name }}
Expand Down
4 changes: 4 additions & 0 deletions charts/kube-descheduler/templates/cronjob.yaml
Expand Up @@ -24,6 +24,10 @@ spec:
{{- .Values.podLabels | toYaml | nindent 12 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
Expand Down
4 changes: 4 additions & 0 deletions charts/otomi-api/templates/deployment.yaml
Expand Up @@ -23,6 +23,10 @@ spec:
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ template "otomi-api.serviceAccountName" . }}
securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
Expand Down
4 changes: 4 additions & 0 deletions charts/otomi-console/templates/deployment.yaml
Expand Up @@ -22,6 +22,10 @@ spec:
{{- end }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ template "otomi-console.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
Expand Down
4 changes: 4 additions & 0 deletions charts/prometheus-msteams/templates/deployment.yaml
Expand Up @@ -23,6 +23,10 @@ spec:
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: config-volume
configMap:
Expand Down
23 changes: 0 additions & 23 deletions charts/pullsecret-patcher/.helmignore

This file was deleted.

28 changes: 0 additions & 28 deletions charts/pullsecret-patcher/Chart.yaml

This file was deleted.

0 comments on commit ab4d832

Please sign in to comment.