From 6bc149bae236243789c6f82d56f6b448721d53a6 Mon Sep 17 00:00:00 2001 From: "Christian M. Adams" Date: Wed, 31 Mar 2021 10:33:30 -0400 Subject: [PATCH] template awxbackup crd into awx-operator.yml for easy deployment --- ansible/chain-operator-files.yml | 8 +- ansible/templates/awx-operator.yaml.j2 | 4 + .../templates/awxbackup_crd.yml.j2 | 0 deploy/awx-operator.yaml | 177 +++--------------- ...ckup_cr.yaml => awxbackup_v1beta1_cr.yaml} | 0 deploy/crds/awxbackup_v1beta1_crd.yaml | 32 ++++ molecule/default/prepare.yml | 2 +- molecule/test-local/converge.yml | 3 +- .../tasks/database_configuration.yml | 20 +- 9 files changed, 81 insertions(+), 165 deletions(-) rename deploy/crds/awx.ansible.com_awxbackups_crd.yaml => ansible/templates/awxbackup_crd.yml.j2 (100%) rename deploy/crds/{awx.ansible.com_v1beta1_awxbackup_cr.yaml => awxbackup_v1beta1_cr.yaml} (100%) create mode 100644 deploy/crds/awxbackup_v1beta1_crd.yaml diff --git a/ansible/chain-operator-files.yml b/ansible/chain-operator-files.yml index 03f460bf..e412f28a 100644 --- a/ansible/chain-operator-files.yml +++ b/ansible/chain-operator-files.yml @@ -6,12 +6,18 @@ gather_facts: false tasks: - - name: Template CRD + - name: Template AWX CRD template: src: crd.yml.j2 dest: "{{ playbook_dir }}/../deploy/crds/awx_v1beta1_crd.yaml" mode: '0644' + - name: Template AWXBackup CRD + template: + src: awxbackup_crd.yml.j2 + dest: "{{ playbook_dir }}/../deploy/crds/awxbackup_v1beta1_crd.yaml" + mode: '0644' + - name: Template awx-operator.yaml template: src: awx-operator.yaml.j2 diff --git a/ansible/templates/awx-operator.yaml.j2 b/ansible/templates/awx-operator.yaml.j2 index 6d1364ba..e7d164ee 100644 --- a/ansible/templates/awx-operator.yaml.j2 +++ b/ansible/templates/awx-operator.yaml.j2 @@ -10,3 +10,7 @@ {% include 'service_account.yml.j2' %} {% include 'operator.yml.j2' %} + +{% include 'crd.yml.j2' %} + +{% include 'awxbackup_crd.yml.j2' %} diff --git a/deploy/crds/awx.ansible.com_awxbackups_crd.yaml b/ansible/templates/awxbackup_crd.yml.j2 similarity index 100% rename from deploy/crds/awx.ansible.com_awxbackups_crd.yaml rename to ansible/templates/awxbackup_crd.yml.j2 diff --git a/deploy/awx-operator.yaml b/deploy/awx-operator.yaml index f87b157d..dc4252da 100644 --- a/deploy/awx-operator.yaml +++ b/deploy/awx-operator.yaml @@ -80,7 +80,7 @@ rules: - awx.ansible.com resources: - '*' - - backups + - awxbackups verbs: - '*' @@ -527,151 +527,34 @@ spec: type: object --- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition metadata: - creationTimestamp: null - name: awx-operator -rules: - - apiGroups: - - route.openshift.io - resources: - - routes - - routes/custom-host - verbs: - - '*' - - apiGroups: - - "" - - "rbac.authorization.k8s.io" - resources: - - pods - - services - - services/finalizers - - serviceaccounts - - endpoints - - persistentvolumeclaims - - events - - configmaps - - secrets - - roles - - rolebindings - verbs: - - '*' - - apiGroups: - - apps - - extensions - resources: - - deployments - - daemonsets - - replicasets - - statefulsets - - ingresses - verbs: - - '*' - - apiGroups: - - monitoring.coreos.com - resources: - - servicemonitors - verbs: - - get - - create - - apiGroups: - - apps - resourceNames: - - awx-operator - resources: - - deployments/finalizers - verbs: - - update - - apiGroups: - - apps - resources: - - deployments/scale - - statefulsets/scale - verbs: - - patch - - apiGroups: - - "" - resources: - - pods/exec - verbs: - - create - - get - - apiGroups: - - apps - resources: - - replicasets - verbs: - - get - - apiGroups: - - awx.ansible.com - resources: - - '*' - verbs: - - '*' - ---- -kind: ClusterRoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: awx-operator -subjects: - - kind: ServiceAccount - name: awx-operator - namespace: default -roleRef: - kind: ClusterRole - name: awx-operator - apiGroup: rbac.authorization.k8s.io - ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: awx-operator - namespace: default - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: awx-operator + name: awxbackups.awx.ansible.com spec: - replicas: 1 - selector: - matchLabels: - name: awx-operator - template: - metadata: - labels: - name: awx-operator - spec: - serviceAccountName: awx-operator - containers: - - name: awx-operator - image: "quay.io/ansible/awx-operator:0.8.0" - imagePullPolicy: "Always" - volumeMounts: - - mountPath: /tmp/ansible-operator/runner - name: runner - env: - # Watch all namespaces (cluster-scoped). - - name: WATCH_NAMESPACE - value: "" - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: awx-operator - - name: ANSIBLE_GATHERING - value: explicit - livenessProbe: - httpGet: - path: /healthz - port: 6789 - initialDelaySeconds: 15 - periodSeconds: 20 - volumes: - - name: runner - emptyDir: {} + group: awx.ansible.com + names: + kind: AWXBackup + listKind: AWXBackupList + plural: awxbackups + singular: awxbackup + scope: Namespaced + versions: + - name: v1beta1 + served: true + storage: true + subresources: + status: {} + schema: + openAPIV3Schema: + type: object + x-kubernetes-preserve-unknown-fields: true + description: Schema validation for the AWXBackup CRD + # TODO: Figure out how to require the tower_name field + properties: + spec: + type: object + properties: + tower_name: + description: Name of the deployment to be backed up + type: string diff --git a/deploy/crds/awx.ansible.com_v1beta1_awxbackup_cr.yaml b/deploy/crds/awxbackup_v1beta1_cr.yaml similarity index 100% rename from deploy/crds/awx.ansible.com_v1beta1_awxbackup_cr.yaml rename to deploy/crds/awxbackup_v1beta1_cr.yaml diff --git a/deploy/crds/awxbackup_v1beta1_crd.yaml b/deploy/crds/awxbackup_v1beta1_crd.yaml new file mode 100644 index 00000000..5e9f9deb --- /dev/null +++ b/deploy/crds/awxbackup_v1beta1_crd.yaml @@ -0,0 +1,32 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: awxbackups.awx.ansible.com +spec: + group: awx.ansible.com + names: + kind: AWXBackup + listKind: AWXBackupList + plural: awxbackups + singular: awxbackup + scope: Namespaced + versions: + - name: v1beta1 + served: true + storage: true + subresources: + status: {} + schema: + openAPIV3Schema: + type: object + x-kubernetes-preserve-unknown-fields: true + description: Schema validation for the AWXBackup CRD + # TODO: Figure out how to require the tower_name field + properties: + spec: + type: object + properties: + tower_name: + description: Name of the deployment to be backed up + type: string diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index bfa93fbb..a738ac1f 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -17,7 +17,7 @@ - name: Create AWXBackup Custom Resource Definition k8s: - definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/awx.ansible.com_awxbackups_crd.yaml'])) }}" + definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/awxbackup_v1beta1_crd.yaml'])) }}" - name: Ensure specified namespace is present k8s: diff --git a/molecule/test-local/converge.yml b/molecule/test-local/converge.yml index 58790fe0..ee5f1a35 100644 --- a/molecule/test-local/converge.yml +++ b/molecule/test-local/converge.yml @@ -29,10 +29,9 @@ operator_image: awx.ansible.com/awx-operator operator_version: testing custom_resource: "{{ lookup('file', '/'.join([deploy_dir, 'crds/awx_v1beta1_molecule.yaml'])) | from_yaml }}" + tasks: - - block: - - name: Delete the Operator Deployment k8s: state: absent diff --git a/roles/installer/tasks/database_configuration.yml b/roles/installer/tasks/database_configuration.yml index 18d408fd..1f52509d 100644 --- a/roles/installer/tasks/database_configuration.yml +++ b/roles/installer/tasks/database_configuration.yml @@ -110,23 +110,15 @@ awx_postgres_host: "{{ pg_config['resources'][0]['data']['host'] | b64decode }}" awx_postgres_sslmode: "{{ pg_config['resources'][0]['data']['sslmode'] | default('prefer'|b64encode) | b64decode }}" -# - name: Set apiVersion and kind variables -# set_fact: -# api_version: '{{ hostvars["localhost"]["inventory_file"].split("/")[4:6] | join("/") }}' -# kind: '{{ hostvars["localhost"]["inventory_file"].split("/")[6] }}' -# -# - name: Look up details for this deployment -# k8s_info: -# api_version: "{{ api_version }}" -# kind: "{{ kind }}" -# name: "{{ meta.name }}" -# namespace: "{{ meta.namespace }}" -# register: this_awx +- name: Set apiVersion and kind variables + set_fact: + api_version: '{{ hostvars["localhost"]["inventory_file"].split("/")[4:6] | join("/") }}' + kind: '{{ hostvars["localhost"]["inventory_file"].split("/")[6] }}' - name: Look up details for this deployment k8s_info: - api_version: 'v1beta1' # TODO: How to parameterize this? - kind: "AWX" # TODO: How to parameterize this? + api_version: "{{ api_version }}" + kind: "{{ kind }}" name: "{{ meta.name }}" namespace: "{{ meta.namespace }}" register: this_awx