Skip to content

Commit

Permalink
Merge f1d15fb into fcdbd12
Browse files Browse the repository at this point in the history
  • Loading branch information
asmacdo committed Dec 12, 2019
2 parents fcdbd12 + f1d15fb commit 0230879
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 480 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,5 @@
## Unreleased


### Added

- Added new `--bundle` flag to the `operator-sdk scorecard` command to support bundle validation testing using the validation API (https://github.com/operator-framework/api). ([#1916](https://github.com/operator-framework/operator-sdk/pull/1916)
Expand All @@ -12,6 +11,8 @@
- Replace usage of `github.com/operator-framework/operator-sdk/pkg/restmapper.DynamicRESTMapper` with `sigs.k8s.io/controller-runtime/pkg/client/apiutil.DynamicRESTMapper`. ([#2309](https://github.com/operator-framework/operator-sdk/pull/2309))
- Upgraded Helm operator packages and base image from Helm v2 to Helm v3. Cluster state for pre-existing CRs using Helm v2-based operators will be automatically migrated to Helm v3's new release storage format, and existing releases may be upgraded due to changes in Helm v3's label injection. ([#2080](https://github.com/operator-framework/operator-sdk/pull/2080))
- Fail `operator-sdk olm-catalog gen-csv` if it is not run from a project's root, which the command already assumes is the case. ([#2322](https://github.com/operator-framework/operator-sdk/pull/2322))
- **Breaking Change:** Extract custom Ansible module `k8s_status`, which is now provided by the `operator_sdk.util` Ansible collection. See [developer_guide](https://github.com/operator-framework/operator-sdk/blob/master/doc/ansible/dev/developer_guide.md#custom-resource-status-management) for new usage. ([#2310](https://github.com/operator-framework/operator-sdk/pull/2310))
- Upgrade minimal Ansible version in the init projects from `2.6` to `2.9` for collections support. ([#2310](https://github.com/operator-framework/operator-sdk/pull/2310))

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion ci/dockerfiles/ansible-e2e-hybrid.Dockerfile
Expand Up @@ -36,10 +36,10 @@ RUN yum clean all && rm -rf /var/cache/yum/* \
&& yum remove -y gcc python36-devel \
&& yum clean all \
&& rm -rf /var/cache/yum
&& ansible-galaxy collection install operator_sdk.util

# install operator binary
COPY --from=builder /memcached-operator ${OPERATOR}
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/library/k8s_status.py /usr/share/ansible/openshift/
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/bin/* /usr/local/bin/
COPY --from=builder /ansible/memcached-operator/watches.yaml ${HOME}/watches.yaml
COPY --from=builder /ansible/memcached-operator/roles/ ${HOME}/roles/
Expand Down
2 changes: 1 addition & 1 deletion ci/dockerfiles/ansible.Dockerfile
Expand Up @@ -35,9 +35,9 @@ RUN yum clean all && rm -rf /var/cache/yum/* \
&& yum remove -y gcc python36-devel \
&& yum clean all \
&& rm -rf /var/cache/yum
&& ansible-galaxy collection install operator_sdk.util

COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/build/operator-sdk ${OPERATOR}
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/library/k8s_status.py /usr/share/ansible/openshift/
COPY --from=builder /go/src/github.com/operator-framework/operator-sdk/bin/* /usr/local/bin/

RUN /usr/local/bin/user_setup
Expand Down
1 change: 0 additions & 1 deletion cmd/operator-sdk/migrate/cmd.go
Expand Up @@ -123,7 +123,6 @@ func migrateAnsible() error {
&dockerfile,
&ansible.Entrypoint{},
&ansible.UserSetup{},
&ansible.K8sStatus{},
&ansible.AoLogs{},
)
if err != nil {
Expand Down
67 changes: 40 additions & 27 deletions doc/ansible/dev/developer_guide.md
Expand Up @@ -364,13 +364,17 @@ status:
type: Running
```

Ansible Operator also allows you as the developer to supply custom status
values with the [k8s_status][k8s_status_module] Ansible Module. This allows the
developer to update the `status` from within Ansible with any key/value pair as
desired. By default, Ansible Operator will always include the generic Ansible
run output as shown above. If you would prefer your application *not* update
the status with Ansible output and would prefer to track the status manually
from your application, then simply update the watches file with `manageStatus`:
Ansible Operator also allows you as the developer to supply custom
status values with the `k8s_status` Ansible Module, which is included in
[operator_sdk util collection](https://galaxy.ansible.com/operator_sdk/util).

This allows the developer to update the `status` from within Ansible
with any key/value pair as desired. By default, Ansible Operator will
always include the generic Ansible run output as shown above. If you
would prefer your application *not* update the status with Ansible
output and would prefer to track the status manually from your
application, then simply update the watches file with `manageStatus`:

```yaml
- version: v1
group: api.example.com
Expand All @@ -379,10 +383,13 @@ from your application, then simply update the watches file with `manageStatus`:
manageStatus: false
```

To update the `status` subresource with key `foo` and value `bar`, `k8s_status`
can be used as shown:
The simplest way to invoke the `k8s_status` module is to
use its fully qualified collection name (fqcn). To update the
`status` subresource with key `foo` and value `bar`, `k8s_status` can be
used as shown:

```yaml
- k8s_status:
- operator_sdk.util.k8s_status:
api_version: app.example.com/v1
kind: Foo
name: "{{ meta.name }}"
Expand All @@ -391,6 +398,24 @@ can be used as shown:
foo: bar
```

Collections can also be declared in the role's `meta/main.yml`, which is
included for new scaffolded ansible operators.

```yaml
collections:
- operator_sdk.util
```

Declaring collections in the role meta allows you to invoke the
`k8s_status` module directly.

```yaml
- k8s_status:
<snip>
status:
foo: bar
```

### Ansible Operator Conditions
The Ansible Operator has a set of conditions which it will use as it performs
its reconciliation procedure. There are only a few main conditions:
Expand Down Expand Up @@ -423,23 +448,12 @@ the Ansible Operator, see the [proposal for user-driven status
management][manage_status_proposal].

If your operator takes advantage of the `k8s_status` Ansible module and you are
interested in testing the operator with `operator-sdk up local`, then it is
imperative that the module is installed in a location that Ansible expects.
This is done with the `library` configuration option for Ansible. For our
example, we will assume the user is placing third-party Ansible modules in
`/usr/share/ansible/library`.

To install the `k8s_status` module, first set `ansible.cfg` to search in
`/usr/share/ansible/library` for installed Ansible modules:
```bash
$ echo "library=/usr/share/ansible/library/" >> /etc/ansible/ansible.cfg
```

Add `k8s_status.py` to `/usr/share/ansible/library/`:
```bash
$ wget https://raw.githubusercontent.com/fabianvf/ansible-k8s-status-module/master/k8s_status.py -O /usr/share/ansible/library/k8s_status.py
```
interested in testing the operator with `operator-sdk up local`, then
you will need to install the collection locally.

```sh
$ ansible-galaxy collection install operator_sdk.util
```
## Extra vars sent to Ansible
The extra vars that are sent to Ansible are managed by the operator. The `spec`
section will pass along the key-value pairs as extra vars. This is equivalent
Expand Down Expand Up @@ -486,7 +500,6 @@ operator. The `meta` fields can be accesses via dot notation in Ansible as so:
```

[k8s_ansible_module]:https://docs.ansible.com/ansible/2.6/modules/k8s_module.html
[k8s_status_module]:https://github.com/fabianvf/ansible-k8s-status-module
[openshift_restclient_python]:https://github.com/openshift/openshift-restclient-python
[ansible_operator_user_guide]:../user-guide.md
[manage_status_proposal]:../../proposals/ansible-operator-status.md
Expand Down
1 change: 0 additions & 1 deletion hack/image/ansible/scaffold-ansible-image.go
Expand Up @@ -38,7 +38,6 @@ func main() {
&ansible.DockerfileHybrid{},
&ansible.Entrypoint{},
&ansible.UserSetup{},
&ansible.K8sStatus{},
&ansible.AoLogs{},
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/scaffold/ansible/dockerfilehybrid.go
Expand Up @@ -74,11 +74,11 @@ RUN yum clean all && rm -rf /var/cache/yum/* \
jmespath \
&& yum remove -y gcc python36-devel \
&& yum clean all \
&& rm -rf /var/cache/yum
&& rm -rf /var/cache/yum \
&& ansible-galaxy collection install operator_sdk.util
COPY build/_output/bin/[[.ProjectName]] ${OPERATOR}
COPY bin /usr/local/bin
COPY library/k8s_status.py /usr/share/ansible/openshift/
RUN /usr/local/bin/user_setup
Expand Down

0 comments on commit 0230879

Please sign in to comment.