Compare commits

..

13 Commits

Author SHA1 Message Date
Shane McDonald
b7c67e75a4 TEST - DNM 2021-06-23 16:11:33 -04:00
Shane McDonald
ca52b6c1c7 Merge pull request #423 from dolgovas/devel
Update README.md
2021-06-23 16:09:49 -04:00
dolgovas
00fd08e731 Update README.md
Add additional information about `image_pull_secret`
2021-06-23 20:06:41 +03:00
Yanis Guenane
e0c865a9f7 Merge pull request #419 from Spredzy/update_vendored
vendor: update dir with kubernetes.core
2021-06-23 00:49:50 +02:00
Yanis Guenane
53ffc8fdae vendor: update dir with kubernetes.core 2021-06-23 00:37:37 +02:00
Shane McDonald
6c1f251558 Merge pull request #417 from shanemcd/fix-uuid
Fix SYSTEM_UUID
2021-06-22 15:02:06 -04:00
Shane McDonald
7310b43a5c Use kubernetes.core 2021-06-22 14:52:54 -04:00
Shane McDonald
9a54ae2937 Delete test-local, run test-minikube in CI
bsycorp/kind is broken. See https://github.com/bsycorp/kind/issues/44
2021-06-22 14:35:39 -04:00
Shane McDonald
64c55c8824 Fix SYSTEM_UUID 2021-06-21 09:49:36 -04:00
Marcelo Moreira de Mello
d6d39889c4 Merge pull request #401 from tchellomello/custom-ca
Added ability to trust a custom bundle CA
2021-06-18 12:07:51 -04:00
Yanis Guenane
68a6a55cfc Merge pull request #411 from Spredzy/remove_extra_space
awx-cro.yml: Remove extra space
2021-06-18 10:23:58 +02:00
Yanis Guenane
ad036c2e65 awx-cro.yml: Remove extra space
Fixes: https://github.com/ansible/awx-operator/issues/410
2021-06-18 09:54:49 +02:00
Marcelo Moreira de Mello
f2e43db37c Added ability to trust a custom bundle CA 2021-06-18 01:48:50 -04:00
29 changed files with 170 additions and 249 deletions

View File

@@ -31,14 +31,21 @@ jobs:
ansible-lint \
openshift \
jmespath \
ansible
ansible-core
- name: Install Collections
run: |
ansible-galaxy collection install community.kubernetes operator_sdk.util
ansible-galaxy collection install community.general kubernetes.core:1.2.1 operator_sdk.util
- name: Setup Minikube
uses: manusa/actions-setup-minikube@v2.4.2
with:
minikube version: 'v1.16.0'
kubernetes version: 'v1.19.2'
github token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Molecule
env:
MOLECULE_VERBOSITY: 3
run: |
molecule test -s test-local
molecule test -s test-minikube

View File

@@ -2,6 +2,7 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Build Status](https://github.com/ansible/awx-operator/workflows/CI/badge.svg?event=push)](https://github.com/ansible/awx-operator/actions)
An [Ansible AWX](https://github.com/ansible/awx) operator for Kubernetes built with [Operator SDK](https://github.com/operator-framework/operator-sdk) and Ansible.
# Table of Contents
@@ -24,7 +25,7 @@ An [Ansible AWX](https://github.com/ansible/awx) operator for Kubernetes built w
* [Deploying a specific version of AWX](#deploying-a-specific-version-of-awx)
* [Privileged Tasks](#privileged-tasks)
* [Containers Resource Requirements](#containers-resource-requirements)
* [LDAP Certificate Authority](#ldap-certificate-authority)
* [Trusting a Custom Certificate Authority](#trusting-a-custom-certificate-authority)
* [Persisting Projects Directory](#persisting-projects-directory)
* [Custom Volume and Volume Mount Options](#custom-volume-and-volume-mount-options)
* [Exporting Environment Variables to Containers](#exporting-environment-variables-to-containers)
@@ -505,28 +506,36 @@ spec:
effect: "NoSchedule"
```
#### LDAP Certificate Authority
#### Trusting a Custom Certificate Authority
If the variable `ldap_cacert_secret` is provided, the operator will look for a the data field `ldap-ca.crt` in the specified secret.
In cases which you need to trust a custom Certificate Authority, there are few variables you can customize for the `awx-operator`.
| Name | Description | Default |
| -------------------------------- | --------------------------------------- | --------|
| ldap_cacert_secret | LDAP Certificate Authority secret name | '' |
Trusting a custom Certificate Authority allows the AWX to access network services configured with SSL certificates issued locally, such as cloning a project from from an internal Git server via HTTPS. It is common for these scenarios, experiencing the error [unable to verify the first certificate](https://github.com/ansible/awx-operator/issues/376).
| Name | Description | Default |
| -------------------------------- | ---------------------------------------- | --------|
| ldap_cacert_secret | LDAP Certificate Authority secret name | '' |
| bundle_cacert_secret | Certificate Authority secret name | '' |
Please note the `awx-operator` will look for the data field `ldap-ca.crt` in the specified secret when using the `ldap_cacert_secret`, whereas the data field `bundle-ca.crt` is required for `bundle_cacert_secret` parameter.
Example of customization could be:
```yaml
---
spec:
...
ldap_cacert_secret: <resourcename>-ldap-ca-cert
ldap_cacert_secret: <resourcename>-custom-certs
bundle_cacert_secret: <resourcename>-custom-certs
```
To create the secret, you can use the command below:
```sh
# kubectl create secret generic <resourcename>-ldap-ca-cert --from-file=ldap-ca.crt=<PATH/TO/YOUR/CA/PEM/FILE>
# kubectl create secret generic <resourcename>-custom-certs \
--from-file=ldap-ca.crt=<PATH/TO/YOUR/CA/PEM/FILE> \
--from-fle=bundle-ca.crt=<PATH/TO/YOUR/CA/PEM/FILE>
```
#### Persisting Projects Directory
@@ -587,7 +596,26 @@ type: Opaque
```
##### Control plane ee from private registry
The images listed in "ee_images" will be added as globally available Execution Environments. The "control_plane_ee_image" will be used to run project updates. In order to use a private image for any of these you'll need to use `image_pull_secret` to provide a k8s pull secret to access it. Currently the same secret is used for any of these images supplied at install time.
The images listed in "ee_images" will be added as globally available Execution Environments. The "control_plane_ee_image" will be used to run project updates. In order to use a private image for any of these you'll need to use `image_pull_secret` to provide a k8s pull secret to access it. Currently the same secret is used for any of these images supplied at install time.
You can create `image_pull_secret`
```
kubectl create secret <resoucename>-cp-pull-credentials regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
```
If you need more control (for example, to set a namespace or a label on the new secret) then you can customise the Secret before storing it
```yaml
---
apiVersion: v1
kind: Secret
metadata:
name: <resoucename>-cp-pull-credentials
namespace: <target namespace>
data:
.dockerconfigjson: <base64 docker config>
type: kubernetes.io/dockerconfigjson
```
Example spec file extra-config
```yaml
---

View File

@@ -9,7 +9,7 @@
obliterate: no
collections:
- community.kubernetes
- kubernetes.core
tasks:
- name: Obliterate Operator

View File

@@ -3,7 +3,7 @@
hosts: localhost
collections:
- community.kubernetes
- kubernetes.core
tasks:
- name: Deploy AWX

View File

@@ -285,6 +285,12 @@ spec:
redis_image_version:
description: Redis container image version to use
type: string
init_container_image:
description: Registry path to the init container to use
type: string
init_container_image_version:
description: Init container image version to use
type: string
postgres_image:
description: Registry path to the PostgreSQL container to use
type: string
@@ -344,6 +350,9 @@ spec:
ldap_cacert_secret:
description: Secret where can be found the LDAP trusted Certificate Authority Bundle
type: string
bundle_cacert_secret:
description: Secret where can be found the trusted Certificate Authority Bundle
type: string
projects_persistence:
description: Whether or not the /var/lib/projects directory will be persistent
default: false

View File

@@ -287,6 +287,12 @@ spec:
redis_image_version:
description: Redis container image version to use
type: string
init_container_image:
description: Registry path to the init container to use
type: string
init_container_image_version:
description: Init container image version to use
type: string
postgres_image:
description: Registry path to the PostgreSQL container to use
type: string
@@ -346,6 +352,9 @@ spec:
ldap_cacert_secret:
description: Secret where can be found the LDAP trusted Certificate Authority Bundle
type: string
bundle_cacert_secret:
description: Secret where can be found the trusted Certificate Authority Bundle
type: string
projects_persistence:
description: Whether or not the /var/lib/projects directory will be persistent
default: false

View File

@@ -285,6 +285,12 @@ spec:
redis_image_version:
description: Redis container image version to use
type: string
init_container_image:
description: Registry path to the init container to use
type: string
init_container_image_version:
description: Init container image version to use
type: string
postgres_image:
description: Registry path to the PostgreSQL container to use
type: string
@@ -344,6 +350,9 @@ spec:
ldap_cacert_secret:
description: Secret where can be found the LDAP trusted Certificate Authority Bundle
type: string
bundle_cacert_secret:
description: Secret where can be found the trusted Certificate Authority Bundle
type: string
projects_persistence:
description: Whether or not the /var/lib/projects directory will be persistent
default: false

View File

@@ -35,6 +35,9 @@ spec:
broadcast_websocket_secret:
description: Secret where the broadcast websocket secret can be found
type: string
bundle_cacert_secret:
description: Secret where can be found the trusted Certificate Authority Bundle
type: string
ca_trust_bundle:
description: Path where the trusted CA bundle is available
type: string
@@ -149,6 +152,12 @@ spec:
- Route
- route
type: string
init_container_image:
description: Registry path to the init container to use
type: string
init_container_image_version:
description: Initcontainer image version to use
type: string
kind:
description: Kind of the deployment type
type: string

View File

@@ -27,8 +27,3 @@ provisioner:
group_vars:
all:
operator_namespace: ${TEST_NAMESPACE:-default}
env:
K8S_AUTH_KUBECONFIG: /tmp/molecule/kind-default/kubeconfig
KUBECONFIG: /tmp/molecule/kind-default/kubeconfig
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles
KIND_PORT: '${TEST_CLUSTER_PORT:-9443}'

View File

@@ -1,2 +0,0 @@
[defaults]
stdout_callback = yaml

View File

@@ -1,133 +0,0 @@
---
- name: Build Operator in Kind container
hosts: k8s
vars:
image_name: awx.ansible.com/awx-operator:testing
tasks:
# using command so we don't need to install any dependencies
- name: Get existing image hash
command: docker images -q {{ image_name }}
register: prev_hash
changed_when: false
- name: Build Operator Image
command: docker build -f /build/build/Dockerfile -t {{ image_name }} /build
register: build_cmd
changed_when: not prev_hash.stdout or (prev_hash.stdout and prev_hash.stdout not in ''.join(build_cmd.stdout_lines[-2:]))
- name: Converge
hosts: localhost
connection: local
vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy"
templates_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/ansible/templates"
pull_policy: Never
operator_image: awx.ansible.com/awx-operator
operator_version: testing
ansible_debug_logs: "true"
custom_resource: "{{ lookup('file', '/'.join([deploy_dir, 'crds/awx_v1beta1_molecule.yaml'])) | from_yaml }}"
tasks:
- block:
- name: Delete the Operator Deployment
k8s:
state: absent
namespace: '{{ operator_namespace }}'
definition: "{{ lookup('template', '/'.join([templates_dir, 'operator.yml.j2'])) }}"
register: delete_deployment
when: hostvars[groups.k8s.0].build_cmd.changed
- name: Wait 30s for Operator Deployment to terminate
k8s_info:
api_version: '{{ definition.apiVersion }}'
kind: '{{ definition.kind }}'
namespace: '{{ operator_namespace }}'
name: '{{ definition.metadata.name }}'
vars:
definition: "{{ lookup('template', '/'.join([templates_dir, 'operator.yml.j2'])) | from_yaml }}"
register: deployment
until: not deployment.resources
delay: 3
retries: 10
when: delete_deployment.changed
- name: Create the Operator Deployment
k8s:
namespace: '{{ operator_namespace }}'
definition: "{{ lookup('template', '/'.join([templates_dir, 'operator.yml.j2'])) }}"
- name: Ensure the AWX custom_resource namespace exists
k8s:
state: present
name: '{{ custom_resource.metadata.namespace }}'
kind: Namespace
api_version: v1
- name: Create the AWX Custom Resource
k8s:
state: present
namespace: '{{ custom_resource.metadata.namespace }}'
definition: '{{ custom_resource }}'
- name: Wait 15m for reconciliation to run
k8s_info:
api_version: '{{ custom_resource.apiVersion }}'
kind: '{{ custom_resource.kind }}'
namespace: '{{ custom_resource.metadata.namespace }}'
name: '{{ custom_resource.metadata.name }}'
register: cr
until:
- "'Successful' in (cr | json_query('resources[].status.conditions[].reason'))"
delay: 6
retries: 150
rescue:
- name: debug cr
ignore_errors: yes
failed_when: false
debug:
var: debug_cr
vars:
debug_cr: '{{ lookup("k8s",
kind=custom_resource.kind,
api_version=custom_resource.apiVersion,
namespace=custom_resource.metadata.namespace,
resource_name=custom_resource.metadata.name)
}}'
- name: debug awx deployment
ignore_errors: yes
failed_when: false
debug:
var: deploy
vars:
deploy: '{{ lookup("k8s",
kind="Deployment",
api_version="apps/v1",
namespace=custom_resource.metadata.namespace,
label_selector="app.kubernetes.io/name=example-awx")
}}'
- name: get operator logs
ignore_errors: yes
failed_when: false
command: kubectl logs deployment/{{ definition.metadata.name }} -n {{ operator_namespace }}
environment:
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
vars:
definition: "{{ lookup('template', '/'.join([templates_dir, 'operator.yml.j2'])) | from_yaml }}"
register: log
- name: print debug output
debug: var=log.stdout_lines
- name: fail if converge didn't succeed
fail:
msg: "Failed on action: converge"
- import_playbook: '{{ playbook_dir }}/../default/asserts.yml'

View File

@@ -1,46 +0,0 @@
---
dependency:
name: galaxy
driver:
name: docker
lint: |
set -e
yamllint .
ansible-lint
platforms:
- name: kind-test-local
groups:
- k8s
image: bsycorp/kind:v1.17.9
privileged: True
override_command: no
exposed_ports:
- 8443/tcp
- 10080/tcp
published_ports:
- 0.0.0.0:${TEST_CLUSTER_PORT:-10443}:8443/tcp
pre_build_image: yes
volumes:
- ${MOLECULE_PROJECT_DIRECTORY}:/build:Z
provisioner:
name: ansible
log: True
inventory:
group_vars:
all:
operator_namespace: ${TEST_NAMESPACE:-default}
env:
K8S_AUTH_KUBECONFIG: /tmp/molecule/kind-test-local/kubeconfig
KUBECONFIG: /tmp/molecule/kind-test-local/kubeconfig
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles
KIND_PORT: '${TEST_CLUSTER_PORT:-10443}'
scenario:
test_sequence:
- lint
- destroy
- dependency
- syntax
- create
- prepare
- converge
- destroy

View File

@@ -1,38 +0,0 @@
---
- name: Prepare kubernetes environment
hosts: k8s
gather_facts: no
vars:
kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}"
tasks:
- name: delete the kubeconfig if present
file:
path: '{{ kubeconfig }}'
state: absent
delegate_to: localhost
- name: Fetch the kubeconfig
fetch:
dest: '{{ kubeconfig }}'
flat: yes
src: /root/.kube/config
- name: Change the kubeconfig port to the proper value
replace:
regexp: 8443
replace: "{{ lookup('env', 'KIND_PORT') }}"
path: '{{ kubeconfig }}'
mode: 0644
delegate_to: localhost
- name: Wait for the Kubernetes API to become available (this could take a minute)
uri:
url: "http://localhost:10080/kubernetes-ready"
status_code: 200
validate_certs: no
register: result
until: (result.status|default(-1)) == 200
retries: 60
delay: 5
- import_playbook: ../default/prepare.yml

View File

@@ -126,8 +126,6 @@
ignore_errors: yes
failed_when: false
command: kubectl logs deployment/{{ definition.metadata.name }} -n {{ operator_namespace }} -c operator
environment:
KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}'
vars:
definition: "{{ lookup('template', '/'.join([templates_dir, 'operator.yml.j2'])) | from_yaml }}"
register: log

View File

@@ -1,6 +1,6 @@
---
collections:
- name: community.kubernetes
version: '==1.1.1'
- name: kubernetes.core
version: '==1.2.1'
- name: operator_sdk.util
version: '==0.1.0'

View File

@@ -27,5 +27,5 @@ galaxy_info:
dependencies: []
collections:
- community.kubernetes
- kubernetes.core
- operator_sdk.util

View File

@@ -23,7 +23,7 @@
- {"key": "secret_key_secret", "value": "{{ this_awx['resources'][0]['status']['secretKeySecret'] }}"}
- {"key": "admin_password_secret", "value": "{{ this_awx['resources'][0]['status']['adminPasswordSecret'] }}"}
- {"key": "broadcast_websocket_secret", "value": "{{ this_awx['resources'][0]['status']['broadcastWebsocketSecret'] }}"}
- {"key": "postgres_configuration_secret", "value": "{{ this_awx['resources'][0]['status']['postgresConfigurationSecret'] }} "}
- {"key": "postgres_configuration_secret", "value": "{{ this_awx['resources'][0]['status']['postgresConfigurationSecret'] }}"}
- name: Write awx object to pvc
k8s_exec:

View File

@@ -111,6 +111,8 @@ redis_image: docker.io/redis
redis_image_version: latest
postgres_image: postgres
postgres_image_version: 12
init_container_image: quay.io/centos/centos
init_container_image_version: 8
image_pull_policy: IfNotPresent
image_pull_secret: ''
@@ -206,6 +208,9 @@ ca_trust_bundle: "/etc/pki/tls/certs/ca-bundle.crt"
#
ldap_cacert_secret: ''
# Secret to lookup that provides the custom CA trusted bundle
bundle_cacert_secret: ''
# Whether secrets should be garbage collected
# on teardown
#

View File

@@ -28,5 +28,5 @@ galaxy_info:
dependencies: []
collections:
- community.kubernetes
- kubernetes.core
- operator_sdk.util

View File

@@ -80,7 +80,7 @@
include_tasks: scale_down_deployment.yml
- name: Scale down PostgreSQL statefulset for migration
community.kubernetes.k8s_scale:
kubernetes.core.k8s_scale:
api_version: apps/v1
kind: StatefulSet
name: "{{ meta.name }}-postgres"

View File

@@ -0,0 +1,12 @@
---
- name: Retrieve bundle Certificate Authority Secret
k8s_info:
kind: Secret
namespace: '{{ meta.namespace }}'
name: '{{ bundle_cacert_secret }}'
register: bundle_cacert
- name: Load bundle Certificate Authority Secret content
set_fact:
bundle_ca_crt: '{{ bundle_cacert["resources"][0]["data"]["bundle-ca.crt"] | b64decode }}'
when: '"bundle-ca.crt" in bundle_cacert["resources"][0]["data"]'

View File

@@ -25,6 +25,11 @@
when:
- ldap_cacert_secret != ''
- name: Load bundle certificate authority certificate
include_tasks: load_bundle_cacert_secret.yml
when:
- bundle_cacert_secret != ''
- name: Include admin password configuration tasks
include_tasks: admin_password_configuration.yml

View File

@@ -9,7 +9,7 @@
register: tower_deployment
- name: Scale down Deployment for migration
community.kubernetes.k8s_scale:
kubernetes.core.k8s_scale:
api_version: v1
kind: Deployment
name: "{{ meta.name }}"

View File

@@ -46,7 +46,7 @@ data:
AWX_AUTO_DEPROVISION_INSTANCES = True
CLUSTER_HOST_ID = socket.gethostname()
SYSTEM_UUID = '00000000-0000-0000-0000-000000000000'
SYSTEM_UUID = os.environ.get('MY_POD_UID', '00000000-0000-0000-0000-000000000000')
CSRF_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False

View File

@@ -32,6 +32,25 @@ spec:
{% if image_pull_secret %}
imagePullSecrets:
- name: {{ image_pull_secret }}
{% endif %}
{% if bundle_ca_crt %}
initContainers:
- name: init
image: '{{ init_container_image }}:{{ init_container_image_version }}'
imagePullPolicy: '{{ image_pull_policy }}'
command:
- /bin/sh
- -c
- |
mkdir -p /etc/pki/ca-trust/extracted/{java,pem,openssl,edk2}
update-ca-trust
volumeMounts:
- name: "ca-trust-extracted"
mountPath: "/etc/pki/ca-trust/extracted"
- name: "{{ meta.name }}-bundle-cacert"
mountPath: /etc/pki/ca-trust/source/anchors/bundle-ca.crt
subPath: bundle-ca.crt
readOnly: true
{% endif %}
containers:
- image: '{{ redis_image }}:{{ redis_image_version }}'
@@ -62,6 +81,14 @@ spec:
- containerPort: 8053
{% endif %}
volumeMounts:
{% if bundle_ca_crt %}
- name: "ca-trust-extracted"
mountPath: "/etc/pki/ca-trust/extracted"
- name: "{{ meta.name }}-bundle-cacert"
mountPath: /etc/pki/ca-trust/source/anchors/bundle-ca.crt
subPath: bundle-ca.crt
readOnly: true
{% endif %}
- name: "{{ meta.name }}-application-credentials"
mountPath: "/etc/tower/conf.d/execution_environments.py"
subPath: execution_environments.py
@@ -141,6 +168,14 @@ spec:
args: {{ task_args }}
{% endif %}
volumeMounts:
{% if bundle_ca_crt %}
- name: "ca-trust-extracted"
mountPath: "/etc/pki/ca-trust/extracted"
- name: "{{ meta.name }}-bundle-cacert"
mountPath: /etc/pki/ca-trust/source/anchors/bundle-ca.crt
subPath: bundle-ca.crt
readOnly: true
{% endif %}
- name: "{{ meta.name }}-application-credentials"
mountPath: "/etc/tower/conf.d/execution_environments.py"
subPath: execution_environments.py
@@ -211,6 +246,14 @@ spec:
resources: {{ ee_resource_requirements }}
args: ['receptor', '--config', '/etc/receptor.conf']
volumeMounts:
{% if bundle_ca_crt %}
- name: "ca-trust-extracted"
mountPath: "/etc/pki/ca-trust/extracted"
- name: "{{ meta.name }}-bundle-cacert"
mountPath: /etc/pki/ca-trust/source/anchors/bundle-ca.crt
subPath: bundle-ca.crt
readOnly: true
{% endif %}
- name: "{{ meta.name }}-receptor-config"
mountPath: "/etc/receptor.conf"
subPath: receptor.conf
@@ -241,6 +284,16 @@ spec:
{{ tolerations | indent(width=8) }}
{% endif %}
volumes:
{% if bundle_ca_crt %}
- name: "ca-trust-extracted"
emptyDir: {}
- name: "{{ meta.name }}-bundle-cacert"
secret:
secretName: "{{ bundle_cacert_secret }}"
items:
- key: bundle-ca.crt
path: 'bundle-ca.crt'
{% endif %}
{% if ingress_type | lower == 'route' and route_tls_termination_mechanism | lower == 'passthrough' %}
- name: "{{ meta.name }}-nginx-certs"
secret:

View File

@@ -2,4 +2,5 @@
postgres_initdb_args: '--auth-host=scram-sha-256'
postgres_host_auth_method: 'scram-sha-256'
ldap_cacert_ca_crt: ''
bundle_ca_crt: ''
projects_existing_claim: ''

View File

@@ -27,5 +27,5 @@ galaxy_info:
dependencies: []
collections:
- community.kubernetes
- kubernetes.core
- operator_sdk.util

Binary file not shown.