| 1 |
name: CI |
| 2 |
on: |
| 3 |
pull_request: |
| 4 |
schedule: |
| 5 |
- cron: "0 3 * * *" |
| 6 |
|
| 7 |
jobs: |
| 8 |
x509_membership_auth: |
| 9 |
runs-on: ubuntu-22.04 |
| 10 |
defaults: |
| 11 |
run: |
| 12 |
working-directory: ansible_collections/community/mongodb/tests/ansible-operator |
| 13 |
steps: |
| 14 |
|
| 15 |
- name: Check out code |
| 16 |
uses: actions/checkout@v5 |
| 17 |
with: |
| 18 |
path: ansible_collections/community/mongodb |
| 19 |
|
| 20 |
- name: Set up Docker |
| 21 |
uses: docker/setup-docker-action@v4 |
| 22 |
|
| 23 |
- name: Enable and start docker |
| 24 |
run: | |
| 25 |
sudo systemctl enable --now docker |
| 26 |
sudo systemctl status docker |
| 27 |
|
| 28 |
- name: Setup Minikube |
| 29 |
uses: manusa/[email protected] |
| 30 |
with: |
| 31 |
minikube version: 'v1.35.0' |
| 32 |
kubernetes version: 'v1.33.0' |
| 33 |
github token: ${{ secrets.GITHUB_TOKEN }} |
| 34 |
driver: docker |
| 35 |
|
| 36 |
- name: Install mongodb-mongosh |
| 37 |
uses: nick-fields/retry@v3 |
| 38 |
with: |
| 39 |
timeout_minutes: 3 |
| 40 |
max_attempts: 3 |
| 41 |
command: | |
| 42 |
sudo apt-get install gnupg curl |
| 43 |
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ |
| 44 |
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor |
| 45 |
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list |
| 46 |
sudo apt-get update |
| 47 |
sudo apt-get install mongodb-mongosh |
| 48 |
|
| 49 |
- name: Install cert-manager |
| 50 |
run: | |
| 51 |
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.2/cert-manager.yaml |
| 52 |
|
| 53 |
- name: Generate certs |
| 54 |
run: | |
| 55 |
openssl genrsa -out ca.key 8192 |
| 56 |
openssl req -x509 -new -nodes -key ca.key -sha256 -subj "/CN=mongodb-cluster-ca.local" -days 36500 -reqexts v3_req -extensions v3_ca -out ca.crt |
| 57 |
|
| 58 |
- name: Wait for cert-manager webhook to be ready |
| 59 |
run: | |
| 60 |
kubectl rollout status deployment/cert-manager-webhook -n cert-manager --timeout=300s |
| 61 |
kubectl wait --for=condition=Available=True deployment/cert-manager-webhook -n cert-manager --timeout=300s |
| 62 |
# Additional wait to ensure the webhook service is reachable |
| 63 |
for i in {1..10}; do |
| 64 |
kubectl get svc cert-manager-webhook -n cert-manager && break || sleep 15 |
| 65 |
done |
| 66 |
|
| 67 |
- name: debug cert-manager |
| 68 |
run: | |
| 69 |
kubectl get pods,secrets -n cert-manager |
| 70 |
|
| 71 |
- name: Register the certs with k8 |
| 72 |
run: | |
| 73 |
kubectl create secret tls mongodb-cluster-ca-key-pair --key=ca.key --cert=ca.crt |
| 74 |
kubectl apply -f ca-issuer.yaml |
| 75 |
|
| 76 |
- name: make install |
| 77 |
run: make install |
| 78 |
|
| 79 |
- name: Create k8 namesapce |
| 80 |
run: kubectl create ns ansible-operator-system |
| 81 |
|
| 82 |
- name: make docker-build |
| 83 |
run: | |
| 84 |
eval $(minikube docker-env --shell sh) |
| 85 |
make docker-build IMG=test-mongodb-operator:latest |
| 86 |
|
| 87 |
- name: make deploy |
| 88 |
run: | |
| 89 |
eval $(minikube docker-env --shell sh) |
| 90 |
make deploy IMG=test-mongodb-operator:latest |
| 91 |
|
| 92 |
- name: Debug controller |
| 93 |
run: kubectl get all -n ansible-operator-system |
| 94 |
|
| 95 |
- name: Wait for controller to be ready |
| 96 |
run: kubectl wait --for=condition=available deployment/ansible-operator-controller-manager -n ansible-operator-system --timeout=120s |
| 97 |
|
| 98 |
- name: Load image into minikube |
| 99 |
run: | |
| 100 |
eval $(minikube docker-env --shell sh) |
| 101 |
minikube image load test-mongodb-operator:latest |
| 102 |
|
| 103 |
- name: Setup the k8 mongodb env |
| 104 |
run: | |
| 105 |
eval $(minikube docker-env --shell sh) |
| 106 |
kubectl apply -f config/samples/mongodb_v1alpha1_mongodb.yaml |
| 107 |
sleep 10 |
| 108 |
kubectl -n ansible-operator-system logs deployment.apps/ansible-operator-controller-manager -c manager |
| 109 |
|
| 110 |
- name: Wait for a bit |
| 111 |
run: sleep 60 |
| 112 |
|
| 113 |
- name: Install socat |
| 114 |
run: | |
| 115 |
sudo apt update |
| 116 |
sudo apt install socat |
| 117 |
|
| 118 |
- name: Forward the local port 27017 to k8 |
| 119 |
run: kubectl port-forward mongodb-sample-0 27017:27017 --address 0.0.0.0 & |
| 120 |
|
| 121 |
- name: Copy the certs to the localhost |
| 122 |
run: | |
| 123 |
managerpod=$(kubectl get pods -n ansible-operator-system --no-headers | tr -s ' ' | cut -d ' ' -f 1) |
| 124 |
kubectl cp ansible-operator-system/${managerpod}:/tmp/mongodb-sample.default/ca.crt ca.crt -c manager |
| 125 |
kubectl cp ansible-operator-system/${managerpod}:/tmp/mongodb-sample.default/tls.key tls.key -c manager |
| 126 |
|
| 127 |
- name: Run mongosh shell command to test x509 membership connectivity |
| 128 |
run: | |
| 129 |
kubectl -n ansible-operator-system exec -ti deployment.apps/ansible-operator-controller-manager -c manager -- \ |
| 130 |
/usr/bin/mongosh mongodb://mongodb-sample.default.svc.cluster.local \ |
| 131 |
--tls \ |
| 132 |
--tlsCAFile /tmp/mongodb-sample.default/ca.crt \ |
| 133 |
--tlsCertificateKeyFile /tmp/mongodb-sample.default/tls.key \ |
| 134 |
--authenticationMechanism MONGODB-X509 \ |
| 135 |
--authenticationDatabase '$external' \ |
| 136 |
--eval "db.adminCommand('listDatabases')" |
| 137 |
|
| 138 |
- name: Run mongosh shell command to test x509 membership connectivity from localhost |
| 139 |
run: | |
| 140 |
/usr/bin/mongosh mongodb://127.0.0.1 \ |
| 141 |
--tls \ |
| 142 |
--tlsCAFile ca.crt \ |
| 143 |
--tlsCertificateKeyFile tls.key \ |
| 144 |
--tlsAllowInvalidHostnames \ |
| 145 |
--authenticationMechanism MONGODB-X509 \ |
| 146 |
--authenticationDatabase '$external' \ |
| 147 |
--eval "db.adminCommand('listDatabases')" |
| 148 |
|
| 149 |
- name: Set up Python 3.13 |
| 150 |
uses: actions/setup-python@v5 |
| 151 |
with: |
| 152 |
python-version: "3.13" |
| 153 |
|
| 154 |
- name: Install ansible-base devel |
| 155 |
uses: nick-invision/retry@v3 |
| 156 |
with: |
| 157 |
timeout_minutes: 3 |
| 158 |
max_attempts: 3 |
| 159 |
command: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check |
| 160 |
|
| 161 |
- name: Build the collection |
| 162 |
run: ansible-galaxy collection build |
| 163 |
working-directory: ansible_collections/community/mongodb |
| 164 |
|
| 165 |
- name: Rename the build artifact |
| 166 |
run: mv community-mongodb-*.tar.gz community-mongodb-latest.tar.gz |
| 167 |
working-directory: ansible_collections/community/mongodb |
| 168 |
|
| 169 |
- name: Install collection |
| 170 |
run: ansible-galaxy collection install community-mongodb-*.tar.gz |
| 171 |
working-directory: ansible_collections/community/mongodb |
| 172 |
|
| 173 |
- name: Install pymongo |
| 174 |
uses: nick-fields/retry@v3 |
| 175 |
with: |
| 176 |
timeout_minutes: 3 |
| 177 |
max_attempts: 3 |
| 178 |
command: pip install pymongo |
| 179 |
|
| 180 |
- name: Run mongodb_user module with membership auth |
| 181 |
run: ansible localhost -m community.mongodb.mongodb_user -a "login_host=localhost login_port=27017 login_database='$external' database='admin' password='secret' ssl=true ssl_ca_certs=ca.crt ssl_certfile=tls.key auth_mechanism=MONGODB-X509 name="test" state=present connection_options='tlsAllowInvalidHostnames=true'" |
| 182 |
|
| 183 |
- name: Run mongodb_info module with membership auth |
| 184 |
run: ansible localhost -m community.mongodb.mongodb_info -a "login_host=localhost login_port=27017 login_database='$external' ssl=true ssl_ca_certs=ca.crt ssl_certfile=tls.key auth_mechanism=MONGODB-X509 connection_options='tlsAllowInvalidHostnames=true'" |
| 185 |
|
| 186 |
- name: Run mongodb_parameter module with membership auth |
| 187 |
run: ansible localhost -m community.mongodb.mongodb_parameter -a "login_host=localhost login_port=27017 login_database='$external' param=syncdelay value=60 param_type=int ssl=true ssl_ca_certs=ca.crt ssl_certfile=tls.key auth_mechanism=MONGODB-X509 connection_options='tlsAllowInvalidHostnames=true'" |