Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for cluster user secrets and settings #858

Merged
merged 18 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .taskfiles/ClusterTasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ tasks:
- kubectl apply --kustomize {{.KUBERNETES_DIR}}/bootstrap
- cat {{.SOPS_AGE_KEY_FILE}} | kubectl -n flux-system create secret generic sops-age --from-file=age.agekey=/dev/stdin
- sops --decrypt {{.KUBERNETES_DIR}}/flux/vars/cluster-secrets.sops.yaml | kubectl apply -f -
- sops --decrypt {{.KUBERNETES_DIR}}/flux/vars/cluster-secrets-user.sops.yaml | kubectl apply -f -
- kubectl apply -f {{.KUBERNETES_DIR}}/flux/vars/cluster-settings.yaml
- kubectl apply -f {{.KUBERNETES_DIR}}/flux/vars/cluster-settings-user.yaml
- kubectl apply --kustomize {{.KUBERNETES_DIR}}/flux/config
preconditions:
- sh: test -f {{.SOPS_AGE_KEY_FILE}}
Expand Down
39 changes: 38 additions & 1 deletion bootstrap/tasks/kubernetes/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,44 @@
with_community.general.filetree: ["../templates/kubernetes/"]

- name: Template Kubernetes unencrypted files
when: item.state == 'file' and 'sops' not in item.path and '.DS_Store' not in item.path
when:
- item.state == 'file'
- "'.DS_Store' not in item.path"
- "'sops' not in item.path"
- "'cluster-settings-user.yaml.j2' not in item.path"
- "'cluster-secrets-user.yaml.j2' not in item.path"
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/{{ item.path | regex_replace('.j2$', '') }}"
mode: "0644"
with_community.general.filetree: ["../templates/kubernetes/"]

- name: Check if the cluster user settings file already exists
stat:
path: "{{ repository_path }}/kubernetes/flux/vars/cluster-settings-user.yaml"
register: cluster_settings_user

- name: Template Kubernetes user cluster settings
when:
- item.state == 'file'
- "'cluster-settings-user.yaml' in item.path"
- not cluster_settings_user.stat.exists
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/{{ item.path | regex_replace('.j2$', '') }}"
mode: "0644"
with_community.general.filetree: ["../templates/kubernetes/"]

- name: Check if the cluster user secrets file already exists
stat:
path: "{{ repository_path }}/kubernetes/flux/vars/cluster-secrets-user.yaml"
register: cluster_secrets_user

- name: Template Kubernetes user cluster secrets
when:
- item.state == 'file'
- "'cluster-secrets-user.yaml' in item.path"
- not cluster_secrets_user.stat.exists
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/{{ item.path | regex_replace('.j2$', '') }}"
Expand Down
8 changes: 8 additions & 0 deletions bootstrap/templates/kubernetes/flux/apps.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ spec:
name: cluster-settings
- kind: Secret
name: cluster-secrets
- kind: ConfigMap
name: cluster-settings-user
- kind: Secret
name: cluster-secrets-user
patches:
- patch: |-
apiVersion: kustomize.toolkit.fluxcd.io/v1
Expand All @@ -38,6 +42,10 @@ spec:
name: cluster-settings
- kind: Secret
name: cluster-secrets
- kind: ConfigMap
name: cluster-settings-user
- kind: Secret
name: cluster-secrets-user
target:
group: kustomize.toolkit.fluxcd.io
kind: Kustomization
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: v1
kind: Secret
metadata:
name: cluster-secrets-user
namespace: flux-system
stringData:
SECRET_PLACEHOLDER: "secret-value"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-settings-user
namespace: flux-system
data:
SETTINGS_PLACEHOLDER: "settings-value"
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./cluster-settings.yaml
- ./cluster-settings-user.yaml
- ./cluster-secrets.sops.yaml
- ./cluster-secrets-user.sops.yaml