-
Notifications
You must be signed in to change notification settings - Fork 38
feat: add configurable namespace for activation job pods #345
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
1353abe
41049e5
9fb5097
7f7b9a1
ed5c717
82c8764
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| apiVersion: eda.ansible.com/v1alpha1 | ||
| kind: EDA | ||
| metadata: | ||
| name: eda-demo | ||
| annotations: | ||
| "ansible.sdk.operatorframework.io/verbosity": "5" | ||
| spec: | ||
| no_log: false | ||
| automation_server_url: http://foo.bar | ||
| activation_worker: | ||
| activation_job_namespace: "eda-jobs" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- | ||
| # Cluster-scoped because the target namespace is user-configurable at | ||
| # runtime via spec.activation_worker.activation_job_namespace. The | ||
| # operator must be able to create Role/RoleBinding resources in whatever | ||
| # namespace the user specifies. | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: eda-activation-job-namespace-manager | ||
| rules: | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - namespaces | ||
| verbs: | ||
| - get | ||
| - list | ||
| - apiGroups: | ||
| - rbac.authorization.k8s.io | ||
| resources: | ||
| - roles | ||
| verbs: | ||
| - bind | ||
| - create | ||
| - delete | ||
| - escalate | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch | ||
| - apiGroups: | ||
| - rbac.authorization.k8s.io | ||
| resources: | ||
| - rolebindings | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: eda-activation-job-namespace-manager-binding | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: eda-activation-job-namespace-manager | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: controller-manager | ||
| namespace: system |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,22 @@ | |
| event_stream_mtls_base_url: "{{ public_base_url.rstrip('/') }}/{{ event_stream_mtls_prefix_path }}" | ||
| when: public_base_url | default('') | length > 0 | ||
|
|
||
| - name: Look up existing ConfigMap for previous activation_job_namespace | ||
| kubernetes.core.k8s_info: | ||
| api_version: v1 | ||
| kind: ConfigMap | ||
| namespace: "{{ ansible_operator_meta.namespace }}" | ||
| name: "{{ ansible_operator_meta.name }}-{{ deployment_type }}-env-properties" | ||
| register: _eda_env_cm | ||
|
|
||
| - name: Record previous activation_job_namespace from ConfigMap | ||
| ansible.builtin.set_fact: | ||
| _previous_activation_job_namespace: >- | ||
| {{ (_eda_env_cm.resources | first).data.EDA_ACTIVATION_JOB_NAMESPACE | default('') }} | ||
| when: | ||
| - _eda_env_cm.resources | length > 0 | ||
| - (_eda_env_cm.resources | first).data is defined | ||
|
|
||
| - name: Apply ConfigMap resources | ||
| k8s: | ||
| apply: yes | ||
|
|
@@ -38,6 +54,28 @@ | |
| wait: yes | ||
| when: public_base_url is defined | ||
|
|
||
| - name: Apply cross-namespace RBAC for activation job pods | ||
| k8s: | ||
| apply: yes | ||
| definition: "{{ lookup('template', 'eda-activation-job-namespace-rbac.yaml.j2') }}" | ||
| wait: yes | ||
| when: combined_activation_worker.activation_job_namespace | default('') | length > 0 | ||
|
|
||
| - name: Remove cross-namespace RBAC from previous namespace | ||
| k8s: | ||
| state: absent | ||
| api_version: rbac.authorization.k8s.io/v1 | ||
| kind: "{{ item.kind }}" | ||
| name: "{{ ansible_operator_meta.name }}-activation-job-manager" | ||
| namespace: "{{ _previous_activation_job_namespace }}" | ||
| loop: | ||
| - { kind: RoleBinding } | ||
| - { kind: Role } | ||
| when: | ||
| - _previous_activation_job_namespace | default('') | length > 0 | ||
| - combined_activation_worker.activation_job_namespace | default('') != _previous_activation_job_namespace | ||
| ignore_errors: yes | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amasolov I don't understand the reason for setting ignore_errors to true on this task. won't the module's
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kaiokmo You're right, state: absent already handles the "not found" case gracefully, and the when guards prevent other runs. Removed ignore_errors so legitimate failures (permission issues, API errors) surface properly. |
||
|
|
||
| - name: Apply Backend deployment resources | ||
| k8s: | ||
| apply: yes | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # RBAC resources for cross-namespace activation job pods. | ||
| # Created when activation_job_namespace is set on the EDA CR. | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| name: '{{ ansible_operator_meta.name }}-activation-job-manager' | ||
| namespace: '{{ combined_activation_worker.activation_job_namespace }}' | ||
| labels: | ||
| {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }} | ||
| rules: | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - secrets | ||
| - pods | ||
| - pods/log | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - services | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch | ||
| - apiGroups: | ||
| - batch | ||
| resources: | ||
| - jobs | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: '{{ ansible_operator_meta.name }}-activation-job-manager' | ||
| namespace: '{{ combined_activation_worker.activation_job_namespace }}' | ||
| labels: | ||
| {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }} | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: Role | ||
| name: '{{ ansible_operator_meta.name }}-activation-job-manager' | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: '{{ ansible_operator_meta.name }}' | ||
| namespace: '{{ ansible_operator_meta.namespace }}' | ||
Uh oh!
There was an error while loading. Please reload this page.