Skip to content

Commit d6375db

Browse files
committed
Document the manageStatus flag
1 parent 6fa4204 commit d6375db

File tree

2 files changed

+49
-73
lines changed

2 files changed

+49
-73
lines changed

doc/ansible/dev/developer_guide.md

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -147,79 +147,6 @@ trigger this Ansible logic when a custom resource changes. In the above
147147
example, we want to map a role to a specific Kubernetes resource that the
148148
operator will watch. This mapping is done in a file called `watches.yaml`.
149149

150-
### Watches file
151-
152-
The Operator expects a mapping file, which lists each GVK to watch and the
153-
corresponding path to an Ansible role or playbook, to be copied into the
154-
container at a predefined location: /opt/ansible/watches.yaml
155-
156-
Dockerfile example:
157-
```Dockerfile
158-
COPY watches.yaml /opt/ansible/watches.yaml
159-
```
160-
161-
The Watches file format is yaml and is an array of objects. The object has
162-
mandatory fields:
163-
164-
**version**: The version of the Custom Resource that you will be watching.
165-
166-
**group**: The group of the Custom Resource that you will be watching.
167-
168-
**kind**: The kind of the Custom Resource that you will be watching.
169-
170-
**playbook**: This is the path to the playbook that you have added to the
171-
container. This playbook is expected to be simply a way to call roles. This
172-
field is mutually exclusive with the "role" field.
173-
174-
**role**: This is the path to the role that you have added to the container.
175-
For example if your roles directory is at `/opt/ansible/roles/` and your role
176-
is named `busybox`, this value will be `/opt/ansible/roles/busybox`. This field
177-
is mutually exclusive with the "playbook" field.
178-
179-
Example specifying a role:
180-
181-
```yaml
182-
---
183-
- version: v1alpha1
184-
group: foo.example.com
185-
kind: Foo
186-
role: /opt/ansible/roles/Foo
187-
```
188-
189-
#### Using playbooks in watches.yaml
190-
191-
By default, `operator-sdk new --type ansible` sets `watches.yaml` to execute a
192-
role directly on a resource event. This works well for new projects, but with a
193-
lot of Ansible code this can be hard to scale if we are putting everything
194-
inside of one role. Using a playbook allows the developer to have more
195-
flexibility in consuming other roles and enabling more customized deployments
196-
of their application. To do this, modify `watches.yaml` to use a playbook
197-
instead of the role:
198-
```yaml
199-
---
200-
- version: v1alpha1
201-
group: foo.example.com
202-
kind: Foo
203-
playbook: /opt/ansible/playbook.yml
204-
```
205-
206-
Modify `tmp/build/Dockerfile` to put `playbook.yml` in `/opt/ansible` in the
207-
container in addition to the role (`/opt/ansible` is the `HOME` environment
208-
variable inside of the Ansible Operator base image):
209-
```Dockerfile
210-
FROM quay.io/water-hole/ansible-operator
211-
212-
COPY roles/ ${HOME}/roles
213-
COPY playbook.yaml ${HOME}/playbook.yaml
214-
COPY watches.yaml ${HOME}/watches.yaml
215-
```
216-
217-
Alternatively, to generate a skeleton project with the above changes, a
218-
developer can also do:
219-
```bash
220-
$ operator-sdk new --type ansible --kind Foo --api-version foo.example.com/v1alpha1 foo-operator --generate-playbook
221-
```
222-
223150
### Custom Resource file
224151

225152
The Custom Resource file format is Kubernetes resource file. The object has

doc/ansible/user-guide.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,55 @@ If you'd like to create your memcached-operator project to be cluster-scoped use
6262
$ operator-sdk new memcached-operator --cluster-scoped --api-version=cache.example.com/v1alpha1 --kind=Memcached --type=ansible
6363
```
6464

65+
### Watches file
66+
67+
The Watches file contains a list of mappings from custom resources, identified
68+
by it's Group, Version, and Kind, to an Ansible Role or Playbook. The Operator
69+
expects this mapping file in a predefined location: `/opt/ansible/watches.yaml`
70+
71+
* **group**: The group of the Custom Resource that you will be watching.
72+
* **version**: The version of the Custom Resource that you will be watching.
73+
* **kind**: The kind of the Custom Resource that you will be watching.
74+
* **role** (default): This is the path to the role that you have added to the
75+
container. For example if your roles directory is at `/opt/ansible/roles/`
76+
and your role is named `busybox`, this value will be
77+
`/opt/ansible/roles/busybox`. This field is mutually exclusive with the
78+
"playbook" field.
79+
* **playbook**: This is the path to the playbook that you have added to the
80+
container. This playbook is expected to be simply a way to call roles. This
81+
field is mutually exclusive with the "role" field.
82+
* **reconcilePeriod** (optional): The reconciliation interval, how often the
83+
role/playbook is run, for a given CR.
84+
* **manageStatus** (optional): Specifies who is managing the status for the CR.
85+
Set to `false` when you want the role/playbook to be solely responsible for
86+
the CR's status.
87+
88+
An example Watches file:
89+
90+
```yaml
91+
---
92+
# Simple example mapping Foo to the Foo role
93+
- version: v1alpha1
94+
group: foo.example.com
95+
kind: Foo
96+
role: /opt/ansible/roles/Foo
97+
98+
# Simple example mapping Bar to a playbook
99+
- version: v1alpha1
100+
group: bar.example.com
101+
kind: Bar
102+
playbook: /opt/ansible/playbook.yaml
103+
104+
# More complex example for our Baz kind
105+
# Here we will disable requeuing and be managing the CR status in the playbook
106+
- version: v1alpha1
107+
group: baz.example.com
108+
kind: Baz
109+
playbook: /opt/ansible/baz.yaml
110+
reconcilePeriod: 0
111+
manageStatus: false
112+
```
113+
65114
## Customize the operator logic
66115
67116
For this example the memcached-operator will execute the following

0 commit comments

Comments
 (0)