diff --git a/roles/helm/tasks/main.yml b/roles/helm/tasks/main.yml index d116c5e..8e42712 100755 --- a/roles/helm/tasks/main.yml +++ b/roles/helm/tasks/main.yml @@ -21,6 +21,11 @@ -config={{ ca_dir }}/ca-config.json \ -profile=kubernetes {{ tiller_cert_cn }}-csr.json | {{ bin_dir }}/cfssljson -bare {{ tiller_cert_cn }}" +- name: 获取当前集群所有 namespaces + shell: "{{ bin_dir }}/kubectl get ns" + register: current_ns + run_once: true + - name: 准备rbac配置 template: src=helm-rbac.yaml.j2 dest=/opt/kube/helm-rbac.yaml diff --git a/roles/helm/templates/helm-rbac.yaml.j2 b/roles/helm/templates/helm-rbac.yaml.j2 index b15bcd5..16a1af8 100644 --- a/roles/helm/templates/helm-rbac.yaml.j2 +++ b/roles/helm/templates/helm-rbac.yaml.j2 @@ -1,10 +1,12 @@ # 绑定helm sa到 cluster-admin,这样可以兼容现有需要集群特权的charts -# +# +{% if helm_namespace not in current_ns.stdout %} --- apiVersion: v1 kind: Namespace metadata: name: {{ helm_namespace }} +{% endif %} --- apiVersion: v1 kind: ServiceAccount