mirror of
https://github.com/openshift/community.okd.git
synced 2026-11-22 07:00:26 +00:00
Compare commits
64
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5ee8f254d | ||
|
|
47d8bdf08f | ||
|
|
278886dfad | ||
|
|
85041157bc | ||
|
|
fd328e619f | ||
|
|
f54fee9a30 | ||
|
|
1313ca4eb1 | ||
|
|
d8d077b754 | ||
|
|
2d2d27ec74 | ||
|
|
a16e726d3d | ||
|
|
cc3e4f1a8d | ||
|
|
75b91d1853 | ||
|
|
af9fb5a730 | ||
|
|
b7e5970831 | ||
|
|
fe082a5730 | ||
|
|
74155f021e | ||
|
|
d30a349e2f | ||
|
|
c2f1d722dc | ||
|
|
cfd6ee1f9b | ||
|
|
d2346e4c8f | ||
|
|
140da75c0f | ||
|
|
f54297c2ac | ||
|
|
69bcd79b92 | ||
|
|
93746f2392 | ||
|
|
a3c3a69bbf | ||
|
|
d1788bed2d | ||
|
|
c1683e6dcc | ||
|
|
0bc2515809 | ||
|
|
a76c07c27a | ||
|
|
0a266a6716 | ||
|
|
ec8d7e8299 | ||
|
|
075c143e40 | ||
|
|
adfb5ee140 | ||
|
|
59e78926ec | ||
|
|
a3704021d3 | ||
|
|
3e37a4cf62 | ||
|
|
0e884c2341 | ||
|
|
050e236aa6 | ||
|
|
2c394132aa | ||
|
|
fcc19da20a | ||
|
|
31c2df50ed | ||
|
|
ca8b491f87 | ||
|
|
b5b2f67015 | ||
|
|
7988daff93 | ||
|
|
408eae11ae | ||
|
|
5244611fa5 | ||
|
|
a63e5b7b36 | ||
|
|
cb796e1298 | ||
|
|
e9c891c5c2 | ||
|
|
81339235c7 | ||
|
|
f94eabffa1 | ||
|
|
499863fa27 | ||
|
|
5834e32c73 | ||
|
|
5aa63e1b07 | ||
|
|
d7f8aa537a | ||
|
|
1691951788 | ||
|
|
ed9fb196f9 | ||
|
|
1819975498 | ||
|
|
01c257ce76 | ||
|
|
5545c0f9ae | ||
|
|
15fff541b1 | ||
|
|
cfbbbb3be1 | ||
|
|
ab83a185f5 | ||
|
|
e69c88ae30 |
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
profile: production
|
||||||
|
|
||||||
|
exclude_paths:
|
||||||
|
- tests/unit
|
||||||
|
- tests/sanity
|
||||||
|
- molecule
|
||||||
|
- changelogs
|
||||||
|
- docs
|
||||||
|
- .ansible
|
||||||
|
- .github
|
||||||
|
|
||||||
|
warn_list:
|
||||||
|
- no-log-password
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
.venv
|
||||||
|
.git
|
||||||
|
.idea
|
||||||
|
.cache/
|
||||||
|
__pycache__/
|
||||||
|
*.tar.gz
|
||||||
|
changelogs/.plugin-cache.yaml
|
||||||
|
tests/output
|
||||||
|
tests/integration/cloud-config-*
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
backport_branch_prefix: patchback/backports/
|
||||||
|
backport_label_prefix: backport-
|
||||||
|
target_branch_prefix: stable-
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
# DO NOT MODIFY
|
||||||
|
|
||||||
|
# Settings: https://probot.github.io/apps/settings/
|
||||||
|
# Pull settings from https://github.com/ansible-collections/.github/blob/master/.github/settings.yml
|
||||||
|
_extends: ".github"
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
# Configuration for probot-stale - https://github.com/probot/stale
|
||||||
|
|
||||||
|
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
||||||
|
daysUntilStale: 90
|
||||||
|
|
||||||
|
# Number of days of inactivity before an Issue or Pull Request with the stale
|
||||||
|
# label is closed. Set to false to disable. If disabled, issues still need to be
|
||||||
|
# closed manually, but will remain marked as stale.
|
||||||
|
daysUntilClose: 30
|
||||||
|
|
||||||
|
# Only issues or pull requests with all of these labels are check if stale.
|
||||||
|
# Defaults to `[]` (disabled)
|
||||||
|
onlyLabels: []
|
||||||
|
|
||||||
|
# Issues or Pull Requests with these labels will never be considered stale. Set
|
||||||
|
# to `[]` to disable
|
||||||
|
exemptLabels:
|
||||||
|
- security
|
||||||
|
- planned
|
||||||
|
- priority/critical
|
||||||
|
- lifecycle/frozen
|
||||||
|
- verified
|
||||||
|
|
||||||
|
# Set to true to ignore issues in a project (defaults to false)
|
||||||
|
exemptProjects: false
|
||||||
|
|
||||||
|
# Set to true to ignore issues in a milestone (defaults to false)
|
||||||
|
exemptMilestones: true
|
||||||
|
|
||||||
|
# Set to true to ignore issues with an assignee (defaults to false)
|
||||||
|
exemptAssignees: false
|
||||||
|
|
||||||
|
# Label to use when marking as stale
|
||||||
|
staleLabel: lifecycle/stale
|
||||||
|
|
||||||
|
# Limit the number of actions per hour, from 1-30. Default is 30
|
||||||
|
limitPerRun: 30
|
||||||
|
|
||||||
|
pulls:
|
||||||
|
markComment: |-
|
||||||
|
PRs go stale after 90 days of inactivity.
|
||||||
|
If there is no further activity, the PR will be closed in another 30 days.
|
||||||
|
|
||||||
|
unmarkComment: >-
|
||||||
|
This pull request is no longer stale.
|
||||||
|
|
||||||
|
closeComment: >-
|
||||||
|
This pull request has been closed due to inactivity.
|
||||||
|
|
||||||
|
issues:
|
||||||
|
markComment: |-
|
||||||
|
Issues go stale after 90 days of inactivity.
|
||||||
|
If there is no further activity, the issue will be closed in another 30 days.
|
||||||
|
|
||||||
|
unmarkComment: >-
|
||||||
|
This issue is no longer stale.
|
||||||
|
|
||||||
|
closeComment: >-
|
||||||
|
This issue has been closed due to inactivity.
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
name: Changelog
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- reopened
|
||||||
|
- labeled
|
||||||
|
- unlabeled
|
||||||
|
- synchronize
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- stable-*
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
changelog:
|
||||||
|
uses: ansible-network/github_actions/.github/workflows/changelog.yml@main
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
name: Linters
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- reopened
|
||||||
|
- labeled
|
||||||
|
- unlabeled
|
||||||
|
- synchronize
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- stable-*
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
jobs:
|
||||||
|
linters:
|
||||||
|
uses: ansible-network/github_actions/.github/workflows/tox-linters.yml@main
|
||||||
|
ansible-lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: ansible-network/github_actions/.github/actions/checkout_dependency@main
|
||||||
|
|
||||||
|
- name: run-ansible-lint
|
||||||
|
uses: ansible/ansible-lint@v25.1.2
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
name: Sanity tests
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- reopened
|
||||||
|
- synchronize
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- stable-*
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sanity:
|
||||||
|
uses: ansible-network/github_actions/.github/workflows/sanity.yml@main
|
||||||
|
with:
|
||||||
|
collection_pre_install: '-r source/tests/sanity/requirements.yml'
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
name: Unit tests
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- reopened
|
||||||
|
- synchronize
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- stable-*
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit-source:
|
||||||
|
uses: ansible-network/github_actions/.github/workflows/unit_source.yml@main
|
||||||
@@ -16,6 +16,3 @@ changelogs/.plugin-cache.yaml
|
|||||||
# Temporary test files.
|
# Temporary test files.
|
||||||
tests/output
|
tests/output
|
||||||
tests/integration/cloud-config-*
|
tests/integration/cloud-config-*
|
||||||
|
|
||||||
# Ignore the ansible_collections that the Makefile generates.
|
|
||||||
ansible_collections
|
|
||||||
|
|||||||
@@ -1,33 +1,15 @@
|
|||||||
---
|
---
|
||||||
# Based on ansible-lint config
|
|
||||||
extends: default
|
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
braces:
|
indentation:
|
||||||
max-spaces-inside: 1
|
ignore: &default_ignores |
|
||||||
level: error
|
# automatically generated, we can't control it
|
||||||
brackets:
|
changelogs/changelog.yaml
|
||||||
max-spaces-inside: 1
|
# Will be gone when we release and automatically reformatted
|
||||||
level: error
|
changelogs/fragments/*
|
||||||
colons:
|
document-start:
|
||||||
max-spaces-after: -1
|
ignore: *default_ignores
|
||||||
level: error
|
line-length:
|
||||||
commas:
|
ignore: *default_ignores
|
||||||
max-spaces-after: -1
|
max: 160
|
||||||
level: error
|
|
||||||
comments: disable
|
ignore-from-file: .gitignore
|
||||||
comments-indentation: disable
|
|
||||||
document-start: disable
|
|
||||||
empty-lines:
|
|
||||||
max: 3
|
|
||||||
level: error
|
|
||||||
hyphens:
|
|
||||||
level: error
|
|
||||||
indentation: disable
|
|
||||||
key-duplicates: enable
|
|
||||||
line-length: disable
|
|
||||||
new-line-at-end-of-file: disable
|
|
||||||
new-lines:
|
|
||||||
type: unix
|
|
||||||
trailing-spaces: disable
|
|
||||||
truthy: disable
|
|
||||||
|
|||||||
+147
@@ -4,6 +4,153 @@ OKD Collection Release Notes
|
|||||||
|
|
||||||
.. contents:: Topics
|
.. contents:: Topics
|
||||||
|
|
||||||
|
v6.0.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
This major release drops support for ansible-core versions below 2.16,
|
||||||
|
replaces all ``ansible.module_utils.six`` imports with Python 3 stdlib equivalents,
|
||||||
|
and fixes deprecated ``ansible.module_utils._text`` imports for compatibility
|
||||||
|
with ansible-core 2.24+.
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- Add sanity test ignore files for ansible-core 2.20 and 2.21 (https://github.com/openshift/community.okd/pull/286).
|
||||||
|
- Replace ``ansible.module_utils.six.moves.urllib_parse`` import with Python 3 ``urllib.parse`` in ``openshift_auth`` module (https://github.com/openshift/community.okd/pull/291).
|
||||||
|
- Replace ``ansible.module_utils.six`` imports (``iteritems``, ``string_types``) with Python 3 stdlib equivalents (https://github.com/openshift/community.okd/pull/286).
|
||||||
|
- Replace deprecated ``ansible.module_utils._text`` imports with ``ansible.module_utils.common.text.converters`` to fix compatibility with ansible-core 2.24+ (https://github.com/openshift/community.okd/issues/275).
|
||||||
|
|
||||||
|
Breaking Changes / Porting Guide
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
- Minimum supported version of ansible-core is now 2.16 (https://github.com/openshift/community.okd/pull/292).
|
||||||
|
|
||||||
|
v5.0.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
This release drops support for ansible-lint < 25.1.2 and removes deprecated openshift inventory plugin.
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- Bump version of ansible-lint to 25.1.2 (https://github.com/openshift/community.okd/pull/255).
|
||||||
|
- Bump version of ansible-lint to minimum 24.7.0 (https://github.com/openshift/community.okd/pull/240).
|
||||||
|
|
||||||
|
Breaking Changes / Porting Guide
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
- Remove openshift inventory plugin deprecated in 3.0.0 (https://github.com/openshift/community.okd/pull/252).
|
||||||
|
|
||||||
|
v4.0.2
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
This patch updates the k8s dependency version to the 5.x range and modifies tests to handle the manual creation of service account tokens.
|
||||||
|
|
||||||
|
v4.0.1
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
This is a bug fix release
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- openshift_auth - fix issue where openshift_auth module sometimes does not delete the auth token. Based on stale PR (https://github.com/openshift/community.okd/pull/194).
|
||||||
|
|
||||||
|
v4.0.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
In this major release we have removed support for ``ansible-core<2.15``.
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- connection/oc - added support of local enviroment variable that will be used for ``oc`` and may be requried for establishing connections ifself (https://github.com/openshift/community.okd/pull/225).
|
||||||
|
- inventory/openshift.py - Defer removal of k8s inventory plugin to version 5.0.0 (https://github.com/openshift/community.okd/pull/224).
|
||||||
|
|
||||||
|
Removed Features (previously deprecated)
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
- k8s - Support for ``merge_type=json`` has been removed in version 4.0.0. Please use ``kubernetes.core.k8s_json_patch`` instead (https://github.com/openshift/community.okd/pull/226).
|
||||||
|
|
||||||
|
v3.0.1
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
This patch release fixes an issue in building the downstream collection.
|
||||||
|
|
||||||
|
v3.0.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Release Summary
|
||||||
|
---------------
|
||||||
|
|
||||||
|
This major release drops support for ansible-core versions lower than 2.14 and Python versions lower than 3.9. It also deprecates ``openshift`` inventory plugin.
|
||||||
|
|
||||||
|
Breaking Changes / Porting Guide
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
- Bump minimum Python suupported version to 3.9 (https://github.com/openshift/community.okd/pull/202).
|
||||||
|
- Remove support for ansible-core < 2.14 (https://github.com/openshift/community.okd/pull/202).
|
||||||
|
|
||||||
|
Deprecated Features
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- openshift - the ``openshift`` inventory plugin has been deprecated and will be removed in release 4.0.0 (https://github.com/ansible-collections/kubernetes.core/issues/31).
|
||||||
|
|
||||||
|
v2.3.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
--------
|
||||||
|
|
||||||
|
- openshift_adm_groups_sync - initialize OpenshiftGroupSync attributes early to avoid Attribute error (https://github.com/openshift/community.okd/issues/155).
|
||||||
|
- openshift_auth - Review the way the discard process is working, add openshift algorithm to convert token to resource object name (https://github.com/openshift/community.okd/issues/176).
|
||||||
|
|
||||||
|
New Modules
|
||||||
|
-----------
|
||||||
|
|
||||||
|
- openshift_adm_prune_builds - Prune old completed and failed builds
|
||||||
|
- openshift_build - Start a new build or Cancel running, pending, or new builds.
|
||||||
|
|
||||||
|
v2.2.0
|
||||||
|
======
|
||||||
|
|
||||||
|
Minor Changes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- add action groups to runtime.yml (https://github.com/openshift/community.okd/issues/41).
|
||||||
|
|
||||||
|
Bugfixes
|
||||||
|
--------
|
||||||
|
|
||||||
|
- fix ocp auth failing against cluster api url with trailing slash (https://github.com/openshift/community.okd/issues/139)
|
||||||
|
|
||||||
|
New Modules
|
||||||
|
-----------
|
||||||
|
|
||||||
|
- openshift_adm_migrate_template_instances - Update TemplateInstances to point to the latest group-version-kinds
|
||||||
|
- openshift_adm_prune_auth - Removes references to the specified roles, clusterroles, users, and groups
|
||||||
|
- openshift_adm_prune_deployments - Remove old completed and failed deployment configs
|
||||||
|
- openshift_adm_prune_images - Remove unreferenced images
|
||||||
|
- openshift_import_image - Import the latest image information from a tag in a container image registry.
|
||||||
|
- openshift_registry_info - Display information about the integrated registry.
|
||||||
|
|
||||||
v2.1.0
|
v2.1.0
|
||||||
======
|
======
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
# Continuous Integration (CI)
|
||||||
|
|
||||||
|
This collection uses two CI systems: **Zuul** for PR validation checks and **Prow** for integration testing.
|
||||||
|
|
||||||
|
## Zuul - PR Validation
|
||||||
|
|
||||||
|
Zuul runs automated tests on every pull request. The Zuul configuration for this collection is defined in the [ansible/ansible-zuul-jobs](https://github.com/ansible/ansible-zuul-jobs/blob/main/zuul.d/project-templates.yaml) repository under the `ansible-collections-community-okd` template.
|
||||||
|
|
||||||
|
### Jobs Run by Zuul
|
||||||
|
|
||||||
|
The following jobs run in the `third-party-check` pipeline on every PR:
|
||||||
|
|
||||||
|
| Job | Description |
|
||||||
|
| --- | ----------- |
|
||||||
|
| `build-ansible-collection` | Builds the collection tarball |
|
||||||
|
| `ansible-galaxy-importer` | Validates collection structure for Galaxy (non-voting) |
|
||||||
|
| `ansible-tox-linters` | Runs `black`, `flake8`, and `ansible-lint` via `tox -e linters` (see [tox.ini](tox.ini)) |
|
||||||
|
| `ansible-test-units-community-okd-python39` | Executes unit tests with Python 3.9 |
|
||||||
|
|
||||||
|
**Upstream Sanity Tests:**
|
||||||
|
- `ansible-test-sanity-docker-devel`
|
||||||
|
- `ansible-test-sanity-docker-milestone`
|
||||||
|
- `ansible-test-sanity-docker-stable-2.16`
|
||||||
|
- `ansible-test-sanity-docker-stable-2.17`
|
||||||
|
- `ansible-test-sanity-docker-stable-2.18`
|
||||||
|
|
||||||
|
**Downstream Sanity Tests** (test the `redhat.openshift` variant):
|
||||||
|
- `ansible-test-sanity-okd-downstream-devel`
|
||||||
|
- `ansible-test-sanity-okd-downstream-milestone`
|
||||||
|
- `ansible-test-sanity-okd-downstream-stable-2.16`
|
||||||
|
- `ansible-test-sanity-okd-downstream-stable-2.17`
|
||||||
|
- `ansible-test-sanity-okd-downstream-stable-2.18`
|
||||||
|
|
||||||
|
## OpenShift Prow - Integration Testing
|
||||||
|
|
||||||
|
Integration tests for community.okd are executed via [OpenShift Prow](https://github.com/kubernetes/test-infra/blob/master/prow/README.md), OpenShift's CI/CD system for testing against live clusters.
|
||||||
|
|
||||||
|
### Prow Configuration
|
||||||
|
|
||||||
|
The Prow configuration for this collection is maintained in the [openshift/release](https://github.com/openshift/release) repository at `ci-operator/config/openshift/community.okd/openshift-community.okd-main.yaml`.
|
||||||
|
|
||||||
|
### Integration Test Workflow
|
||||||
|
|
||||||
|
The integration test workflow follows these steps:
|
||||||
|
|
||||||
|
1. **Prow builds the test runner image** defined in [ci/Dockerfile](ci/Dockerfile)
|
||||||
|
- Based on `registry.access.redhat.com/ubi9/ubi`
|
||||||
|
- Includes Python 3.12, ansible-core, molecule, kubernetes client, and OKD CLI tools
|
||||||
|
|
||||||
|
2. **Prow executes `make test-integration-incluster`**
|
||||||
|
- This runs [ci/incluster_integration.sh](ci/incluster_integration.sh)
|
||||||
|
|
||||||
|
3. **The script spawns a Kubernetes Job** that runs `make test-integration` using the previously built image
|
||||||
|
- Job runs with cluster-admin permissions
|
||||||
|
- 30-minute timeout
|
||||||
|
- Backoff limit of 2 retries
|
||||||
|
|
||||||
|
4. **`make test-integration` runs both upstream and downstream tests:**
|
||||||
|
- **Upstream tests** (`upstream-test-integration`): Runs molecule tests for `community.okd` collection
|
||||||
|
- **Downstream tests** (`downstream-test-integration`): Runs `ci/downstream.sh -i` to convert the collection to `redhat.openshift` and test the downstream variant
|
||||||
|
|
||||||
|
### Test Framework
|
||||||
|
|
||||||
|
Integration tests use the Molecule framework and require a live OpenShift or Kubernetes cluster (>=1.24). Tests are located in the `molecule/default/` directory and cover check mode, creation, idempotency, modification, and deletion scenarios.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
.PHONY: molecule
|
.PHONY: molecule
|
||||||
|
|
||||||
# Also needs to be updated in galaxy.yml
|
# Also needs to be updated in galaxy.yml
|
||||||
VERSION = 2.1.0
|
VERSION = 6.0.0
|
||||||
|
|
||||||
SANITY_TEST_ARGS ?= --docker --color
|
SANITY_TEST_ARGS ?= --docker --color
|
||||||
UNITS_TEST_ARGS ?= --docker --color
|
UNITS_TEST_ARGS ?= --docker --color
|
||||||
@@ -16,7 +16,7 @@ build: clean
|
|||||||
ansible-galaxy collection build
|
ansible-galaxy collection build
|
||||||
|
|
||||||
install: build
|
install: build
|
||||||
ansible-galaxy collection install -p ansible_collections community-okd-$(VERSION).tar.gz
|
ansible-galaxy collection install --force -p ansible_collections community-okd-$(VERSION).tar.gz
|
||||||
|
|
||||||
sanity: install
|
sanity: install
|
||||||
cd ansible_collections/community/okd && ansible-test sanity -v --python $(PYTHON_VERSION) $(SANITY_TEST_ARGS)
|
cd ansible_collections/community/okd && ansible-test sanity -v --python $(PYTHON_VERSION) $(SANITY_TEST_ARGS)
|
||||||
|
|||||||
+10
-10
@@ -1,19 +1,19 @@
|
|||||||
aliases:
|
aliases:
|
||||||
community.okd-approvers:
|
community.okd-approvers:
|
||||||
- gravesm
|
|
||||||
- akasurde
|
|
||||||
- fabianvf
|
|
||||||
- tima
|
|
||||||
- goneri
|
|
||||||
- jillr
|
- jillr
|
||||||
|
- GomathiselviS
|
||||||
- alinabuzachis
|
- alinabuzachis
|
||||||
- abikouo
|
- abikouo
|
||||||
|
- beeankha
|
||||||
|
- mandar242
|
||||||
|
- oraNod
|
||||||
|
- brahmanim
|
||||||
community.okd-reviewers:
|
community.okd-reviewers:
|
||||||
- gravesm
|
|
||||||
- akasurde
|
|
||||||
- fabianvf
|
|
||||||
- tima
|
|
||||||
- goneri
|
|
||||||
- jillr
|
- jillr
|
||||||
|
- GomathiselviS
|
||||||
- alinabuzachis
|
- alinabuzachis
|
||||||
- abikouo
|
- abikouo
|
||||||
|
- beeankha
|
||||||
|
- mandar242
|
||||||
|
- oraNod
|
||||||
|
- brahmanim
|
||||||
|
|||||||
@@ -1,50 +1,84 @@
|
|||||||
# OKD Collection for Ansible
|
# OKD Collection for Ansible
|
||||||
|
|
||||||
|
This repo hosts the `community.okd` Ansible Collection.
|
||||||
|
|
||||||
|
## Description
|
||||||
|
The collection includes a variety of Ansible content to help automate the management of applications in OKD clusters, as well as the provisioning and maintenance of clusters themselves.
|
||||||
|
|
||||||
<!--- STARTREMOVE --->
|
<!--- STARTREMOVE --->
|
||||||
[](https://github.com/ansible-collections/community.okd/actions) [](https://codecov.io/gh/ansible-collections/community.okd)
|
[](https://github.com/ansible-collections/community.okd/actions) [](https://codecov.io/gh/ansible-collections/community.okd)
|
||||||
|
|
||||||
This repo hosts the `community.okd` Ansible Collection.
|
## Communication
|
||||||
|
|
||||||
The collection includes a variety of Ansible content to help automate the management of applications in OKD clusters, as well as the provisioning and maintenance of clusters themselves.
|
* Join the Ansible forum:
|
||||||
|
* [Get Help](https://forum.ansible.com/c/help/6): get help or help others.
|
||||||
|
* [POSTS TAGGED WITH 'YOUR TAG'](https://forum.ansible.com/tag/YOUR_TAG): subscribe to participate in collection-related conversations.
|
||||||
|
* [REFER TO YOUR FORUM GROUP HERE IF EXISTS](https://forum.ansible.com/g/): by joining the team you will automatically get subscribed to the posts tagged with [your group forum tag here](https://forum.ansible.com/tags).
|
||||||
|
* [Social Spaces](https://forum.ansible.com/c/chat/4): gather and interact with fellow enthusiasts.
|
||||||
|
* [News & Announcements](https://forum.ansible.com/c/news/5): track project-wide announcements including social events.
|
||||||
|
|
||||||
|
* The Ansible [Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn): used to announce releases and important changes.
|
||||||
|
|
||||||
|
For more information about communication, see the [Ansible communication guide](https://docs.ansible.com/ansible/devel/community/communication.html).
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
<!--start requires_ansible-->
|
<!--start requires_ansible-->
|
||||||
## Ansible version compatibility
|
### Ansible version compatibility
|
||||||
|
|
||||||
This collection has been tested against following Ansible versions: **>=2.9.17**.
|
This collection has been tested against following Ansible versions: **>=2.16.0**.
|
||||||
|
|
||||||
|
Please ensure to update the `network_os` to use the fully qualified collection name (for example, `cisco.ios.ios`).
|
||||||
Plugins and modules within a collection may be tested with only specific Ansible versions.
|
Plugins and modules within a collection may be tested with only specific Ansible versions.
|
||||||
A collection may contain metadata that identifies these versions.
|
A collection may contain metadata that identifies these versions.
|
||||||
PEP440 is the schema used to describe the versions of Ansible.
|
PEP440 is the schema used to describe the versions of Ansible.
|
||||||
<!--end requires_ansible-->
|
<!--end requires_ansible-->
|
||||||
|
|
||||||
## Included content
|
### Python Support
|
||||||
|
|
||||||
|
* Collection supports 3.9+
|
||||||
|
|
||||||
|
### Kubernetes Version Support
|
||||||
|
|
||||||
|
This collection supports Kubernetes versions >=1.24.
|
||||||
|
|
||||||
|
### Included content
|
||||||
|
|
||||||
Click on the name of a plugin or module to view that content's documentation:
|
Click on the name of a plugin or module to view that content's documentation:
|
||||||
|
|
||||||
<!--start collection content-->
|
<!--start collection content-->
|
||||||
### Connection plugins
|
#### Connection plugins
|
||||||
Name | Description
|
Name | Description
|
||||||
--- | ---
|
--- | ---
|
||||||
[community.okd.oc](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.oc_connection.rst)|Execute tasks in pods running on OpenShift.
|
[community.okd.oc](https://github.com/openshift/community.okd/blob/main/docs/community.okd.oc_connection.rst)|Execute tasks in pods running on OpenShift.
|
||||||
|
|
||||||
### Inventory plugins
|
#### Inventory plugins
|
||||||
Name | Description
|
Name | Description
|
||||||
--- | ---
|
--- | ---
|
||||||
[community.okd.openshift](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.openshift_inventory.rst)|OpenShift inventory source
|
[community.okd.openshift](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_inventory.rst)|OpenShift inventory source
|
||||||
|
|
||||||
### Modules
|
#### Modules
|
||||||
Name | Description
|
Name | Description
|
||||||
--- | ---
|
--- | ---
|
||||||
[community.okd.k8s](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.k8s_module.rst)|Manage OpenShift objects
|
[community.okd.k8s](https://github.com/openshift/community.okd/blob/main/docs/community.okd.k8s_module.rst)|Manage OpenShift objects
|
||||||
[community.okd.openshift_auth](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.openshift_auth_module.rst)|Authenticate to OpenShift clusters which require an explicit login step
|
[community.okd.openshift_adm_groups_sync](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_adm_groups_sync_module.rst)|Sync OpenShift Groups with records from an external provider.
|
||||||
[community.okd.openshift_process](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.openshift_process_module.rst)|Process an OpenShift template.openshift.io/v1 Template
|
[community.okd.openshift_adm_migrate_template_instances](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_adm_migrate_template_instances_module.rst)|Update TemplateInstances to point to the latest group-version-kinds
|
||||||
[community.okd.openshift_route](https://github.com/ansible-collections/community.okd/blob/main/docs/community.okd.openshift_route_module.rst)|Expose a Service as an OpenShift Route.
|
[community.okd.openshift_adm_prune_auth](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_adm_prune_auth_module.rst)|Removes references to the specified roles, clusterroles, users, and groups
|
||||||
|
[community.okd.openshift_adm_prune_builds](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_adm_prune_builds_module.rst)|Prune old completed and failed builds
|
||||||
|
[community.okd.openshift_adm_prune_deployments](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_adm_prune_deployments_module.rst)|Remove old completed and failed deployment configs
|
||||||
|
[community.okd.openshift_adm_prune_images](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_adm_prune_images_module.rst)|Remove unreferenced images
|
||||||
|
[community.okd.openshift_auth](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_auth_module.rst)|Authenticate to OpenShift clusters which require an explicit login step
|
||||||
|
[community.okd.openshift_build](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_build_module.rst)|Start a new build or Cancel running, pending, or new builds.
|
||||||
|
[community.okd.openshift_import_image](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_import_image_module.rst)|Import the latest image information from a tag in a container image registry.
|
||||||
|
[community.okd.openshift_process](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_process_module.rst)|Process an OpenShift template.openshift.io/v1 Template
|
||||||
|
[community.okd.openshift_registry_info](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_registry_info_module.rst)|Display information about the integrated registry.
|
||||||
|
[community.okd.openshift_route](https://github.com/openshift/community.okd/blob/main/docs/community.okd.openshift_route_module.rst)|Expose a Service as an OpenShift Route.
|
||||||
|
|
||||||
<!--end collection content-->
|
<!--end collection content-->
|
||||||
|
|
||||||
<!--- ENDREMOVE --->
|
<!--- ENDREMOVE --->
|
||||||
|
|
||||||
## Installation and Usage
|
## Installation
|
||||||
|
|
||||||
### Installing the Collection from Ansible Galaxy
|
### Installing the Collection from Ansible Galaxy
|
||||||
|
|
||||||
@@ -58,7 +92,7 @@ You can also include it in a `requirements.yml` file and install it via `ansible
|
|||||||
---
|
---
|
||||||
collections:
|
collections:
|
||||||
- name: community.okd
|
- name: community.okd
|
||||||
version: 2.1.0
|
version: 5.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
### Installing the Kubernetes Python Library
|
### Installing the Kubernetes Python Library
|
||||||
@@ -67,6 +101,8 @@ Content in this collection requires the [Kubernetes Python client](https://pypi.
|
|||||||
|
|
||||||
pip3 install kubernetes
|
pip3 install kubernetes
|
||||||
|
|
||||||
|
## Use Cases
|
||||||
|
|
||||||
### Using modules from the OKD Collection in your playbooks
|
### Using modules from the OKD Collection in your playbooks
|
||||||
|
|
||||||
It's preferable to use content in this collection using their Fully Qualified Collection Namespace (FQCN), for example `community.okd.openshift`:
|
It's preferable to use content in this collection using their Fully Qualified Collection Namespace (FQCN), for example `community.okd.openshift`:
|
||||||
@@ -81,29 +117,30 @@ connections:
|
|||||||
|
|
||||||
For documentation on how to use individual plugins included in this collection, please see the links in the 'Included content' section earlier in this README.
|
For documentation on how to use individual plugins included in this collection, please see the links in the 'Included content' section earlier in this README.
|
||||||
|
|
||||||
## Ansible Turbo mode Tech Preview
|
### Ansible Turbo mode Tech Preview
|
||||||
|
|
||||||
|
The `community.okd` collection supports Ansible Turbo mode as a tech preview via the `cloud.common` collection. By default, this feature is disabled. To enable Turbo mode, set the environment variable `ENABLE_TURBO_MODE=1` on the managed node. For example:
|
||||||
|
|
||||||
The ``community.okd`` collection supports Ansible Turbo mode as a tech preview via the ``cloud.common`` collection. By default, this feature is disabled. To enable Turbo mode, set the environment variable `ENABLE_TURBO_MODE=1` on the managed node. For example:
|
```yaml
|
||||||
|
---
|
||||||
|
- hosts: remote
|
||||||
|
environment:
|
||||||
|
ENABLE_TURBO_MODE: 1
|
||||||
|
tasks:
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
```yaml
|
Please read more about Ansible Turbo mode - [here](https://github.com/ansible-collections/community.okd/blob/main/docs/ansible_turbo_mode.rst).
|
||||||
---
|
|
||||||
- hosts: remote
|
|
||||||
environment:
|
|
||||||
ENABLE_TURBO_MODE: 1
|
|
||||||
tasks:
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
Please read more about Ansible Turbo mode - [here](https://github.com/ansible-collections/community.okd/blob/main/docs/ansible_turbo_mode.rst).
|
|
||||||
|
|
||||||
<!--- STARTREMOVE --->
|
<!--- STARTREMOVE --->
|
||||||
## Testing and Development
|
## Contributing to the collection
|
||||||
|
|
||||||
If you want to develop new content for this collection or improve what's already here, the easiest way to work on the collection is to clone it into one of the configured [`COLLECTIONS_PATHS`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths), and work on it there.
|
If you want to develop new content for this collection or improve what's already here, the easiest way to work on the collection is to clone it into one of the configured [`COLLECTIONS_PATHS`](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths), and work on it there.
|
||||||
|
|
||||||
See [Contributing to community.okd](CONTRIBUTING.md).
|
See [Contributing to community.okd](CONTRIBUTING.md).
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
The `tests` directory contains configuration for running sanity tests using [`ansible-test`](https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html).
|
The `tests` directory contains configuration for running sanity tests using [`ansible-test`](https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html).
|
||||||
|
|
||||||
You can run the `ansible-test` sanity tests with the command:
|
You can run the `ansible-test` sanity tests with the command:
|
||||||
@@ -141,25 +178,51 @@ where the `IMAGE_FORMAT` environment variable is the full reference to your cont
|
|||||||
|
|
||||||
Releases are automatically built and pushed to Ansible Galaxy for any new tag. Before tagging a release, make sure to do the following:
|
Releases are automatically built and pushed to Ansible Galaxy for any new tag. Before tagging a release, make sure to do the following:
|
||||||
|
|
||||||
1. Update the version in the following places:
|
1. Update the version in the following places:
|
||||||
a. The `version` in `galaxy.yml`
|
* a. The `version` in `galaxy.yml`
|
||||||
b. This README's `requirements.yml` example
|
* b. This README's `requirements.yml` example
|
||||||
c. The `DOWNSTREAM_VERSION` in `ci/downstream.sh`
|
* c. The `DOWNSTREAM_VERSION` in `ci/downstream.sh`
|
||||||
d. The `VERSION` in `Makefile`
|
* d. The `VERSION` in `Makefile`
|
||||||
1. Update the CHANGELOG:
|
* e. The version in `requirements.yml`
|
||||||
1. Make sure you have [`antsibull-changelog`](https://pypi.org/project/antsibull-changelog/) installed.
|
2. Update the CHANGELOG:
|
||||||
1. Make sure there are fragments for all known changes in `changelogs/fragments`.
|
* 1. Make sure you have [`antsibull-changelog`](https://pypi.org/project/antsibull-changelog/) installed.
|
||||||
1. Run `antsibull-changelog release`.
|
* 2. Make sure there are fragments for all known changes in `changelogs/fragments`.
|
||||||
1. Commit the changes and create a PR with the changes. Wait for tests to pass, then merge it once they have.
|
* 3. Run `antsibull-changelog release`.
|
||||||
1. Tag the version in Git and push to GitHub.
|
3. Commit the changes and create a PR with the changes. Wait for tests to pass, then merge it once they have.
|
||||||
|
4. Tag the version in Git and push to GitHub.
|
||||||
|
|
||||||
After the version is published, verify it exists on the [OKD Collection Galaxy page](https://galaxy.ansible.com/community/okd).
|
After the version is published, verify it exists on the [OKD Collection Galaxy page](https://galaxy.ansible.com/community/okd).
|
||||||
<!--- ENDREMOVE --->
|
<!--- ENDREMOVE --->
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
<!--List available communication channels. In addition to channels specific to your collection, we also recommend to use the following ones.-->
|
||||||
|
|
||||||
|
We announce releases and important changes through Ansible's [The Bullhorn newsletter](https://github.com/ansible/community/wiki/News#the-bullhorn). Be sure you are [subscribed](https://eepurl.com/gZmiEP).
|
||||||
|
|
||||||
|
We take part in the global quarterly [Ansible Contributor Summit](https://github.com/ansible/community/wiki/Contributor-Summit) virtually or in-person. Track [The Bullhorn newsletter](https://eepurl.com/gZmiEP) and join us.
|
||||||
|
|
||||||
|
For more information about communication, refer to the [Ansible Communication guide](https://docs.ansible.com/ansible/devel/community/communication.html).
|
||||||
|
|
||||||
|
For the latest supported versions, refer to the release notes below.
|
||||||
|
|
||||||
|
If you encounter issues or have questions, you can submit a support request through the following channels:
|
||||||
|
- GitHub Issues: Report bugs, request features, or ask questions by opening an issue in the [GitHub repository](https://github.com/openshift/community.okd/).
|
||||||
|
|
||||||
|
## Release notes
|
||||||
|
|
||||||
|
See the [raw generated changelog](https://github.com/openshift/community.okd/blob/main/CHANGELOG.rst).
|
||||||
|
|
||||||
## More Information
|
## More Information
|
||||||
|
|
||||||
For more information about Ansible's Kubernetes and OpenShift integrations, join the `#ansible-kubernetes` channel on [libera.chat](https://libera.chat/) IRC, and browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page.
|
For more information about Ansible's Kubernetes and OpenShift integrations, join the `#ansible-kubernetes` channel on [libera.chat](https://libera.chat/) IRC, and browse the resources in the [Kubernetes Working Group](https://github.com/ansible/community/wiki/Kubernetes) Community wiki page.
|
||||||
|
|
||||||
|
## Code of Conduct
|
||||||
|
|
||||||
|
We follow the [Ansible Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html) in all our interactions within this project.
|
||||||
|
|
||||||
|
If you encounter abusive behavior, please refer to the [policy violations](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html#policy-violations) section of the Code for information on how to raise a complaint.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
GNU General Public License v3.0 or later
|
GNU General Public License v3.0 or later
|
||||||
|
|||||||
@@ -149,3 +149,156 @@ releases:
|
|||||||
- 102-support-turbo-mode.yaml
|
- 102-support-turbo-mode.yaml
|
||||||
- 99-openshift_route-add-support-for-annotations.yml
|
- 99-openshift_route-add-support-for-annotations.yml
|
||||||
release_date: '2021-10-20'
|
release_date: '2021-10-20'
|
||||||
|
2.2.0:
|
||||||
|
changes:
|
||||||
|
bugfixes:
|
||||||
|
- fix ocp auth failing against cluster api url with trailing slash (https://github.com/openshift/community.okd/issues/139)
|
||||||
|
minor_changes:
|
||||||
|
- add action groups to runtime.yml (https://github.com/openshift/community.okd/issues/41).
|
||||||
|
fragments:
|
||||||
|
- 152-add-action-groups.yml
|
||||||
|
- auth-against-api-with-trailing-slash.yaml
|
||||||
|
modules:
|
||||||
|
- description: Update TemplateInstances to point to the latest group-version-kinds
|
||||||
|
name: openshift_adm_migrate_template_instances
|
||||||
|
namespace: ''
|
||||||
|
- description: Removes references to the specified roles, clusterroles, users,
|
||||||
|
and groups
|
||||||
|
name: openshift_adm_prune_auth
|
||||||
|
namespace: ''
|
||||||
|
- description: Remove old completed and failed deployment configs
|
||||||
|
name: openshift_adm_prune_deployments
|
||||||
|
namespace: ''
|
||||||
|
- description: Remove unreferenced images
|
||||||
|
name: openshift_adm_prune_images
|
||||||
|
namespace: ''
|
||||||
|
- description: Import the latest image information from a tag in a container image
|
||||||
|
registry.
|
||||||
|
name: openshift_import_image
|
||||||
|
namespace: ''
|
||||||
|
- description: Display information about the integrated registry.
|
||||||
|
name: openshift_registry_info
|
||||||
|
namespace: ''
|
||||||
|
release_date: '2022-05-05'
|
||||||
|
2.3.0:
|
||||||
|
changes:
|
||||||
|
bugfixes:
|
||||||
|
- openshift_adm_groups_sync - initialize OpenshiftGroupSync attributes early
|
||||||
|
to avoid Attribute error (https://github.com/openshift/community.okd/issues/155).
|
||||||
|
- openshift_auth - Review the way the discard process is working, add openshift
|
||||||
|
algorithm to convert token to resource object name (https://github.com/openshift/community.okd/issues/176).
|
||||||
|
fragments:
|
||||||
|
- 165-initialize-attributes-early.yml
|
||||||
|
- 178-openshift_auth-fix-revoke-token.yml
|
||||||
|
- 180-default-values-doc.yml
|
||||||
|
modules:
|
||||||
|
- description: Prune old completed and failed builds
|
||||||
|
name: openshift_adm_prune_builds
|
||||||
|
namespace: ''
|
||||||
|
- description: Start a new build or Cancel running, pending, or new builds.
|
||||||
|
name: openshift_build
|
||||||
|
namespace: ''
|
||||||
|
release_date: '2023-02-03'
|
||||||
|
3.0.0:
|
||||||
|
changes:
|
||||||
|
breaking_changes:
|
||||||
|
- Bump minimum Python suupported version to 3.9 (https://github.com/openshift/community.okd/pull/202).
|
||||||
|
- Remove support for ansible-core < 2.14 (https://github.com/openshift/community.okd/pull/202).
|
||||||
|
deprecated_features:
|
||||||
|
- openshift - the ``openshift`` inventory plugin has been deprecated and will
|
||||||
|
be removed in release 4.0.0 (https://github.com/ansible-collections/kubernetes.core/issues/31).
|
||||||
|
release_summary: This major release drops support for ansible-core versions
|
||||||
|
lower than 2.14 and Python versions lower than 3.9. It also deprecates ``openshift``
|
||||||
|
inventory plugin.
|
||||||
|
fragments:
|
||||||
|
- 20230206-deprecate-openshift-inventory.yml
|
||||||
|
- 20231107-move-sanity-and-units-to-gha.yml
|
||||||
|
release_date: '2023-11-20'
|
||||||
|
3.0.1:
|
||||||
|
changes:
|
||||||
|
release_summary: 'This patch release fixes an issue in building the downstream
|
||||||
|
collection.
|
||||||
|
|
||||||
|
'
|
||||||
|
fragments:
|
||||||
|
- downstream-gitignore.yml
|
||||||
|
- release_summary.yml
|
||||||
|
release_date: '2023-11-30'
|
||||||
|
4.0.0:
|
||||||
|
changes:
|
||||||
|
minor_changes:
|
||||||
|
- connection/oc - added support of local enviroment variable that will be used
|
||||||
|
for ``oc`` and may be requried for establishing connections ifself (https://github.com/openshift/community.okd/pull/225).
|
||||||
|
- inventory/openshift.py - Defer removal of k8s inventory plugin to version
|
||||||
|
5.0.0 (https://github.com/openshift/community.okd/pull/224).
|
||||||
|
release_summary: In this major release we have removed support for ``ansible-core<2.15``.
|
||||||
|
removed_features:
|
||||||
|
- k8s - Support for ``merge_type=json`` has been removed in version 4.0.0. Please
|
||||||
|
use ``kubernetes.core.k8s_json_patch`` instead (https://github.com/openshift/community.okd/pull/226).
|
||||||
|
fragments:
|
||||||
|
- 20240523-connection-oc-add-support-for-local-env-vars.yml
|
||||||
|
- 4.0.0.yaml
|
||||||
|
- defer_removal_of_inventory_plugin.yaml
|
||||||
|
- k8s-merge_type=json-removed.yml
|
||||||
|
release_date: '2024-05-29'
|
||||||
|
4.0.1:
|
||||||
|
changes:
|
||||||
|
minor_changes:
|
||||||
|
- openshift_auth - fix issue where openshift_auth module sometimes does not
|
||||||
|
delete the auth token. Based on stale PR (https://github.com/openshift/community.okd/pull/194).
|
||||||
|
release_summary: This is a bug fix release
|
||||||
|
fragments:
|
||||||
|
- 242-fix-failed-token-deletion.yml
|
||||||
|
release_date: '2024-12-03'
|
||||||
|
4.0.2:
|
||||||
|
changes:
|
||||||
|
release_summary: This patch updates the k8s dependency version to the 5.x range
|
||||||
|
and modifies tests to handle the manual creation of service account tokens.
|
||||||
|
fragments:
|
||||||
|
- 4.0.2.yml
|
||||||
|
release_date: '2025-05-28'
|
||||||
|
5.0.0:
|
||||||
|
changes:
|
||||||
|
breaking_changes:
|
||||||
|
- Remove openshift inventory plugin deprecated in 3.0.0 (https://github.com/openshift/community.okd/pull/252).
|
||||||
|
minor_changes:
|
||||||
|
- Bump version of ansible-lint to 25.1.2 (https://github.com/openshift/community.okd/pull/255).
|
||||||
|
- Bump version of ansible-lint to minimum 24.7.0 (https://github.com/openshift/community.okd/pull/240).
|
||||||
|
release_summary: This release drops support for ansible-lint < 25.1.2 and removes
|
||||||
|
deprecated openshift inventory plugin.
|
||||||
|
fragments:
|
||||||
|
- 240-bump-ansible-lint-version.yml
|
||||||
|
- 5.0.0.yml
|
||||||
|
- ansible-lint-update.yml
|
||||||
|
- readme_template_update.yml
|
||||||
|
release_date: '2025-06-10'
|
||||||
|
6.0.0:
|
||||||
|
changes:
|
||||||
|
breaking_changes:
|
||||||
|
- Minimum supported version of ansible-core is now 2.16 (https://github.com/openshift/community.okd/pull/292).
|
||||||
|
minor_changes:
|
||||||
|
- Add sanity test ignore files for ansible-core 2.20 and 2.21 (https://github.com/openshift/community.okd/pull/286).
|
||||||
|
- Replace ``ansible.module_utils.six.moves.urllib_parse`` import with Python
|
||||||
|
3 ``urllib.parse`` in ``openshift_auth`` module (https://github.com/openshift/community.okd/pull/291).
|
||||||
|
- Replace ``ansible.module_utils.six`` imports (``iteritems``, ``string_types``)
|
||||||
|
with Python 3 stdlib equivalents (https://github.com/openshift/community.okd/pull/286).
|
||||||
|
- Replace deprecated ``ansible.module_utils._text`` imports with ``ansible.module_utils.common.text.converters``
|
||||||
|
to fix compatibility with ansible-core 2.24+ (https://github.com/openshift/community.okd/issues/275).
|
||||||
|
release_summary: 'This major release drops support for ansible-core versions
|
||||||
|
below 2.16,
|
||||||
|
|
||||||
|
replaces all ``ansible.module_utils.six`` imports with Python 3 stdlib equivalents,
|
||||||
|
|
||||||
|
and fixes deprecated ``ansible.module_utils._text`` imports for compatibility
|
||||||
|
|
||||||
|
with ansible-core 2.24+.
|
||||||
|
|
||||||
|
'
|
||||||
|
fragments:
|
||||||
|
- 187-lowercase-booleans.yml
|
||||||
|
- 286-replace-six-imports.yml
|
||||||
|
- 292-bump-min-ansible-core.yml
|
||||||
|
- fix-deprecated-text-imports.yml
|
||||||
|
- replace-six-urllib-parse.yml
|
||||||
|
- v6.0.0-release-summary.yml
|
||||||
|
release_date: '2026-08-17'
|
||||||
|
|||||||
+16
-16
@@ -10,21 +10,21 @@ notesdir: fragments
|
|||||||
prelude_section_name: release_summary
|
prelude_section_name: release_summary
|
||||||
prelude_section_title: Release Summary
|
prelude_section_title: Release Summary
|
||||||
sections:
|
sections:
|
||||||
- - major_changes
|
- - major_changes
|
||||||
- Major Changes
|
- Major Changes
|
||||||
- - minor_changes
|
- - minor_changes
|
||||||
- Minor Changes
|
- Minor Changes
|
||||||
- - breaking_changes
|
- - breaking_changes
|
||||||
- Breaking Changes / Porting Guide
|
- Breaking Changes / Porting Guide
|
||||||
- - deprecated_features
|
- - deprecated_features
|
||||||
- Deprecated Features
|
- Deprecated Features
|
||||||
- - removed_features
|
- - removed_features
|
||||||
- Removed Features (previously deprecated)
|
- Removed Features (previously deprecated)
|
||||||
- - security_fixes
|
- - security_fixes
|
||||||
- Security Fixes
|
- Security Fixes
|
||||||
- - bugfixes
|
- - bugfixes
|
||||||
- Bugfixes
|
- Bugfixes
|
||||||
- - known_issues
|
- - known_issues
|
||||||
- Known Issues
|
- Known Issues
|
||||||
title: OKD Collection
|
title: OKD Collection
|
||||||
trivial_section_name: trivial
|
trivial_section_name: trivial
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
minor_changes:
|
|
||||||
- add action groups to runtime.yml (https://github.com/openshift/community.okd/issues/41).
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
bugfixes:
|
|
||||||
- fix ocp auth failing against cluster api url with trailing slash (https://github.com/openshift/community.okd/issues/139)
|
|
||||||
+12
-11
@@ -1,29 +1,30 @@
|
|||||||
FROM registry.access.redhat.com/ubi8/ubi
|
FROM registry.access.redhat.com/ubi9/ubi
|
||||||
|
|
||||||
ENV OPERATOR=/usr/local/bin/ansible-operator \
|
ENV OPERATOR=/usr/local/bin/ansible-operator \
|
||||||
USER_UID=1001 \
|
USER_UID=1001 \
|
||||||
USER_NAME=ansible-operator\
|
USER_NAME=ansible-operator\
|
||||||
HOME=/opt/ansible \
|
HOME=/opt/ansible \
|
||||||
ANSIBLE_LOCAL_TMP=/opt/ansible/tmp
|
ANSIBLE_LOCAL_TMP=/opt/ansible/tmp \
|
||||||
|
DOWNSTREAM_BUILD_PYTHON=python3.12
|
||||||
|
|
||||||
RUN yum install -y \
|
RUN yum install -y \
|
||||||
glibc-langpack-en \
|
glibc-langpack-en \
|
||||||
git \
|
git \
|
||||||
make \
|
make \
|
||||||
python3 \
|
python3.12 \
|
||||||
python3-devel \
|
python3.12-devel \
|
||||||
python3-pip \
|
python3.12-pip \
|
||||||
python3-setuptools \
|
python3.12-setuptools \
|
||||||
gcc \
|
gcc \
|
||||||
openldap-devel \
|
openldap-devel \
|
||||||
&& pip3 install --no-cache-dir --upgrade setuptools pip \
|
&& python3.12 -m pip install --no-cache-dir --upgrade setuptools pip \
|
||||||
&& pip3 install --no-cache-dir \
|
&& python3.12 -m pip install --no-cache-dir \
|
||||||
kubernetes \
|
kubernetes \
|
||||||
ansible==2.9.* \
|
"ansible-core" \
|
||||||
"molecule<3.3.0" \
|
"molecule" \
|
||||||
&& yum clean all \
|
&& yum clean all \
|
||||||
&& rm -rf $HOME/.cache \
|
&& rm -rf $HOME/.cache \
|
||||||
&& curl -L https://github.com/openshift/okd/releases/download/4.5.0-0.okd-2020-08-12-020541/openshift-client-linux-4.5.0-0.okd-2020-08-12-020541.tar.gz | tar -xz -C /usr/local/bin
|
&& curl -L https://github.com/okd-project/okd/releases/download/4.20.0-okd-scos.17/openshift-client-linux-amd64-rhel9-4.20.0-okd-scos.17.tar.gz | tar -xz -C /usr/local/bin
|
||||||
# TODO: Is there a better way to install this client in ubi8?
|
# TODO: Is there a better way to install this client in ubi8?
|
||||||
|
|
||||||
COPY . /opt/ansible
|
COPY . /opt/ansible
|
||||||
|
|||||||
+8
-8
@@ -9,7 +9,7 @@
|
|||||||
# - All functions are prefixed with f_ so it's obvious where they come
|
# - All functions are prefixed with f_ so it's obvious where they come
|
||||||
# from when in use throughout the script
|
# from when in use throughout the script
|
||||||
|
|
||||||
DOWNSTREAM_VERSION="2.1.0"
|
DOWNSTREAM_VERSION="6.0.0"
|
||||||
KEEP_DOWNSTREAM_TMPDIR="${KEEP_DOWNSTREAM_TMPDIR:-''}"
|
KEEP_DOWNSTREAM_TMPDIR="${KEEP_DOWNSTREAM_TMPDIR:-''}"
|
||||||
INSTALL_DOWNSTREAM_COLLECTION_PATH="${INSTALL_DOWNSTREAM_COLLECTION_PATH:-}"
|
INSTALL_DOWNSTREAM_COLLECTION_PATH="${INSTALL_DOWNSTREAM_COLLECTION_PATH:-}"
|
||||||
_build_dir=""
|
_build_dir=""
|
||||||
@@ -41,15 +41,16 @@ f_text_sub()
|
|||||||
sed -i.bak "s/Ansible Galaxy/Automation Hub/" "${_build_dir}/README.md"
|
sed -i.bak "s/Ansible Galaxy/Automation Hub/" "${_build_dir}/README.md"
|
||||||
sed -i.bak "s/community-okd/redhat-openshift/" "${_build_dir}/Makefile"
|
sed -i.bak "s/community-okd/redhat-openshift/" "${_build_dir}/Makefile"
|
||||||
sed -i.bak "s/community\/okd/redhat\/openshift/" "${_build_dir}/Makefile"
|
sed -i.bak "s/community\/okd/redhat\/openshift/" "${_build_dir}/Makefile"
|
||||||
sed -i.bak "s/^VERSION\:/VERSION: ${DOWNSTREAM_VERSION}/" "${_build_dir}/Makefile"
|
sed -i.bak "s/^VERSION = .*$/VERSION = ${DOWNSTREAM_VERSION}/" "${_build_dir}/Makefile"
|
||||||
sed -i.bak "s/name\:.*$/name: openshift/" "${_build_dir}/galaxy.yml"
|
sed -i.bak "s/name\:.*$/name: openshift/" "${_build_dir}/galaxy.yml"
|
||||||
sed -i.bak "s/namespace\:.*$/namespace: redhat/" "${_build_dir}/galaxy.yml"
|
sed -i.bak "s/namespace\:.*$/namespace: redhat/" "${_build_dir}/galaxy.yml"
|
||||||
sed -i.bak "s/Kubernetes/OpenShift/g" "${_build_dir}/galaxy.yml"
|
sed -i.bak "s/Kubernetes/OpenShift/g" "${_build_dir}/galaxy.yml"
|
||||||
sed -i.bak "s/^version\:.*$/version: ${DOWNSTREAM_VERSION}/" "${_build_dir}/galaxy.yml"
|
sed -i.bak "s/^version\:.*$/version: ${DOWNSTREAM_VERSION}/" "${_build_dir}/galaxy.yml"
|
||||||
sed -i.bak "/STARTREMOVE/,/ENDREMOVE/d" "${_build_dir}/README.md"
|
sed -i.bak "/STARTREMOVE/,/ENDREMOVE/d" "${_build_dir}/README.md"
|
||||||
sed -i.bak "s/[[:space:]]okd:$/ openshift:/" ${_build_dir}/meta/runtime.yml
|
sed -i.bak "s/[[:space:]]okd:$/ openshift:/" "${_build_dir}/meta/runtime.yml"
|
||||||
|
|
||||||
find "${_build_dir}" -type f ! -name galaxy.yml -exec sed -i.bak "s/community\.okd/redhat\.openshift/g" {} \;
|
find "${_build_dir}" -type f ! -name galaxy.yml -exec sed -i.bak "s/community\.okd/redhat\.openshift/g" {} \;
|
||||||
|
find "${_build_dir}" -type f ! -name galaxy.yml -exec sed -i.bak "s/group\/redhat\.openshift\.okd/redhat\.openshift\.openshift/g" {} \;
|
||||||
find "${_build_dir}" -type f -name "*.bak" -delete
|
find "${_build_dir}" -type f -name "*.bak" -delete
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,12 +63,13 @@ f_prep()
|
|||||||
|
|
||||||
# Files to copy downstream (relative repo root dir path)
|
# Files to copy downstream (relative repo root dir path)
|
||||||
_file_manifest=(
|
_file_manifest=(
|
||||||
|
.gitignore
|
||||||
|
.ansible-lint
|
||||||
CHANGELOG.rst
|
CHANGELOG.rst
|
||||||
galaxy.yml
|
galaxy.yml
|
||||||
LICENSE
|
LICENSE
|
||||||
README.md
|
README.md
|
||||||
Makefile
|
Makefile
|
||||||
setup.cfg
|
|
||||||
.yamllint
|
.yamllint
|
||||||
requirements.txt
|
requirements.txt
|
||||||
requirements.yml
|
requirements.yml
|
||||||
@@ -145,7 +147,7 @@ f_handle_doc_fragments_workaround()
|
|||||||
local rendered_fragments="./rendereddocfragments.txt"
|
local rendered_fragments="./rendereddocfragments.txt"
|
||||||
|
|
||||||
# FIXME: Check Python interpreter from environment variable to work with prow
|
# FIXME: Check Python interpreter from environment variable to work with prow
|
||||||
PYTHON=${DOWNSTREAM_BUILD_PYTHON:-/usr/bin/python3.6}
|
PYTHON=${DOWNSTREAM_BUILD_PYTHON:-/usr/bin/python3}
|
||||||
f_log_info "Using Python interpreter: ${PYTHON}"
|
f_log_info "Using Python interpreter: ${PYTHON}"
|
||||||
|
|
||||||
# Modules with inherited doc fragments from kubernetes.core that need
|
# Modules with inherited doc fragments from kubernetes.core that need
|
||||||
@@ -156,7 +158,7 @@ f_handle_doc_fragments_workaround()
|
|||||||
# Build the collection, export docs, render them, stitch it all back together
|
# Build the collection, export docs, render them, stitch it all back together
|
||||||
pushd "${_build_dir}" || return
|
pushd "${_build_dir}" || return
|
||||||
ansible-galaxy collection build
|
ansible-galaxy collection build
|
||||||
ansible-galaxy collection install -p "${install_collections_dir}" ./*.tar.gz
|
ansible-galaxy collection install --force-with-deps -p "${install_collections_dir}" ./*.tar.gz
|
||||||
rm ./*.tar.gz
|
rm ./*.tar.gz
|
||||||
for doc_fragment_mod in "${_doc_fragment_modules[@]}"
|
for doc_fragment_mod in "${_doc_fragment_modules[@]}"
|
||||||
do
|
do
|
||||||
@@ -186,8 +188,6 @@ f_copy_collection_to_working_dir()
|
|||||||
cp "${_build_dir}"/*.tar.gz ./
|
cp "${_build_dir}"/*.tar.gz ./
|
||||||
# Install downstream collection into provided path
|
# Install downstream collection into provided path
|
||||||
if [[ -n ${INSTALL_DOWNSTREAM_COLLECTION_PATH} ]]; then
|
if [[ -n ${INSTALL_DOWNSTREAM_COLLECTION_PATH} ]]; then
|
||||||
rm -fr "${INSTALL_DOWNSTREAM_COLLECTION_PATH:?}/*"
|
|
||||||
##mkdir -p "${INSTALL_DOWNSTREAM_COLLECTION_PATH}"
|
|
||||||
f_log_info "Install built collection *.tar.gz into ${INSTALL_DOWNSTREAM_COLLECTION_PATH}"
|
f_log_info "Install built collection *.tar.gz into ${INSTALL_DOWNSTREAM_COLLECTION_PATH}"
|
||||||
ansible-galaxy collection install -p "${INSTALL_DOWNSTREAM_COLLECTION_PATH}" "${_build_dir}"/*.tar.gz
|
ansible-galaxy collection install -p "${INSTALL_DOWNSTREAM_COLLECTION_PATH}" "${_build_dir}"/*.tar.gz
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ with open("./rendereddocfragments.txt", 'w') as df_fd:
|
|||||||
with open(sys.argv[2], 'r') as fd:
|
with open(sys.argv[2], 'r') as fd:
|
||||||
json_docs = json.load(fd)
|
json_docs = json.load(fd)
|
||||||
|
|
||||||
|
# ansible-doc has introduced a 'doc.plugin_name' on branch 'stable-2.17'
|
||||||
|
# This change generated the following sanity tests error.
|
||||||
|
# invalid-documentation: DOCUMENTATION.plugin_name: extra keys not allowed @ data['plugin_name'].
|
||||||
|
# This will be removed from the module documentation
|
||||||
|
|
||||||
|
json_docs[sys.argv[1]]['doc'].pop('plugin_name', '')
|
||||||
json_docs[sys.argv[1]]['doc'].pop('collection', '')
|
json_docs[sys.argv[1]]['doc'].pop('collection', '')
|
||||||
json_docs[sys.argv[1]]['doc'].pop('filename', '')
|
json_docs[sys.argv[1]]['doc'].pop('filename', '')
|
||||||
json_docs[sys.argv[1]]['doc'].pop('has_action', '')
|
json_docs[sys.argv[1]]['doc'].pop('has_action', '')
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ function check_failure {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime="15 minute"
|
runtime="30 minute"
|
||||||
endtime=$(date -ud "$runtime" +%s)
|
endtime=$(date -ud "$runtime" +%s)
|
||||||
|
|
||||||
echo "Waiting for test job to complete"
|
echo "Waiting for test job to complete"
|
||||||
|
|||||||
@@ -351,6 +351,41 @@ Parameters
|
|||||||
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="3">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="3">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
@@ -375,13 +410,15 @@ Parameters
|
|||||||
<b>kubeconfig</b>
|
<b>kubeconfig</b>
|
||||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
<div style="font-size: small">
|
<div style="font-size: small">
|
||||||
<span style="color: purple">path</span>
|
<span style="color: purple">raw</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -396,7 +433,6 @@ Parameters
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
<li>json</li>
|
|
||||||
<li>merge</li>
|
<li>merge</li>
|
||||||
<li>strategic-merge</li>
|
<li>strategic-merge</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -408,7 +444,7 @@ Parameters
|
|||||||
<div>If more than one merge_type is given, the merge_types will be tried in order</div>
|
<div>If more than one merge_type is given, the merge_types will be tried in order</div>
|
||||||
<div>Defaults to <code>['strategic-merge', 'merge']</code>, which is ideal for using the same parameters on resource kinds that combine Custom Resources and built-in resources.</div>
|
<div>Defaults to <code>['strategic-merge', 'merge']</code>, which is ideal for using the same parameters on resource kinds that combine Custom Resources and built-in resources.</div>
|
||||||
<div>mutually exclusive with <code>apply</code></div>
|
<div>mutually exclusive with <code>apply</code></div>
|
||||||
<div><em>merge_type=json</em> is deprecated and will be removed in version 3.0.0. Please use <span class='module'>kubernetes.core.k8s_json_patch</span> instead.</div>
|
<div><em>merge_type=json</em> has been removed in version 4.0.0. Please use <span class='module'>kubernetes.core.k8s_json_patch</span> instead.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -447,6 +483,25 @@ Parameters
|
|||||||
<div>If <em>resource definition</em> is provided, the <em>metadata.namespace</em> value from the <em>resource_definition</em> will override this option.</div>
|
<div>If <em>resource definition</em> is provided, the <em>metadata.namespace</em> value from the <em>resource_definition</em> will override this option.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="3">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
@@ -602,7 +657,8 @@ Parameters
|
|||||||
<td>
|
<td>
|
||||||
<div>Provide a path to a file containing a valid YAML definition of an object or objects to be created or updated. Mutually exclusive with <em>resource_definition</em>. NOTE: <em>kind</em>, <em>api_version</em>, <em>name</em>, and <em>namespace</em> will be overwritten by corresponding values found in the configuration read in from the <em>src</em> file.</div>
|
<div>Provide a path to a file containing a valid YAML definition of an object or objects to be created or updated. Mutually exclusive with <em>resource_definition</em>. NOTE: <em>kind</em>, <em>api_version</em>, <em>name</em>, and <em>namespace</em> will be overwritten by corresponding values found in the configuration read in from the <em>src</em> file.</div>
|
||||||
<div>Reads from the local file system. To read from the Ansible controller's file system, including vaulted files, use the file lookup plugin or template lookup plugin, combined with the from_yaml filter, and pass the result to <em>resource_definition</em>. See Examples below.</div>
|
<div>Reads from the local file system. To read from the Ansible controller's file system, including vaulted files, use the file lookup plugin or template lookup plugin, combined with the from_yaml filter, and pass the result to <em>resource_definition</em>. See Examples below.</div>
|
||||||
<div>Mutually exclusive with <em>template</em> in case of <span class='module'>k8s</span> module.</div>
|
<div>The URL to manifest files that can be used to create the resource. Added in version 2.4.0.</div>
|
||||||
|
<div>Mutually exclusive with <em>template</em> in case of <span class='module'>kubernetes.core.k8s</span> module.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -913,6 +969,15 @@ Examples
|
|||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
- name: Create an OCP project
|
||||||
|
community.okd.k8s:
|
||||||
|
state: present
|
||||||
|
resource_definition:
|
||||||
|
apiVersion: project.openshift.io/v1
|
||||||
|
kind: Project
|
||||||
|
metadata:
|
||||||
|
name: testing
|
||||||
|
|
||||||
- name: Create a k8s namespace
|
- name: Create a k8s namespace
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
name: testing
|
name: testing
|
||||||
@@ -937,10 +1002,10 @@ Examples
|
|||||||
app: galaxy
|
app: galaxy
|
||||||
service: web
|
service: web
|
||||||
ports:
|
ports:
|
||||||
- protocol: TCP
|
- protocol: TCP
|
||||||
targetPort: 8000
|
targetPort: 8000
|
||||||
name: port-8000-tcp
|
name: port-8000-tcp
|
||||||
port: 8000
|
port: 8000
|
||||||
|
|
||||||
- name: Remove an existing Service object
|
- name: Remove an existing Service object
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
@@ -974,15 +1039,15 @@ Examples
|
|||||||
state: present
|
state: present
|
||||||
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
||||||
validate:
|
validate:
|
||||||
fail_on_error: yes
|
fail_on_error: true
|
||||||
|
|
||||||
- name: warn on validation errors, check for unexpected properties
|
- name: warn on validation errors, check for unexpected properties
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
state: present
|
state: present
|
||||||
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
||||||
validate:
|
validate:
|
||||||
fail_on_error: no
|
fail_on_error: false
|
||||||
strict: yes
|
strict: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1059,7 +1124,7 @@ Common return values are documented `here <https://docs.ansible.com/ansible/late
|
|||||||
</td>
|
</td>
|
||||||
<td>error</td>
|
<td>error</td>
|
||||||
<td>
|
<td>
|
||||||
<div>error while trying to create/delete the object.</div>
|
<div>Error while trying to create/delete the object.</div>
|
||||||
<br/>
|
<br/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -208,6 +208,27 @@ Parameters
|
|||||||
<div>Path to a oc config file. Defaults to <em>~/.kube/config</em></div>
|
<div>Path to a oc config file. Defaults to <em>~/.kube/config</em></div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>oc_local_env_vars</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 4.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">{}</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>var: ansible_oc_local_env_vars</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Local environment variable to be passed locally to the oc command line.</div>
|
||||||
|
<div>Please be aware that this passes information directly on the command line and it could expose sensitive data.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="1">
|
<td colspan="1">
|
||||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
@@ -308,7 +329,7 @@ Status
|
|||||||
Authors
|
Authors
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
|
||||||
- xuxinkun
|
- xuxinkun (@xuxinkun)
|
||||||
|
|
||||||
|
|
||||||
.. hint::
|
.. hint::
|
||||||
|
|||||||
@@ -0,0 +1,582 @@
|
|||||||
|
.. _community.okd.openshift_adm_groups_sync_module:
|
||||||
|
|
||||||
|
|
||||||
|
***************************************
|
||||||
|
community.okd.openshift_adm_groups_sync
|
||||||
|
***************************************
|
||||||
|
|
||||||
|
**Sync OpenShift Groups with records from an external provider.**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 2.1.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- In order to sync/prune OpenShift Group records with those from an external provider, determine which Groups you wish to sync and where their records live.
|
||||||
|
- Analogous to `oc adm prune groups` and `oc adm group sync`.
|
||||||
|
- LDAP sync configuration file syntax can be found here https://docs.openshift.com/container-platform/4.9/authentication/ldap-syncing.html.
|
||||||
|
- The bindPassword attribute of the LDAP sync configuration is expected to be a string, please use ansible-vault encryption to secure this information.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
- python-ldap
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>allow_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">[]</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Allowed groups, could be openshift group name or LDAP group dn value.</div>
|
||||||
|
<div>When parameter <code>type</code> is set to <em>ldap</em> this should contains only LDAP group definition like <em>cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat</em>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>deny_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">[]</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Denied groups, could be openshift group name or LDAP group dn value.</div>
|
||||||
|
<div>When parameter <code>type</code> is set to <em>ldap</em> this should contains only LDAP group definition like <em>cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat</em>.</div>
|
||||||
|
<div>The elements specified in this list will override the ones specified in <code>allow_groups</code>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
<div>Please read the description of the <code>username</code> option for a discussion of when this option is applicable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>persist_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable.</div>
|
||||||
|
<div>When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file.</div>
|
||||||
|
<div>Default to false.</div>
|
||||||
|
<div>Please note that the current version of the k8s python client library does not support setting this flag to True yet.</div>
|
||||||
|
<div>The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY).</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_headers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The Header used for the HTTP proxy.</div>
|
||||||
|
<div>Documentation can be found here <a href='https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers'>https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers</a>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for proxy basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_PROXY_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>user_agent</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>String representing the user-agent you want, such as foo/1.0.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_USER_AGENT environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>state</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>absent</li>
|
||||||
|
<li><div style="color: blue"><b>present</b> ←</div></li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Determines if the group should be sync when set to <code>present</code> or pruned when set to <code>absent</code>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>sync_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a valid YAML definition of an LDAP sync configuration.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: config, src</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>type</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>ldap</b> ←</div></li>
|
||||||
|
<li>openshift</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>which groups allow and deny list entries refer to.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
<div>Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the <span class='module'>community.okd.k8s_auth</span> module, as that might do what you need.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
- To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
# Prune all orphaned groups
|
||||||
|
- name: Prune all orphan groups
|
||||||
|
openshift_adm_groups_sync:
|
||||||
|
state: absent
|
||||||
|
src: "{{ lookup('file', '/path/to/ldap-sync-config.yaml') | from_yaml }}"
|
||||||
|
|
||||||
|
# Prune all orphaned groups from a list of specific groups specified in allow_groups
|
||||||
|
- name: Prune all orphan groups from a list of specific groups specified in allow_groups
|
||||||
|
openshift_adm_groups_sync:
|
||||||
|
state: absent
|
||||||
|
src: "{{ lookup('file', '/path/to/ldap-sync-config.yaml') | from_yaml }}"
|
||||||
|
allow_groups:
|
||||||
|
- cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat
|
||||||
|
- cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat
|
||||||
|
|
||||||
|
# Sync all groups from an LDAP server
|
||||||
|
- name: Sync all groups from an LDAP server
|
||||||
|
openshift_adm_groups_sync:
|
||||||
|
src:
|
||||||
|
kind: LDAPSyncConfig
|
||||||
|
apiVersion: v1
|
||||||
|
url: ldap://localhost:1390
|
||||||
|
insecure: true
|
||||||
|
bindDN: cn=admin,dc=example,dc=org
|
||||||
|
bindPassword: adminpassword
|
||||||
|
rfc2307:
|
||||||
|
groupsQuery:
|
||||||
|
baseDN: "cn=admins,ou=groups,dc=example,dc=org"
|
||||||
|
scope: sub
|
||||||
|
derefAliases: never
|
||||||
|
filter: (objectClass=*)
|
||||||
|
pageSize: 0
|
||||||
|
groupUIDAttribute: dn
|
||||||
|
groupNameAttributes: [cn]
|
||||||
|
groupMembershipAttributes: [member]
|
||||||
|
usersQuery:
|
||||||
|
baseDN: "ou=users,dc=example,dc=org"
|
||||||
|
scope: sub
|
||||||
|
derefAliases: never
|
||||||
|
pageSize: 0
|
||||||
|
userUIDAttribute: dn
|
||||||
|
userNameAttributes: [mail]
|
||||||
|
tolerateMemberNotFoundErrors: true
|
||||||
|
tolerateMemberOutOfScopeErrors: true
|
||||||
|
|
||||||
|
# Sync all groups except the ones from the deny_groups from an LDAP server
|
||||||
|
- name: Sync all groups from an LDAP server using deny_groups
|
||||||
|
openshift_adm_groups_sync:
|
||||||
|
src: "{{ lookup('file', '/path/to/ldap-sync-config.yaml') | from_yaml }}"
|
||||||
|
deny_groups:
|
||||||
|
- cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat
|
||||||
|
- cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat
|
||||||
|
|
||||||
|
# Sync all OpenShift Groups that have been synced previously with an LDAP server
|
||||||
|
- name: Sync all OpenShift Groups that have been synced previously with an LDAP server
|
||||||
|
openshift_adm_groups_sync:
|
||||||
|
src: "{{ lookup('file', '/path/to/ldap-sync-config.yaml') | from_yaml }}"
|
||||||
|
type: openshift
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="1">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>builds</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>The groups that were created, updated or deleted</div>
|
||||||
|
<br/>
|
||||||
|
<div style="font-size: smaller"><b>Sample:</b></div>
|
||||||
|
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[{'apiVersion': 'user.openshift.io/v1', 'kind': 'Group', 'metadata': {'annotations': {'openshift.io/ldap.sync-time': '2021-12-17T12:20:28.125282', 'openshift.io/ldap.uid': 'cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat', 'openshift.io/ldap.url': 'localhost:1390'}, 'creationTimestamp': '2021-12-17T11:09:49Z', 'labels': {'openshift.io/ldap.host': 'localhost'}, 'managedFields': [{'apiVersion': 'user.openshift.io/v1', 'fieldsType': 'FieldsV1', 'fieldsV1': {'f:metadata': {'f:annotations': {'.': {}, 'f:openshift.io/ldap.sync-time': {}, 'f:openshift.io/ldap.uid': {}, 'f:openshift.io/ldap.url': {}}, 'f:labels': {'.': {}, 'f:openshift.io/ldap.host': {}}}, 'f:users': {}}, 'manager': 'OpenAPI-Generator', 'operation': 'Update', 'time': '2021-12-17T11:09:49Z'}], 'name': 'developers', 'resourceVersion': '2014696', 'uid': '8dc211cb-1544-41e1-96b1-efffeed2d7d7'}, 'users': ['jordanbulls@ansible.org']}]</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
@@ -0,0 +1,587 @@
|
|||||||
|
.. _community.okd.openshift_adm_migrate_template_instances_module:
|
||||||
|
|
||||||
|
|
||||||
|
******************************************************
|
||||||
|
community.okd.openshift_adm_migrate_template_instances
|
||||||
|
******************************************************
|
||||||
|
|
||||||
|
**Update TemplateInstances to point to the latest group-version-kinds**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 2.2.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- Update TemplateInstances to point to the latest group-version-kinds.
|
||||||
|
- Analogous to ``oc adm migrate template-instances``.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>namespace</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The namespace that the template can be found in.</div>
|
||||||
|
<div>If no namespace if specified, migrate objects in all namespaces.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
<div>Please read the description of the <code>username</code> option for a discussion of when this option is applicable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>persist_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable.</div>
|
||||||
|
<div>When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file.</div>
|
||||||
|
<div>Default to false.</div>
|
||||||
|
<div>Please note that the current version of the k8s python client library does not support setting this flag to True yet.</div>
|
||||||
|
<div>The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY).</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_headers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The Header used for the HTTP proxy.</div>
|
||||||
|
<div>Documentation can be found here <a href='https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers'>https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers</a>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for proxy basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_PROXY_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>user_agent</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>String representing the user-agent you want, such as foo/1.0.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_USER_AGENT environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
<div>Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the <span class='module'>community.okd.k8s_auth</span> module, as that might do what you need.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>wait</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>no</b> ←</div></li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether to wait for certain resource kinds to end up in the desired state.</div>
|
||||||
|
<div>By default the module exits once Kubernetes has received the request.</div>
|
||||||
|
<div>Implemented for <code>state=present</code> for <code>Deployment</code>, <code>DaemonSet</code> and <code>Pod</code>, and for <code>state=absent</code> for all resource kinds.</div>
|
||||||
|
<div>For resource kinds without an implementation, <code>wait</code> returns immediately unless <code>wait_condition</code> is set.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>wait_condition</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specifies a custom condition on the status to wait for.</div>
|
||||||
|
<div>Ignored if <code>wait</code> is not set or is set to False.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>reason</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The value of the reason field in your desired condition</div>
|
||||||
|
<div>For example, if a <code>Deployment</code> is paused, The <code>Progressing</code> <code>type</code> will have the <code>DeploymentPaused</code> reason.</div>
|
||||||
|
<div>The possible reasons in a condition are specific to each resource type in Kubernetes.</div>
|
||||||
|
<div>See the API documentation of the status field for a given resource to see possible choices.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>status</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>True</b> ←</div></li>
|
||||||
|
<li>False</li>
|
||||||
|
<li>Unknown</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The value of the status field in your desired condition.</div>
|
||||||
|
<div>For example, if a <code>Deployment</code> is paused, the <code>Progressing</code> <code>type</code> will have the <code>Unknown</code> status.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>type</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The type of condition to wait for.</div>
|
||||||
|
<div>For example, the <code>Pod</code> resource will set the <code>Ready</code> condition (among others).</div>
|
||||||
|
<div>Required if you are specifying a <code>wait_condition</code>.</div>
|
||||||
|
<div>If left empty, the <code>wait_condition</code> field will be ignored.</div>
|
||||||
|
<div>The possible types for a condition are specific to each resource type in Kubernetes.</div>
|
||||||
|
<div>See the API documentation of the status field for a given resource to see possible choices.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>wait_sleep</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">integer</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">5</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Number of seconds to sleep between checks.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>wait_timeout</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">integer</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">120</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>How long in seconds to wait for the resource to end up in the desired state.</div>
|
||||||
|
<div>Ignored if <code>wait</code> is not set.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
- To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
- name: Migrate TemplateInstances in namespace=test
|
||||||
|
community.okd.openshift_adm_migrate_template_instances:
|
||||||
|
namespace: test
|
||||||
|
register: _result
|
||||||
|
|
||||||
|
- name: Migrate TemplateInstances in all namespaces
|
||||||
|
community.okd.openshift_adm_migrate_template_instances:
|
||||||
|
register: _result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="1">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>result</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>List with all TemplateInstances that have been migrated.</div>
|
||||||
|
<br/>
|
||||||
|
<div style="font-size: smaller"><b>Sample:</b></div>
|
||||||
|
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[{'apiVersion': 'template.openshift.io/v1', 'kind': 'TemplateInstance', 'metadata': {'creationTimestamp': '2021-11-10T11:12:09Z', 'finalizers': ['template.openshift.io/finalizer'], 'managedFields': [{'apiVersion': 'template.openshift.io/v1', 'fieldsType': 'FieldsV1', 'fieldsV1': {'f:spec': {'f:template': {'f:metadata': {'f:name': {}}, 'f:objects': {}, 'f:parameters': {}}}}, 'manager': 'kubectl-create', 'operation': 'Update', 'time': '2021-11-10T11:12:09Z'}, {'apiVersion': 'template.openshift.io/v1', 'fieldsType': 'FieldsV1', 'fieldsV1': {'f:metadata': {'f:finalizers': {'.': {}, 'v:"template.openshift.io/finalizer"': {}}}, 'f:status': {'f:conditions': {}}}, 'manager': 'openshift-controller-manager', 'operation': 'Update', 'time': '2021-11-10T11:12:09Z'}, {'apiVersion': 'template.openshift.io/v1', 'fieldsType': 'FieldsV1', 'fieldsV1': {'f:status': {'f:objects': {}}}, 'manager': 'OpenAPI-Generator', 'operation': 'Update', 'time': '2021-11-10T11:12:33Z'}], 'name': 'demo', 'namespace': 'test', 'resourceVersion': '545370', 'uid': '09b795d7-7f07-4d94-bf0f-2150ee66f88d'}, 'spec': {'requester': {'groups': ['system:masters', 'system:authenticated'], 'username': 'system:admin'}, 'template': {'metadata': {'creationTimestamp': None, 'name': 'template'}, 'objects': [{'apiVersion': 'v1', 'kind': 'Secret', 'metadata': {'labels': {'foo': 'bar'}, 'name': 'secret'}}, {'apiVersion': 'apps/v1', 'kind': 'Deployment', 'metadata': {'name': 'deployment'}, 'spec': {'replicas': 0, 'selector': {'matchLabels': {'key': 'value'}}, 'template': {'metadata': {'labels': {'key': 'value'}}, 'spec': {'containers': [{'image': 'k8s.gcr.io/e2e-test-images/agnhost:2.32', 'name': 'hello-openshift'}]}}}}, {'apiVersion': 'v1', 'kind': 'Route', 'metadata': {'name': 'route'}, 'spec': {'to': {'name': 'foo'}}}], 'parameters': [{'name': 'NAME', 'value': '${NAME}'}]}}, 'status': {'conditions': [{'lastTransitionTime': '2021-11-10T11:12:09Z', 'message': '', 'reason': 'Created', 'status': 'True', 'type': 'Ready'}], 'objects': [{'ref': {'apiVersion': 'v1', 'kind': 'Secret', 'name': 'secret', 'namespace': 'test', 'uid': '33fad364-6d47-4f9c-9e51-92cba5602a57'}}, {'ref': {'apiVersion': 'apps/v1', 'kind': 'Deployment', 'name': 'deployment', 'namespace': 'test', 'uid': '3b527f88-42a1-4811-9e2f-baad4e4d8807'}}, {'ref': {'apiVersion': 'route.openshift.io/v1.Route', 'kind': 'Route', 'name': 'route', 'namespace': 'test', 'uid': '5b5411de-8769-4e27-ba52-6781630e4008'}}]}}, '...']</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Alina Buzachis (@alinabuzachis)
|
||||||
@@ -0,0 +1,569 @@
|
|||||||
|
.. _community.okd.openshift_adm_prune_auth_module:
|
||||||
|
|
||||||
|
|
||||||
|
**************************************
|
||||||
|
community.okd.openshift_adm_prune_auth
|
||||||
|
**************************************
|
||||||
|
|
||||||
|
**Removes references to the specified roles, clusterroles, users, and groups**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 2.2.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- This module allow administrators to remove references to the specified roles, clusterroles, users, and groups.
|
||||||
|
- Analogous to ``oc adm prune auth``.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>label_selectors</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Selector (label query) to filter on.</div>
|
||||||
|
<div>Mutually exclusive with option <em>name</em>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>name</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Use to specify an object name to remove.</div>
|
||||||
|
<div>Mutually exclusive with option <em>label_selectors</em>.</div>
|
||||||
|
<div>If neither <em>name</em> nor <em>label_selectors</em> are specified, prune all resources in the namespace.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>namespace</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Use to specify an object namespace.</div>
|
||||||
|
<div>Ignored when <em>resource</em> is set to <code>clusterroles</code>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
<div>Please read the description of the <code>username</code> option for a discussion of when this option is applicable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>persist_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable.</div>
|
||||||
|
<div>When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file.</div>
|
||||||
|
<div>Default to false.</div>
|
||||||
|
<div>Please note that the current version of the k8s python client library does not support setting this flag to True yet.</div>
|
||||||
|
<div>The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY).</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_headers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The Header used for the HTTP proxy.</div>
|
||||||
|
<div>Documentation can be found here <a href='https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers'>https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers</a>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for proxy basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_PROXY_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>user_agent</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>String representing the user-agent you want, such as foo/1.0.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_USER_AGENT environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>resource</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>roles</li>
|
||||||
|
<li>clusterroles</li>
|
||||||
|
<li>users</li>
|
||||||
|
<li>groups</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The specified resource to remove.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
<div>Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the <span class='module'>community.okd.k8s_auth</span> module, as that might do what you need.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
- To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
- name: Prune all roles from default namespace
|
||||||
|
openshift_adm_prune_auth:
|
||||||
|
resource: roles
|
||||||
|
namespace: testing
|
||||||
|
|
||||||
|
- name: Prune clusterroles using label selectors
|
||||||
|
openshift_adm_prune_auth:
|
||||||
|
resource: roles
|
||||||
|
namespace: testing
|
||||||
|
label_selectors:
|
||||||
|
- phase=production
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="1">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>authorization</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><em>resource=users</em></td>
|
||||||
|
<td>
|
||||||
|
<div>list of OAuthClientAuthorization deleted.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>cluster_role_binding</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>always</td>
|
||||||
|
<td>
|
||||||
|
<div>list of cluster role binding deleted.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>group</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><em>resource=users</em></td>
|
||||||
|
<td>
|
||||||
|
<div>list of Security Context Constraints deleted.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>role_binding</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><em>resource=users</em> or <em>resource=groups</em> or <em>resource=clusterroles</em></td>
|
||||||
|
<td>
|
||||||
|
<div>list of role binding deleted.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>security_context_constraints</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><em>resource=users</em> or <em>resource=groups</em></td>
|
||||||
|
<td>
|
||||||
|
<div>list of Security Context Constraints deleted.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
@@ -0,0 +1,571 @@
|
|||||||
|
.. _community.okd.openshift_adm_prune_builds_module:
|
||||||
|
|
||||||
|
|
||||||
|
****************************************
|
||||||
|
community.okd.openshift_adm_prune_builds
|
||||||
|
****************************************
|
||||||
|
|
||||||
|
**Prune old completed and failed builds**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 2.3.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- This module allow administrators to delete old completed and failed builds.
|
||||||
|
- Analogous to ``oc adm prune builds``.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>keep_younger_than</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">integer</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify the minimum age (in minutes) of a Build for it to be considered a candidate for pruning.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>namespace</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Use to specify namespace for builds to be deleted.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>orphans</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>no</b> ←</div></li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>If <code>true</code>, prune all builds whose associated BuildConfig no longer exists and whose status is complete, failed, error, or cancelled.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
<div>Please read the description of the <code>username</code> option for a discussion of when this option is applicable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>persist_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable.</div>
|
||||||
|
<div>When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file.</div>
|
||||||
|
<div>Default to false.</div>
|
||||||
|
<div>Please note that the current version of the k8s python client library does not support setting this flag to True yet.</div>
|
||||||
|
<div>The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY).</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_headers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The Header used for the HTTP proxy.</div>
|
||||||
|
<div>Documentation can be found here <a href='https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers'>https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers</a>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for proxy basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_PROXY_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>user_agent</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>String representing the user-agent you want, such as foo/1.0.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_USER_AGENT environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
<div>Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the <span class='module'>community.okd.k8s_auth</span> module, as that might do what you need.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
- To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
# Run deleting older completed and failed builds and also including
|
||||||
|
# all builds whose associated BuildConfig no longer exists
|
||||||
|
- name: Run delete orphan Builds
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
orphans: true
|
||||||
|
|
||||||
|
# Run deleting older completed and failed builds keep younger than 2hours
|
||||||
|
- name: Run delete builds, keep younger than 2h
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
keep_younger_than: 120
|
||||||
|
|
||||||
|
# Run deleting builds from specific namespace
|
||||||
|
- name: Run delete builds from namespace
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
namespace: testing_namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>builds</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">complex</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>The builds that were deleted</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>api_version</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>The versioned schema of this representation of an object.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>kind</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Represents the REST resource this object represents.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>metadata</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Standard object metadata. Includes name, namespace, annotations, labels, etc.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>spec</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Specific attributes of the object. Will vary based on the <em>api_version</em> and <em>kind</em>.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>status</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Current status details for the object.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
@@ -0,0 +1,483 @@
|
|||||||
|
.. _community.okd.openshift_adm_prune_deployments_module:
|
||||||
|
|
||||||
|
|
||||||
|
*********************************************
|
||||||
|
community.okd.openshift_adm_prune_deployments
|
||||||
|
*********************************************
|
||||||
|
|
||||||
|
**Remove old completed and failed deployment configs**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 2.2.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- This module allow administrators to remove old completed and failed deployment configs.
|
||||||
|
- Analogous to ``oc adm prune deployments``.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>keep_younger_than</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">integer</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify the minimum age (in minutes) of a deployment for it to be considered a candidate for pruning.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>namespace</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Use to specify namespace for deployments to be deleted.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>orphans</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>no</b> ←</div></li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>If <code>true</code>, prune all deployments where the associated DeploymentConfig no longer exists, the status is complete or failed, and the replica size is <code>0</code>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
<div>Please read the description of the <code>username</code> option for a discussion of when this option is applicable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>persist_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable.</div>
|
||||||
|
<div>When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file.</div>
|
||||||
|
<div>Default to false.</div>
|
||||||
|
<div>Please note that the current version of the k8s python client library does not support setting this flag to True yet.</div>
|
||||||
|
<div>The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY).</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_headers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The Header used for the HTTP proxy.</div>
|
||||||
|
<div>Documentation can be found here <a href='https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers'>https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers</a>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for proxy basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_PROXY_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>user_agent</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>String representing the user-agent you want, such as foo/1.0.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_USER_AGENT environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
<div>Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the <span class='module'>community.okd.k8s_auth</span> module, as that might do what you need.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
- To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
- name: Prune Deployments from testing namespace
|
||||||
|
community.okd.openshift_adm_prune_deployments:
|
||||||
|
namespace: testing
|
||||||
|
|
||||||
|
- name: Prune orphans deployments, keep younger than 2hours
|
||||||
|
community.okd.openshift_adm_prune_deployments:
|
||||||
|
orphans: true
|
||||||
|
keep_younger_than: 120
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="1">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>replication_controllers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>always</td>
|
||||||
|
<td>
|
||||||
|
<div>list of replication controllers candidate for pruning.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
File diff suppressed because one or more lines are too long
@@ -171,37 +171,40 @@ Examples
|
|||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|
||||||
- hosts: localhost
|
- name: Example Playbook
|
||||||
|
hosts: localhost
|
||||||
module_defaults:
|
module_defaults:
|
||||||
group/k8s:
|
group/community.okd.okd:
|
||||||
host: https://k8s.example.com/
|
host: https://k8s.example.com/
|
||||||
ca_cert: ca.pem
|
ca_cert: ca.pem
|
||||||
tasks:
|
tasks:
|
||||||
- block:
|
- name: Authenticate to OpenShift cluster and gell a list of all pods from any namespace
|
||||||
# It's good practice to store login credentials in a secure vault and not
|
block:
|
||||||
# directly in playbooks.
|
# It's good practice to store login credentials in a secure vault and not
|
||||||
- include_vars: openshift_passwords.yml
|
# directly in playbooks.
|
||||||
|
- name: Include 'openshift_passwords.yml'
|
||||||
|
ansible.builtin.include_vars: openshift_passwords.yml
|
||||||
|
|
||||||
- name: Log in (obtain access token)
|
- name: Log in (obtain access token)
|
||||||
community.okd.openshift_auth:
|
community.okd.openshift_auth:
|
||||||
username: admin
|
username: admin
|
||||||
password: "{{ openshift_admin_password }}"
|
password: "{{ openshift_admin_password }}"
|
||||||
register: openshift_auth_results
|
register: openshift_auth_results
|
||||||
|
|
||||||
# Previous task provides the token/api_key, while all other parameters
|
# Previous task provides the token/api_key, while all other parameters
|
||||||
# are taken from module_defaults
|
# are taken from module_defaults
|
||||||
- name: Get a list of all pods from any namespace
|
- name: Get a list of all pods from any namespace
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
||||||
kind: Pod
|
kind: Pod
|
||||||
register: pod_list
|
register: pod_list
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: If login succeeded, try to log out (revoke access token)
|
- name: If login succeeded, try to log out (revoke access token)
|
||||||
when: openshift_auth_results.openshift_auth.api_key is defined
|
when: openshift_auth_results.openshift_auth.api_key is defined
|
||||||
community.okd.openshift_auth:
|
community.okd.openshift_auth:
|
||||||
state: absent
|
state: absent
|
||||||
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,844 @@
|
|||||||
|
.. _community.okd.openshift_build_module:
|
||||||
|
|
||||||
|
|
||||||
|
*****************************
|
||||||
|
community.okd.openshift_build
|
||||||
|
*****************************
|
||||||
|
|
||||||
|
**Start a new build or Cancel running, pending, or new builds.**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 2.3.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- This module starts a new build from the provided build config or build name.
|
||||||
|
- This module also cancel a new, pending or running build by requesting a graceful shutdown of the build. There may be a delay between requesting the build and the time the build is terminated.
|
||||||
|
- This can also restart a new build when the current is cancelled.
|
||||||
|
- Analogous to ``oc cancel-build`` and ``oc start-build``.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>build_args</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify a list of key-value pair to pass to Docker during the build.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>name</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>docker build argument name.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>value</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>docker build argument value.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>build_config_name</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify the name of a build config from which a new build will be run.</div>
|
||||||
|
<div>Mutually exclusive with parameter <em>build_name</em>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>build_name</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify the name of a build which should be re-run.</div>
|
||||||
|
<div>Mutually exclusive with parameter <em>build_config_name</em>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>build_phases</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>New</li>
|
||||||
|
<li>Pending</li>
|
||||||
|
<li>Running</li>
|
||||||
|
</ul>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">[]</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>List of state for build to cancel.</div>
|
||||||
|
<div>Ignored when <code>state=started</code>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>commit</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify the source code commit identifier the build should use; requires a build based on a Git repository.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>env_vars</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify a list of key-value pair for an environment variable to set for the build container.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>name</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Environment variable name.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>value</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Environment variable value.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>incremental</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Overrides the incremental setting in a source-strategy build, ignored if not specified.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>namespace</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify the namespace for the build or the build config.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_cache</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Overrides the noCache setting in a docker-strategy build, ignored if not specified.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
<div>Please read the description of the <code>username</code> option for a discussion of when this option is applicable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>persist_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable.</div>
|
||||||
|
<div>When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file.</div>
|
||||||
|
<div>Default to false.</div>
|
||||||
|
<div>Please note that the current version of the k8s python client library does not support setting this flag to True yet.</div>
|
||||||
|
<div>The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY).</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_headers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The Header used for the HTTP proxy.</div>
|
||||||
|
<div>Documentation can be found here <a href='https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers'>https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers</a>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for proxy basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_PROXY_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>user_agent</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>String representing the user-agent you want, such as foo/1.0.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_USER_AGENT environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>state</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>started</b> ←</div></li>
|
||||||
|
<li>cancelled</li>
|
||||||
|
<li>restarted</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Determines if a Build should be started ,cancelled or restarted.</div>
|
||||||
|
<div>When set to <code>restarted</code> a new build will be created after the current build is cancelled.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
<div>Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the <span class='module'>community.okd.k8s_auth</span> module, as that might do what you need.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>wait</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>no</b> ←</div></li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>When <code>state=started</code>, specify whether to wait for a build to complete and exit with a non-zero return code if the build fails.</div>
|
||||||
|
<div>When <em>state=cancelled</em>, specify whether to wait for a build phase to be Cancelled.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>wait_sleep</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">integer</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">5</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Number of seconds to sleep between checks.</div>
|
||||||
|
<div>Ignored if <code>wait=false</code>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>wait_timeout</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">integer</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<b>Default:</b><br/><div style="color: blue">120</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>How long in seconds to wait for a build to complete.</div>
|
||||||
|
<div>Ignored if <code>wait=false</code>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
- To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
# Starts build from build config default/hello-world
|
||||||
|
- name: Starts build from build config
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: default
|
||||||
|
build_config_name: hello-world
|
||||||
|
|
||||||
|
# Starts build from a previous build "default/hello-world-1"
|
||||||
|
- name: Starts build from a previous build
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: default
|
||||||
|
build_name: hello-world-1
|
||||||
|
|
||||||
|
# Cancel the build with the given name
|
||||||
|
- name: Cancel build from default namespace
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "default"
|
||||||
|
build_name: ruby-build-1
|
||||||
|
state: cancelled
|
||||||
|
|
||||||
|
# Cancel the named build and create a new one with the same parameters
|
||||||
|
- name: Cancel build from default namespace and create a new one
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "default"
|
||||||
|
build_name: ruby-build-1
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
# Cancel all builds created from 'ruby-build' build configuration that are in 'new' state
|
||||||
|
- name: Cancel build from default namespace and create a new one
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "default"
|
||||||
|
build_config_name: ruby-build
|
||||||
|
build_phases:
|
||||||
|
- New
|
||||||
|
state: cancelled
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>builds</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">complex</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>The builds that were started/cancelled.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>api_version</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>The versioned schema of this representation of an object.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>kind</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Represents the REST resource this object represents.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>metadata</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Standard object metadata. Includes name, namespace, annotations, labels, etc.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>spec</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Specific attributes of the build.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>status</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Current status details for the object.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
@@ -0,0 +1,681 @@
|
|||||||
|
.. _community.okd.openshift_import_image_module:
|
||||||
|
|
||||||
|
|
||||||
|
************************************
|
||||||
|
community.okd.openshift_import_image
|
||||||
|
************************************
|
||||||
|
|
||||||
|
**Import the latest image information from a tag in a container image registry.**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 2.2.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- Image streams allow you to control which images are rolled out to your builds and applications.
|
||||||
|
- This module fetches the latest version of an image from a remote repository and updates the image stream tag if it does not match the previous value.
|
||||||
|
- Running the module multiple times will not create duplicate entries.
|
||||||
|
- When importing an image, only the image metadata is copied, not the image contents.
|
||||||
|
- Analogous to ``oc import-image``.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
- docker-image-py
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>all</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>no</b> ←</div></li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>If set to <em>true</em>, import all tags from the provided source on creation or if <code>source</code> is specified.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>name</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Image stream to import tag into.</div>
|
||||||
|
<div>This can be provided as a list of images streams or a single value.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>namespace</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
/ <span style="color: red">required</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Use to specify namespace for image stream to create/update.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
<div>Please read the description of the <code>username</code> option for a discussion of when this option is applicable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>persist_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable.</div>
|
||||||
|
<div>When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file.</div>
|
||||||
|
<div>Default to false.</div>
|
||||||
|
<div>Please note that the current version of the k8s python client library does not support setting this flag to True yet.</div>
|
||||||
|
<div>The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY).</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_headers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The Header used for the HTTP proxy.</div>
|
||||||
|
<div>Documentation can be found here <a href='https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers'>https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers</a>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for proxy basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_PROXY_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>user_agent</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>String representing the user-agent you want, such as foo/1.0.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_USER_AGENT environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>reference_policy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>source</b> ←</div></li>
|
||||||
|
<li>local</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Allow to request pullthrough for external image when set to <em>local</em>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>scheduled</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>no</b> ←</div></li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Set each imported Docker image to be periodically imported from a remote repository.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>source</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>A Docker image repository to import images from.</div>
|
||||||
|
<div>Should be provided as 'registry.io/repo/image'</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
<div>Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the <span class='module'>community.okd.k8s_auth</span> module, as that might do what you need.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_registry_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>If set to <em>true</em>, allow importing from registries that have invalid HTTPS certificates. or are hosted via HTTP. This parameter will take precedence over the insecure annotation.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
- To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
# Import tag latest into a new image stream.
|
||||||
|
- name: Import tag latest into new image stream
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: testing
|
||||||
|
name: mystream
|
||||||
|
source: registry.io/repo/image:latest
|
||||||
|
|
||||||
|
# Update imported data for tag latest in an already existing image stream.
|
||||||
|
- name: Update imported data for tag latest
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: testing
|
||||||
|
name: mystream
|
||||||
|
|
||||||
|
# Update imported data for tag 'stable' in an already existing image stream.
|
||||||
|
- name: Update imported data for tag latest
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: testing
|
||||||
|
name: mystream:stable
|
||||||
|
|
||||||
|
# Update imported data for all tags in an existing image stream.
|
||||||
|
- name: Update imported data for all tags
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: testing
|
||||||
|
name: mystream
|
||||||
|
all: true
|
||||||
|
|
||||||
|
# Import all tags into a new image stream.
|
||||||
|
- name: Import all tags into a new image stream.
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: testing
|
||||||
|
name: mystream
|
||||||
|
source: registry.io/repo/image:latest
|
||||||
|
all: true
|
||||||
|
|
||||||
|
# Import all tags into a new image stream for a list of image streams
|
||||||
|
- name: Import all tags into a new image stream.
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: testing
|
||||||
|
name:
|
||||||
|
- mystream1
|
||||||
|
- mystream2
|
||||||
|
- mystream3
|
||||||
|
source: registry.io/repo/image:latest
|
||||||
|
all: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>result</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>List with all ImageStreamImport that have been created.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>api_version</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>The versioned schema of this representation of an object.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>kind</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Represents the REST resource this object represents.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>metadata</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Standard object metadata. Includes name, namespace, annotations, labels, etc.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>spec</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Specific attributes of the object. Will vary based on the <em>api_version</em> and <em>kind</em>.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>status</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Current status details for the object.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
@@ -13,6 +13,15 @@ community.okd.openshift
|
|||||||
:local:
|
:local:
|
||||||
:depth: 1
|
:depth: 1
|
||||||
|
|
||||||
|
DEPRECATED
|
||||||
|
----------
|
||||||
|
:Removed in collection release after
|
||||||
|
:Why: As discussed in https://github.com/ansible-collections/kubernetes.core/issues/31, we decided to
|
||||||
|
remove the openshift inventory plugin in release 5.0.0.
|
||||||
|
|
||||||
|
:Alternative: Use :ref:`kubernetes.core.k8s_info <kubernetes.core.k8s_info_module>` and :ref:`ansible.builtin.add_host <ansible.builtin.add_host_module>` instead.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Synopsis
|
Synopsis
|
||||||
--------
|
--------
|
||||||
@@ -320,24 +329,24 @@ Examples
|
|||||||
|
|
||||||
# File must be named openshift.yaml or openshift.yml
|
# File must be named openshift.yaml or openshift.yml
|
||||||
|
|
||||||
# Authenticate with token, and return all pods and services for all namespaces
|
- name: Authenticate with token, and return all pods and services for all namespaces
|
||||||
plugin: community.okd.openshift
|
plugin: community.okd.openshift
|
||||||
connections:
|
connections:
|
||||||
- host: https://192.168.64.4:8443
|
- host: https://192.168.64.4:8443
|
||||||
api_key: xxxxxxxxxxxxxxxx
|
api_key: xxxxxxxxxxxxxxxx
|
||||||
verify_ssl: false
|
verify_ssl: false
|
||||||
|
|
||||||
# Use default config (~/.kube/config) file and active context, and return objects for a specific namespace
|
- name: Use default config (~/.kube/config) file and active context, and return objects for a specific namespace
|
||||||
plugin: community.okd.openshift
|
plugin: community.okd.openshift
|
||||||
connections:
|
connections:
|
||||||
- namespaces:
|
- namespaces:
|
||||||
- testing
|
- testing
|
||||||
|
|
||||||
# Use a custom config file, and a specific context.
|
- name: Use a custom config file, and a specific context.
|
||||||
plugin: community.okd.openshift
|
plugin: community.okd.openshift
|
||||||
connections:
|
connections:
|
||||||
- kubeconfig: /path/to/config
|
- kubeconfig: /path/to/config
|
||||||
context: 'awx/192-168-64-4:8443/developer'
|
context: 'awx/192-168-64-4:8443/developer'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -346,10 +355,14 @@ Status
|
|||||||
------
|
------
|
||||||
|
|
||||||
|
|
||||||
|
- This inventory will be removed in version 5.0.0. *[deprecated]*
|
||||||
|
- For more information see `DEPRECATED`_.
|
||||||
|
|
||||||
|
|
||||||
Authors
|
Authors
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
|
||||||
- Chris Houseknecht <@chouseknecht>
|
- Chris Houseknecht (@chouseknecht)
|
||||||
|
|
||||||
|
|
||||||
.. hint::
|
.. hint::
|
||||||
|
|||||||
@@ -137,19 +137,56 @@ Parameters
|
|||||||
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
<b>kubeconfig</b>
|
<b>kubeconfig</b>
|
||||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
<div style="font-size: small">
|
<div style="font-size: small">
|
||||||
<span style="color: purple">path</span>
|
<span style="color: purple">raw</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -191,7 +228,7 @@ Parameters
|
|||||||
<b>namespace_target</b>
|
<b>namespace_target</b>
|
||||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
<div style="font-size: small">
|
<div style="font-size: small">
|
||||||
<span style="color: purple">-</span>
|
<span style="color: purple">string</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -201,6 +238,25 @@ Parameters
|
|||||||
<div>Only used when <em>state</em> is present or absent.</div>
|
<div>Only used when <em>state</em> is present or absent.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
@@ -388,7 +444,8 @@ Parameters
|
|||||||
<td>
|
<td>
|
||||||
<div>Provide a path to a file containing a valid YAML definition of an object or objects to be created or updated. Mutually exclusive with <em>resource_definition</em>. NOTE: <em>kind</em>, <em>api_version</em>, <em>name</em>, and <em>namespace</em> will be overwritten by corresponding values found in the configuration read in from the <em>src</em> file.</div>
|
<div>Provide a path to a file containing a valid YAML definition of an object or objects to be created or updated. Mutually exclusive with <em>resource_definition</em>. NOTE: <em>kind</em>, <em>api_version</em>, <em>name</em>, and <em>namespace</em> will be overwritten by corresponding values found in the configuration read in from the <em>src</em> file.</div>
|
||||||
<div>Reads from the local file system. To read from the Ansible controller's file system, including vaulted files, use the file lookup plugin or template lookup plugin, combined with the from_yaml filter, and pass the result to <em>resource_definition</em>. See Examples below.</div>
|
<div>Reads from the local file system. To read from the Ansible controller's file system, including vaulted files, use the file lookup plugin or template lookup plugin, combined with the from_yaml filter, and pass the result to <em>resource_definition</em>. See Examples below.</div>
|
||||||
<div>Mutually exclusive with <em>template</em> in case of <span class='module'>k8s</span> module.</div>
|
<div>The URL to manifest files that can be used to create the resource. Added in version 2.4.0.</div>
|
||||||
|
<div>Mutually exclusive with <em>template</em> in case of <span class='module'>kubernetes.core.k8s</span> module.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -615,8 +672,8 @@ Examples
|
|||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
namespace: default
|
namespace: default
|
||||||
definition: '{{ item }}'
|
definition: '{{ item }}'
|
||||||
wait: yes
|
wait: true
|
||||||
apply: yes
|
apply: true
|
||||||
loop: '{{ result.resources }}'
|
loop: '{{ result.resources }}'
|
||||||
|
|
||||||
- name: Process a template with parameters from an env file and create the resources
|
- name: Process a template with parameters from an env file and create the resources
|
||||||
@@ -626,7 +683,7 @@ Examples
|
|||||||
namespace_target: default
|
namespace_target: default
|
||||||
parameter_file: 'files/nginx.env'
|
parameter_file: 'files/nginx.env'
|
||||||
state: present
|
state: present
|
||||||
wait: yes
|
wait: true
|
||||||
|
|
||||||
- name: Process a local template and create the resources
|
- name: Process a local template and create the resources
|
||||||
community.okd.openshift_process:
|
community.okd.openshift_process:
|
||||||
@@ -641,7 +698,7 @@ Examples
|
|||||||
parameter_file: files/example.env
|
parameter_file: files/example.env
|
||||||
namespace_target: default
|
namespace_target: default
|
||||||
state: absent
|
state: absent
|
||||||
wait: yes
|
wait: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,519 @@
|
|||||||
|
.. _community.okd.openshift_registry_info_module:
|
||||||
|
|
||||||
|
|
||||||
|
*************************************
|
||||||
|
community.okd.openshift_registry_info
|
||||||
|
*************************************
|
||||||
|
|
||||||
|
**Display information about the integrated registry.**
|
||||||
|
|
||||||
|
|
||||||
|
Version added: 2.2.0
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
:depth: 1
|
||||||
|
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
- This module exposes information about the integrated registry.
|
||||||
|
- Use ``check`` to verify your local client can access the registry.
|
||||||
|
- If the adminstrator has not configured a public hostname for the registry then this command may fail when run outside of the server.
|
||||||
|
- Analogous to ``oc registry info``.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
The below requirements are needed on the host that executes this module.
|
||||||
|
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
- docker-image-py
|
||||||
|
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Parameter</th>
|
||||||
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
|
<th width="100%">Comments</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>api_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>ca_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>check</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li><div style="color: blue"><b>no</b> ←</div></li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Attempt to contact the integrated registry using local client.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_cert</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: cert_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>client_key</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">path</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: key_file</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>context</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>host</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>kubeconfig</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">raw</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>password</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable.</div>
|
||||||
|
<div>Please read the description of the <code>username</code> option for a discussion of when this option is applicable.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>persist_config</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable.</div>
|
||||||
|
<div>When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file.</div>
|
||||||
|
<div>Default to false.</div>
|
||||||
|
<div>Please note that the current version of the k8s python client library does not support setting this flag to True yet.</div>
|
||||||
|
<div>The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY).</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_headers</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.0.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The Header used for the HTTP proxy.</div>
|
||||||
|
<div>Documentation can be found here <a href='https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers'>https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html?highlight=proxy_headers#urllib3.util.make_headers</a>.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>proxy_basic_auth</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Colon-separated username:password for proxy basic authentication header.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_PROXY_BASIC_AUTH environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"></td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>user_agent</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>String representing the user-agent you want, such as foo/1.0.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_PROXY_HEADERS_USER_AGENT environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>username</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable.</div>
|
||||||
|
<div>Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the <span class='module'>community.okd.k8s_auth</span> module, as that might do what you need.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>validate_certs</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">boolean</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<ul style="margin: 0; padding: 0"><b>Choices:</b>
|
||||||
|
<li>no</li>
|
||||||
|
<li>yes</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether or not to verify the API server's SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable.</div>
|
||||||
|
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
- To avoid SSL certificate validation errors when ``validate_certs`` is *True*, the full certificate chain for the API server must be provided via ``ca_cert`` or in the kubeconfig file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
# Get registry information
|
||||||
|
- name: Read integrated registry information
|
||||||
|
community.okd.openshift_registry_info:
|
||||||
|
|
||||||
|
# Read registry integrated information and attempt to contact using local client.
|
||||||
|
- name: Attempt to contact integrated registry using local client
|
||||||
|
community.okd.openshift_registry_info:
|
||||||
|
check: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
-------------
|
||||||
|
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<table border=0 cellpadding=0 class="documentation-table">
|
||||||
|
<tr>
|
||||||
|
<th colspan="2">Key</th>
|
||||||
|
<th>Returned</th>
|
||||||
|
<th width="100%">Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>check</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether the local client can contact or not the registry.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>msg</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>always</td>
|
||||||
|
<td>
|
||||||
|
<div>message describing the ping operation.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="elbow-placeholder"> </td>
|
||||||
|
<td colspan="1">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>reached</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>Whether the registry has been reached or not.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>internal_hostname</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>The internal registry hostname.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="return-"></div>
|
||||||
|
<b>public_hostname</b>
|
||||||
|
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>success</td>
|
||||||
|
<td>
|
||||||
|
<div>The public registry hostname.</div>
|
||||||
|
<br/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
|
||||||
|
Status
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
@@ -19,7 +19,7 @@ Synopsis
|
|||||||
--------
|
--------
|
||||||
- Looks up a Service and creates a new Route based on it.
|
- Looks up a Service and creates a new Route based on it.
|
||||||
- Analogous to `oc expose` and `oc create route` for creating Routes, but does not support creating Services.
|
- Analogous to `oc expose` and `oc create route` for creating Routes, but does not support creating Services.
|
||||||
- For creating Services from other resources, see kubernetes.core.k8s_expose
|
- For creating Services from other resources, see kubernetes.core.k8s.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -43,6 +43,23 @@ Parameters
|
|||||||
<th>Choices/<font color="blue">Defaults</font></th>
|
<th>Choices/<font color="blue">Defaults</font></th>
|
||||||
<th width="100%">Comments</th>
|
<th width="100%">Comments</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>annotations</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">dictionary</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.1.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Specify the Route Annotations.</div>
|
||||||
|
<div>A set of key: value pairs.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
@@ -170,19 +187,56 @@ Parameters
|
|||||||
<div>The hostname for the Route.</div>
|
<div>The hostname for the Route.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_groups</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">list</span>
|
||||||
|
/ <span style="color: purple">elements=string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Group(s) to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_GROUPS environment. Example: Group1,Group2</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>impersonate_user</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>Username to impersonate for the operation.</div>
|
||||||
|
<div>Can also be specified via K8S_AUTH_IMPERSONATE_USER environment.</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
<b>kubeconfig</b>
|
<b>kubeconfig</b>
|
||||||
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
<div style="font-size: small">
|
<div style="font-size: small">
|
||||||
<span style="color: purple">path</span>
|
<span style="color: purple">raw</span>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
<div>Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the Kubernetes client will attempt to load the default configuration file from <em>~/.kube/config</em>. Can also be specified via K8S_AUTH_KUBECONFIG environment variable.</div>
|
||||||
|
<div>Multiple Kubernetes config file can be provided using separator ';' for Windows platform or ':' for others platforms.</div>
|
||||||
|
<div>The kubernetes configuration can be provided as dictionary. This feature requires a python kubernetes client version >= 17.17.0. Added in version 2.2.0.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -234,6 +288,25 @@ Parameters
|
|||||||
<div>The Route will be created in this namespace as well.</div>
|
<div>The Route will be created in this namespace as well.</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
|
<b>no_proxy</b>
|
||||||
|
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
|
||||||
|
<div style="font-size: small">
|
||||||
|
<span style="color: purple">string</span>
|
||||||
|
</div>
|
||||||
|
<div style="font-style: italic; font-size: small; color: darkgreen">added in 2.3.0</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>The comma separated list of hosts/domains/IP/CIDR that shouldn't go through proxy. Can also be specified via K8S_AUTH_NO_PROXY environment variable.</div>
|
||||||
|
<div>Please note that this module does not pick up typical proxy settings from the environment (e.g. NO_PROXY).</div>
|
||||||
|
<div>This feature requires kubernetes>=19.15.0. When kubernetes library is less than 19.15.0, it fails even no_proxy set in correct.</div>
|
||||||
|
<div>example value is "localhost,.local,.example.com,127.0.0.1,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
<div class="ansibleOptionAnchor" id="parameter-"></div>
|
||||||
@@ -783,10 +856,10 @@ Examples
|
|||||||
app: hello-kubernetes
|
app: hello-kubernetes
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: hello-kubernetes
|
- name: hello-kubernetes
|
||||||
image: paulbouwer/hello-kubernetes:1.8
|
image: paulbouwer/hello-kubernetes:1.8
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
|
||||||
- name: Create Service for the hello-world deployment
|
- name: Create Service for the hello-world deployment
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
@@ -798,8 +871,8 @@ Examples
|
|||||||
namespace: default
|
namespace: default
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- port: 80
|
- port: 80
|
||||||
targetPort: 8080
|
targetPort: 8080
|
||||||
selector:
|
selector:
|
||||||
app: hello-kubernetes
|
app: hello-kubernetes
|
||||||
|
|
||||||
@@ -808,6 +881,8 @@ Examples
|
|||||||
service: hello-kubernetes
|
service: hello-kubernetes
|
||||||
namespace: default
|
namespace: default
|
||||||
insecure_policy: allow
|
insecure_policy: allow
|
||||||
|
annotations:
|
||||||
|
haproxy.router.openshift.io/balance: roundrobin
|
||||||
register: route
|
register: route
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@ authors:
|
|||||||
- willthames (https://github.com/willthames)
|
- willthames (https://github.com/willthames)
|
||||||
- Akasurde (https://github.com/akasurde)
|
- Akasurde (https://github.com/akasurde)
|
||||||
dependencies:
|
dependencies:
|
||||||
kubernetes.core: '>=2.1.0,<2.3.0'
|
kubernetes.core: '>=6.0.0'
|
||||||
description: OKD Collection for Ansible.
|
description: OKD Collection for Ansible.
|
||||||
documentation: ''
|
documentation: ''
|
||||||
homepage: ''
|
homepage: ''
|
||||||
@@ -24,4 +24,4 @@ tags:
|
|||||||
- okd
|
- okd
|
||||||
- cluster
|
- cluster
|
||||||
# Also needs to be updated in the Makefile
|
# Also needs to be updated in the Makefile
|
||||||
version: 2.1.0
|
version: 6.0.0
|
||||||
|
|||||||
+7
-1
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
requires_ansible: '>=2.9.17'
|
requires_ansible: '>=2.16.0'
|
||||||
action_groups:
|
action_groups:
|
||||||
okd:
|
okd:
|
||||||
- k8s
|
- k8s
|
||||||
@@ -17,6 +17,12 @@ plugin_routing:
|
|||||||
modules:
|
modules:
|
||||||
k8s_auth:
|
k8s_auth:
|
||||||
redirect: community.okd.openshift_auth
|
redirect: community.okd.openshift_auth
|
||||||
|
inventory:
|
||||||
|
openshift:
|
||||||
|
tombstone:
|
||||||
|
removal_version: 5.0.0
|
||||||
|
warning_text: >-
|
||||||
|
Use kubernetes.core.k8s_info and ansible.builtin.add_host instead.
|
||||||
action:
|
action:
|
||||||
k8s:
|
k8s:
|
||||||
redirect: kubernetes.core.k8s_info
|
redirect: kubernetes.core.k8s_info
|
||||||
|
|||||||
@@ -21,16 +21,13 @@
|
|||||||
debug:
|
debug:
|
||||||
var: output
|
var: output
|
||||||
|
|
||||||
- name: Create deployment config
|
- name: Create deployment
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
state: present
|
state: present
|
||||||
name: hello-world
|
name: hello-world
|
||||||
namespace: testing
|
namespace: testing
|
||||||
definition: '{{ okd_dc_template }}'
|
definition: '{{ okd_dc_template }}'
|
||||||
wait: yes
|
wait: yes
|
||||||
wait_condition:
|
|
||||||
type: Available
|
|
||||||
status: True
|
|
||||||
vars:
|
vars:
|
||||||
k8s_pod_name: hello-world
|
k8s_pod_name: hello-world
|
||||||
k8s_pod_image: python
|
k8s_pod_image: python
|
||||||
@@ -71,19 +68,12 @@
|
|||||||
namespace: '{{ namespace }}'
|
namespace: '{{ namespace }}'
|
||||||
definition: '{{ okd_imagestream_template }}'
|
definition: '{{ okd_imagestream_template }}'
|
||||||
|
|
||||||
- name: Create DeploymentConfig to reference ImageStream
|
|
||||||
community.okd.k8s:
|
|
||||||
name: '{{ k8s_pod_name }}'
|
|
||||||
namespace: '{{ namespace }}'
|
|
||||||
definition: '{{ okd_dc_template }}'
|
|
||||||
vars:
|
|
||||||
k8s_pod_name: is-idempotent-dc
|
|
||||||
|
|
||||||
- name: Create Deployment to reference ImageStream
|
- name: Create Deployment to reference ImageStream
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
name: '{{ k8s_pod_name }}'
|
name: '{{ k8s_pod_name }}'
|
||||||
namespace: '{{ namespace }}'
|
namespace: '{{ namespace }}'
|
||||||
definition: '{{ k8s_deployment_template | combine(metadata) }}'
|
definition: '{{ k8s_deployment_template | combine(metadata) }}'
|
||||||
|
wait: true
|
||||||
vars:
|
vars:
|
||||||
k8s_pod_annotations:
|
k8s_pod_annotations:
|
||||||
"alpha.image.policy.openshift.io/resolve-names": "*"
|
"alpha.image.policy.openshift.io/resolve-names": "*"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Want to make sure comments don't break it
|
# Want to make sure comments don't break it
|
||||||
export NAME=test123
|
export NAME=test123
|
||||||
NAMESPACE=openshift
|
NAMESPACE=openshift
|
||||||
|
NGINX_VERSION=1.22-ubi8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ objects:
|
|||||||
name: "Pod-${{ NAME }}"
|
name: "Pod-${{ NAME }}"
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- args:
|
- args:
|
||||||
- /bin/sh
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- while true; do echo $(date); sleep 15; done
|
- while true; do echo $(date); sleep 15; done
|
||||||
image: python:3.7-alpine
|
image: python:3.7-alpine
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
name: python
|
name: python
|
||||||
parameters:
|
parameters:
|
||||||
- name: NAME
|
- name: NAME
|
||||||
description: trailing name of the pod
|
description: trailing name of the pod
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
@@ -1,11 +1,49 @@
|
|||||||
---
|
---
|
||||||
apiVersion: apiextensions.k8s.io/v1beta1
|
apiVersion: apiextensions.k8s.io/v1
|
||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
metadata:
|
metadata:
|
||||||
name: certificates.certmanager.k8s.io
|
name: certificates.certmanager.k8s.io
|
||||||
|
annotations:
|
||||||
|
"api-approved.kubernetes.io": "https://github.com/kubernetes/kubernetes/pull/78458"
|
||||||
spec:
|
spec:
|
||||||
group: certmanager.k8s.io
|
group: certmanager.k8s.io
|
||||||
version: v1alpha1
|
versions:
|
||||||
|
- name: v1alpha1
|
||||||
|
served: true
|
||||||
|
storage: true
|
||||||
|
schema:
|
||||||
|
openAPIV3Schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
certificate:
|
||||||
|
type: string
|
||||||
|
secretName:
|
||||||
|
type: string
|
||||||
|
dnsNames:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
acme:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
config:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
ingressClass:
|
||||||
|
type: string
|
||||||
|
domains:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
issuerRef:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
kind:
|
||||||
|
type: string
|
||||||
scope: Namespaced
|
scope: Namespaced
|
||||||
names:
|
names:
|
||||||
kind: Certificate
|
kind: Certificate
|
||||||
|
|||||||
@@ -13,22 +13,22 @@ metadata:
|
|||||||
tags: quickstart,examples
|
tags: quickstart,examples
|
||||||
name: simple-example
|
name: simple-example
|
||||||
objects:
|
objects:
|
||||||
- apiVersion: v1
|
- apiVersion: v1
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
description: Big example
|
description: Big example
|
||||||
name: ${NAME}
|
name: ${NAME}
|
||||||
data:
|
data:
|
||||||
content: "${CONTENT}"
|
content: "${CONTENT}"
|
||||||
parameters:
|
parameters:
|
||||||
- description: The name assigned to the ConfigMap
|
- description: The name assigned to the ConfigMap
|
||||||
displayName: Name
|
displayName: Name
|
||||||
name: NAME
|
name: NAME
|
||||||
required: true
|
required: true
|
||||||
value: example
|
value: example
|
||||||
- description: The value for the content key of the configmap
|
- description: The value for the content key of the configmap
|
||||||
displayName: Content
|
displayName: Content
|
||||||
name: CONTENT
|
name: CONTENT
|
||||||
required: true
|
required: true
|
||||||
value: ''
|
value: ''
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ dependency:
|
|||||||
options:
|
options:
|
||||||
requirements-file: requirements.yml
|
requirements-file: requirements.yml
|
||||||
driver:
|
driver:
|
||||||
name: delegated
|
name: default
|
||||||
platforms:
|
platforms:
|
||||||
- name: cluster
|
- name: cluster
|
||||||
groups:
|
groups:
|
||||||
@@ -14,34 +14,22 @@ provisioner:
|
|||||||
log: true
|
log: true
|
||||||
options:
|
options:
|
||||||
vvv: True
|
vvv: True
|
||||||
config_options:
|
|
||||||
inventory:
|
|
||||||
enable_plugins: community.okd.openshift
|
|
||||||
lint: |
|
|
||||||
set -e
|
|
||||||
ansible-lint
|
|
||||||
inventory:
|
inventory:
|
||||||
hosts:
|
|
||||||
plugin: community.okd.openshift
|
|
||||||
host_vars:
|
host_vars:
|
||||||
localhost:
|
localhost:
|
||||||
virtualenv: ${MOLECULE_EPHEMERAL_DIRECTORY}/virtualenv
|
virtualenv: ${MOLECULE_EPHEMERAL_DIRECTORY}/virtualenv
|
||||||
virtualenv_command: '{{ ansible_playbook_python }} -m virtualenv'
|
virtualenv_command: '{{ ansible_playbook_python }} -m venv'
|
||||||
virtualenv_interpreter: '{{ virtualenv }}/bin/python'
|
virtualenv_interpreter: '{{ virtualenv }}/bin/python3'
|
||||||
playbook_namespace: molecule-tests
|
playbook_namespace: molecule-tests
|
||||||
env:
|
env:
|
||||||
ANSIBLE_FORCE_COLOR: 'true'
|
ANSIBLE_FORCE_COLOR: 'true'
|
||||||
ANSIBLE_COLLECTIONS_PATHS: ${OVERRIDE_COLLECTION_PATH:-$MOLECULE_PROJECT_DIRECTORY}
|
ANSIBLE_COLLECTIONS_PATHS: ${OVERRIDE_COLLECTION_PATH:-$MOLECULE_PROJECT_DIRECTORY}
|
||||||
verifier:
|
verifier:
|
||||||
name: ansible
|
name: ansible
|
||||||
lint: |
|
|
||||||
set -e
|
|
||||||
ansible-lint
|
|
||||||
scenario:
|
scenario:
|
||||||
name: default
|
name: default
|
||||||
test_sequence:
|
test_sequence:
|
||||||
- dependency
|
- dependency
|
||||||
- lint
|
|
||||||
- syntax
|
- syntax
|
||||||
- prepare
|
- prepare
|
||||||
- converge
|
- converge
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
- kubernetes>=12.0.0
|
- kubernetes>=12.0.0
|
||||||
- coverage
|
- coverage
|
||||||
- python-ldap
|
- python-ldap
|
||||||
|
- packaging
|
||||||
virtualenv: "{{ virtualenv }}"
|
virtualenv: "{{ virtualenv }}"
|
||||||
virtualenv_command: "{{ virtualenv_command }}"
|
virtualenv_command: "{{ virtualenv_command }}"
|
||||||
virtualenv_site_packages: no
|
virtualenv_site_packages: no
|
||||||
@@ -37,12 +38,12 @@
|
|||||||
name: cluster
|
name: cluster
|
||||||
spec:
|
spec:
|
||||||
identityProviders:
|
identityProviders:
|
||||||
- name: htpasswd_provider
|
- name: htpasswd_provider
|
||||||
mappingMethod: claim
|
mappingMethod: claim
|
||||||
type: HTPasswd
|
type: HTPasswd
|
||||||
htpasswd:
|
htpasswd:
|
||||||
fileData:
|
fileData:
|
||||||
name: htpass-secret
|
name: htpass-secret
|
||||||
|
|
||||||
- name: Create ClusterRoleBinding for test user
|
- name: Create ClusterRoleBinding for test user
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
@@ -54,7 +55,7 @@
|
|||||||
roleRef:
|
roleRef:
|
||||||
apiGroup: rbac.authorization.k8s.io
|
apiGroup: rbac.authorization.k8s.io
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
name: cluster-reader
|
name: cluster-admin
|
||||||
subjects:
|
subjects:
|
||||||
- apiGroup: rbac.authorization.k8s.io
|
- apiGroup: rbac.authorization.k8s.io
|
||||||
kind: User
|
kind: User
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ def execute():
|
|||||||
|
|
||||||
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
||||||
connection = ldap.initialize(module.params['server_uri'])
|
connection = ldap.initialize(module.params['server_uri'])
|
||||||
|
connection.set_option(ldap.OPT_REFERRALS, 0)
|
||||||
try:
|
try:
|
||||||
connection.simple_bind_s(module.params['bind_dn'], module.params['bind_pw'])
|
connection.simple_bind_s(module.params['bind_dn'], module.params['bind_pw'])
|
||||||
except ldap.LDAPError as e:
|
except ldap.LDAPError as e:
|
||||||
|
|||||||
@@ -1,227 +1,227 @@
|
|||||||
|
---
|
||||||
- block:
|
- block:
|
||||||
- name: Get LDAP definition
|
- name: Get LDAP definition
|
||||||
set_fact:
|
set_fact:
|
||||||
ldap_entries: "{{ lookup('template', 'ad/definition.j2') | from_yaml }}"
|
ldap_entries: "{{ lookup('template', 'ad/definition.j2') | from_yaml }}"
|
||||||
|
|
||||||
- name: Delete openshift groups if existing
|
- name: Delete openshift groups if existing
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
state: absent
|
state: absent
|
||||||
kind: Group
|
kind: Group
|
||||||
version: "user.openshift.io/v1"
|
version: "user.openshift.io/v1"
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
with_items:
|
with_items:
|
||||||
- admins
|
- admins
|
||||||
- developers
|
|
||||||
|
|
||||||
- name: Delete existing LDAP Entries
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ item.dn }}"
|
|
||||||
state: absent
|
|
||||||
with_items: "{{ ldap_entries.users + ldap_entries.units | reverse | list }}"
|
|
||||||
|
|
||||||
- name: Create LDAP Entries
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ item.dn }}"
|
|
||||||
attributes: "{{ item.attr }}"
|
|
||||||
objectClass: "{{ item.class }}"
|
|
||||||
with_items: "{{ ldap_entries.units + ldap_entries.users }}"
|
|
||||||
|
|
||||||
- name: Load test configurations
|
|
||||||
set_fact:
|
|
||||||
sync_config: "{{ lookup('template', 'ad/sync-config.j2') | from_yaml }}"
|
|
||||||
|
|
||||||
- name: Synchronize Groups
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ sync_config }}"
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- admins_group
|
|
||||||
- devs_group
|
|
||||||
- '"jane.smith@ansible.org" in {{ admins_group.users }}'
|
|
||||||
- '"jim.adams@ansible.org" in {{ admins_group.users }}'
|
|
||||||
- '"jordanbulls@ansible.org" in {{ devs_group.users }}'
|
|
||||||
- admins_group.users | length == 2
|
|
||||||
- devs_group.users | length == 1
|
|
||||||
vars:
|
|
||||||
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'admins') | first }}"
|
|
||||||
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'developers') | first }}"
|
|
||||||
|
|
||||||
|
|
||||||
- name: Synchronize Groups (Remove check_mode)
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ sync_config }}"
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
|
|
||||||
- name: Read admins group
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: admins
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate group was created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result.resources | length == 1
|
|
||||||
- '"jane.smith@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
- '"jim.adams@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
|
|
||||||
- name: Read developers group
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: developers
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate group was created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result.resources | length == 1
|
|
||||||
- '"jordanbulls@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
|
|
||||||
- name: Define user dn to delete
|
|
||||||
set_fact:
|
|
||||||
user_to_delete: "cn=Jane,ou=engineers,ou=activeD,{{ ldap_root }}"
|
|
||||||
|
|
||||||
- name: Delete 1 admin user
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ user_to_delete }}"
|
|
||||||
state: absent
|
|
||||||
|
|
||||||
- name: Synchronize Openshift groups using allow_groups
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ sync_config }}"
|
|
||||||
allow_groups:
|
|
||||||
- developers
|
- developers
|
||||||
type: openshift
|
|
||||||
register: openshift_sync
|
|
||||||
|
|
||||||
- name: Validate that only developers group was sync
|
- name: Delete existing LDAP Entries
|
||||||
assert:
|
openshift_ldap_entry:
|
||||||
that:
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
- openshift_sync is changed
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
- openshift_sync.groups | length == 1
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
- openshift_sync.groups.0.metadata.name == "developers"
|
dn: "{{ item.dn }}"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ ldap_entries.users + ldap_entries.units | reverse | list }}"
|
||||||
|
|
||||||
- name: Read admins group
|
- name: Create LDAP Entries
|
||||||
kubernetes.core.k8s_info:
|
openshift_ldap_entry:
|
||||||
kind: Group
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
version: "user.openshift.io/v1"
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
name: admins
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
register: result
|
dn: "{{ item.dn }}"
|
||||||
|
attributes: "{{ item.attr }}"
|
||||||
|
objectClass: "{{ item.class }}"
|
||||||
|
with_items: "{{ ldap_entries.units + ldap_entries.users }}"
|
||||||
|
|
||||||
- name: Validate admins group content has not changed
|
- name: Load test configurations
|
||||||
assert:
|
set_fact:
|
||||||
that:
|
sync_config: "{{ lookup('template', 'ad/sync-config.j2') | from_yaml }}"
|
||||||
- result.resources | length == 1
|
|
||||||
- '"jane.smith@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
- '"jim.adams@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
|
|
||||||
- name: Synchronize Openshift groups using deny_groups
|
- name: Synchronize Groups
|
||||||
community.okd.openshift_adm_groups_sync:
|
community.okd.openshift_adm_groups_sync:
|
||||||
config: "{{ sync_config }}"
|
config: "{{ sync_config }}"
|
||||||
deny_groups:
|
check_mode: yes
|
||||||
- developers
|
register: result
|
||||||
type: openshift
|
|
||||||
register: openshift_sync
|
|
||||||
|
|
||||||
- name: Validate that only admins group was sync
|
- name: Validate Group going to be created
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- openshift_sync is changed
|
- result is changed
|
||||||
- openshift_sync.groups | length == 1
|
- admins_group | length > 0
|
||||||
- openshift_sync.groups.0.metadata.name == "admins"
|
- devs_group | length > 0
|
||||||
|
- '"jane.smith@ansible.org" in admins_group.users'
|
||||||
|
- '"jim.adams@ansible.org" in admins_group.users'
|
||||||
|
- '"jordanbulls@ansible.org" in devs_group.users'
|
||||||
|
- admins_group.users | length == 2
|
||||||
|
- devs_group.users | length == 1
|
||||||
|
vars:
|
||||||
|
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'admins') | first }}"
|
||||||
|
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'developers') | first }}"
|
||||||
|
|
||||||
- name: Read admins group
|
- name: Synchronize Groups (Remove check_mode)
|
||||||
kubernetes.core.k8s_info:
|
community.okd.openshift_adm_groups_sync:
|
||||||
kind: Group
|
config: "{{ sync_config }}"
|
||||||
version: "user.openshift.io/v1"
|
register: result
|
||||||
name: admins
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate admins group contains only 1 user now
|
- name: Validate Group going to be created
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result.resources | length == 1
|
- result is changed
|
||||||
- result.resources.0.users == ["jim.adams@ansible.org"]
|
|
||||||
|
|
||||||
- name: Set users to delete (delete all developers users)
|
- name: Read admins group
|
||||||
set_fact:
|
kubernetes.core.k8s_info:
|
||||||
user_to_delete: "cn=Jordan,ou=engineers,ou=activeD,{{ ldap_root }}"
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: admins
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Delete 1 admin user
|
- name: Validate group was created
|
||||||
openshift_ldap_entry:
|
assert:
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
that:
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
- result.resources | length == 1
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
- '"jane.smith@ansible.org" in result.resources.0.users'
|
||||||
dn: "{{ user_to_delete }}"
|
- '"jim.adams@ansible.org" in result.resources.0.users'
|
||||||
state: absent
|
|
||||||
|
|
||||||
- name: Prune groups
|
- name: Read developers group
|
||||||
community.okd.openshift_adm_groups_sync:
|
kubernetes.core.k8s_info:
|
||||||
config: "{{ sync_config }}"
|
kind: Group
|
||||||
state: absent
|
version: "user.openshift.io/v1"
|
||||||
register: result
|
name: developers
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Validate result is changed (only developers group be deleted)
|
- name: Validate group was created
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result.resources | length == 1
|
||||||
- result.groups | length == 1
|
- '"jordanbulls@ansible.org" in result.resources.0.users'
|
||||||
|
|
||||||
- name: Get developers group info
|
- name: Define user dn to delete
|
||||||
kubernetes.core.k8s_info:
|
set_fact:
|
||||||
kind: Group
|
user_to_delete: "cn=Jane,ou=engineers,ou=activeD,{{ ldap_root }}"
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: developers
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: assert group was deleted
|
- name: Delete 1 admin user
|
||||||
assert:
|
openshift_ldap_entry:
|
||||||
that:
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
- result.resources | length == 0
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
|
dn: "{{ user_to_delete }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Get admins group info
|
- name: Synchronize Openshift groups using allow_groups
|
||||||
kubernetes.core.k8s_info:
|
community.okd.openshift_adm_groups_sync:
|
||||||
kind: Group
|
config: "{{ sync_config }}"
|
||||||
version: "user.openshift.io/v1"
|
allow_groups:
|
||||||
name: admins
|
- developers
|
||||||
register: result
|
type: openshift
|
||||||
|
register: openshift_sync
|
||||||
|
|
||||||
- name: assert group was not deleted
|
- name: Validate that only developers group was sync
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result.resources | length == 1
|
- openshift_sync is changed
|
||||||
|
- openshift_sync.groups | length == 1
|
||||||
|
- openshift_sync.groups.0.metadata.name == "developers"
|
||||||
|
|
||||||
- name: Prune groups once again (idempotency)
|
- name: Read admins group
|
||||||
community.okd.openshift_adm_groups_sync:
|
kubernetes.core.k8s_info:
|
||||||
config: "{{ sync_config }}"
|
kind: Group
|
||||||
state: absent
|
version: "user.openshift.io/v1"
|
||||||
register: result
|
name: admins
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Assert nothing was changed
|
- name: Validate admins group content has not changed
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result.resources | length == 1
|
||||||
|
- '"jane.smith@ansible.org" in result.resources.0.users'
|
||||||
|
- '"jim.adams@ansible.org" in result.resources.0.users'
|
||||||
|
|
||||||
|
- name: Synchronize Openshift groups using deny_groups
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ sync_config }}"
|
||||||
|
deny_groups:
|
||||||
|
- developers
|
||||||
|
type: openshift
|
||||||
|
register: openshift_sync
|
||||||
|
|
||||||
|
- name: Validate that only admins group was sync
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- openshift_sync is changed
|
||||||
|
- openshift_sync.groups | length == 1
|
||||||
|
- openshift_sync.groups.0.metadata.name == "admins"
|
||||||
|
|
||||||
|
- name: Read admins group
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: admins
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate admins group contains only 1 user now
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
- result.resources.0.users == ["jim.adams@ansible.org"]
|
||||||
|
|
||||||
|
- name: Set users to delete (delete all developers users)
|
||||||
|
set_fact:
|
||||||
|
user_to_delete: "cn=Jordan,ou=engineers,ou=activeD,{{ ldap_root }}"
|
||||||
|
|
||||||
|
- name: Delete 1 admin user
|
||||||
|
openshift_ldap_entry:
|
||||||
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
|
dn: "{{ user_to_delete }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Prune groups
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ sync_config }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate result is changed (only developers group be deleted)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.groups | length == 1
|
||||||
|
|
||||||
|
- name: Get developers group info
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: developers
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert group was deleted
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 0
|
||||||
|
|
||||||
|
- name: Get admins group info
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: admins
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert group was not deleted
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
|
||||||
|
- name: Prune groups once again (idempotency)
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ sync_config }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Assert nothing was changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is not changed
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete openshift groups if existing
|
- name: Delete openshift groups if existing
|
||||||
|
|||||||
@@ -1,166 +1,165 @@
|
|||||||
|
---
|
||||||
- block:
|
- block:
|
||||||
- name: Get LDAP definition
|
- name: Get LDAP definition
|
||||||
set_fact:
|
set_fact:
|
||||||
ldap_entries: "{{ lookup('template', 'augmented-ad/definition.j2') | from_yaml }}"
|
ldap_entries: "{{ lookup('template', 'augmented-ad/definition.j2') | from_yaml }}"
|
||||||
|
|
||||||
- name: Delete openshift groups if existing
|
- name: Delete openshift groups if existing
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
state: absent
|
state: absent
|
||||||
kind: Group
|
kind: Group
|
||||||
version: "user.openshift.io/v1"
|
version: "user.openshift.io/v1"
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
with_items:
|
with_items:
|
||||||
- banking
|
- banking
|
||||||
- insurance
|
- insurance
|
||||||
|
|
||||||
- name: Delete existing LDAP entries
|
- name: Delete existing LDAP entries
|
||||||
openshift_ldap_entry:
|
openshift_ldap_entry:
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
dn: "{{ item.dn }}"
|
dn: "{{ item.dn }}"
|
||||||
state: absent
|
state: absent
|
||||||
with_items: "{{ ldap_entries.users + ldap_entries.groups + ldap_entries.units | reverse | list }}"
|
with_items: "{{ ldap_entries.users + ldap_entries.groups + ldap_entries.units | reverse | list }}"
|
||||||
|
|
||||||
- name: Create LDAP Entries
|
- name: Create LDAP Entries
|
||||||
openshift_ldap_entry:
|
openshift_ldap_entry:
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
dn: "{{ item.dn }}"
|
dn: "{{ item.dn }}"
|
||||||
attributes: "{{ item.attr }}"
|
attributes: "{{ item.attr }}"
|
||||||
objectClass: "{{ item.class }}"
|
objectClass: "{{ item.class }}"
|
||||||
with_items: "{{ ldap_entries.units + ldap_entries.groups + ldap_entries.users }}"
|
with_items: "{{ ldap_entries.units + ldap_entries.groups + ldap_entries.users }}"
|
||||||
|
|
||||||
- name: Load test configurations
|
- name: Load test configurations
|
||||||
set_fact:
|
set_fact:
|
||||||
sync_config: "{{ lookup('template', 'augmented-ad/sync-config.j2') | from_yaml }}"
|
sync_config: "{{ lookup('template', 'augmented-ad/sync-config.j2') | from_yaml }}"
|
||||||
|
|
||||||
- name: Synchronize Groups
|
- name: Synchronize Groups
|
||||||
community.okd.openshift_adm_groups_sync:
|
community.okd.openshift_adm_groups_sync:
|
||||||
config: "{{ sync_config }}"
|
config: "{{ sync_config }}"
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Validate that 'banking' and 'insurance' groups were created
|
- name: Validate that 'banking' and 'insurance' groups were created
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- banking_group
|
- banking_group | length > 0
|
||||||
- insurance_group
|
- insurance_group | length > 0
|
||||||
- '"james-allan@ansible.org" in {{ banking_group.users }}'
|
- '"james-allan@ansible.org" in banking_group.users'
|
||||||
- '"gordon-kane@ansible.org" in {{ banking_group.users }}'
|
- '"gordon-kane@ansible.org" in banking_group.users'
|
||||||
- '"alice-courtney@ansible.org" in {{ insurance_group.users }}'
|
- '"alice-courtney@ansible.org" in insurance_group.users'
|
||||||
- banking_group.users | length == 2
|
- banking_group.users | length == 2
|
||||||
- insurance_group.users | length == 1
|
- insurance_group.users | length == 1
|
||||||
vars:
|
vars:
|
||||||
banking_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'banking') | first }}"
|
banking_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'banking') | first }}"
|
||||||
insurance_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'insurance') | first }}"
|
insurance_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'insurance') | first }}"
|
||||||
|
|
||||||
|
- name: Synchronize Groups (Remove check_mode)
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ sync_config }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Synchronize Groups (Remove check_mode)
|
- name: Validate Group going to be created
|
||||||
community.okd.openshift_adm_groups_sync:
|
assert:
|
||||||
config: "{{ sync_config }}"
|
that:
|
||||||
register: result
|
- result is changed
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
- name: Define facts for group to create
|
||||||
assert:
|
set_fact:
|
||||||
that:
|
ldap_groups:
|
||||||
- result is changed
|
- name: banking
|
||||||
|
users:
|
||||||
|
- "james-allan@ansible.org"
|
||||||
|
- "gordon-kane@ansible.org"
|
||||||
|
- name: insurance
|
||||||
|
users:
|
||||||
|
- "alice-courtney@ansible.org"
|
||||||
|
|
||||||
- name: Define facts for group to create
|
- name: Read 'banking' openshift group
|
||||||
set_fact:
|
kubernetes.core.k8s_info:
|
||||||
ldap_groups:
|
kind: Group
|
||||||
- name: banking
|
version: "user.openshift.io/v1"
|
||||||
users:
|
name: banking
|
||||||
- "james-allan@ansible.org"
|
register: result
|
||||||
- "gordon-kane@ansible.org"
|
|
||||||
- name: insurance
|
|
||||||
users:
|
|
||||||
- "alice-courtney@ansible.org"
|
|
||||||
|
|
||||||
|
- name: Validate group info
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
- '"james-allan@ansible.org" in result.resources.0.users'
|
||||||
|
- '"gordon-kane@ansible.org" in result.resources.0.users'
|
||||||
|
|
||||||
- name: Read 'banking' openshift group
|
- name: Read 'insurance' openshift group
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
kind: Group
|
kind: Group
|
||||||
version: "user.openshift.io/v1"
|
version: "user.openshift.io/v1"
|
||||||
name: banking
|
name: insurance
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Validate group info
|
- name: Validate group info
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result.resources | length == 1
|
- result.resources | length == 1
|
||||||
- '"james-allan@ansible.org" in {{ result.resources.0.users }}'
|
- 'result.resources.0.users == ["alice-courtney@ansible.org"]'
|
||||||
- '"gordon-kane@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
|
|
||||||
- name: Read 'insurance' openshift group
|
- name: Delete employee from 'insurance' group
|
||||||
kubernetes.core.k8s_info:
|
openshift_ldap_entry:
|
||||||
kind: Group
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
version: "user.openshift.io/v1"
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
name: insurance
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
register: result
|
dn: "cn=Alice,ou=employee,ou=augmentedAD,{{ ldap_root }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Validate group info
|
- name: Prune groups
|
||||||
assert:
|
community.okd.openshift_adm_groups_sync:
|
||||||
that:
|
config: "{{ sync_config }}"
|
||||||
- result.resources | length == 1
|
state: absent
|
||||||
- 'result.resources.0.users == ["alice-courtney@ansible.org"]'
|
register: result
|
||||||
|
|
||||||
- name: Delete employee from 'insurance' group
|
- name: Validate result is changed (only insurance group be deleted)
|
||||||
openshift_ldap_entry:
|
assert:
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
that:
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
- result is changed
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
- result.groups | length == 1
|
||||||
dn: "cn=Alice,ou=employee,ou=augmentedAD,{{ ldap_root }}"
|
|
||||||
state: absent
|
|
||||||
|
|
||||||
- name: Prune groups
|
- name: Get 'insurance' openshift group info
|
||||||
community.okd.openshift_adm_groups_sync:
|
kubernetes.core.k8s_info:
|
||||||
config: "{{ sync_config }}"
|
kind: Group
|
||||||
state: absent
|
version: "user.openshift.io/v1"
|
||||||
register: result
|
name: insurance
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: Validate result is changed (only insurance group be deleted)
|
- name: assert group was deleted
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result.resources | length == 0
|
||||||
- result.groups | length == 1
|
|
||||||
|
|
||||||
- name: Get 'insurance' openshift group info
|
- name: Get 'banking' openshift group info
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
kind: Group
|
kind: Group
|
||||||
version: "user.openshift.io/v1"
|
version: "user.openshift.io/v1"
|
||||||
name: insurance
|
name: banking
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: assert group was deleted
|
- name: assert group was not deleted
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result.resources | length == 0
|
- result.resources | length == 1
|
||||||
|
|
||||||
- name: Get 'banking' openshift group info
|
- name: Prune groups once again (idempotency)
|
||||||
kubernetes.core.k8s_info:
|
community.okd.openshift_adm_groups_sync:
|
||||||
kind: Group
|
config: "{{ sync_config }}"
|
||||||
version: "user.openshift.io/v1"
|
state: absent
|
||||||
name: banking
|
register: result
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: assert group was not deleted
|
- name: Assert no change was made
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result.resources | length == 1
|
- result is not changed
|
||||||
|
|
||||||
- name: Prune groups once again (idempotency)
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ sync_config }}"
|
|
||||||
state: absent
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Assert no change was made
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is not changed
|
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete openshift groups if existing
|
- name: Delete openshift groups if existing
|
||||||
@@ -171,4 +170,4 @@
|
|||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
with_items:
|
with_items:
|
||||||
- banking
|
- banking
|
||||||
- insurance
|
- insurance
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Get cluster information
|
- name: Get cluster information
|
||||||
kubernetes.core.k8s_cluster_info:
|
kubernetes.core.k8s_cluster_info:
|
||||||
register: info
|
register: info
|
||||||
|
|
||||||
@@ -16,30 +16,30 @@
|
|||||||
app: ldap
|
app: ldap
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: ldap
|
- name: ldap
|
||||||
image: bitnami/openldap
|
# bitnami is no longer supporting this image. we should probably find a replacement
|
||||||
env:
|
image: docker.io/bitnamilegacy/openldap:latest
|
||||||
- name: LDAP_ADMIN_USERNAME
|
env:
|
||||||
value: "{{ ldap_admin_user }}"
|
- name: LDAP_ADMIN_USERNAME
|
||||||
- name: LDAP_ADMIN_PASSWORD
|
value: "{{ ldap_admin_user }}"
|
||||||
value: "{{ ldap_admin_password }}"
|
- name: LDAP_ADMIN_PASSWORD
|
||||||
- name: LDAP_USERS
|
value: "{{ ldap_admin_password }}"
|
||||||
value: "ansible"
|
- name: LDAP_USERS
|
||||||
- name: LDAP_PASSWORDS
|
value: "ansible"
|
||||||
value: "ansible123"
|
- name: LDAP_PASSWORDS
|
||||||
- name: LDAP_ROOT
|
value: "ansible123"
|
||||||
value: "{{ ldap_root }}"
|
- name: LDAP_ROOT
|
||||||
ports:
|
value: "{{ ldap_root }}"
|
||||||
- containerPort: 1389
|
ports:
|
||||||
|
- containerPort: 1389
|
||||||
|
name: ldap-server
|
||||||
register: pod_info
|
register: pod_info
|
||||||
|
|
||||||
- name: Set Pod Internal IP
|
|
||||||
set_fact:
|
|
||||||
podIp: "{{ pod_info.result.status.podIP }}"
|
|
||||||
|
|
||||||
- name: Set LDAP Common facts
|
- name: Set LDAP Common facts
|
||||||
set_fact:
|
set_fact:
|
||||||
ldap_server_uri: "ldap://{{ podIp }}:1389"
|
# we can use the Pod IP directly because the integration are running inside a Pod in the
|
||||||
|
# same openshift cluster
|
||||||
|
ldap_server_uri: "ldap://{{ pod_info.result.status.podIP }}:1389"
|
||||||
ldap_bind_dn: "cn={{ ldap_admin_user }},{{ ldap_root }}"
|
ldap_bind_dn: "cn={{ ldap_admin_user }},{{ ldap_root }}"
|
||||||
ldap_bind_pw: "{{ ldap_admin_password }}"
|
ldap_bind_pw: "{{ ldap_admin_password }}"
|
||||||
|
|
||||||
@@ -53,9 +53,12 @@
|
|||||||
bind_pw: "{{ ldap_bind_pw }}"
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
dn: "ou=users,{{ ldap_root }}"
|
dn: "ou=users,{{ ldap_root }}"
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
# ignore_errors: true
|
register: test_ldap
|
||||||
# register: ping_ldap
|
retries: 10
|
||||||
|
delay: 5
|
||||||
|
until: test_ldap is not failed
|
||||||
|
|
||||||
|
- include_tasks: "tasks/python-ldap-not-installed.yml"
|
||||||
- include_tasks: "tasks/rfc2307.yml"
|
- include_tasks: "tasks/rfc2307.yml"
|
||||||
- include_tasks: "tasks/activeDirectory.yml"
|
- include_tasks: "tasks/activeDirectory.yml"
|
||||||
- include_tasks: "tasks/augmentedActiveDirectory.yml"
|
- include_tasks: "tasks/augmentedActiveDirectory.yml"
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
---
|
||||||
|
- block:
|
||||||
|
- name: Create temp directory
|
||||||
|
tempfile:
|
||||||
|
state: directory
|
||||||
|
register: test_dir
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
test_dir: "{{ test_dir.path }}"
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
venv: "{{ test_dir }}/virtualenv"
|
||||||
|
|
||||||
|
- pip:
|
||||||
|
name:
|
||||||
|
- python-ldap
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Load test configurations
|
||||||
|
set_fact:
|
||||||
|
configs: "{{ lookup('template', 'rfc2307/sync-config.j2') | from_yaml }}"
|
||||||
|
|
||||||
|
- name: Synchronize Groups without python-ldap
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ configs.simple }}"
|
||||||
|
register: result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Check that module failed gracefully
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- '"Failed to import the required Python library (python-ldap)" in result.msg'
|
||||||
|
|
||||||
|
always:
|
||||||
|
- pip:
|
||||||
|
name:
|
||||||
|
- python-ldap
|
||||||
|
- name: Remove temp directory
|
||||||
|
file:
|
||||||
|
path: "{{ test_dir }}"
|
||||||
|
state: absent
|
||||||
|
ignore_errors: true
|
||||||
@@ -1,459 +1,460 @@
|
|||||||
|
---
|
||||||
- block:
|
- block:
|
||||||
- name: Get LDAP definition
|
- name: Get LDAP definition
|
||||||
set_fact:
|
set_fact:
|
||||||
ldap_resources: "{{ lookup('template', 'rfc2307/definition.j2') | from_yaml }}"
|
ldap_resources: "{{ lookup('template', 'rfc2307/definition.j2') | from_yaml }}"
|
||||||
|
|
||||||
- name: Delete openshift groups if existing
|
- name: Delete openshift groups if existing
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
state: absent
|
state: absent
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: "{{ item }}"
|
|
||||||
with_items:
|
|
||||||
- admins
|
|
||||||
- engineers
|
|
||||||
- developers
|
|
||||||
|
|
||||||
- name: Delete existing LDAP entries
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ item.dn }}"
|
|
||||||
state: absent
|
|
||||||
with_items: "{{ ldap_resources.users + ldap_resources.groups + ldap_resources.units | reverse | list }}"
|
|
||||||
|
|
||||||
- name: Create LDAP units
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ item.dn }}"
|
|
||||||
attributes: "{{ item.attr }}"
|
|
||||||
objectClass: "{{ item.class }}"
|
|
||||||
with_items: "{{ ldap_resources.units }}"
|
|
||||||
|
|
||||||
- name: Create LDAP Groups
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ item.dn }}"
|
|
||||||
attributes: "{{ item.attr }}"
|
|
||||||
objectClass: "{{ item.class }}"
|
|
||||||
with_items: "{{ ldap_resources.groups }}"
|
|
||||||
|
|
||||||
- name: Create LDAP users
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ item.dn }}"
|
|
||||||
attributes: "{{ item.attr }}"
|
|
||||||
objectClass: "{{ item.class }}"
|
|
||||||
with_items: "{{ ldap_resources.users }}"
|
|
||||||
|
|
||||||
- name: Load test configurations
|
|
||||||
set_fact:
|
|
||||||
configs: "{{ lookup('template', 'rfc2307/sync-config.j2') | from_yaml }}"
|
|
||||||
|
|
||||||
- name: Synchronize Groups
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ configs.simple }}"
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- admins_group
|
|
||||||
- devs_group
|
|
||||||
- '"jane.smith@ansible.org" in {{ admins_group.users }}'
|
|
||||||
- '"jim.adams@ansible.org" in {{ devs_group.users }}'
|
|
||||||
- '"jordanbulls@ansible.org" in {{ devs_group.users }}'
|
|
||||||
- admins_group.users | length == 1
|
|
||||||
- devs_group.users | length == 2
|
|
||||||
vars:
|
|
||||||
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'admins') | first }}"
|
|
||||||
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'developers') | first }}"
|
|
||||||
|
|
||||||
- name: Synchronize Groups - User defined mapping
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ configs.user_defined }}"
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- admins_group
|
|
||||||
- devs_group
|
|
||||||
- '"jane.smith@ansible.org" in {{ admins_group.users }}'
|
|
||||||
- '"jim.adams@ansible.org" in {{ devs_group.users }}'
|
|
||||||
- '"jordanbulls@ansible.org" in {{ devs_group.users }}'
|
|
||||||
- admins_group.users | length == 1
|
|
||||||
- devs_group.users | length == 2
|
|
||||||
vars:
|
|
||||||
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-admins') | first }}"
|
|
||||||
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-devs') | first }}"
|
|
||||||
|
|
||||||
- name: Synchronize Groups - Using dn for every query
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ configs.dn_everywhere }}"
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- admins_group
|
|
||||||
- devs_group
|
|
||||||
- '"cn=Jane,ou=people,ou=rfc2307,{{ ldap_root }}" in {{ admins_group.users }}'
|
|
||||||
- '"cn=Jim,ou=people,ou=rfc2307,{{ ldap_root }}" in {{ devs_group.users }}'
|
|
||||||
- '"cn=Jordan,ou=people,ou=rfc2307,{{ ldap_root }}" in {{ devs_group.users }}'
|
|
||||||
- admins_group.users | length == 1
|
|
||||||
- devs_group.users | length == 2
|
|
||||||
vars:
|
|
||||||
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'cn=admins,ou=groups,ou=rfc2307,' + ldap_root ) | first }}"
|
|
||||||
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'cn=developers,ou=groups,ou=rfc2307,' + ldap_root ) | first }}"
|
|
||||||
|
|
||||||
- name: Synchronize Groups - Partially user defined mapping
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ configs.partially_user_defined }}"
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- admins_group
|
|
||||||
- devs_group
|
|
||||||
- '"jane.smith@ansible.org" in {{ admins_group.users }}'
|
|
||||||
- '"jim.adams@ansible.org" in {{ devs_group.users }}'
|
|
||||||
- '"jordanbulls@ansible.org" in {{ devs_group.users }}'
|
|
||||||
- admins_group.users | length == 1
|
|
||||||
- devs_group.users | length == 2
|
|
||||||
vars:
|
|
||||||
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-admins') | first }}"
|
|
||||||
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'developers') | first }}"
|
|
||||||
|
|
||||||
- name: Delete Group 'engineers' if created before
|
|
||||||
community.okd.k8s:
|
|
||||||
state: absent
|
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: 'engineers'
|
|
||||||
wait: yes
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|
||||||
- name: Synchronize Groups - Partially user defined mapping
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ configs.out_scope }}"
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|
||||||
- name: Assert group sync failed due to non-existent member
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is failed
|
|
||||||
- result.msg.startswith("Entry not found for base='cn=Matthew,ou=people,ou=outrfc2307,{{ ldap_root }}'")
|
|
||||||
|
|
||||||
- name: Define sync configuration with tolerateMemberNotFoundErrors
|
|
||||||
set_fact:
|
|
||||||
config_out_of_scope_tolerate_not_found: "{{ configs.out_scope | combine({'rfc2307': merge_rfc2307 })}}"
|
|
||||||
vars:
|
|
||||||
merge_rfc2307: "{{ configs.out_scope.rfc2307 | combine({'tolerateMemberNotFoundErrors': 'true'}) }}"
|
|
||||||
|
|
||||||
- name: Synchronize Groups - Partially user defined mapping (tolerateMemberNotFoundErrors=true)
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ config_out_of_scope_tolerate_not_found }}"
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Assert group sync did not fail (tolerateMemberNotFoundErrors=true)
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- result.groups | length == 1
|
|
||||||
- result.groups.0.metadata.name == 'engineers'
|
|
||||||
- result.groups.0.users == ['Abraham']
|
|
||||||
|
|
||||||
- name: Create Group 'engineers'
|
|
||||||
community.okd.k8s:
|
|
||||||
state: present
|
|
||||||
wait: yes
|
|
||||||
definition:
|
|
||||||
kind: Group
|
kind: Group
|
||||||
apiVersion: "user.openshift.io/v1"
|
version: "user.openshift.io/v1"
|
||||||
metadata:
|
name: "{{ item }}"
|
||||||
name: engineers
|
with_items:
|
||||||
users: []
|
- admins
|
||||||
|
- engineers
|
||||||
- name: Try to sync LDAP group with Openshift existing group not created using sync should failed
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ config_out_of_scope_tolerate_not_found }}"
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|
||||||
- name: Validate group sync failed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is failed
|
|
||||||
- '"openshift.io/ldap.host label did not match sync host" in result.msg'
|
|
||||||
|
|
||||||
- name: Define allow_groups and deny_groups groups
|
|
||||||
set_fact:
|
|
||||||
allow_groups:
|
|
||||||
- "cn=developers,ou=groups,ou=rfc2307,{{ ldap_root }}"
|
|
||||||
deny_groups:
|
|
||||||
- "cn=admins,ou=groups,ou=rfc2307,{{ ldap_root }}"
|
|
||||||
|
|
||||||
- name: Synchronize Groups using allow_groups
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ configs.simple }}"
|
|
||||||
allow_groups: "{{ allow_groups }}"
|
|
||||||
register: result
|
|
||||||
check_mode: yes
|
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- result.groups | length == 1
|
|
||||||
- result.groups.0.metadata.name == "developers"
|
|
||||||
|
|
||||||
- name: Synchronize Groups using deny_groups
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ configs.simple }}"
|
|
||||||
deny_groups: "{{ deny_groups }}"
|
|
||||||
register: result
|
|
||||||
check_mode: yes
|
|
||||||
|
|
||||||
- name: Validate Group going to be created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- result.groups | length == 1
|
|
||||||
- result.groups.0.metadata.name == "developers"
|
|
||||||
|
|
||||||
- name: Synchronize groups, remove check_mode
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ configs.simple }}"
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate result is changed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
|
|
||||||
- name: Read Groups
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: admins
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate group was created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result.resources | length == 1
|
|
||||||
- '"jane.smith@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
|
|
||||||
- name: Read Groups
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: developers
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate group was created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result.resources | length == 1
|
|
||||||
- '"jim.adams@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
- '"jordanbulls@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
|
|
||||||
- name: Set users to delete (no admins users anymore and only 1 developer kept)
|
|
||||||
set_fact:
|
|
||||||
users_to_delete:
|
|
||||||
- "cn=Jane,ou=people,ou=rfc2307,{{ ldap_root }}"
|
|
||||||
- "cn=Jim,ou=people,ou=rfc2307,{{ ldap_root }}"
|
|
||||||
|
|
||||||
- name: Delete users from LDAP servers
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ item }}"
|
|
||||||
state: absent
|
|
||||||
with_items: "{{ users_to_delete }}"
|
|
||||||
|
|
||||||
- name: Define sync configuration with tolerateMemberNotFoundErrors
|
|
||||||
set_fact:
|
|
||||||
config_simple_tolerate_not_found: "{{ configs.simple | combine({'rfc2307': merge_rfc2307 })}}"
|
|
||||||
vars:
|
|
||||||
merge_rfc2307: "{{ configs.simple.rfc2307 | combine({'tolerateMemberNotFoundErrors': 'true'}) }}"
|
|
||||||
|
|
||||||
- name: Synchronize groups once again after users deletion
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ config_simple_tolerate_not_found }}"
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate result is changed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
|
|
||||||
- name: Read Groups
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: admins
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate admins group does not contains users anymore
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result.resources | length == 1
|
|
||||||
- result.resources.0.users == []
|
|
||||||
|
|
||||||
- name: Read Groups
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: developers
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Validate group was created
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result.resources | length == 1
|
|
||||||
- '"jordanbulls@ansible.org" in {{ result.resources.0.users }}'
|
|
||||||
|
|
||||||
- name: Set group to delete
|
|
||||||
set_fact:
|
|
||||||
groups_to_delete:
|
|
||||||
- "cn=developers,ou=groups,ou=rfc2307,{{ ldap_root }}"
|
|
||||||
|
|
||||||
- name: Delete Group from LDAP servers
|
|
||||||
openshift_ldap_entry:
|
|
||||||
bind_dn: "{{ ldap_bind_dn }}"
|
|
||||||
bind_pw: "{{ ldap_bind_pw }}"
|
|
||||||
server_uri: "{{ ldap_server_uri }}"
|
|
||||||
dn: "{{ item }}"
|
|
||||||
state: absent
|
|
||||||
with_items: "{{ groups_to_delete }}"
|
|
||||||
|
|
||||||
- name: Prune groups
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ config_simple_tolerate_not_found }}"
|
|
||||||
state: absent
|
|
||||||
register: result
|
|
||||||
check_mode: yes
|
|
||||||
|
|
||||||
- name: Validate that only developers group is candidate for Prune
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is changed
|
|
||||||
- result.groups | length == 1
|
|
||||||
- result.groups.0.metadata.name == "developers"
|
|
||||||
|
|
||||||
- name: Read Group (validate that check_mode did not performed update in the cluster)
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: Group
|
|
||||||
version: "user.openshift.io/v1"
|
|
||||||
name: developers
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: Assert group was found
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result.resources | length == 1
|
|
||||||
|
|
||||||
- name: Prune using allow_groups
|
|
||||||
community.okd.openshift_adm_groups_sync:
|
|
||||||
config: "{{ config_simple_tolerate_not_found }}"
|
|
||||||
allow_groups:
|
|
||||||
- developers
|
- developers
|
||||||
state: absent
|
|
||||||
register: result
|
|
||||||
check_mode: yes
|
|
||||||
|
|
||||||
- name: assert developers group was candidate for prune
|
- name: Delete existing LDAP entries
|
||||||
assert:
|
openshift_ldap_entry:
|
||||||
that:
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
- result is changed
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
- result.groups | length == 1
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
- result.groups.0.metadata.name == "developers"
|
dn: "{{ item.dn }}"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ ldap_resources.users + ldap_resources.groups + ldap_resources.units | reverse | list }}"
|
||||||
|
|
||||||
- name: Prune using deny_groups
|
- name: Create LDAP units
|
||||||
community.okd.openshift_adm_groups_sync:
|
openshift_ldap_entry:
|
||||||
config: "{{ config_simple_tolerate_not_found }}"
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
deny_groups:
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
- developers
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
state: absent
|
dn: "{{ item.dn }}"
|
||||||
register: result
|
attributes: "{{ item.attr }}"
|
||||||
check_mode: yes
|
objectClass: "{{ item.class }}"
|
||||||
|
with_items: "{{ ldap_resources.units }}"
|
||||||
|
|
||||||
- name: assert nothing found candidate for prune
|
- name: Create LDAP Groups
|
||||||
assert:
|
openshift_ldap_entry:
|
||||||
that:
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
- result is not changed
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
- result.groups | length == 0
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
|
dn: "{{ item.dn }}"
|
||||||
|
attributes: "{{ item.attr }}"
|
||||||
|
objectClass: "{{ item.class }}"
|
||||||
|
with_items: "{{ ldap_resources.groups }}"
|
||||||
|
|
||||||
- name: Prune groups
|
- name: Create LDAP users
|
||||||
community.okd.openshift_adm_groups_sync:
|
openshift_ldap_entry:
|
||||||
config: "{{ config_simple_tolerate_not_found }}"
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
state: absent
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
register: result
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
|
dn: "{{ item.dn }}"
|
||||||
|
attributes: "{{ item.attr }}"
|
||||||
|
objectClass: "{{ item.class }}"
|
||||||
|
with_items: "{{ ldap_resources.users }}"
|
||||||
|
|
||||||
- name: Validate result is changed
|
- name: Load test configurations
|
||||||
assert:
|
set_fact:
|
||||||
that:
|
configs: "{{ lookup('template', 'rfc2307/sync-config.j2') | from_yaml }}"
|
||||||
- result is changed
|
|
||||||
- result.groups | length == 1
|
|
||||||
|
|
||||||
- name: Get developers group info
|
- name: Synchronize Groups
|
||||||
kubernetes.core.k8s_info:
|
community.okd.openshift_adm_groups_sync:
|
||||||
kind: Group
|
config: "{{ configs.simple }}"
|
||||||
version: "user.openshift.io/v1"
|
check_mode: yes
|
||||||
name: developers
|
register: result
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: assert group was deleted
|
- name: Validate Group going to be created
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result.resources | length == 0
|
- result is changed
|
||||||
|
- admins_group | length > 0
|
||||||
|
- devs_group | length > 0
|
||||||
|
- '"jane.smith@ansible.org" in admins_group.users'
|
||||||
|
- '"jim.adams@ansible.org" in devs_group.users'
|
||||||
|
- '"jordanbulls@ansible.org" in devs_group.users'
|
||||||
|
- admins_group.users | length == 1
|
||||||
|
- devs_group.users | length == 2
|
||||||
|
vars:
|
||||||
|
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'admins') | first }}"
|
||||||
|
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'developers') | first }}"
|
||||||
|
|
||||||
- name: Get admins group info
|
- name: Synchronize Groups - User defined mapping
|
||||||
kubernetes.core.k8s_info:
|
community.okd.openshift_adm_groups_sync:
|
||||||
kind: Group
|
config: "{{ configs.user_defined }}"
|
||||||
version: "user.openshift.io/v1"
|
check_mode: yes
|
||||||
name: admins
|
register: result
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: assert group was not deleted
|
- name: Validate Group going to be created
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result.resources | length == 1
|
- result is changed
|
||||||
|
- admins_group | length > 0
|
||||||
|
- devs_group | length > 0
|
||||||
|
- '"jane.smith@ansible.org" in admins_group.users'
|
||||||
|
- '"jim.adams@ansible.org" in devs_group.users'
|
||||||
|
- '"jordanbulls@ansible.org" in devs_group.users'
|
||||||
|
- admins_group.users | length == 1
|
||||||
|
- devs_group.users | length == 2
|
||||||
|
vars:
|
||||||
|
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-admins') | first }}"
|
||||||
|
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-devs') | first }}"
|
||||||
|
|
||||||
- name: Prune groups once again (idempotency)
|
- name: Synchronize Groups - Using dn for every query
|
||||||
community.okd.openshift_adm_groups_sync:
|
community.okd.openshift_adm_groups_sync:
|
||||||
config: "{{ config_simple_tolerate_not_found }}"
|
config: "{{ configs.dn_everywhere }}"
|
||||||
state: absent
|
check_mode: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Assert nothing changed
|
- name: Validate Group going to be created
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is changed
|
||||||
- result.groups | length == 0
|
- admins_group | length > 0
|
||||||
|
- devs_group | length > 0
|
||||||
|
- '"cn=Jane,ou=people,ou=rfc2307,"+ldap_root in admins_group.users'
|
||||||
|
- '"cn=Jim,ou=people,ou=rfc2307,"+ldap_root in devs_group.users'
|
||||||
|
- '"cn=Jordan,ou=people,ou=rfc2307,"+ldap_root in devs_group.users'
|
||||||
|
- admins_group.users | length == 1
|
||||||
|
- devs_group.users | length == 2
|
||||||
|
vars:
|
||||||
|
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'cn=admins,ou=groups,ou=rfc2307,' + ldap_root ) | first }}"
|
||||||
|
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'cn=developers,ou=groups,ou=rfc2307,' + ldap_root ) | first }}"
|
||||||
|
|
||||||
|
- name: Synchronize Groups - Partially user defined mapping
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ configs.partially_user_defined }}"
|
||||||
|
check_mode: yes
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate Group going to be created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- admins_group | length > 0
|
||||||
|
- devs_group | length > 0
|
||||||
|
- '"jane.smith@ansible.org" in admins_group.users'
|
||||||
|
- '"jim.adams@ansible.org" in devs_group.users'
|
||||||
|
- '"jordanbulls@ansible.org" in devs_group.users'
|
||||||
|
- admins_group.users | length == 1
|
||||||
|
- devs_group.users | length == 2
|
||||||
|
vars:
|
||||||
|
admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-admins') | first }}"
|
||||||
|
devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'developers') | first }}"
|
||||||
|
|
||||||
|
- name: Delete Group 'engineers' if created before
|
||||||
|
community.okd.k8s:
|
||||||
|
state: absent
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: 'engineers'
|
||||||
|
wait: yes
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Synchronize Groups - Partially user defined mapping
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ configs.out_scope }}"
|
||||||
|
check_mode: yes
|
||||||
|
register: result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Assert group sync failed due to non-existent member
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is failed
|
||||||
|
- result.msg.startswith("Entry not found for base='cn=Matthew,ou=people,ou=outrfc2307,"+ldap_root+"'")
|
||||||
|
|
||||||
|
- name: Define sync configuration with tolerateMemberNotFoundErrors
|
||||||
|
set_fact:
|
||||||
|
config_out_of_scope_tolerate_not_found: "{{ configs.out_scope | combine({'rfc2307': merge_rfc2307 })}}"
|
||||||
|
vars:
|
||||||
|
merge_rfc2307: "{{ configs.out_scope.rfc2307 | combine({'tolerateMemberNotFoundErrors': 'true'}) }}"
|
||||||
|
|
||||||
|
- name: Synchronize Groups - Partially user defined mapping (tolerateMemberNotFoundErrors=true)
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ config_out_of_scope_tolerate_not_found }}"
|
||||||
|
check_mode: yes
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Assert group sync did not fail (tolerateMemberNotFoundErrors=true)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.groups | length == 1
|
||||||
|
- result.groups.0.metadata.name == 'engineers'
|
||||||
|
- result.groups.0.users == ['Abraham']
|
||||||
|
|
||||||
|
- name: Create Group 'engineers'
|
||||||
|
community.okd.k8s:
|
||||||
|
state: present
|
||||||
|
wait: yes
|
||||||
|
definition:
|
||||||
|
kind: Group
|
||||||
|
apiVersion: "user.openshift.io/v1"
|
||||||
|
metadata:
|
||||||
|
name: engineers
|
||||||
|
users: []
|
||||||
|
|
||||||
|
- name: Try to sync LDAP group with Openshift existing group not created using sync should failed
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ config_out_of_scope_tolerate_not_found }}"
|
||||||
|
check_mode: yes
|
||||||
|
register: result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Validate group sync failed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is failed
|
||||||
|
- '"openshift.io/ldap.host label did not match sync host" in result.msg'
|
||||||
|
|
||||||
|
- name: Define allow_groups and deny_groups groups
|
||||||
|
set_fact:
|
||||||
|
allow_groups:
|
||||||
|
- "cn=developers,ou=groups,ou=rfc2307,{{ ldap_root }}"
|
||||||
|
deny_groups:
|
||||||
|
- "cn=admins,ou=groups,ou=rfc2307,{{ ldap_root }}"
|
||||||
|
|
||||||
|
- name: Synchronize Groups using allow_groups
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ configs.simple }}"
|
||||||
|
allow_groups: "{{ allow_groups }}"
|
||||||
|
register: result
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: Validate Group going to be created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.groups | length == 1
|
||||||
|
- result.groups.0.metadata.name == "developers"
|
||||||
|
|
||||||
|
- name: Synchronize Groups using deny_groups
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ configs.simple }}"
|
||||||
|
deny_groups: "{{ deny_groups }}"
|
||||||
|
register: result
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: Validate Group going to be created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.groups | length == 1
|
||||||
|
- result.groups.0.metadata.name == "developers"
|
||||||
|
|
||||||
|
- name: Synchronize groups, remove check_mode
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ configs.simple }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate result is changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
|
||||||
|
- name: Read Groups
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: admins
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate group was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
- '"jane.smith@ansible.org" in result.resources.0.users'
|
||||||
|
|
||||||
|
- name: Read Groups
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: developers
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate group was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
- '"jim.adams@ansible.org" in result.resources.0.users'
|
||||||
|
- '"jordanbulls@ansible.org" in result.resources.0.users'
|
||||||
|
|
||||||
|
- name: Set users to delete (no admins users anymore and only 1 developer kept)
|
||||||
|
set_fact:
|
||||||
|
users_to_delete:
|
||||||
|
- "cn=Jane,ou=people,ou=rfc2307,{{ ldap_root }}"
|
||||||
|
- "cn=Jim,ou=people,ou=rfc2307,{{ ldap_root }}"
|
||||||
|
|
||||||
|
- name: Delete users from LDAP servers
|
||||||
|
openshift_ldap_entry:
|
||||||
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
|
dn: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ users_to_delete }}"
|
||||||
|
|
||||||
|
- name: Define sync configuration with tolerateMemberNotFoundErrors
|
||||||
|
set_fact:
|
||||||
|
config_simple_tolerate_not_found: "{{ configs.simple | combine({'rfc2307': merge_rfc2307 })}}"
|
||||||
|
vars:
|
||||||
|
merge_rfc2307: "{{ configs.simple.rfc2307 | combine({'tolerateMemberNotFoundErrors': 'true'}) }}"
|
||||||
|
|
||||||
|
- name: Synchronize groups once again after users deletion
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ config_simple_tolerate_not_found }}"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate result is changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
|
||||||
|
- name: Read Groups
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: admins
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate admins group does not contains users anymore
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
- result.resources.0.users == []
|
||||||
|
|
||||||
|
- name: Read Groups
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: developers
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate group was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
- '"jordanbulls@ansible.org" in result.resources.0.users'
|
||||||
|
|
||||||
|
- name: Set group to delete
|
||||||
|
set_fact:
|
||||||
|
groups_to_delete:
|
||||||
|
- "cn=developers,ou=groups,ou=rfc2307,{{ ldap_root }}"
|
||||||
|
|
||||||
|
- name: Delete Group from LDAP servers
|
||||||
|
openshift_ldap_entry:
|
||||||
|
bind_dn: "{{ ldap_bind_dn }}"
|
||||||
|
bind_pw: "{{ ldap_bind_pw }}"
|
||||||
|
server_uri: "{{ ldap_server_uri }}"
|
||||||
|
dn: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
with_items: "{{ groups_to_delete }}"
|
||||||
|
|
||||||
|
- name: Prune groups
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ config_simple_tolerate_not_found }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: Validate that only developers group is candidate for Prune
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.groups | length == 1
|
||||||
|
- result.groups.0.metadata.name == "developers"
|
||||||
|
|
||||||
|
- name: Read Group (validate that check_mode did not performed update in the cluster)
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: developers
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Assert group was found
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
|
||||||
|
- name: Prune using allow_groups
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ config_simple_tolerate_not_found }}"
|
||||||
|
allow_groups:
|
||||||
|
- developers
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: assert developers group was candidate for prune
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.groups | length == 1
|
||||||
|
- result.groups.0.metadata.name == "developers"
|
||||||
|
|
||||||
|
- name: Prune using deny_groups
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ config_simple_tolerate_not_found }}"
|
||||||
|
deny_groups:
|
||||||
|
- developers
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: assert nothing found candidate for prune
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is not changed
|
||||||
|
- result.groups | length == 0
|
||||||
|
|
||||||
|
- name: Prune groups
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ config_simple_tolerate_not_found }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Validate result is changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.groups | length == 1
|
||||||
|
|
||||||
|
- name: Get developers group info
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: developers
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert group was deleted
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 0
|
||||||
|
|
||||||
|
- name: Get admins group info
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Group
|
||||||
|
version: "user.openshift.io/v1"
|
||||||
|
name: admins
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert group was not deleted
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.resources | length == 1
|
||||||
|
|
||||||
|
- name: Prune groups once again (idempotency)
|
||||||
|
community.okd.openshift_adm_groups_sync:
|
||||||
|
config: "{{ config_simple_tolerate_not_found }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Assert nothing changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is not changed
|
||||||
|
- result.groups | length == 0
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete openshift groups if existing
|
- name: Delete openshift groups if existing
|
||||||
@@ -465,4 +466,4 @@
|
|||||||
with_items:
|
with_items:
|
||||||
- admins
|
- admins
|
||||||
- engineers
|
- engineers
|
||||||
- developers
|
- developers
|
||||||
|
|||||||
@@ -1,300 +1,288 @@
|
|||||||
|
---
|
||||||
- block:
|
- block:
|
||||||
- set_fact:
|
- set_fact:
|
||||||
test_sa: "clusterrole-sa"
|
test_sa: "clusterrole-sa"
|
||||||
test_ns: "clusterrole-ns"
|
test_ns: "clusterrole-ns"
|
||||||
|
test_tn: "clusterrole-tn"
|
||||||
|
|
||||||
- name: Ensure namespace
|
- name: Ensure namespace
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: "{{ test_ns }}"
|
name: "{{ test_ns }}"
|
||||||
|
|
||||||
- name: Get cluster information
|
- name: Get cluster information
|
||||||
kubernetes.core.k8s_cluster_info:
|
kubernetes.core.k8s_cluster_info:
|
||||||
register: cluster_info
|
register: cluster_info
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
cluster_host: "{{ cluster_info['connection']['host'] }}"
|
cluster_host: "{{ cluster_info['connection']['host'] }}"
|
||||||
|
|
||||||
- name: Create Service account
|
- name: Create Service account
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
definition:
|
definition:
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ServiceAccount
|
kind: ServiceAccount
|
||||||
metadata:
|
metadata:
|
||||||
name: "{{ test_sa }}"
|
name: "{{ test_sa }}"
|
||||||
namespace: "{{ test_ns }}"
|
namespace: "{{ test_ns }}"
|
||||||
|
|
||||||
- name: Read Service Account
|
- name: Create SA token
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s:
|
||||||
kind: ServiceAccount
|
definition:
|
||||||
namespace: "{{ test_ns }}"
|
apiVersion: v1
|
||||||
name: "{{ test_sa }}"
|
kind: Secret
|
||||||
register: result
|
metadata:
|
||||||
|
name: "{{ test_tn }}"
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/service-account.name: "{{ test_sa }}"
|
||||||
|
type: kubernetes.io/service-account-token
|
||||||
|
|
||||||
- set_fact:
|
- name: Get secret details
|
||||||
secret_token: "{{ result.resources[0]['secrets'][0]['name'] }}"
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Secret
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
name: "{{ test_tn }}"
|
||||||
|
register: _secret
|
||||||
|
|
||||||
- name: Get secret details
|
- set_fact:
|
||||||
kubernetes.core.k8s_info:
|
api_token: "{{ _secret.resources[0]['data']['token'] | b64decode }}"
|
||||||
kind: Secret
|
|
||||||
namespace: '{{ test_ns }}'
|
|
||||||
name: '{{ secret_token }}'
|
|
||||||
register: _secret
|
|
||||||
retries: 10
|
|
||||||
delay: 10
|
|
||||||
until:
|
|
||||||
- ("'openshift.io/token-secret.value' in _secret.resources[0]['metadata']['annotations']") or ("'token' in _secret.resources[0]['data']")
|
|
||||||
|
|
||||||
- set_fact:
|
- name: list Node should failed (forbidden user)
|
||||||
api_token: "{{ _secret.resources[0]['metadata']['annotations']['openshift.io/token-secret.value'] }}"
|
kubernetes.core.k8s_info:
|
||||||
when: "'openshift.io/token-secret.value' in _secret.resources[0]['metadata']['annotations']"
|
api_key: "{{ api_token }}"
|
||||||
|
host: "{{ cluster_host }}"
|
||||||
- set_fact:
|
validate_certs: no
|
||||||
api_token: "{{ _secret.resources[0]['data']['token'] | b64decode }}"
|
kind: Node
|
||||||
when: "'token' in _secret.resources[0]['data']"
|
register: error
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: list Node should failed (forbidden user)
|
- assert:
|
||||||
kubernetes.core.k8s_info:
|
that:
|
||||||
api_key: "{{ api_token }}"
|
- '"nodes is forbidden: User" in error.msg'
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
kind: Node
|
|
||||||
register: error
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
- name: list Pod for all namespace should failed
|
||||||
that:
|
kubernetes.core.k8s_info:
|
||||||
- error is failed
|
api_key: "{{ api_token }}"
|
||||||
# - '"nodes is forbidden: User" in error.msg'
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
kind: Pod
|
||||||
|
register: error
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: list Pod for all namespace should failed
|
- assert:
|
||||||
kubernetes.core.k8s_info:
|
that:
|
||||||
api_key: "{{ api_token }}"
|
- '"pods is forbidden: User" in error.msg'
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
kind: Pod
|
|
||||||
register: error
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
- name: list Pod for test namespace should failed
|
||||||
that:
|
kubernetes.core.k8s_info:
|
||||||
- error is failed
|
api_key: "{{ api_token }}"
|
||||||
# - '"pods is forbidden: User" in error.msg'
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
kind: Pod
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
register: error
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: list Pod for test namespace should failed
|
- assert:
|
||||||
kubernetes.core.k8s_info:
|
that:
|
||||||
api_key: "{{ api_token }}"
|
- '"pods is forbidden: User" in error.msg'
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
kind: Pod
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
register: error
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
- set_fact:
|
||||||
that:
|
test_labels:
|
||||||
- error is failed
|
phase: dev
|
||||||
# - '"pods is forbidden: User" in error.msg'
|
cluster_roles:
|
||||||
|
- name: pod-manager
|
||||||
|
resources:
|
||||||
|
- pods
|
||||||
|
verbs:
|
||||||
|
- list
|
||||||
|
api_version_binding: "authorization.openshift.io/v1"
|
||||||
|
- name: node-manager
|
||||||
|
resources:
|
||||||
|
- nodes
|
||||||
|
verbs:
|
||||||
|
- list
|
||||||
|
api_version_binding: "rbac.authorization.k8s.io/v1"
|
||||||
|
|
||||||
- set_fact:
|
- name: Create cluster roles
|
||||||
test_labels:
|
kubernetes.core.k8s:
|
||||||
phase: dev
|
definition:
|
||||||
cluster_roles:
|
|
||||||
- name: pod-manager
|
|
||||||
resources:
|
|
||||||
- pods
|
|
||||||
verbs:
|
|
||||||
- list
|
|
||||||
api_version_binding: "authorization.openshift.io/v1"
|
|
||||||
- name: node-manager
|
|
||||||
resources:
|
|
||||||
- nodes
|
|
||||||
verbs:
|
|
||||||
- list
|
|
||||||
api_version_binding: "rbac.authorization.k8s.io/v1"
|
|
||||||
|
|
||||||
- name: Create cluster roles
|
|
||||||
kubernetes.core.k8s:
|
|
||||||
definition:
|
|
||||||
kind: ClusterRole
|
|
||||||
apiVersion: "rbac.authorization.k8s.io/v1"
|
|
||||||
metadata:
|
|
||||||
name: "{{ item.name }}"
|
|
||||||
labels: "{{ test_labels }}"
|
|
||||||
rules:
|
|
||||||
- apiGroups: [""]
|
|
||||||
resources: "{{ item.resources }}"
|
|
||||||
verbs: "{{ item.verbs }}"
|
|
||||||
with_items: '{{ cluster_roles }}'
|
|
||||||
|
|
||||||
- name: Create Role Binding (namespaced)
|
|
||||||
kubernetes.core.k8s:
|
|
||||||
definition:
|
|
||||||
kind: RoleBinding
|
|
||||||
apiVersion: "rbac.authorization.k8s.io/v1"
|
|
||||||
metadata:
|
|
||||||
name: "{{ cluster_roles[0].name }}-binding"
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
labels: "{{ test_labels }}"
|
|
||||||
subjects:
|
|
||||||
- kind: ServiceAccount
|
|
||||||
name: "{{ test_sa }}"
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
apiGroup: ""
|
|
||||||
roleRef:
|
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
name: "{{ cluster_roles[0].name }}"
|
apiVersion: "rbac.authorization.k8s.io/v1"
|
||||||
apiGroup: ""
|
metadata:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
labels: "{{ test_labels }}"
|
||||||
|
rules:
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: "{{ item.resources }}"
|
||||||
|
verbs: "{{ item.verbs }}"
|
||||||
|
with_items: '{{ cluster_roles }}'
|
||||||
|
|
||||||
- name: list Pod for all namespace should failed
|
- name: Create Role Binding (namespaced)
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s:
|
||||||
api_key: "{{ api_token }}"
|
definition:
|
||||||
host: "{{ cluster_host }}"
|
kind: RoleBinding
|
||||||
validate_certs: no
|
apiVersion: "rbac.authorization.k8s.io/v1"
|
||||||
kind: Pod
|
metadata:
|
||||||
register: error
|
name: "{{ cluster_roles[0].name }}-binding"
|
||||||
ignore_errors: true
|
namespace: "{{ test_ns }}"
|
||||||
|
labels: "{{ test_labels }}"
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: "{{ test_sa }}"
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
apiGroup: ""
|
||||||
|
roleRef:
|
||||||
|
kind: ClusterRole
|
||||||
|
name: "{{ cluster_roles[0].name }}"
|
||||||
|
apiGroup: ""
|
||||||
|
|
||||||
- assert:
|
- name: list Pod for all namespace should failed
|
||||||
that:
|
kubernetes.core.k8s_info:
|
||||||
- error is failed
|
api_key: "{{ api_token }}"
|
||||||
# - '"pods is forbidden: User" in error.msg'
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
kind: Pod
|
||||||
|
register: error
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: list Pod for test namespace should succeed
|
- assert:
|
||||||
kubernetes.core.k8s_info:
|
that:
|
||||||
api_key: "{{ api_token }}"
|
- '"pods is forbidden: User" in error.msg'
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
kind: Pod
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
no_log: true
|
|
||||||
|
|
||||||
- name: Create Cluster role Binding
|
- name: list Pod for test namespace should succeed
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s_info:
|
||||||
definition:
|
api_key: "{{ api_token }}"
|
||||||
kind: ClusterRoleBinding
|
host: "{{ cluster_host }}"
|
||||||
apiVersion: "{{ item.api_version_binding }}"
|
validate_certs: no
|
||||||
metadata:
|
kind: Pod
|
||||||
name: "{{ item.name }}-binding"
|
namespace: "{{ test_ns }}"
|
||||||
labels: "{{ test_labels }}"
|
no_log: true
|
||||||
subjects:
|
|
||||||
- kind: ServiceAccount
|
|
||||||
name: "{{ test_sa }}"
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
apiGroup: ""
|
|
||||||
roleRef:
|
|
||||||
kind: ClusterRole
|
|
||||||
name: "{{ item.name }}"
|
|
||||||
apiGroup: ""
|
|
||||||
with_items: "{{ cluster_roles }}"
|
|
||||||
|
|
||||||
- name: list Pod for all namespace should succeed
|
- name: Create Cluster role Binding
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s:
|
||||||
api_key: "{{ api_token }}"
|
definition:
|
||||||
host: "{{ cluster_host }}"
|
kind: ClusterRoleBinding
|
||||||
validate_certs: no
|
apiVersion: "{{ item.api_version_binding }}"
|
||||||
kind: Pod
|
metadata:
|
||||||
no_log: true
|
name: "{{ item.name }}-binding"
|
||||||
|
labels: "{{ test_labels }}"
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: "{{ test_sa }}"
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
apiGroup: ""
|
||||||
|
roleRef:
|
||||||
|
kind: ClusterRole
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
apiGroup: ""
|
||||||
|
with_items: "{{ cluster_roles }}"
|
||||||
|
|
||||||
- name: list Pod for test namespace should succeed
|
- name: list Pod for all namespace should succeed
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
api_key: "{{ api_token }}"
|
api_key: "{{ api_token }}"
|
||||||
host: "{{ cluster_host }}"
|
host: "{{ cluster_host }}"
|
||||||
validate_certs: no
|
validate_certs: no
|
||||||
kind: Pod
|
kind: Pod
|
||||||
namespace: "{{ test_ns }}"
|
no_log: true
|
||||||
no_log: true
|
|
||||||
|
|
||||||
- name: list Node using ServiceAccount
|
- name: list Pod for test namespace should succeed
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
api_key: "{{ api_token }}"
|
api_key: "{{ api_token }}"
|
||||||
host: "{{ cluster_host }}"
|
host: "{{ cluster_host }}"
|
||||||
validate_certs: no
|
validate_certs: no
|
||||||
kind: Node
|
kind: Pod
|
||||||
namespace: "{{ test_ns }}"
|
namespace: "{{ test_ns }}"
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
- name: Prune clusterroles (check mode)
|
- name: list Node using ServiceAccount
|
||||||
community.okd.openshift_adm_prune_auth:
|
kubernetes.core.k8s_info:
|
||||||
resource: clusterroles
|
api_key: "{{ api_token }}"
|
||||||
label_selectors:
|
host: "{{ cluster_host }}"
|
||||||
- phase=dev
|
validate_certs: no
|
||||||
register: check
|
kind: Node
|
||||||
check_mode: true
|
namespace: "{{ test_ns }}"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: validate clusterrole binding candidates for prune
|
- name: Prune clusterroles (check mode)
|
||||||
assert:
|
community.okd.openshift_adm_prune_auth:
|
||||||
that:
|
resource: clusterroles
|
||||||
- '"{{ item.name }}-binding" in check.cluster_role_binding'
|
label_selectors:
|
||||||
- '"{{ test_ns }}/{{ cluster_roles[0].name }}-binding" in check.role_binding'
|
- phase=dev
|
||||||
with_items: "{{ cluster_roles }}"
|
register: check
|
||||||
|
check_mode: true
|
||||||
|
|
||||||
- name: Prune Cluster Role for managing Pod
|
- name: validate clusterrole binding candidates for prune
|
||||||
community.okd.openshift_adm_prune_auth:
|
assert:
|
||||||
resource: clusterroles
|
that:
|
||||||
name: "{{ cluster_roles[0].name }}"
|
- 'item["name"]+"-binding" in check.cluster_role_binding'
|
||||||
|
- 'test_ns+"/"+cluster_roles[0].name+"-binding" in check.role_binding'
|
||||||
|
with_items: "{{ cluster_roles }}"
|
||||||
|
|
||||||
- name: list Pod for all namespace should failed
|
- name: Prune Cluster Role for managing Pod
|
||||||
kubernetes.core.k8s_info:
|
community.okd.openshift_adm_prune_auth:
|
||||||
api_key: "{{ api_token }}"
|
resource: clusterroles
|
||||||
host: "{{ cluster_host }}"
|
name: "{{ cluster_roles[0].name }}"
|
||||||
validate_certs: no
|
|
||||||
kind: Pod
|
|
||||||
register: error
|
|
||||||
no_log: true
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
- name: list Pod for all namespace should failed
|
||||||
that:
|
kubernetes.core.k8s_info:
|
||||||
- error is failed
|
api_key: "{{ api_token }}"
|
||||||
# - '"pods is forbidden: User" in error.msg'
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
kind: Pod
|
||||||
|
register: error
|
||||||
|
no_log: true
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: list Pod for test namespace should failed
|
- assert:
|
||||||
kubernetes.core.k8s_info:
|
that:
|
||||||
api_key: "{{ api_token }}"
|
- '"pods is forbidden: User" in error.msg'
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
kind: Pod
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
register: error
|
|
||||||
no_log: true
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
- name: list Pod for test namespace should failed
|
||||||
that:
|
kubernetes.core.k8s_info:
|
||||||
- error is failed
|
api_key: "{{ api_token }}"
|
||||||
# - '"pods is forbidden: User" in error.msg'
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
kind: Pod
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
register: error
|
||||||
|
no_log: true
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: list Node using ServiceAccount
|
- assert:
|
||||||
kubernetes.core.k8s_info:
|
that:
|
||||||
api_key: "{{ api_token }}"
|
- '"pods is forbidden: User" in error.msg'
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
kind: Node
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
no_log: true
|
|
||||||
|
|
||||||
- name: Prune clusterroles (remaining)
|
- name: list Node using ServiceAccount
|
||||||
community.okd.openshift_adm_prune_auth:
|
kubernetes.core.k8s_info:
|
||||||
resource: clusterroles
|
api_key: "{{ api_token }}"
|
||||||
label_selectors:
|
host: "{{ cluster_host }}"
|
||||||
- phase=dev
|
validate_certs: no
|
||||||
|
kind: Node
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: list Node using ServiceAccount
|
- name: Prune clusterroles (remaining)
|
||||||
kubernetes.core.k8s_info:
|
community.okd.openshift_adm_prune_auth:
|
||||||
api_key: "{{ api_token }}"
|
resource: clusterroles
|
||||||
host: "{{ cluster_host }}"
|
label_selectors:
|
||||||
validate_certs: no
|
- phase=dev
|
||||||
kind: Node
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
register: error
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
- name: list Node using ServiceAccount should fail
|
||||||
that:
|
kubernetes.core.k8s_info:
|
||||||
- error is failed
|
api_key: "{{ api_token }}"
|
||||||
# - '"nodes is forbidden: User" in error.msg'
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
kind: Node
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
register: error
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- '"nodes is forbidden: User" in error.msg'
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Ensure namespace is deleted
|
- name: Ensure namespace is deleted
|
||||||
@@ -302,7 +290,6 @@
|
|||||||
state: absent
|
state: absent
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: "{{ test_ns }}"
|
name: "{{ test_ns }}"
|
||||||
wait: yes
|
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Delete ClusterRoleBinding
|
- name: Delete ClusterRoleBinding
|
||||||
|
|||||||
@@ -1,339 +1,330 @@
|
|||||||
|
---
|
||||||
- block:
|
- block:
|
||||||
- set_fact:
|
- set_fact:
|
||||||
test_ns: "prune-roles"
|
test_ns: "prune-roles"
|
||||||
sa_name: "roles-sa"
|
sa_name: "roles-sa"
|
||||||
pod_name: "pod-prune"
|
pod_name: "pod-prune"
|
||||||
role_definition:
|
tn_name: "roles-sa-token"
|
||||||
- name: pod-list
|
role_definition:
|
||||||
labels:
|
- name: pod-list
|
||||||
action: list
|
labels:
|
||||||
verbs:
|
action: list
|
||||||
- list
|
verbs:
|
||||||
role_binding:
|
- list
|
||||||
api_version: rbac.authorization.k8s.io/v1
|
role_binding:
|
||||||
- name: pod-create
|
api_version: rbac.authorization.k8s.io/v1
|
||||||
labels:
|
- name: pod-create
|
||||||
action: create
|
labels:
|
||||||
verbs:
|
action: create
|
||||||
- create
|
verbs:
|
||||||
- get
|
- create
|
||||||
role_binding:
|
- get
|
||||||
api_version: authorization.openshift.io/v1
|
role_binding:
|
||||||
- name: pod-delete
|
api_version: authorization.openshift.io/v1
|
||||||
labels:
|
- name: pod-delete
|
||||||
action: delete
|
labels:
|
||||||
verbs:
|
action: delete
|
||||||
- delete
|
verbs:
|
||||||
role_binding:
|
- delete
|
||||||
api_version: rbac.authorization.k8s.io/v1
|
role_binding:
|
||||||
|
api_version: rbac.authorization.k8s.io/v1
|
||||||
|
|
||||||
- name: Ensure namespace
|
- name: Ensure namespace
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: '{{ test_ns }}'
|
name: '{{ test_ns }}'
|
||||||
|
|
||||||
- name: Get cluster information
|
- name: Get cluster information
|
||||||
kubernetes.core.k8s_cluster_info:
|
kubernetes.core.k8s_cluster_info:
|
||||||
register: cluster_info
|
register: cluster_info
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
cluster_host: "{{ cluster_info['connection']['host'] }}"
|
cluster_host: "{{ cluster_info['connection']['host'] }}"
|
||||||
|
|
||||||
- name: Create Service account
|
- name: Create Service account
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
definition:
|
definition:
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ServiceAccount
|
kind: ServiceAccount
|
||||||
metadata:
|
metadata:
|
||||||
name: '{{ sa_name }}'
|
name: '{{ sa_name }}'
|
||||||
namespace: '{{ test_ns }}'
|
namespace: '{{ test_ns }}'
|
||||||
|
|
||||||
- name: Read Service Account
|
- name: Create SA secret
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s:
|
||||||
kind: ServiceAccount
|
definition:
|
||||||
namespace: '{{ test_ns }}'
|
apiVersion: v1
|
||||||
name: '{{ sa_name }}'
|
kind: Secret
|
||||||
register: sa_out
|
metadata:
|
||||||
|
name: "{{ tn_name }}"
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/service-account.name: "{{ sa_name }}"
|
||||||
|
type: kubernetes.io/service-account-token
|
||||||
|
|
||||||
- set_fact:
|
- name: Get secret details
|
||||||
secret_token: "{{ sa_out.resources[0]['secrets'][0]['name'] }}"
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Secret
|
||||||
|
namespace: '{{ test_ns }}'
|
||||||
|
name: '{{ tn_name }}'
|
||||||
|
register: r_secret
|
||||||
|
|
||||||
- name: Get secret details
|
- set_fact:
|
||||||
kubernetes.core.k8s_info:
|
api_token: "{{ r_secret.resources[0]['data']['token'] | b64decode }}"
|
||||||
kind: Secret
|
|
||||||
namespace: '{{ test_ns }}'
|
|
||||||
name: '{{ secret_token }}'
|
|
||||||
register: r_secret
|
|
||||||
retries: 10
|
|
||||||
delay: 10
|
|
||||||
until:
|
|
||||||
- ("'openshift.io/token-secret.value' in r_secret.resources[0]['metadata']['annotations']") or ("'token' in r_secret.resources[0]['data']")
|
|
||||||
|
|
||||||
- set_fact:
|
- name: list resources using service account
|
||||||
api_token: "{{ r_secret.resources[0]['metadata']['annotations']['openshift.io/token-secret.value'] }}"
|
kubernetes.core.k8s_info:
|
||||||
when: "'openshift.io/token-secret.value' in r_secret.resources[0]['metadata']['annotations']"
|
api_key: '{{ api_token }}'
|
||||||
|
host: '{{ cluster_host }}'
|
||||||
- set_fact:
|
validate_certs: no
|
||||||
api_token: "{{ r_secret.resources[0]['data']['token'] | b64decode }}"
|
kind: Pod
|
||||||
when: "'token' in r_secret.resources[0]['data']"
|
namespace: '{{ test_ns }}'
|
||||||
|
register: error
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: list resources using service account
|
- assert:
|
||||||
kubernetes.core.k8s_info:
|
that:
|
||||||
api_key: '{{ api_token }}'
|
- '"pods is forbidden: User" in error.msg'
|
||||||
host: '{{ cluster_host }}'
|
|
||||||
validate_certs: no
|
|
||||||
kind: Pod
|
|
||||||
namespace: '{{ test_ns }}'
|
|
||||||
register: error
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- error is failed
|
|
||||||
# - '"pods is forbidden: User" in error.module_stderr'
|
|
||||||
|
|
||||||
- name: Create a role to manage Pod from namespace "{{ test_ns }}"
|
- name: Create a role to manage Pod from namespace "{{ test_ns }}"
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
definition:
|
definition:
|
||||||
kind: Role
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
|
||||||
metadata:
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: "{{ item.name }}"
|
|
||||||
labels: "{{ item.labels }}"
|
|
||||||
rules:
|
|
||||||
- apiGroups: [""]
|
|
||||||
resources: ["pods"]
|
|
||||||
verbs: "{{ item.verbs }}"
|
|
||||||
with_items: "{{ role_definition }}"
|
|
||||||
|
|
||||||
- name: Create Role Binding
|
|
||||||
kubernetes.core.k8s:
|
|
||||||
definition:
|
|
||||||
kind: RoleBinding
|
|
||||||
apiVersion: "{{ item.role_binding.api_version }}"
|
|
||||||
metadata:
|
|
||||||
name: "{{ item.name }}-bind"
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
subjects:
|
|
||||||
- kind: ServiceAccount
|
|
||||||
name: "{{ sa_name }}"
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
apiGroup: ""
|
|
||||||
roleRef:
|
|
||||||
kind: Role
|
kind: Role
|
||||||
name: "{{ item.name }}"
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
namespace: "{{ test_ns }}"
|
metadata:
|
||||||
apiGroup: ""
|
namespace: "{{ test_ns }}"
|
||||||
with_items: "{{ role_definition }}"
|
name: "{{ item.name }}"
|
||||||
|
labels: "{{ item.labels }}"
|
||||||
|
rules:
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources: ["pods"]
|
||||||
|
verbs: "{{ item.verbs }}"
|
||||||
|
with_items: "{{ role_definition }}"
|
||||||
|
|
||||||
- name: Create Pod should succeed
|
- name: Create Role Binding
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
api_key: "{{ api_token }}"
|
definition:
|
||||||
host: "{{ cluster_host }}"
|
kind: RoleBinding
|
||||||
validate_certs: no
|
apiVersion: "{{ item.role_binding.api_version }}"
|
||||||
namespace: "{{ test_ns }}"
|
metadata:
|
||||||
definition:
|
name: "{{ item.name }}-bind"
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: "{{ sa_name }}"
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
apiGroup: ""
|
||||||
|
roleRef:
|
||||||
|
kind: Role
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
apiGroup: ""
|
||||||
|
with_items: "{{ role_definition }}"
|
||||||
|
|
||||||
|
- name: Create Pod should succeed
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
api_key: "{{ api_token }}"
|
||||||
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
definition:
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: "{{ pod_name }}"
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: python
|
||||||
|
image: python:3.7-alpine
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- while true; do echo $(date); sleep 15; done
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert pod creation succeed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is successful
|
||||||
|
|
||||||
|
- name: List Pod
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
api_key: "{{ api_token }}"
|
||||||
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
kind: Pod
|
kind: Pod
|
||||||
metadata:
|
register: result
|
||||||
name: "{{ pod_name }}"
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: python
|
|
||||||
image: python:3.7-alpine
|
|
||||||
command:
|
|
||||||
- /bin/sh
|
|
||||||
- -c
|
|
||||||
- while true; do echo $(date); sleep 15; done
|
|
||||||
imagePullPolicy: IfNotPresent
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: assert pod creation succeed
|
- name: assert user is still authorize to list pods
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is successful
|
- result is successful
|
||||||
|
|
||||||
- name: List Pod
|
- name: Prune auth roles (check mode)
|
||||||
kubernetes.core.k8s_info:
|
community.okd.openshift_adm_prune_auth:
|
||||||
api_key: "{{ api_token }}"
|
resource: roles
|
||||||
host: "{{ cluster_host }}"
|
namespace: "{{ test_ns }}"
|
||||||
validate_certs: no
|
register: check
|
||||||
namespace: "{{ test_ns }}"
|
check_mode: true
|
||||||
kind: Pod
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: assert user is still authorize to list pods
|
- name: validate that list role binding are candidates for prune
|
||||||
assert:
|
assert:
|
||||||
that:
|
that: 'test_ns+"/"+item["name"]+"-bind" in check.role_binding'
|
||||||
- result is successful
|
with_items: "{{ role_definition }}"
|
||||||
|
|
||||||
- name: Prune auth roles (check mode)
|
- name: Prune resource using label_selectors option
|
||||||
community.okd.openshift_adm_prune_auth:
|
community.okd.openshift_adm_prune_auth:
|
||||||
resource: roles
|
resource: roles
|
||||||
namespace: "{{ test_ns }}"
|
namespace: "{{ test_ns }}"
|
||||||
register: check
|
label_selectors:
|
||||||
check_mode: true
|
- action=delete
|
||||||
|
register: prune
|
||||||
|
|
||||||
- name: validate that list role binding are candidates for prune
|
- name: assert that role binding 'delete' was pruned
|
||||||
assert:
|
assert:
|
||||||
that: '"{{ test_ns }}/{{ item.name }}-bind" in check.role_binding'
|
that:
|
||||||
with_items: "{{ role_definition }}"
|
- prune is changed
|
||||||
|
- 'test_ns+"/"+role_definition[2]["name"]+"-bind" in check.role_binding'
|
||||||
|
|
||||||
- name: Prune resource using label_selectors option
|
- name: assert that user could not delete pod anymore
|
||||||
community.okd.openshift_adm_prune_auth:
|
kubernetes.core.k8s:
|
||||||
resource: roles
|
api_key: "{{ api_token }}"
|
||||||
namespace: "{{ test_ns }}"
|
host: "{{ cluster_host }}"
|
||||||
label_selectors:
|
validate_certs: no
|
||||||
- action=delete
|
state: absent
|
||||||
register: prune
|
namespace: "{{ test_ns }}"
|
||||||
|
|
||||||
- name: assert that role binding 'delete' was pruned
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- prune is changed
|
|
||||||
- '"{{ test_ns }}/{{ role_definition[2].name }}-bind" in check.role_binding'
|
|
||||||
|
|
||||||
- name: assert that user could not delete pod anymore
|
|
||||||
kubernetes.core.k8s:
|
|
||||||
api_key: "{{ api_token }}"
|
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
state: absent
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
kind: Pod
|
|
||||||
name: "{{ pod_name }}"
|
|
||||||
register: result
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: assert pod deletion failed due to forbidden user
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is failed
|
|
||||||
# - '"forbidden: User" in error.module_stderr'
|
|
||||||
|
|
||||||
- name: List Pod
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
api_key: "{{ api_token }}"
|
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
kind: Pod
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: assert user is still able to list pods
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- result is successful
|
|
||||||
|
|
||||||
- name: Create Pod should succeed
|
|
||||||
kubernetes.core.k8s:
|
|
||||||
api_key: "{{ api_token }}"
|
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
definition:
|
|
||||||
kind: Pod
|
kind: Pod
|
||||||
metadata:
|
name: "{{ pod_name }}"
|
||||||
name: "{{ pod_name }}-1"
|
register: result
|
||||||
spec:
|
ignore_errors: true
|
||||||
containers:
|
|
||||||
- name: python
|
|
||||||
image: python:3.7-alpine
|
|
||||||
command:
|
|
||||||
- /bin/sh
|
|
||||||
- -c
|
|
||||||
- while true; do echo $(date); sleep 15; done
|
|
||||||
imagePullPolicy: IfNotPresent
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- name: assert user is still authorize to create pod
|
- name: assert pod deletion failed due to forbidden user
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is successful
|
- '"forbidden: User" in error.msg'
|
||||||
|
|
||||||
- name: Prune role using name
|
- name: List Pod
|
||||||
community.okd.openshift_adm_prune_auth:
|
kubernetes.core.k8s_info:
|
||||||
resource: roles
|
api_key: "{{ api_token }}"
|
||||||
namespace: "{{ test_ns }}"
|
host: "{{ cluster_host }}"
|
||||||
name: "{{ role_definition[1].name }}"
|
validate_certs: no
|
||||||
register: prune
|
namespace: "{{ test_ns }}"
|
||||||
|
|
||||||
- name: assert that role binding 'create' was pruned
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- prune is changed
|
|
||||||
- '"{{ test_ns }}/{{ role_definition[1].name }}-bind" in check.role_binding'
|
|
||||||
|
|
||||||
- name: Create Pod (should failed)
|
|
||||||
kubernetes.core.k8s:
|
|
||||||
api_key: "{{ api_token }}"
|
|
||||||
host: "{{ cluster_host }}"
|
|
||||||
validate_certs: no
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
definition:
|
|
||||||
kind: Pod
|
kind: Pod
|
||||||
metadata:
|
register: result
|
||||||
name: "{{ pod_name }}-2"
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: python
|
|
||||||
image: python:3.7-alpine
|
|
||||||
command:
|
|
||||||
- /bin/sh
|
|
||||||
- -c
|
|
||||||
- while true; do echo $(date); sleep 15; done
|
|
||||||
imagePullPolicy: IfNotPresent
|
|
||||||
register: result
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: assert user is not authorize to create pod anymore
|
- name: assert user is still able to list pods
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- result is successful
|
||||||
# - '"forbidden: User" in error.module_stderr'
|
|
||||||
|
|
||||||
- name: List Pod
|
- name: Create Pod should succeed
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s:
|
||||||
api_key: "{{ api_token }}"
|
api_key: "{{ api_token }}"
|
||||||
host: "{{ cluster_host }}"
|
host: "{{ cluster_host }}"
|
||||||
validate_certs: no
|
validate_certs: no
|
||||||
namespace: "{{ test_ns }}"
|
namespace: "{{ test_ns }}"
|
||||||
kind: Pod
|
definition:
|
||||||
register: result
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: "{{ pod_name }}-1"
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: python
|
||||||
|
image: python:3.7-alpine
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- while true; do echo $(date); sleep 15; done
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
register: result
|
||||||
|
|
||||||
- name: assert user is still able to list pods
|
- name: assert user is still authorize to create pod
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is successful
|
- result is successful
|
||||||
|
|
||||||
- name: Prune all role for namespace (neither name nor label_selectors are specified)
|
- name: Prune role using name
|
||||||
community.okd.openshift_adm_prune_auth:
|
community.okd.openshift_adm_prune_auth:
|
||||||
resource: roles
|
resource: roles
|
||||||
namespace: "{{ test_ns }}"
|
namespace: "{{ test_ns }}"
|
||||||
register: prune
|
name: "{{ role_definition[1].name }}"
|
||||||
|
register: prune
|
||||||
|
|
||||||
- name: assert that role binding 'list' was pruned
|
- name: assert that role binding 'create' was pruned
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- prune is changed
|
- prune is changed
|
||||||
- '"{{ test_ns }}/{{ role_definition[0].name }}-bind" in check.role_binding'
|
- 'test_ns+"/"+role_definition[1]["name"]+"-bind" in check.role_binding'
|
||||||
|
|
||||||
- name: List Pod
|
- name: Create Pod (should failed)
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s:
|
||||||
api_key: "{{ api_token }}"
|
api_key: "{{ api_token }}"
|
||||||
host: "{{ cluster_host }}"
|
host: "{{ cluster_host }}"
|
||||||
validate_certs: no
|
validate_certs: no
|
||||||
namespace: "{{ test_ns }}"
|
namespace: "{{ test_ns }}"
|
||||||
kind: Pod
|
definition:
|
||||||
register: result
|
kind: Pod
|
||||||
ignore_errors: true
|
metadata:
|
||||||
|
name: "{{ pod_name }}-2"
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: python
|
||||||
|
image: python:3.7-alpine
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- while true; do echo $(date); sleep 15; done
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
register: result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: assert user is not authorize to list pod anymore
|
- name: assert user is not authorize to create pod anymore
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- '"forbidden: User" in error.msg'
|
||||||
# - '"forbidden: User" in error.module_stderr'
|
|
||||||
|
- name: List Pod
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
api_key: "{{ api_token }}"
|
||||||
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
kind: Pod
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert user is still able to list pods
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is successful
|
||||||
|
|
||||||
|
- name: Prune all role for namespace (neither name nor label_selectors are specified)
|
||||||
|
community.okd.openshift_adm_prune_auth:
|
||||||
|
resource: roles
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
register: prune
|
||||||
|
|
||||||
|
- name: assert that role binding 'list' was pruned
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- prune is changed
|
||||||
|
- 'test_ns+"/"+role_definition[0]["name"]+"-bind" in check.role_binding'
|
||||||
|
|
||||||
|
- name: List Pod
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
api_key: "{{ api_token }}"
|
||||||
|
host: "{{ cluster_host }}"
|
||||||
|
validate_certs: no
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
kind: Pod
|
||||||
|
register: result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: assert user is not authorize to list pod anymore
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- '"forbidden: User" in error.msg'
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Ensure namespace is deleted
|
- name: Ensure namespace is deleted
|
||||||
|
|||||||
@@ -1,255 +1,255 @@
|
|||||||
|
---
|
||||||
- name: Prune deployments
|
- name: Prune deployments
|
||||||
block:
|
block:
|
||||||
- set_fact:
|
- set_fact:
|
||||||
dc_name: "hello"
|
dc_name: "hello"
|
||||||
deployment_ns: "prune-deployments"
|
deployment_ns: "prune-deployments"
|
||||||
deployment_ns_2: "prune-deployments-2"
|
deployment_ns_2: "prune-deployments-2"
|
||||||
|
|
||||||
|
|
||||||
- name: Ensure namespace
|
- name: Ensure namespace
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: '{{ deployment_ns }}'
|
name: '{{ deployment_ns }}'
|
||||||
|
|
||||||
- name: Create deployment config
|
- name: Create deployment config
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
namespace: '{{ deployment_ns }}'
|
namespace: '{{ deployment_ns }}'
|
||||||
definition:
|
definition:
|
||||||
kind: DeploymentConfig
|
kind: DeploymentConfig
|
||||||
apiVersion: apps.openshift.io/v1
|
apiVersion: apps.openshift.io/v1
|
||||||
metadata:
|
metadata:
|
||||||
name: '{{ dc_name }}'
|
|
||||||
spec:
|
|
||||||
replicas: 1
|
|
||||||
selector:
|
|
||||||
name: '{{ dc_name }}'
|
name: '{{ dc_name }}'
|
||||||
template:
|
spec:
|
||||||
metadata:
|
replicas: 1
|
||||||
labels:
|
selector:
|
||||||
name: '{{ dc_name }}'
|
name: '{{ dc_name }}'
|
||||||
spec:
|
template:
|
||||||
containers:
|
metadata:
|
||||||
- name: hello-openshift
|
labels:
|
||||||
imagePullPolicy: IfNotPresent
|
name: '{{ dc_name }}'
|
||||||
image: python:3.7-alpine
|
spec:
|
||||||
command: [ "/bin/sh", "-c", "while true;do date;sleep 2s; done"]
|
containers:
|
||||||
wait: yes
|
- name: hello-openshift
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
image: python:3.7-alpine
|
||||||
|
command: [ "/bin/sh", "-c", "while true;do date;sleep 2s; done"]
|
||||||
|
wait: yes
|
||||||
|
|
||||||
- name: prune deployments (no candidate DeploymentConfig)
|
- name: prune deployments (no candidate DeploymentConfig)
|
||||||
community.okd.openshift_adm_prune_deployments:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
namespace: "{{ deployment_ns }}"
|
namespace: "{{ deployment_ns }}"
|
||||||
register: test_prune
|
register: test_prune
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- test_prune is not changed
|
- test_prune is not changed
|
||||||
- test_prune.replication_controllers | length == 0
|
- test_prune.replication_controllers | length == 0
|
||||||
|
|
||||||
- name: Update DeploymentConfig - set replicas to 0
|
- name: Update DeploymentConfig - set replicas to 0
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
namespace: "{{ deployment_ns }}"
|
namespace: "{{ deployment_ns }}"
|
||||||
definition:
|
definition:
|
||||||
kind: DeploymentConfig
|
kind: DeploymentConfig
|
||||||
apiVersion: "apps.openshift.io/v1"
|
apiVersion: "apps.openshift.io/v1"
|
||||||
metadata:
|
metadata:
|
||||||
name: "{{ dc_name }}"
|
|
||||||
spec:
|
|
||||||
replicas: 0
|
|
||||||
selector:
|
|
||||||
name: "{{ dc_name }}"
|
name: "{{ dc_name }}"
|
||||||
template:
|
spec:
|
||||||
metadata:
|
replicas: 0
|
||||||
labels:
|
selector:
|
||||||
name: "{{ dc_name }}"
|
name: "{{ dc_name }}"
|
||||||
spec:
|
template:
|
||||||
containers:
|
metadata:
|
||||||
- name: hello-openshift
|
labels:
|
||||||
imagePullPolicy: IfNotPresent
|
name: "{{ dc_name }}"
|
||||||
image: python:3.7-alpine
|
spec:
|
||||||
command: [ "/bin/sh", "-c", "while true;do date;sleep 2s; done"]
|
containers:
|
||||||
wait: yes
|
- name: hello-openshift
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
image: python:3.7-alpine
|
||||||
|
command: [ "/bin/sh", "-c", "while true;do date;sleep 2s; done"]
|
||||||
|
wait: yes
|
||||||
|
|
||||||
- name: Wait for ReplicationController candidate for pruning
|
- name: Wait for ReplicationController candidate for pruning
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
kind: ReplicationController
|
kind: ReplicationController
|
||||||
namespace: "{{ deployment_ns }}"
|
namespace: "{{ deployment_ns }}"
|
||||||
register: result
|
register: result
|
||||||
retries: 10
|
retries: 10
|
||||||
delay: 30
|
delay: 30
|
||||||
until:
|
until:
|
||||||
- result.resources.0.metadata.annotations["openshift.io/deployment.phase"] in ("Failed", "Complete")
|
- result.resources.0.metadata.annotations["openshift.io/deployment.phase"] in ("Failed", "Complete")
|
||||||
|
|
||||||
- name: Prune deployments - should delete 1 ReplicationController
|
- name: Prune deployments - should delete 1 ReplicationController
|
||||||
community.okd.openshift_adm_prune_deployments:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
namespace: "{{ deployment_ns }}"
|
namespace: "{{ deployment_ns }}"
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: test_prune
|
register: test_prune
|
||||||
|
|
||||||
- name: Read ReplicationController
|
- name: Read ReplicationController
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
kind: ReplicationController
|
kind: ReplicationController
|
||||||
namespace: "{{ deployment_ns }}"
|
namespace: "{{ deployment_ns }}"
|
||||||
register: replications
|
register: replications
|
||||||
|
|
||||||
- name: Assert that Replication controller was not deleted
|
- name: Assert that Replication controller was not deleted
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- replications.resources | length == 1
|
- replications.resources | length == 1
|
||||||
- 'replications.resources.0.metadata.name is match("{{ dc_name }}-*")'
|
- replications.resources.0.metadata.name is match(dc_name+"-*")
|
||||||
|
|
||||||
- name: Assure that candidate ReplicationController was found for pruning
|
- name: Assure that candidate ReplicationController was found for pruning
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- test_prune is changed
|
- test_prune is changed
|
||||||
- test_prune.replication_controllers | length == 1
|
- test_prune.replication_controllers | length == 1
|
||||||
- test_prune.replication_controllers.0.metadata.name == replications.resources.0.metadata.name
|
- test_prune.replication_controllers.0.metadata.name == replications.resources.0.metadata.name
|
||||||
- test_prune.replication_controllers.0.metadata.namespace == replications.resources.0.metadata.namespace
|
- test_prune.replication_controllers.0.metadata.namespace == replications.resources.0.metadata.namespace
|
||||||
|
|
||||||
- name: Prune deployments - keep younger than 45min (check_mode)
|
- name: Prune deployments - keep younger than 45min (check_mode)
|
||||||
community.okd.openshift_adm_prune_deployments:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
keep_younger_than: 45
|
keep_younger_than: 45
|
||||||
namespace: "{{ deployment_ns }}"
|
namespace: "{{ deployment_ns }}"
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: keep_younger
|
register: keep_younger
|
||||||
|
|
||||||
- name: assert no candidate was found
|
- name: assert no candidate was found
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- keep_younger is not changed
|
- keep_younger is not changed
|
||||||
- keep_younger.replication_controllers == []
|
- keep_younger.replication_controllers == []
|
||||||
|
|
||||||
- name: Ensure second namespace is created
|
- name: Ensure second namespace is created
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: '{{ deployment_ns_2 }}'
|
name: '{{ deployment_ns_2 }}'
|
||||||
|
|
||||||
- name: Create deployment config from 2nd namespace
|
- name: Create deployment config from 2nd namespace
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
namespace: '{{ deployment_ns_2 }}'
|
namespace: '{{ deployment_ns_2 }}'
|
||||||
definition:
|
definition:
|
||||||
kind: DeploymentConfig
|
kind: DeploymentConfig
|
||||||
apiVersion: apps.openshift.io/v1
|
apiVersion: apps.openshift.io/v1
|
||||||
metadata:
|
metadata:
|
||||||
name: '{{ dc_name }}2'
|
|
||||||
spec:
|
|
||||||
replicas: 1
|
|
||||||
selector:
|
|
||||||
name: '{{ dc_name }}2'
|
name: '{{ dc_name }}2'
|
||||||
template:
|
spec:
|
||||||
metadata:
|
replicas: 1
|
||||||
labels:
|
selector:
|
||||||
name: '{{ dc_name }}2'
|
name: '{{ dc_name }}2'
|
||||||
spec:
|
template:
|
||||||
containers:
|
metadata:
|
||||||
- name: hello-openshift
|
labels:
|
||||||
imagePullPolicy: IfNotPresent
|
name: '{{ dc_name }}2'
|
||||||
image: python:3.7-alpine
|
spec:
|
||||||
command: [ "/bin/sh", "-c", "while true;do date;sleep 2s; done"]
|
containers:
|
||||||
wait: yes
|
- name: hello-openshift
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
image: python:3.7-alpine
|
||||||
|
command: [ "/bin/sh", "-c", "while true;do date;sleep 2s; done"]
|
||||||
|
wait: yes
|
||||||
|
|
||||||
- name: Stop deployment config - replicas = 0
|
- name: Stop deployment config - replicas = 0
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
namespace: '{{ deployment_ns_2 }}'
|
namespace: '{{ deployment_ns_2 }}'
|
||||||
definition:
|
definition:
|
||||||
kind: DeploymentConfig
|
kind: DeploymentConfig
|
||||||
apiVersion: apps.openshift.io/v1
|
apiVersion: apps.openshift.io/v1
|
||||||
metadata:
|
metadata:
|
||||||
name: '{{ dc_name }}2'
|
|
||||||
spec:
|
|
||||||
replicas: 0
|
|
||||||
selector:
|
|
||||||
name: '{{ dc_name }}2'
|
name: '{{ dc_name }}2'
|
||||||
template:
|
spec:
|
||||||
metadata:
|
replicas: 0
|
||||||
labels:
|
selector:
|
||||||
name: '{{ dc_name }}2'
|
name: '{{ dc_name }}2'
|
||||||
spec:
|
template:
|
||||||
containers:
|
metadata:
|
||||||
- name: hello-openshift
|
labels:
|
||||||
imagePullPolicy: IfNotPresent
|
name: '{{ dc_name }}2'
|
||||||
image: python:3.7-alpine
|
spec:
|
||||||
command: [ "/bin/sh", "-c", "while true;do date;sleep 2s; done"]
|
containers:
|
||||||
wait: yes
|
- name: hello-openshift
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
image: python:3.7-alpine
|
||||||
|
command: [ "/bin/sh", "-c", "while true;do date;sleep 2s; done"]
|
||||||
|
wait: yes
|
||||||
|
|
||||||
- name: Wait for ReplicationController candidate for pruning
|
- name: Wait for ReplicationController candidate for pruning
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
kind: ReplicationController
|
kind: ReplicationController
|
||||||
namespace: "{{ deployment_ns_2 }}"
|
namespace: "{{ deployment_ns_2 }}"
|
||||||
register: result
|
register: result
|
||||||
retries: 10
|
retries: 10
|
||||||
delay: 30
|
delay: 30
|
||||||
until:
|
until:
|
||||||
- result.resources.0.metadata.annotations["openshift.io/deployment.phase"] in ("Failed", "Complete")
|
- result.resources.0.metadata.annotations["openshift.io/deployment.phase"] in ("Failed", "Complete")
|
||||||
|
|
||||||
# Prune from one namespace should not have any effect on others namespaces
|
# Prune from one namespace should not have any effect on others namespaces
|
||||||
- name: Prune deployments from 2nd namespace
|
- name: Prune deployments from 2nd namespace
|
||||||
community.okd.openshift_adm_prune_deployments:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
namespace: "{{ deployment_ns_2 }}"
|
namespace: "{{ deployment_ns_2 }}"
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: test_prune
|
register: test_prune
|
||||||
|
|
||||||
- name: Assure that candidate ReplicationController was found for pruning
|
- name: Assure that candidate ReplicationController was found for pruning
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- test_prune is changed
|
- test_prune is changed
|
||||||
- test_prune.replication_controllers | length == 1
|
- test_prune.replication_controllers | length == 1
|
||||||
- "test_prune.replication_controllers.0.metadata.namespace == deployment_ns_2"
|
- "test_prune.replication_controllers.0.metadata.namespace == deployment_ns_2"
|
||||||
|
|
||||||
# Prune without namespace option
|
# Prune without namespace option
|
||||||
- name: Prune from all namespace should update more deployments
|
- name: Prune from all namespace should update more deployments
|
||||||
community.okd.openshift_adm_prune_deployments:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: no_namespace_prune
|
register: no_namespace_prune
|
||||||
|
|
||||||
- name: Assure multiple ReplicationController were found for pruning
|
- name: Assure multiple ReplicationController were found for pruning
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- no_namespace_prune is changed
|
- no_namespace_prune is changed
|
||||||
- no_namespace_prune.replication_controllers | length == 2
|
- no_namespace_prune.replication_controllers | length == 2
|
||||||
|
|
||||||
# Execute Prune from 2nd namespace
|
|
||||||
- name: Read ReplicationController before Prune operation
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: ReplicationController
|
|
||||||
namespace: "{{ deployment_ns_2 }}"
|
|
||||||
register: replications
|
|
||||||
|
|
||||||
- assert:
|
# Execute Prune from 2nd namespace
|
||||||
that:
|
- name: Read ReplicationController before Prune operation
|
||||||
- replications.resources | length == 1
|
kubernetes.core.k8s_info:
|
||||||
|
kind: ReplicationController
|
||||||
|
namespace: "{{ deployment_ns_2 }}"
|
||||||
|
register: replications
|
||||||
|
|
||||||
- name: Prune DeploymentConfig from 2nd namespace
|
- assert:
|
||||||
community.okd.openshift_adm_prune_deployments:
|
that:
|
||||||
namespace: "{{ deployment_ns_2 }}"
|
- replications.resources | length == 1
|
||||||
register: _prune
|
|
||||||
|
|
||||||
- name: Assert DeploymentConfig was deleted
|
- name: Prune DeploymentConfig from 2nd namespace
|
||||||
assert:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
that:
|
namespace: "{{ deployment_ns_2 }}"
|
||||||
- _prune is changed
|
register: _prune
|
||||||
- _prune.replication_controllers | length == 1
|
|
||||||
- _prune.replication_controllers.0.details.name == replications.resources.0.metadata.name
|
|
||||||
|
|
||||||
# Execute Prune without namespace option
|
- name: Assert DeploymentConfig was deleted
|
||||||
- name: Read ReplicationController before Prune operation
|
assert:
|
||||||
kubernetes.core.k8s_info:
|
that:
|
||||||
kind: ReplicationController
|
- _prune is changed
|
||||||
namespace: "{{ deployment_ns }}"
|
- _prune.replication_controllers | length == 1
|
||||||
register: replications
|
- _prune.replication_controllers.0.details.name == replications.resources.0.metadata.name
|
||||||
|
|
||||||
- assert:
|
# Execute Prune without namespace option
|
||||||
that:
|
- name: Read ReplicationController before Prune operation
|
||||||
- replications.resources | length == 1
|
kubernetes.core.k8s_info:
|
||||||
|
kind: ReplicationController
|
||||||
|
namespace: "{{ deployment_ns }}"
|
||||||
|
register: replications
|
||||||
|
|
||||||
- name: Prune from all namespace should update more deployments
|
- assert:
|
||||||
community.okd.openshift_adm_prune_deployments:
|
that:
|
||||||
register: _prune
|
- replications.resources | length == 1
|
||||||
|
|
||||||
- name: Assure multiple ReplicationController were found for pruning
|
- name: Prune from all namespace should update more deployments
|
||||||
assert:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
that:
|
register: _prune
|
||||||
- _prune is changed
|
|
||||||
- _prune.replication_controllers | length > 0
|
- name: Assure multiple ReplicationController were found for pruning
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- _prune is changed
|
||||||
|
- _prune.replication_controllers | length > 0
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete 1st namespace
|
- name: Delete 1st namespace
|
||||||
@@ -266,4 +266,4 @@
|
|||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: "{{ deployment_ns_2 }}"
|
name: "{{ deployment_ns_2 }}"
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
when: deployment_ns_2 is defined
|
when: deployment_ns_2 is defined
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
---
|
---
|
||||||
- block:
|
- block:
|
||||||
|
- set_fact:
|
||||||
|
admin_user: test
|
||||||
|
admin_pass: testing123
|
||||||
|
|
||||||
- name: Retrieve cluster info
|
- name: Retrieve cluster info
|
||||||
kubernetes.core.k8s_cluster_info:
|
kubernetes.core.k8s_cluster_info:
|
||||||
register: k8s_cluster
|
register: k8s_cluster
|
||||||
@@ -10,47 +14,98 @@
|
|||||||
|
|
||||||
- name: Log in (obtain access token)
|
- name: Log in (obtain access token)
|
||||||
community.okd.openshift_auth:
|
community.okd.openshift_auth:
|
||||||
username: test
|
username: "{{ admin_user }}"
|
||||||
password: testing123
|
password: "{{ admin_pass }}"
|
||||||
host: '{{ openshift_host }}'
|
host: '{{ openshift_host }}'
|
||||||
verify_ssl: false
|
verify_ssl: false
|
||||||
register: openshift_auth_results
|
register: openshift_auth_results
|
||||||
|
|
||||||
- name: Get the test User
|
- set_fact:
|
||||||
|
auth_api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
||||||
|
|
||||||
|
- name: "Get the {{ admin_user }} User"
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
api_key: "{{ auth_api_key }}"
|
||||||
host: '{{ openshift_host }}'
|
host: '{{ openshift_host }}'
|
||||||
verify_ssl: false
|
verify_ssl: false
|
||||||
kind: User
|
kind: User
|
||||||
api_version: user.openshift.io/v1
|
api_version: user.openshift.io/v1
|
||||||
name: test
|
name: "{{ admin_user }}"
|
||||||
register: user_result
|
register: user_result
|
||||||
|
|
||||||
- name: assert that the user was found
|
- name: assert that the user was found
|
||||||
assert:
|
assert:
|
||||||
that: (user_result.resources | length) == 1
|
that: (user_result.resources | length) == 1
|
||||||
|
|
||||||
|
- name: list available tokens
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: UserOAuthAccessToken
|
||||||
|
version: oauth.openshift.io/v1
|
||||||
|
register: tokens
|
||||||
|
|
||||||
|
- debug: var=tokens
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
token_names: "{{ tokens.resources | map(attribute='metadata.name') | list }}"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- debug: var=token_names
|
||||||
|
|
||||||
|
- name: Revoke access token
|
||||||
|
community.okd.openshift_auth:
|
||||||
|
state: absent
|
||||||
|
api_key: "{{ auth_api_key }}"
|
||||||
|
host: '{{ openshift_host }}'
|
||||||
|
verify_ssl: false
|
||||||
|
register: _revoke
|
||||||
|
|
||||||
|
- name: Ensure that token has been revoked
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- _revoke is changed
|
||||||
|
|
||||||
|
- name: "Get the {{ admin_user }} User (after token deletion)"
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
api_key: "{{ auth_api_key }}"
|
||||||
|
host: '{{ openshift_host }}'
|
||||||
|
verify_ssl: false
|
||||||
|
kind: User
|
||||||
|
api_version: user.openshift.io/v1
|
||||||
|
name: "{{ admin_user }}"
|
||||||
|
ignore_errors: true
|
||||||
|
retries: 50
|
||||||
|
until: user_result is failed
|
||||||
|
delay: 20
|
||||||
|
register: user_result
|
||||||
|
|
||||||
|
- name: Ensure that task has failed due to revoked token
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- user_result is failed
|
||||||
|
|
||||||
|
- name: Revoke access token once again (should fail)
|
||||||
|
community.okd.openshift_auth:
|
||||||
|
state: absent
|
||||||
|
api_key: "{{ auth_api_key }}"
|
||||||
|
host: '{{ openshift_host }}'
|
||||||
|
verify_ssl: false
|
||||||
|
register: _revoke
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Ensure that nothing changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- _revoke is failed
|
||||||
|
- _revoke.msg.startswith("Couldn't delete user oauth access token")
|
||||||
|
|
||||||
|
when: token_names | length > 0
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: If login succeeded, try to log out (revoke access token)
|
- name: If login succeeded, try to log out (revoke access token)
|
||||||
when: openshift_auth_results.openshift_auth.api_key is defined
|
when: auth_api_key is defined
|
||||||
community.okd.openshift_auth:
|
community.okd.openshift_auth:
|
||||||
state: absent
|
state: absent
|
||||||
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
api_key: "{{ auth_api_key }}"
|
||||||
host: '{{ openshift_host }}'
|
host: '{{ openshift_host }}'
|
||||||
verify_ssl: false
|
verify_ssl: false
|
||||||
|
ignore_errors: true
|
||||||
- name: Get the test user
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
|
||||||
host: '{{ openshift_host }}'
|
|
||||||
verify_ssl: false
|
|
||||||
kind: User
|
|
||||||
name: test
|
|
||||||
api_version: user.openshift.io/v1
|
|
||||||
register: failed_user_result
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|
||||||
# TODO(fabianvf) determine why token is not being rejected, maybe add more info to return
|
|
||||||
# - name: assert that the user was not found
|
|
||||||
# assert:
|
|
||||||
# that: (failed_user_result.resources | length) == 0
|
|
||||||
|
|||||||
@@ -0,0 +1,250 @@
|
|||||||
|
---
|
||||||
|
- block:
|
||||||
|
- set_fact:
|
||||||
|
build_ns: "builds"
|
||||||
|
build_config: "start-build"
|
||||||
|
is_name: "ruby"
|
||||||
|
prune_build: "prune-build"
|
||||||
|
|
||||||
|
- name: Ensure namespace
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
kind: Namespace
|
||||||
|
name: "{{ build_ns }}"
|
||||||
|
|
||||||
|
- name: Create ImageStream
|
||||||
|
community.okd.k8s:
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
definition:
|
||||||
|
apiVersion: image.openshift.io/v1
|
||||||
|
kind: ImageStream
|
||||||
|
metadata:
|
||||||
|
name: "{{ is_name }}"
|
||||||
|
spec:
|
||||||
|
lookupPolicy:
|
||||||
|
local: false
|
||||||
|
tags: []
|
||||||
|
|
||||||
|
- name: Create build configuration
|
||||||
|
community.okd.k8s:
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
definition:
|
||||||
|
kind: BuildConfig
|
||||||
|
apiVersion: build.openshift.io/v1
|
||||||
|
metadata:
|
||||||
|
name: "{{ build_config }}"
|
||||||
|
spec:
|
||||||
|
source:
|
||||||
|
dockerfile: |
|
||||||
|
FROM openshift/ruby-22-centos7
|
||||||
|
RUN sleep 60s
|
||||||
|
USER ansible
|
||||||
|
strategy:
|
||||||
|
type: Docker
|
||||||
|
output:
|
||||||
|
to:
|
||||||
|
kind: "ImageStreamTag"
|
||||||
|
name: "{{ is_name }}:latest"
|
||||||
|
|
||||||
|
- name: Start Build from Build configuration
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
build_config_name: "{{ build_config }}"
|
||||||
|
register: new_build
|
||||||
|
|
||||||
|
- name: Assert that a build has been created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- new_build is changed
|
||||||
|
- new_build.builds.0.metadata.name == build_config+"-1"
|
||||||
|
|
||||||
|
- name: Start a new Build from previous Build
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
build_name: "{{ new_build.builds.0.metadata.name }}"
|
||||||
|
register: rerun_build
|
||||||
|
|
||||||
|
- name: Assert that another build has been created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- rerun_build is changed
|
||||||
|
- rerun_build.builds.0.metadata.name == build_config+"-2"
|
||||||
|
|
||||||
|
- name: Cancel first build created
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
build_name: "{{ build_config }}-1"
|
||||||
|
state: cancelled
|
||||||
|
wait: yes
|
||||||
|
register: cancel
|
||||||
|
|
||||||
|
- name: Assert that the Build was cancelled
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- cancel is changed
|
||||||
|
- cancel.builds | length == 1
|
||||||
|
- cancel.builds.0.metadata.name == build_config+"-1"
|
||||||
|
- cancel.builds.0.metadata.namespace == build_ns
|
||||||
|
- '"cancelled" in cancel.builds.0.status'
|
||||||
|
- cancel.builds.0.status.cancelled
|
||||||
|
|
||||||
|
- name: Get info for 1st Build
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
version: build.openshift.io/v1
|
||||||
|
kind: Build
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
name: "{{ cancel.builds.0.metadata.name }}"
|
||||||
|
register: build
|
||||||
|
|
||||||
|
- name: Assert that build phase is cancelled
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- build.resources | length == 1
|
||||||
|
- '"cancelled" in build.resources.0.status'
|
||||||
|
- build.resources.0.status.cancelled
|
||||||
|
- build.resources.0.status.phase == 'Cancelled'
|
||||||
|
|
||||||
|
- name: Cancel and restart Build using build config name
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
build_config_name: "{{ build_config }}"
|
||||||
|
state: restarted
|
||||||
|
build_phases:
|
||||||
|
- Pending
|
||||||
|
- Running
|
||||||
|
- New
|
||||||
|
register: restart
|
||||||
|
|
||||||
|
- name: assert that new build was created
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- restart is changed
|
||||||
|
- restart.builds | length == 1
|
||||||
|
- restart.builds.0.metadata.name == build_config+"-3"
|
||||||
|
|
||||||
|
- name: Get info for 2nd Build
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
version: build.openshift.io/v1
|
||||||
|
kind: Build
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
name: "{{ build_config }}-2"
|
||||||
|
register: build
|
||||||
|
|
||||||
|
- name: Assert that build phase is cancelled
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- build.resources | length == 1
|
||||||
|
- '"cancelled" in build.resources.0.status'
|
||||||
|
- build.resources.0.status.cancelled
|
||||||
|
- build.resources.0.status.phase == 'Cancelled'
|
||||||
|
|
||||||
|
- name: Get info for 3rd build
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
version: build.openshift.io/v1
|
||||||
|
kind: Build
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
name: "{{ build_config }}-3"
|
||||||
|
register: build
|
||||||
|
|
||||||
|
- name: Assert that Build is not cancelled
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- build.resources | length == 1
|
||||||
|
- '"cancelled" not in build.resources.0.status'
|
||||||
|
- "build.resources.0.status.phase in ('New', 'Pending', 'Running')"
|
||||||
|
|
||||||
|
- name: Prune Builds keep younger than 30min
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
keep_younger_than: 30
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
register: prune
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: Assert that no Builds were found
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not prune.changed
|
||||||
|
- prune.builds | length == 0
|
||||||
|
|
||||||
|
- name: Prune Builds without namespace
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
register: prune_without_ns
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: Assert that completed build are candidate for prune
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- prune_without_ns is changed
|
||||||
|
- prune_without_ns.builds | length > 0
|
||||||
|
- 'build_config+"-1" in build_names'
|
||||||
|
- 'build_config+"-2" in build_names'
|
||||||
|
vars:
|
||||||
|
build_names: '{{ prune_without_ns.builds | map(attribute="metadata") | flatten | map(attribute="name") | list }}'
|
||||||
|
|
||||||
|
- name: Prune Builds using namespace
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
register: prune_with_ns
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: Assert that prune operation found the completed build
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- prune_with_ns is changed
|
||||||
|
- prune_with_ns.builds | length == 2
|
||||||
|
|
||||||
|
- name: Check Build before prune
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Build
|
||||||
|
api_version: build.openshift.io/v1
|
||||||
|
name: "{{ build_config }}-1"
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
register: resource
|
||||||
|
|
||||||
|
- name: Validate that any previous build operation executed with check_mode did not deleted the build
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- resource.resources | length == 1
|
||||||
|
|
||||||
|
- name: Execute prune operation
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
register: prune
|
||||||
|
|
||||||
|
- name: assert prune is changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- prune is changed
|
||||||
|
|
||||||
|
- name: Check Build
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Build
|
||||||
|
api_version: build.openshift.io/v1
|
||||||
|
name: "{{ build_config }}-1"
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
register: resource
|
||||||
|
|
||||||
|
- name: Assert that the Build does not exist anymore
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- resource.resources | length == 0
|
||||||
|
|
||||||
|
- name: Check Build
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Build
|
||||||
|
api_version: build.openshift.io/v1
|
||||||
|
name: "{{ build_config }}-2"
|
||||||
|
namespace: "{{ build_ns }}"
|
||||||
|
register: resource
|
||||||
|
|
||||||
|
- name: Assert that the Build does not exist anymore
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- resource.resources | length == 0
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Ensure namespace is deleted
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
state: absent
|
||||||
|
kind: Namespace
|
||||||
|
name: "{{ build_ns }}"
|
||||||
|
ignore_errors: true
|
||||||
@@ -1,174 +1,175 @@
|
|||||||
|
---
|
||||||
- name: Openshift import image testing
|
- name: Openshift import image testing
|
||||||
block:
|
block:
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
test_ns: "import-images"
|
test_ns: "import-images"
|
||||||
|
|
||||||
- name: Ensure namespace
|
- name: Ensure namespace
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
name: '{{ test_ns }}'
|
name: '{{ test_ns }}'
|
||||||
|
|
||||||
- name: Import image using tag (should import latest tag only)
|
- name: Import image using tag (should import latest tag only)
|
||||||
community.okd.openshift_import_image:
|
community.okd.openshift_import_image:
|
||||||
namespace: "{{ test_ns }}"
|
namespace: "{{ test_ns }}"
|
||||||
name: "ansible/awx"
|
name: "ansible/awx"
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: import_tag
|
register: import_tag
|
||||||
|
|
||||||
- name: Assert only latest was imported
|
- name: Assert only latest was imported
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- import_tag is changed
|
- import_tag is changed
|
||||||
- import_tag.result | length == 1
|
- import_tag.result | length == 1
|
||||||
- import_tag.result.0.spec.import
|
- import_tag.result.0.spec.import
|
||||||
- import_tag.result.0.spec.images.0.from.kind == "DockerImage"
|
- import_tag.result.0.spec.images.0.from.kind == "DockerImage"
|
||||||
- import_tag.result.0.spec.images.0.from.name == "ansible/awx"
|
- import_tag.result.0.spec.images.0.from.name == "ansible/awx"
|
||||||
|
|
||||||
- name: check image stream
|
- name: check image stream
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
kind: ImageStream
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: awx
|
|
||||||
register: resource
|
|
||||||
|
|
||||||
- name: assert that image stream is not created when using check_mode=yes
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- resource.resources == []
|
|
||||||
|
|
||||||
- name: Import image using tag (should import latest tag only)
|
|
||||||
community.okd.openshift_import_image:
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: "ansible/awx"
|
|
||||||
register: import_tag
|
|
||||||
|
|
||||||
- name: Assert only latest was imported
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- import_tag is changed
|
|
||||||
|
|
||||||
- name: check image stream
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: ImageStream
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: awx
|
|
||||||
register: resource
|
|
||||||
|
|
||||||
- name: assert that image stream contains only tag latest
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- resource.resources | length == 1
|
|
||||||
- resource.resources.0.status.tags.0.tag == 'latest'
|
|
||||||
|
|
||||||
- name: Import once again the latest tag
|
|
||||||
community.okd.openshift_import_image:
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: "ansible/awx"
|
|
||||||
register: import_tag
|
|
||||||
|
|
||||||
- name: assert change was performed
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- import_tag is changed
|
|
||||||
|
|
||||||
- name: check image stream
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
kind: ImageStream
|
|
||||||
version: image.openshift.io/v1
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: awx
|
|
||||||
register: resource
|
|
||||||
|
|
||||||
- name: assert that image stream still contains unique tag
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- resource.resources | length == 1
|
|
||||||
- resource.resources.0.status.tags.0.tag == 'latest'
|
|
||||||
|
|
||||||
- name: Import another tags
|
|
||||||
community.okd.openshift_import_image:
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: "ansible/awx:17.1.0"
|
|
||||||
register: import_another_tag
|
|
||||||
ignore_errors: yes
|
|
||||||
|
|
||||||
- name: assert that another tag was imported
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- import_another_tag is failed
|
|
||||||
- '"the tag 17.1.0 does not exist on the image stream" in import_another_tag.msg'
|
|
||||||
|
|
||||||
- name: Create simple ImageStream (without docker external container)
|
|
||||||
community.okd.k8s:
|
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: "local-is"
|
|
||||||
definition:
|
|
||||||
apiVersion: image.openshift.io/v1
|
|
||||||
kind: ImageStream
|
kind: ImageStream
|
||||||
spec:
|
namespace: "{{ test_ns }}"
|
||||||
lookupPolicy:
|
name: awx
|
||||||
local: false
|
register: resource
|
||||||
tags: []
|
|
||||||
|
|
||||||
- name: Import all tag for image stream not pointing on external container image should failed
|
- name: assert that image stream is not created when using check_mode=yes
|
||||||
community.okd.openshift_import_image:
|
assert:
|
||||||
namespace: "{{ test_ns }}"
|
that:
|
||||||
name: "local-is"
|
- resource.resources == []
|
||||||
all: true
|
|
||||||
register: error_tag
|
|
||||||
ignore_errors: true
|
|
||||||
check_mode: yes
|
|
||||||
|
|
||||||
- name: Assert module cannot import from non-existing tag from ImageStream
|
- name: Import image using tag (should import latest tag only)
|
||||||
assert:
|
community.okd.openshift_import_image:
|
||||||
that:
|
namespace: "{{ test_ns }}"
|
||||||
- error_tag is failed
|
name: "ansible/awx"
|
||||||
- 'error_tag.msg == "image stream {{ test_ns }}/local-is does not have tags pointing to external container images"'
|
register: import_tag
|
||||||
|
|
||||||
- name: import all tags for container image ibmcom/pause and specific tag for redhat/ubi8-micro
|
- name: Assert only latest was imported
|
||||||
community.okd.openshift_import_image:
|
assert:
|
||||||
namespace: "{{ test_ns }}"
|
that:
|
||||||
name:
|
- import_tag is changed
|
||||||
- "ibmcom/pause"
|
|
||||||
- "redhat/ubi8-micro:8.5-437"
|
|
||||||
all: true
|
|
||||||
register: multiple_import
|
|
||||||
|
|
||||||
- name: Assert that import succeed
|
- name: check image stream
|
||||||
assert:
|
kubernetes.core.k8s_info:
|
||||||
that:
|
kind: ImageStream
|
||||||
- multiple_import is changed
|
namespace: "{{ test_ns }}"
|
||||||
- multiple_import.result | length == 2
|
name: awx
|
||||||
|
register: resource
|
||||||
|
|
||||||
- name: Read ibmcom/pause ImageStream
|
- name: assert that image stream contains only tag latest
|
||||||
kubernetes.core.k8s_info:
|
assert:
|
||||||
version: image.openshift.io/v1
|
that:
|
||||||
kind: ImageStream
|
- resource.resources | length == 1
|
||||||
namespace: "{{ test_ns }}"
|
- resource.resources.0.status.tags.0.tag == 'latest'
|
||||||
name: pause
|
|
||||||
register: pause
|
|
||||||
|
|
||||||
- name: assert that ibmcom/pause has multiple tags
|
- name: Import once again the latest tag
|
||||||
assert:
|
community.okd.openshift_import_image:
|
||||||
that:
|
namespace: "{{ test_ns }}"
|
||||||
- pause.resources | length == 1
|
name: "ansible/awx"
|
||||||
- pause.resources.0.status.tags | length > 1
|
register: import_tag
|
||||||
|
|
||||||
- name: Read redhat/ubi8-micro ImageStream
|
- name: assert change was performed
|
||||||
kubernetes.core.k8s_info:
|
assert:
|
||||||
version: image.openshift.io/v1
|
that:
|
||||||
kind: ImageStream
|
- import_tag is changed
|
||||||
namespace: "{{ test_ns }}"
|
|
||||||
name: ubi8-micro
|
|
||||||
register: resource
|
|
||||||
|
|
||||||
- name: assert that redhat/ubi8-micro has only one tag
|
- name: check image stream
|
||||||
assert:
|
kubernetes.core.k8s_info:
|
||||||
that:
|
kind: ImageStream
|
||||||
- resource.resources | length == 1
|
version: image.openshift.io/v1
|
||||||
- resource.resources.0.status.tags | length == 1
|
namespace: "{{ test_ns }}"
|
||||||
- 'resource.resources.0.status.tags.0.tag == "8.5-437"'
|
name: awx
|
||||||
|
register: resource
|
||||||
|
|
||||||
|
- name: assert that image stream still contains unique tag
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- resource.resources | length == 1
|
||||||
|
- resource.resources.0.status.tags.0.tag == 'latest'
|
||||||
|
|
||||||
|
- name: Import another tags
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
name: "ansible/awx:17.1.0"
|
||||||
|
register: import_another_tag
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: assert that another tag was imported
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- import_another_tag is failed
|
||||||
|
- '"the tag 17.1.0 does not exist on the image stream" in import_another_tag.msg'
|
||||||
|
|
||||||
|
- name: Create simple ImageStream (without docker external container)
|
||||||
|
community.okd.k8s:
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
name: "local-is"
|
||||||
|
definition:
|
||||||
|
apiVersion: image.openshift.io/v1
|
||||||
|
kind: ImageStream
|
||||||
|
spec:
|
||||||
|
lookupPolicy:
|
||||||
|
local: false
|
||||||
|
tags: []
|
||||||
|
|
||||||
|
- name: Import all tag for image stream not pointing on external container image should failed
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
name: "local-is"
|
||||||
|
all: true
|
||||||
|
register: error_tag
|
||||||
|
ignore_errors: true
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- name: Assert module cannot import from non-existing tag from ImageStream
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- error_tag is failed
|
||||||
|
- error_tag.msg == "image stream "+test_ns+"/local-is does not have tags pointing to external container images"
|
||||||
|
|
||||||
|
- name: import all tags for container image ibmcom/pause and specific tag for redhat/ubi8-micro
|
||||||
|
community.okd.openshift_import_image:
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
name:
|
||||||
|
- "ibmcom/pause"
|
||||||
|
- "redhat/ubi8-micro:8.5-437"
|
||||||
|
all: true
|
||||||
|
register: multiple_import
|
||||||
|
|
||||||
|
- name: Assert that import succeed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- multiple_import is changed
|
||||||
|
- multiple_import.result | length == 2
|
||||||
|
|
||||||
|
- name: Read ibmcom/pause ImageStream
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
version: image.openshift.io/v1
|
||||||
|
kind: ImageStream
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
name: pause
|
||||||
|
register: pause
|
||||||
|
|
||||||
|
- name: assert that ibmcom/pause has multiple tags
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- pause.resources | length == 1
|
||||||
|
- pause.resources.0.status.tags | length > 1
|
||||||
|
|
||||||
|
- name: Read redhat/ubi8-micro ImageStream
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
version: image.openshift.io/v1
|
||||||
|
kind: ImageStream
|
||||||
|
namespace: "{{ test_ns }}"
|
||||||
|
name: ubi8-micro
|
||||||
|
register: resource
|
||||||
|
|
||||||
|
- name: assert that redhat/ubi8-micro has only one tag
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- resource.resources | length == 1
|
||||||
|
- resource.resources.0.status.tags | length == 1
|
||||||
|
- 'resource.resources.0.status.tags.0.tag == "8.5-437"'
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete testing namespace
|
- name: Delete testing namespace
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
parameters:
|
parameters:
|
||||||
NAMESPACE: openshift
|
NAMESPACE: openshift
|
||||||
NAME: test123
|
NAME: test123
|
||||||
|
NGINX_VERSION: "{{ nginx_version }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Create the rendered resources
|
- name: Create the rendered resources
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
parameters:
|
parameters:
|
||||||
NAMESPACE: openshift
|
NAMESPACE: openshift
|
||||||
NAME: test123
|
NAME: test123
|
||||||
|
NGINX_VERSION: "{{ nginx_version }}"
|
||||||
state: present
|
state: present
|
||||||
namespace_target: process-test
|
namespace_target: process-test
|
||||||
register: result
|
register: result
|
||||||
@@ -44,6 +46,7 @@
|
|||||||
NAMESPACE: openshift
|
NAMESPACE: openshift
|
||||||
NAME: test123
|
NAME: test123
|
||||||
MEMORY_LIMIT: 1Gi
|
MEMORY_LIMIT: 1Gi
|
||||||
|
NGINX_VERSION: "{{ nginx_version }}"
|
||||||
state: present
|
state: present
|
||||||
namespace_target: process-test
|
namespace_target: process-test
|
||||||
register: result
|
register: result
|
||||||
@@ -55,6 +58,7 @@
|
|||||||
parameters:
|
parameters:
|
||||||
NAMESPACE: openshift
|
NAMESPACE: openshift
|
||||||
NAME: test123
|
NAME: test123
|
||||||
|
NGINX_VERSION: "{{ nginx_version }}"
|
||||||
state: absent
|
state: absent
|
||||||
namespace_target: process-test
|
namespace_target: process-test
|
||||||
register: result
|
register: result
|
||||||
|
|||||||
@@ -38,12 +38,12 @@
|
|||||||
name: "{{ pod_name }}"
|
name: "{{ pod_name }}"
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: test-container
|
- name: test-container
|
||||||
image: "{{ prune_registry }}/{{ prune_ns }}/{{ container.name }}:latest"
|
image: "{{ prune_registry }}/{{ prune_ns }}/{{ container.name }}:latest"
|
||||||
command:
|
command:
|
||||||
- /bin/sh
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- while true;do date;sleep 5; done
|
- while true;do date;sleep 5; done
|
||||||
|
|
||||||
- name: Create limit range for images size
|
- name: Create limit range for images size
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
- type: openshift.io/Image
|
- type: openshift.io/Image
|
||||||
max:
|
max:
|
||||||
storage: 1Gi
|
storage: 1Gi
|
||||||
|
|
||||||
- name: Prune images from namespace
|
- name: Prune images from namespace
|
||||||
community.okd.openshift_adm_prune_images:
|
community.okd.openshift_adm_prune_images:
|
||||||
registry_url: "{{ prune_registry }}"
|
registry_url: "{{ prune_registry }}"
|
||||||
@@ -204,27 +204,15 @@
|
|||||||
- stream.resources | length == 1
|
- stream.resources | length == 1
|
||||||
- '"tags" not in stream.resources.0.status'
|
- '"tags" not in stream.resources.0.status'
|
||||||
|
|
||||||
- name: Validate that Image was deleted
|
|
||||||
kubernetes.core.k8s_info:
|
|
||||||
version: image.openshift.io/v1
|
|
||||||
kind: Image
|
|
||||||
name: "{{ is_image_name }}"
|
|
||||||
register: image
|
|
||||||
|
|
||||||
- name: Assert that image was deleted
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- image.resources | length == 0
|
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete namespace
|
- name: Delete namespace
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
name: "{{ prune_ns }}"
|
name: "{{ prune_ns }}"
|
||||||
kind: Namespace
|
kind: Namespace
|
||||||
state: absent
|
state: absent
|
||||||
wait: yes
|
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
when:
|
when:
|
||||||
- registry.public_hostname
|
- registry.public_hostname is not none
|
||||||
|
- registry.public_hostname | length > 0
|
||||||
- registry.check.reached
|
- registry.check.reached
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
app: hello-kubernetes
|
app: hello-kubernetes
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: hello-kubernetes
|
- name: hello-kubernetes
|
||||||
image: docker.io/openshift/hello-openshift
|
image: docker.io/openshift/hello-openshift
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
|
||||||
- name: Create Service
|
- name: Create Service
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
@@ -35,8 +35,8 @@
|
|||||||
namespace: default
|
namespace: default
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- port: 80
|
- port: 80
|
||||||
targetPort: 8080
|
targetPort: 8080
|
||||||
selector:
|
selector:
|
||||||
app: hello-kubernetes
|
app: hello-kubernetes
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,6 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- unknown_kind is successful
|
- unknown_kind is successful
|
||||||
- "'warnings' in unknown_kind"
|
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: remove custom resource
|
- name: remove custom resource
|
||||||
|
|||||||
@@ -22,4 +22,4 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- k8s_no_validate is failed
|
- k8s_no_validate is failed
|
||||||
- "k8s_no_validate.msg == 'kubernetes-validate python library is required to validate resources'"
|
- k8s_no_validate.msg.startswith('Failed to import the required Python library (kubernetes-validate)')
|
||||||
|
|||||||
@@ -64,14 +64,16 @@ okd_dc_triggers:
|
|||||||
|
|
||||||
okd_dc_spec:
|
okd_dc_spec:
|
||||||
template: '{{ k8s_pod_template }}'
|
template: '{{ k8s_pod_template }}'
|
||||||
triggers: '{{ okd_dc_triggers }}'
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: "{{ k8s_pod_name }}"
|
||||||
replicas: 1
|
replicas: 1
|
||||||
strategy:
|
strategy:
|
||||||
type: Recreate
|
type: Recreate
|
||||||
|
|
||||||
okd_dc_template:
|
okd_dc_template:
|
||||||
apiVersion: v1
|
apiVersion: apps/v1
|
||||||
kind: DeploymentConfig
|
kind: Deployment
|
||||||
spec: '{{ okd_dc_spec }}'
|
spec: '{{ okd_dc_spec }}'
|
||||||
|
|
||||||
okd_imagestream_template:
|
okd_imagestream_template:
|
||||||
@@ -83,12 +85,12 @@ okd_imagestream_template:
|
|||||||
lookupPolicy:
|
lookupPolicy:
|
||||||
local: true
|
local: true
|
||||||
tags:
|
tags:
|
||||||
- annotations: null
|
- annotations: null
|
||||||
from:
|
from:
|
||||||
kind: DockerImage
|
kind: DockerImage
|
||||||
name: '{{ image }}'
|
name: '{{ image }}'
|
||||||
name: '{{ image_tag }}'
|
name: '{{ image_tag }}'
|
||||||
referencePolicy:
|
referencePolicy:
|
||||||
type: Source
|
type: Source
|
||||||
|
|
||||||
image_tag: latest
|
image_tag: latest
|
||||||
|
|||||||
+30
-10
@@ -1,9 +1,31 @@
|
|||||||
---
|
---
|
||||||
- name: Verify inventory and connection plugins
|
- name: Create inventory of pods
|
||||||
# This group is created by the openshift_inventory plugin
|
# We need to manually create the inventory of pods now that the inventory plugin has been removed
|
||||||
# It is automatically configured to use the `oc` connection plugin
|
gather_facts: false
|
||||||
|
hosts: localhost
|
||||||
|
connection: local
|
||||||
|
tasks:
|
||||||
|
- name: Get pods
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
kind: Pod
|
||||||
|
namespace: testing
|
||||||
|
register: pods
|
||||||
|
|
||||||
|
- name: Add pods to inventory
|
||||||
|
ansible.builtin.add_host:
|
||||||
|
name: "{{ item.metadata.name }}"
|
||||||
|
groups:
|
||||||
|
- namespace_testing_pods
|
||||||
|
ansible_oc_pod: "{{ item.metadata.name }}"
|
||||||
|
ansible_oc_namespace: "{{ item.metadata.namespace }}"
|
||||||
|
pod_phase: "{{ item.status.phase }}"
|
||||||
|
ansible_remote_tmp: /tmp/.ansible
|
||||||
|
loop: "{{ pods.resources }}"
|
||||||
|
|
||||||
|
- name: Verify connection plugin
|
||||||
hosts: namespace_testing_pods
|
hosts: namespace_testing_pods
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
|
connection: community.okd.oc
|
||||||
vars:
|
vars:
|
||||||
file_content: |
|
file_content: |
|
||||||
Hello world
|
Hello world
|
||||||
@@ -43,20 +65,16 @@
|
|||||||
ansible_python_interpreter: '{{ virtualenv_interpreter }}'
|
ansible_python_interpreter: '{{ virtualenv_interpreter }}'
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
# No explicit `virtualenv:` param is necessary with the following pip tasks.
|
||||||
|
# prepare.yml creates the venv and ansible_python_interpreter sets it.
|
||||||
- pip:
|
- pip:
|
||||||
name: kubernetes-validate==1.12.0
|
name: kubernetes-validate==1.35.0
|
||||||
virtualenv: "{{ virtualenv }}"
|
|
||||||
virtualenv_command: "{{ virtualenv_command }}"
|
|
||||||
virtualenv_site_packages: no
|
|
||||||
|
|
||||||
- import_tasks: tasks/validate_installed.yml
|
- import_tasks: tasks/validate_installed.yml
|
||||||
|
|
||||||
- pip:
|
- pip:
|
||||||
name: kubernetes-validate
|
name: kubernetes-validate
|
||||||
state: absent
|
state: absent
|
||||||
virtualenv: "{{ virtualenv }}"
|
|
||||||
virtualenv_command: "{{ virtualenv_command }}"
|
|
||||||
virtualenv_site_packages: no
|
|
||||||
|
|
||||||
- import_tasks: tasks/validate_not_installed.yml
|
- import_tasks: tasks/validate_not_installed.yml
|
||||||
|
|
||||||
@@ -64,6 +82,7 @@
|
|||||||
- import_tasks: tasks/openshift_adm_prune_auth_clusterroles.yml
|
- import_tasks: tasks/openshift_adm_prune_auth_clusterroles.yml
|
||||||
- import_tasks: tasks/openshift_adm_prune_auth_roles.yml
|
- import_tasks: tasks/openshift_adm_prune_auth_roles.yml
|
||||||
- import_tasks: tasks/openshift_adm_prune_deployments.yml
|
- import_tasks: tasks/openshift_adm_prune_deployments.yml
|
||||||
|
- import_tasks: tasks/openshift_builds.yml
|
||||||
- import_tasks: tasks/openshift_route.yml
|
- import_tasks: tasks/openshift_route.yml
|
||||||
- import_tasks: tasks/openshift_import_images.yml
|
- import_tasks: tasks/openshift_import_images.yml
|
||||||
- import_tasks: tasks/openshift_prune_images.yml
|
- import_tasks: tasks/openshift_prune_images.yml
|
||||||
@@ -76,6 +95,7 @@
|
|||||||
- import_tasks: tasks/openshift_process.yml
|
- import_tasks: tasks/openshift_process.yml
|
||||||
vars:
|
vars:
|
||||||
files_dir: '{{ playbook_dir }}/files'
|
files_dir: '{{ playbook_dir }}/files'
|
||||||
|
nginx_version: 1.22-ubi8
|
||||||
always:
|
always:
|
||||||
- name: Delete namespace
|
- name: Delete namespace
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
|
|||||||
+31
-18
@@ -17,14 +17,15 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = """
|
||||||
author:
|
author:
|
||||||
- xuxinkun
|
- xuxinkun (@xuxinkun)
|
||||||
|
|
||||||
connection: oc
|
name: oc
|
||||||
|
|
||||||
short_description: Execute tasks in pods running on OpenShift.
|
short_description: Execute tasks in pods running on OpenShift.
|
||||||
|
|
||||||
@@ -105,6 +106,15 @@ DOCUMENTATION = '''
|
|||||||
env:
|
env:
|
||||||
- name: K8S_AUTH_TOKEN
|
- name: K8S_AUTH_TOKEN
|
||||||
- name: K8S_AUTH_API_KEY
|
- name: K8S_AUTH_API_KEY
|
||||||
|
oc_local_env_vars:
|
||||||
|
description:
|
||||||
|
- Local environment variable to be passed locally to the oc command line.
|
||||||
|
- Please be aware that this passes information directly on the command line and it could expose sensitive data.
|
||||||
|
default: {}
|
||||||
|
type: dict
|
||||||
|
version_added: 4.0.0
|
||||||
|
vars:
|
||||||
|
- name: ansible_oc_local_env_vars
|
||||||
client_cert:
|
client_cert:
|
||||||
description:
|
description:
|
||||||
- Path to a certificate used to authenticate with the API.
|
- Path to a certificate used to authenticate with the API.
|
||||||
@@ -145,29 +155,32 @@ DOCUMENTATION = '''
|
|||||||
env:
|
env:
|
||||||
- name: K8S_AUTH_VERIFY_SSL
|
- name: K8S_AUTH_VERIFY_SSL
|
||||||
aliases: [ oc_verify_ssl ]
|
aliases: [ oc_verify_ssl ]
|
||||||
'''
|
"""
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.connection.kubectl import Connection as KubectlConnection
|
from ansible_collections.kubernetes.core.plugins.connection.kubectl import (
|
||||||
|
Connection as KubectlConnection,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
CONNECTION_TRANSPORT = 'oc'
|
CONNECTION_TRANSPORT = "oc"
|
||||||
|
|
||||||
CONNECTION_OPTIONS = {
|
CONNECTION_OPTIONS = {
|
||||||
'oc_container': '-c',
|
"oc_container": "-c",
|
||||||
'oc_namespace': '-n',
|
"oc_namespace": "-n",
|
||||||
'oc_kubeconfig': '--kubeconfig',
|
"oc_kubeconfig": "--kubeconfig",
|
||||||
'oc_context': '--context',
|
"oc_context": "--context",
|
||||||
'oc_host': '--server',
|
"oc_host": "--server",
|
||||||
'client_cert': '--client-certificate',
|
"client_cert": "--client-certificate",
|
||||||
'client_key': '--client-key',
|
"client_key": "--client-key",
|
||||||
'ca_cert': '--certificate-authority',
|
"ca_cert": "--certificate-authority",
|
||||||
'validate_certs': '--insecure-skip-tls-verify',
|
"validate_certs": "--insecure-skip-tls-verify",
|
||||||
'oc_token': '--token'
|
"oc_token": "--token",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Connection(KubectlConnection):
|
class Connection(KubectlConnection):
|
||||||
''' Local oc based connections '''
|
"""Local oc based connections"""
|
||||||
|
|
||||||
transport = CONNECTION_TRANSPORT
|
transport = CONNECTION_TRANSPORT
|
||||||
connection_options = CONNECTION_OPTIONS
|
connection_options = CONNECTION_OPTIONS
|
||||||
documentation = DOCUMENTATION
|
documentation = DOCUMENTATION
|
||||||
|
|||||||
@@ -1,204 +0,0 @@
|
|||||||
# Copyright (c) 2018 Ansible Project
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
|
||||||
name: openshift
|
|
||||||
plugin_type: inventory
|
|
||||||
author:
|
|
||||||
- Chris Houseknecht <@chouseknecht>
|
|
||||||
|
|
||||||
short_description: OpenShift inventory source
|
|
||||||
|
|
||||||
description:
|
|
||||||
- Fetch containers, services and routes for one or more clusters
|
|
||||||
- Groups by cluster name, namespace, namespace_services, namespace_pods, namespace_routes, and labels
|
|
||||||
- Uses openshift.(yml|yaml) YAML configuration file to set parameter values.
|
|
||||||
|
|
||||||
options:
|
|
||||||
plugin:
|
|
||||||
description: token that ensures this is a source file for the 'openshift' plugin.
|
|
||||||
required: True
|
|
||||||
choices: ['openshift', 'community.okd.openshift']
|
|
||||||
connections:
|
|
||||||
description:
|
|
||||||
- Optional list of cluster connection settings. If no connections are provided, the default
|
|
||||||
I(~/.kube/config) and active context will be used, and objects will be returned for all namespaces
|
|
||||||
the active user is authorized to access.
|
|
||||||
suboptions:
|
|
||||||
name:
|
|
||||||
description:
|
|
||||||
- Optional name to assign to the cluster. If not provided, a name is constructed from the server
|
|
||||||
and port.
|
|
||||||
kubeconfig:
|
|
||||||
description:
|
|
||||||
- Path to an existing Kubernetes config file. If not provided, and no other connection
|
|
||||||
options are provided, the Kubernetes client will attempt to load the default
|
|
||||||
configuration file from I(~/.kube/config). Can also be specified via K8S_AUTH_KUBECONFIG
|
|
||||||
environment variable.
|
|
||||||
context:
|
|
||||||
description:
|
|
||||||
- The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment
|
|
||||||
variable.
|
|
||||||
host:
|
|
||||||
description:
|
|
||||||
- Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable.
|
|
||||||
api_key:
|
|
||||||
description:
|
|
||||||
- Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment
|
|
||||||
variable.
|
|
||||||
username:
|
|
||||||
description:
|
|
||||||
- Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME
|
|
||||||
environment variable.
|
|
||||||
password:
|
|
||||||
description:
|
|
||||||
- Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD
|
|
||||||
environment variable.
|
|
||||||
client_cert:
|
|
||||||
description:
|
|
||||||
- Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE
|
|
||||||
environment variable.
|
|
||||||
aliases: [ cert_file ]
|
|
||||||
client_key:
|
|
||||||
description:
|
|
||||||
- Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE
|
|
||||||
environment variable.
|
|
||||||
aliases: [ key_file ]
|
|
||||||
ca_cert:
|
|
||||||
description:
|
|
||||||
- Path to a CA certificate used to authenticate with the API. Can also be specified via
|
|
||||||
K8S_AUTH_SSL_CA_CERT environment variable.
|
|
||||||
aliases: [ ssl_ca_cert ]
|
|
||||||
validate_certs:
|
|
||||||
description:
|
|
||||||
- "Whether or not to verify the API server's SSL certificates. Can also be specified via
|
|
||||||
K8S_AUTH_VERIFY_SSL environment variable."
|
|
||||||
type: bool
|
|
||||||
aliases: [ verify_ssl ]
|
|
||||||
namespaces:
|
|
||||||
description:
|
|
||||||
- List of namespaces. If not specified, will fetch all containers for all namespaces user is authorized
|
|
||||||
to access.
|
|
||||||
|
|
||||||
requirements:
|
|
||||||
- "python >= 3.6"
|
|
||||||
- "kubernetes >= 12.0.0"
|
|
||||||
- "PyYAML >= 3.11"
|
|
||||||
'''
|
|
||||||
|
|
||||||
EXAMPLES = '''
|
|
||||||
# File must be named openshift.yaml or openshift.yml
|
|
||||||
|
|
||||||
# Authenticate with token, and return all pods and services for all namespaces
|
|
||||||
plugin: community.okd.openshift
|
|
||||||
connections:
|
|
||||||
- host: https://192.168.64.4:8443
|
|
||||||
api_key: xxxxxxxxxxxxxxxx
|
|
||||||
verify_ssl: false
|
|
||||||
|
|
||||||
# Use default config (~/.kube/config) file and active context, and return objects for a specific namespace
|
|
||||||
plugin: community.okd.openshift
|
|
||||||
connections:
|
|
||||||
- namespaces:
|
|
||||||
- testing
|
|
||||||
|
|
||||||
# Use a custom config file, and a specific context.
|
|
||||||
plugin: community.okd.openshift
|
|
||||||
connections:
|
|
||||||
- kubeconfig: /path/to/config
|
|
||||||
context: 'awx/192-168-64-4:8443/developer'
|
|
||||||
'''
|
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.inventory.k8s import K8sInventoryException, InventoryModule as K8sInventoryModule, format_dynamic_api_exc
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import get_api_client
|
|
||||||
|
|
||||||
try:
|
|
||||||
from kubernetes.dynamic.exceptions import DynamicApiError
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InventoryModule(K8sInventoryModule):
|
|
||||||
NAME = 'community.okd.openshift'
|
|
||||||
|
|
||||||
connection_plugin = 'community.okd.oc'
|
|
||||||
transport = 'oc'
|
|
||||||
|
|
||||||
def fetch_objects(self, connections):
|
|
||||||
super(InventoryModule, self).fetch_objects(connections)
|
|
||||||
|
|
||||||
if connections:
|
|
||||||
if not isinstance(connections, list):
|
|
||||||
raise K8sInventoryException("Expecting connections to be a list.")
|
|
||||||
|
|
||||||
for connection in connections:
|
|
||||||
client = get_api_client(**connection)
|
|
||||||
name = connection.get('name', self.get_default_host_name(client.configuration.host))
|
|
||||||
if connection.get('namespaces'):
|
|
||||||
namespaces = connection['namespaces']
|
|
||||||
else:
|
|
||||||
namespaces = self.get_available_namespaces(client)
|
|
||||||
for namespace in namespaces:
|
|
||||||
self.get_routes_for_namespace(client, name, namespace)
|
|
||||||
else:
|
|
||||||
client = get_api_client()
|
|
||||||
name = self.get_default_host_name(client.configuration.host)
|
|
||||||
namespaces = self.get_available_namespaces(client)
|
|
||||||
for namespace in namespaces:
|
|
||||||
self.get_routes_for_namespace(client, name, namespace)
|
|
||||||
|
|
||||||
def get_routes_for_namespace(self, client, name, namespace):
|
|
||||||
v1_route = client.resources.get(api_version='route.openshift.io/v1', kind='Route')
|
|
||||||
try:
|
|
||||||
obj = v1_route.get(namespace=namespace)
|
|
||||||
except DynamicApiError as exc:
|
|
||||||
self.display.debug(exc)
|
|
||||||
raise K8sInventoryException('Error fetching Routes list: %s' % format_dynamic_api_exc(exc))
|
|
||||||
|
|
||||||
namespace_group = 'namespace_{0}'.format(namespace)
|
|
||||||
namespace_routes_group = '{0}_routes'.format(namespace_group)
|
|
||||||
|
|
||||||
self.inventory.add_group(name)
|
|
||||||
self.inventory.add_group(namespace_group)
|
|
||||||
self.inventory.add_child(name, namespace_group)
|
|
||||||
self.inventory.add_group(namespace_routes_group)
|
|
||||||
self.inventory.add_child(namespace_group, namespace_routes_group)
|
|
||||||
for route in obj.items:
|
|
||||||
route_name = route.metadata.name
|
|
||||||
route_annotations = {} if not route.metadata.annotations else dict(route.metadata.annotations)
|
|
||||||
|
|
||||||
self.inventory.add_host(route_name)
|
|
||||||
|
|
||||||
if route.metadata.labels:
|
|
||||||
# create a group for each label_value
|
|
||||||
for key, value in route.metadata.labels:
|
|
||||||
group_name = 'label_{0}_{1}'.format(key, value)
|
|
||||||
self.inventory.add_group(group_name)
|
|
||||||
self.inventory.add_child(group_name, route_name)
|
|
||||||
route_labels = dict(route.metadata.labels)
|
|
||||||
else:
|
|
||||||
route_labels = {}
|
|
||||||
|
|
||||||
self.inventory.add_child(namespace_routes_group, route_name)
|
|
||||||
|
|
||||||
# add hostvars
|
|
||||||
self.inventory.set_variable(route_name, 'labels', route_labels)
|
|
||||||
self.inventory.set_variable(route_name, 'annotations', route_annotations)
|
|
||||||
self.inventory.set_variable(route_name, 'cluster_name', route.metadata.clusterName)
|
|
||||||
self.inventory.set_variable(route_name, 'object_type', 'route')
|
|
||||||
self.inventory.set_variable(route_name, 'self_link', route.metadata.selfLink)
|
|
||||||
self.inventory.set_variable(route_name, 'resource_version', route.metadata.resourceVersion)
|
|
||||||
self.inventory.set_variable(route_name, 'uid', route.metadata.uid)
|
|
||||||
|
|
||||||
if route.spec.host:
|
|
||||||
self.inventory.set_variable(route_name, 'host', route.spec.host)
|
|
||||||
|
|
||||||
if route.spec.path:
|
|
||||||
self.inventory.set_variable(route_name, 'path', route.spec.path)
|
|
||||||
|
|
||||||
if hasattr(route.spec.port, 'targetPort') and route.spec.port.targetPort:
|
|
||||||
self.inventory.set_variable(route_name, 'port', dict(route.spec.port))
|
|
||||||
+239
-104
@@ -1,94 +1,165 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import operator
|
import operator
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
import traceback
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
AnsibleOpenshiftModule,
|
||||||
K8sAnsibleMixin,
|
|
||||||
get_api_client,
|
|
||||||
)
|
)
|
||||||
from ansible.module_utils._text import to_native
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError, ForbiddenError
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.resource import (
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
create_definitions,
|
||||||
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions import (
|
||||||
|
CoreException,
|
||||||
|
)
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
|
try:
|
||||||
|
from kubernetes.dynamic.exceptions import (
|
||||||
|
DynamicApiError,
|
||||||
|
NotFoundError,
|
||||||
|
ForbiddenError,
|
||||||
|
)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
pass
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
|
|
||||||
TRIGGER_ANNOTATION = 'image.openshift.io/triggers'
|
TRIGGER_ANNOTATION = "image.openshift.io/triggers"
|
||||||
TRIGGER_CONTAINER = re.compile(r"(?P<path>.*)\[((?P<index>[0-9]+)|\?\(@\.name==[\"'\\]*(?P<name>[a-z0-9]([-a-z0-9]*[a-z0-9])?))")
|
TRIGGER_CONTAINER = re.compile(
|
||||||
|
r"(?P<path>.*)\[((?P<index>[0-9]+)|\?\(@\.name==[\"'\\]*(?P<name>[a-z0-9]([-a-z0-9]*[a-z0-9])?))"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OKDRawModule(K8sAnsibleMixin):
|
class OKDRawModule(AnsibleOpenshiftModule):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(OKDRawModule, self).__init__(**kwargs)
|
||||||
|
|
||||||
def __init__(self, module, k8s_kind=None, *args, **kwargs):
|
@property
|
||||||
self.module = module
|
def module(self):
|
||||||
self.client = get_api_client(module=module)
|
return self._module
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.params = self.module.params
|
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.fail = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
super(OKDRawModule, self).__init__(module, *args, **kwargs)
|
def execute_module(self):
|
||||||
|
results = []
|
||||||
|
changed = False
|
||||||
|
|
||||||
self.warnings = []
|
try:
|
||||||
|
definitions = create_definitions(self.params)
|
||||||
|
except Exception as e:
|
||||||
|
msg = "Failed to load resource definition: {0}".format(e)
|
||||||
|
raise CoreException(msg) from e
|
||||||
|
|
||||||
self.kind = k8s_kind or self.params.get('kind')
|
for definition in definitions:
|
||||||
self.api_version = self.params.get('api_version')
|
result = {"changed": False, "result": {}}
|
||||||
self.name = self.params.get('name')
|
warnings = []
|
||||||
self.namespace = self.params.get('namespace')
|
|
||||||
|
|
||||||
self.check_library_version()
|
if self.params.get("state") != "absent":
|
||||||
self.set_resource_definitions(module)
|
existing = None
|
||||||
|
name = definition.get("metadata", {}).get("name")
|
||||||
|
namespace = definition.get("metadata", {}).get("namespace")
|
||||||
|
if definition.get("kind") in ["Project", "ProjectRequest"]:
|
||||||
|
try:
|
||||||
|
resource = self.svc.find_resource(
|
||||||
|
kind=definition.get("kind"),
|
||||||
|
api_version=definition.get("apiVersion", "v1"),
|
||||||
|
)
|
||||||
|
existing = resource.get(
|
||||||
|
name=name, namespace=namespace
|
||||||
|
).to_dict()
|
||||||
|
except (NotFoundError, ForbiddenError):
|
||||||
|
result = self.create_project_request(definition)
|
||||||
|
changed |= result["changed"]
|
||||||
|
results.append(result)
|
||||||
|
continue
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
self.fail_json(
|
||||||
|
msg="Failed to retrieve requested object: {0}".format(
|
||||||
|
exc.body
|
||||||
|
),
|
||||||
|
error=exc.status,
|
||||||
|
status=exc.status,
|
||||||
|
reason=exc.reason,
|
||||||
|
)
|
||||||
|
|
||||||
def perform_action(self, resource, definition):
|
if definition.get("kind") not in ["Project", "ProjectRequest"]:
|
||||||
state = self.params.get('state', None)
|
try:
|
||||||
name = definition['metadata'].get('name')
|
resource = self.svc.find_resource(
|
||||||
namespace = definition['metadata'].get('namespace')
|
kind=definition.get("kind"),
|
||||||
|
api_version=definition.get("apiVersion", "v1"),
|
||||||
|
)
|
||||||
|
existing = resource.get(
|
||||||
|
name=name, namespace=namespace
|
||||||
|
).to_dict()
|
||||||
|
except Exception:
|
||||||
|
existing = None
|
||||||
|
|
||||||
if state != 'absent':
|
if existing:
|
||||||
|
if resource.kind == "DeploymentConfig":
|
||||||
|
if definition.get("spec", {}).get("triggers"):
|
||||||
|
definition = self.resolve_imagestream_triggers(
|
||||||
|
existing, definition
|
||||||
|
)
|
||||||
|
elif (
|
||||||
|
existing["metadata"]
|
||||||
|
.get("annotations", {})
|
||||||
|
.get(TRIGGER_ANNOTATION)
|
||||||
|
):
|
||||||
|
definition = self.resolve_imagestream_trigger_annotation(
|
||||||
|
existing, definition
|
||||||
|
)
|
||||||
|
|
||||||
if resource.kind in ['Project', 'ProjectRequest']:
|
if self.params.get("validate") is not None:
|
||||||
try:
|
warnings = self.validate(definition)
|
||||||
resource.get(name, namespace)
|
|
||||||
except (NotFoundError, ForbiddenError):
|
|
||||||
return self.create_project_request(definition)
|
|
||||||
except DynamicApiError as exc:
|
|
||||||
self.fail_json(msg='Failed to retrieve requested object: {0}'.format(exc.body),
|
|
||||||
error=exc.status, status=exc.status, reason=exc.reason)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
existing = resource.get(name=name, namespace=namespace).to_dict()
|
result = self.perform_action(definition, self.params)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
existing = None
|
try:
|
||||||
|
error = e.result
|
||||||
|
except AttributeError:
|
||||||
|
error = {}
|
||||||
|
try:
|
||||||
|
error["reason"] = e.__cause__.reason
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
error["msg"] = to_native(e)
|
||||||
|
if warnings:
|
||||||
|
error.setdefault("warnings", []).extend(warnings)
|
||||||
|
|
||||||
if existing:
|
if self.params.get("continue_on_error"):
|
||||||
if resource.kind == 'DeploymentConfig':
|
result["error"] = error
|
||||||
if definition.get('spec', {}).get('triggers'):
|
else:
|
||||||
definition = self.resolve_imagestream_triggers(existing, definition)
|
self.fail_json(**error)
|
||||||
elif existing['metadata'].get('annotations', {}).get(TRIGGER_ANNOTATION):
|
|
||||||
definition = self.resolve_imagestream_trigger_annotation(existing, definition)
|
|
||||||
|
|
||||||
return super(OKDRawModule, self).perform_action(resource, definition)
|
if warnings:
|
||||||
|
result.setdefault("warnings", []).extend(warnings)
|
||||||
|
changed |= result["changed"]
|
||||||
|
results.append(result)
|
||||||
|
|
||||||
|
if len(results) == 1:
|
||||||
|
self.exit_json(**results[0])
|
||||||
|
|
||||||
|
self.exit_json(**{"changed": changed, "result": {"results": results}})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_index(desired, objects, keys):
|
def get_index(desired, objects, keys):
|
||||||
""" Iterates over keys, returns the first object from objects where the value of the key
|
"""Iterates over keys, returns the first object from objects where the value of the key
|
||||||
matches the value in desired
|
matches the value in desired
|
||||||
"""
|
"""
|
||||||
# pylint: disable=use-a-generator
|
# pylint: disable=use-a-generator
|
||||||
# Use a generator instead 'all(desired.get(key, True) == item.get(key, False) for key in keys)'
|
# Use a generator instead 'all(desired.get(key, True) == item.get(key, False) for key in keys)'
|
||||||
for i, item in enumerate(objects):
|
for i, item in enumerate(objects):
|
||||||
if item and all([desired.get(key, True) == item.get(key, False) for key in keys]):
|
if item and all(
|
||||||
|
[desired.get(key, True) == item.get(key, False) for key in keys]
|
||||||
|
):
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def resolve_imagestream_trigger_annotation(self, existing, definition):
|
def resolve_imagestream_trigger_annotation(self, existing, definition):
|
||||||
@@ -103,84 +174,148 @@ class OKDRawModule(K8sAnsibleMixin):
|
|||||||
def set_from_fields(d, fields, value):
|
def set_from_fields(d, fields, value):
|
||||||
get_from_fields(d, fields[:-1])[fields[-1]] = value
|
get_from_fields(d, fields[:-1])[fields[-1]] = value
|
||||||
|
|
||||||
if TRIGGER_ANNOTATION in definition['metadata'].get('annotations', {}).keys():
|
if TRIGGER_ANNOTATION in definition["metadata"].get("annotations", {}).keys():
|
||||||
triggers = yaml.safe_load(definition['metadata']['annotations'][TRIGGER_ANNOTATION] or '[]')
|
triggers = yaml.safe_load(
|
||||||
|
definition["metadata"]["annotations"][TRIGGER_ANNOTATION] or "[]"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
triggers = yaml.safe_load(existing['metadata'].get('annotations', '{}').get(TRIGGER_ANNOTATION, '[]'))
|
triggers = yaml.safe_load(
|
||||||
|
existing["metadata"]
|
||||||
|
.get("annotations", "{}")
|
||||||
|
.get(TRIGGER_ANNOTATION, "[]")
|
||||||
|
)
|
||||||
|
|
||||||
if not isinstance(triggers, list):
|
if not isinstance(triggers, list):
|
||||||
return definition
|
return definition
|
||||||
|
|
||||||
for trigger in triggers:
|
for trigger in triggers:
|
||||||
if trigger.get('fieldPath'):
|
if trigger.get("fieldPath"):
|
||||||
parsed = self.parse_trigger_fieldpath(trigger['fieldPath'])
|
parsed = self.parse_trigger_fieldpath(trigger["fieldPath"])
|
||||||
path = parsed.get('path', '').split('.')
|
path = parsed.get("path", "").split(".")
|
||||||
if path:
|
if path:
|
||||||
existing_containers = get_from_fields(existing, path)
|
existing_containers = get_from_fields(existing, path)
|
||||||
new_containers = get_from_fields(definition, path)
|
new_containers = get_from_fields(definition, path)
|
||||||
if parsed.get('name'):
|
if parsed.get("name"):
|
||||||
existing_index = self.get_index({'name': parsed['name']}, existing_containers, ['name'])
|
existing_index = self.get_index(
|
||||||
new_index = self.get_index({'name': parsed['name']}, new_containers, ['name'])
|
{"name": parsed["name"]}, existing_containers, ["name"]
|
||||||
elif parsed.get('index') is not None:
|
)
|
||||||
existing_index = new_index = int(parsed['index'])
|
new_index = self.get_index(
|
||||||
|
{"name": parsed["name"]}, new_containers, ["name"]
|
||||||
|
)
|
||||||
|
elif parsed.get("index") is not None:
|
||||||
|
existing_index = new_index = int(parsed["index"])
|
||||||
else:
|
else:
|
||||||
existing_index = new_index = None
|
existing_index = new_index = None
|
||||||
if existing_index is not None and new_index is not None:
|
if existing_index is not None and new_index is not None:
|
||||||
if existing_index < len(existing_containers) and new_index < len(new_containers):
|
if existing_index < len(
|
||||||
set_from_fields(definition, path + [new_index, 'image'], get_from_fields(existing, path + [existing_index, 'image']))
|
existing_containers
|
||||||
|
) and new_index < len(new_containers):
|
||||||
|
set_from_fields(
|
||||||
|
definition,
|
||||||
|
path + [new_index, "image"],
|
||||||
|
get_from_fields(
|
||||||
|
existing, path + [existing_index, "image"]
|
||||||
|
),
|
||||||
|
)
|
||||||
return definition
|
return definition
|
||||||
|
|
||||||
def resolve_imagestream_triggers(self, existing, definition):
|
def resolve_imagestream_triggers(self, existing, definition):
|
||||||
|
existing_triggers = existing.get("spec", {}).get("triggers")
|
||||||
existing_triggers = existing.get('spec', {}).get('triggers')
|
new_triggers = definition["spec"]["triggers"]
|
||||||
new_triggers = definition['spec']['triggers']
|
existing_containers = (
|
||||||
existing_containers = existing.get('spec', {}).get('template', {}).get('spec', {}).get('containers', [])
|
existing.get("spec", {})
|
||||||
new_containers = definition.get('spec', {}).get('template', {}).get('spec', {}).get('containers', [])
|
.get("template", {})
|
||||||
|
.get("spec", {})
|
||||||
|
.get("containers", [])
|
||||||
|
)
|
||||||
|
new_containers = (
|
||||||
|
definition.get("spec", {})
|
||||||
|
.get("template", {})
|
||||||
|
.get("spec", {})
|
||||||
|
.get("containers", [])
|
||||||
|
)
|
||||||
for i, trigger in enumerate(new_triggers):
|
for i, trigger in enumerate(new_triggers):
|
||||||
if trigger.get('type') == 'ImageChange' and trigger.get('imageChangeParams'):
|
if trigger.get("type") == "ImageChange" and trigger.get(
|
||||||
names = trigger['imageChangeParams'].get('containerNames', [])
|
"imageChangeParams"
|
||||||
|
):
|
||||||
|
names = trigger["imageChangeParams"].get("containerNames", [])
|
||||||
for name in names:
|
for name in names:
|
||||||
old_container_index = self.get_index({'name': name}, existing_containers, ['name'])
|
old_container_index = self.get_index(
|
||||||
new_container_index = self.get_index({'name': name}, new_containers, ['name'])
|
{"name": name}, existing_containers, ["name"]
|
||||||
if old_container_index is not None and new_container_index is not None:
|
)
|
||||||
image = existing['spec']['template']['spec']['containers'][old_container_index]['image']
|
new_container_index = self.get_index(
|
||||||
definition['spec']['template']['spec']['containers'][new_container_index]['image'] = image
|
{"name": name}, new_containers, ["name"]
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
old_container_index is not None
|
||||||
|
and new_container_index is not None
|
||||||
|
):
|
||||||
|
image = existing["spec"]["template"]["spec"]["containers"][
|
||||||
|
old_container_index
|
||||||
|
]["image"]
|
||||||
|
definition["spec"]["template"]["spec"]["containers"][
|
||||||
|
new_container_index
|
||||||
|
]["image"] = image
|
||||||
|
|
||||||
existing_index = self.get_index(trigger['imageChangeParams'],
|
existing_index = self.get_index(
|
||||||
[x.get('imageChangeParams') for x in existing_triggers],
|
trigger["imageChangeParams"],
|
||||||
['containerNames'])
|
[x.get("imageChangeParams") for x in existing_triggers],
|
||||||
|
["containerNames"],
|
||||||
|
)
|
||||||
if existing_index is not None:
|
if existing_index is not None:
|
||||||
existing_image = existing_triggers[existing_index].get('imageChangeParams', {}).get('lastTriggeredImage')
|
existing_image = (
|
||||||
|
existing_triggers[existing_index]
|
||||||
|
.get("imageChangeParams", {})
|
||||||
|
.get("lastTriggeredImage")
|
||||||
|
)
|
||||||
if existing_image:
|
if existing_image:
|
||||||
definition['spec']['triggers'][i]['imageChangeParams']['lastTriggeredImage'] = existing_image
|
definition["spec"]["triggers"][i]["imageChangeParams"][
|
||||||
existing_from = existing_triggers[existing_index].get('imageChangeParams', {}).get('from', {})
|
"lastTriggeredImage"
|
||||||
new_from = trigger['imageChangeParams'].get('from', {})
|
] = existing_image
|
||||||
existing_namespace = existing_from.get('namespace')
|
existing_from = (
|
||||||
existing_name = existing_from.get('name', False)
|
existing_triggers[existing_index]
|
||||||
new_name = new_from.get('name', True)
|
.get("imageChangeParams", {})
|
||||||
add_namespace = existing_namespace and 'namespace' not in new_from.keys() and existing_name == new_name
|
.get("from", {})
|
||||||
|
)
|
||||||
|
new_from = trigger["imageChangeParams"].get("from", {})
|
||||||
|
existing_namespace = existing_from.get("namespace")
|
||||||
|
existing_name = existing_from.get("name", False)
|
||||||
|
new_name = new_from.get("name", True)
|
||||||
|
add_namespace = (
|
||||||
|
existing_namespace
|
||||||
|
and "namespace" not in new_from.keys()
|
||||||
|
and existing_name == new_name
|
||||||
|
)
|
||||||
if add_namespace:
|
if add_namespace:
|
||||||
definition['spec']['triggers'][i]['imageChangeParams']['from']['namespace'] = existing_from['namespace']
|
definition["spec"]["triggers"][i]["imageChangeParams"][
|
||||||
|
"from"
|
||||||
|
]["namespace"] = existing_from["namespace"]
|
||||||
|
|
||||||
return definition
|
return definition
|
||||||
|
|
||||||
def parse_trigger_fieldpath(self, expression):
|
def parse_trigger_fieldpath(self, expression):
|
||||||
parsed = TRIGGER_CONTAINER.search(expression).groupdict()
|
parsed = TRIGGER_CONTAINER.search(expression).groupdict()
|
||||||
if parsed.get('index'):
|
if parsed.get("index"):
|
||||||
parsed['index'] = int(parsed['index'])
|
parsed["index"] = int(parsed["index"])
|
||||||
return parsed
|
return parsed
|
||||||
|
|
||||||
def create_project_request(self, definition):
|
def create_project_request(self, definition):
|
||||||
definition['kind'] = 'ProjectRequest'
|
definition["kind"] = "ProjectRequest"
|
||||||
result = {'changed': False, 'result': {}}
|
result = {"changed": False, "result": {}}
|
||||||
resource = self.find_resource('ProjectRequest', definition['apiVersion'], fail=True)
|
resource = self.svc.find_resource(
|
||||||
|
kind="ProjectRequest", api_version=definition["apiVersion"], fail=True
|
||||||
|
)
|
||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
try:
|
try:
|
||||||
k8s_obj = resource.create(definition)
|
k8s_obj = resource.create(definition)
|
||||||
result['result'] = k8s_obj.to_dict()
|
result["result"] = k8s_obj.to_dict()
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
self.fail_json(msg="Failed to create object: {0}".format(exc.body),
|
self.fail_json(
|
||||||
error=exc.status, status=exc.status, reason=exc.reason)
|
msg="Failed to create object: {0}".format(exc.body),
|
||||||
result['changed'] = True
|
error=exc.status,
|
||||||
result['method'] = 'create'
|
status=exc.status,
|
||||||
|
reason=exc.reason,
|
||||||
|
)
|
||||||
|
result["changed"] = True
|
||||||
|
result["method"] = "create"
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -1,22 +1,14 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import traceback
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
|
AnsibleOpenshiftModule,
|
||||||
try:
|
)
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
|
||||||
K8sAnsibleMixin,
|
|
||||||
get_api_client,
|
|
||||||
)
|
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes import client
|
from kubernetes import client
|
||||||
@@ -25,50 +17,40 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftAdmPruneAuth(K8sAnsibleMixin):
|
class OpenShiftAdmPruneAuth(AnsibleOpenshiftModule):
|
||||||
def __init__(self, module):
|
def __init__(self, **kwargs):
|
||||||
self.module = module
|
super(OpenShiftAdmPruneAuth, self).__init__(**kwargs)
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.module.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception),
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftAdmPruneAuth, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
|
|
||||||
def prune_resource_binding(self, kind, api_version, ref_kind, ref_namespace_names, propagation_policy=None):
|
|
||||||
|
|
||||||
|
def prune_resource_binding(
|
||||||
|
self, kind, api_version, ref_kind, ref_namespace_names, propagation_policy=None
|
||||||
|
):
|
||||||
resource = self.find_resource(kind=kind, api_version=api_version, fail=True)
|
resource = self.find_resource(kind=kind, api_version=api_version, fail=True)
|
||||||
candidates = []
|
candidates = []
|
||||||
for ref_namespace, ref_name in ref_namespace_names:
|
for ref_namespace, ref_name in ref_namespace_names:
|
||||||
try:
|
try:
|
||||||
result = resource.get(name=None, namespace=ref_namespace)
|
result = resource.get(name=None, namespace=ref_namespace)
|
||||||
result = result.to_dict()
|
result = result.to_dict()
|
||||||
result = result.get('items') if 'items' in result else [result]
|
result = result.get("items") if "items" in result else [result]
|
||||||
for obj in result:
|
for obj in result:
|
||||||
namespace = obj['metadata'].get('namespace', None)
|
namespace = obj["metadata"].get("namespace", None)
|
||||||
name = obj['metadata'].get('name')
|
name = obj["metadata"].get("name")
|
||||||
if ref_kind and obj['roleRef']['kind'] != ref_kind:
|
if ref_kind and obj["roleRef"]["kind"] != ref_kind:
|
||||||
# skip this binding as the roleRef.kind does not match
|
# skip this binding as the roleRef.kind does not match
|
||||||
continue
|
continue
|
||||||
if obj['roleRef']['name'] == ref_name:
|
if obj["roleRef"]["name"] == ref_name:
|
||||||
# select this binding as the roleRef.name match
|
# select this binding as the roleRef.name match
|
||||||
candidates.append((namespace, name))
|
candidates.append((namespace, name))
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
continue
|
continue
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
msg = "Failed to get {kind} resource due to: {msg}".format(kind=kind, msg=exc.body)
|
msg = "Failed to get {kind} resource due to: {msg}".format(
|
||||||
|
kind=kind, msg=exc.body
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = "Failed to get {kind} due to: {msg}".format(kind=kind, msg=to_native(e))
|
msg = "Failed to get {kind} due to: {msg}".format(
|
||||||
|
kind=kind, msg=to_native(e)
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
|
|
||||||
if len(candidates) == 0 or self.check_mode:
|
if len(candidates) == 0 or self.check_mode:
|
||||||
@@ -80,24 +62,29 @@ class OpenShiftAdmPruneAuth(K8sAnsibleMixin):
|
|||||||
|
|
||||||
for namespace, name in candidates:
|
for namespace, name in candidates:
|
||||||
try:
|
try:
|
||||||
result = resource.delete(name=name, namespace=namespace, body=delete_options)
|
result = resource.delete(
|
||||||
|
name=name, namespace=namespace, body=delete_options
|
||||||
|
)
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
msg = "Failed to delete {kind} {namespace}/{name} due to: {msg}".format(kind=kind, namespace=namespace, name=name, msg=exc.body)
|
msg = "Failed to delete {kind} {namespace}/{name} due to: {msg}".format(
|
||||||
|
kind=kind, namespace=namespace, name=name, msg=exc.body
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = "Failed to delete {kind} {namespace}/{name} due to: {msg}".format(kind=kind, namespace=namespace, name=name, msg=to_native(e))
|
msg = "Failed to delete {kind} {namespace}/{name} due to: {msg}".format(
|
||||||
|
kind=kind, namespace=namespace, name=name, msg=to_native(e)
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
return [y if x is None else x + "/" + y for x, y in candidates]
|
return [y if x is None else x + "/" + y for x, y in candidates]
|
||||||
|
|
||||||
def update_resource_binding(self, ref_kind, ref_names, namespaced=False):
|
def update_resource_binding(self, ref_kind, ref_names, namespaced=False):
|
||||||
|
kind = "ClusterRoleBinding"
|
||||||
kind = 'ClusterRoleBinding'
|
api_version = "rbac.authorization.k8s.io/v1"
|
||||||
api_version = "rbac.authorization.k8s.io/v1",
|
|
||||||
if namespaced:
|
if namespaced:
|
||||||
kind = "RoleBinding"
|
kind = "RoleBinding"
|
||||||
resource = self.find_resource(kind=kind, api_version=api_version, fail=True)
|
resource = self.find_resource(kind=kind, api_version=api_version, fail=True)
|
||||||
result = resource.get(name=None, namespace=None).to_dict()
|
result = resource.get(name=None, namespace=None).to_dict()
|
||||||
result = result.get('items') if 'items' in result else [result]
|
result = result.get("items") if "items" in result else [result]
|
||||||
|
|
||||||
if len(result) == 0:
|
if len(result) == 0:
|
||||||
return [], False
|
return [], False
|
||||||
@@ -105,29 +92,40 @@ class OpenShiftAdmPruneAuth(K8sAnsibleMixin):
|
|||||||
def _update_user_group(binding_namespace, subjects):
|
def _update_user_group(binding_namespace, subjects):
|
||||||
users, groups = [], []
|
users, groups = [], []
|
||||||
for x in subjects:
|
for x in subjects:
|
||||||
if x['kind'] == 'User':
|
if x["kind"] == "User":
|
||||||
users.append(x['name'])
|
users.append(x["name"])
|
||||||
elif x['kind'] == 'Group':
|
elif x["kind"] == "Group":
|
||||||
groups.append(x['name'])
|
groups.append(x["name"])
|
||||||
elif x['kind'] == 'ServiceAccount':
|
elif x["kind"] == "ServiceAccount":
|
||||||
namespace = binding_namespace
|
namespace = binding_namespace
|
||||||
if x.get('namespace') is not None:
|
if x.get("namespace") is not None:
|
||||||
namespace = x.get('namespace')
|
namespace = x.get("namespace")
|
||||||
if namespace is not None:
|
if namespace is not None:
|
||||||
users.append("system:serviceaccount:%s:%s" % (namespace, x['name']))
|
users.append(
|
||||||
|
"system:serviceaccount:%s:%s" % (namespace, x["name"])
|
||||||
|
)
|
||||||
return users, groups
|
return users, groups
|
||||||
|
|
||||||
candidates = []
|
candidates = []
|
||||||
changed = False
|
changed = False
|
||||||
for item in result:
|
for item in result:
|
||||||
subjects = item.get('subjects', [])
|
subjects = item.get("subjects", [])
|
||||||
retainedSubjects = [x for x in subjects if x['kind'] == ref_kind and x['name'] in ref_names]
|
retainedSubjects = [
|
||||||
|
x for x in subjects if x["kind"] == ref_kind and x["name"] in ref_names
|
||||||
|
]
|
||||||
if len(subjects) != len(retainedSubjects):
|
if len(subjects) != len(retainedSubjects):
|
||||||
updated_binding = item
|
updated_binding = item
|
||||||
updated_binding['subjects'] = retainedSubjects
|
updated_binding["subjects"] = retainedSubjects
|
||||||
binding_namespace = item['metadata'].get('namespace', None)
|
binding_namespace = item["metadata"].get("namespace", None)
|
||||||
updated_binding['userNames'], updated_binding['groupNames'] = _update_user_group(binding_namespace, retainedSubjects)
|
(
|
||||||
candidates.append(binding_namespace + "/" + item['metadata']['name'] if binding_namespace else item['metadata']['name'])
|
updated_binding["userNames"],
|
||||||
|
updated_binding["groupNames"],
|
||||||
|
) = _update_user_group(binding_namespace, retainedSubjects)
|
||||||
|
candidates.append(
|
||||||
|
binding_namespace + "/" + item["metadata"]["name"]
|
||||||
|
if binding_namespace
|
||||||
|
else item["metadata"]["name"]
|
||||||
|
)
|
||||||
changed = True
|
changed = True
|
||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
try:
|
try:
|
||||||
@@ -138,20 +136,25 @@ class OpenShiftAdmPruneAuth(K8sAnsibleMixin):
|
|||||||
return candidates, changed
|
return candidates, changed
|
||||||
|
|
||||||
def update_security_context(self, ref_names, key):
|
def update_security_context(self, ref_names, key):
|
||||||
params = {'kind': 'SecurityContextConstraints', 'api_version': 'security.openshift.io/v1'}
|
params = {
|
||||||
|
"kind": "SecurityContextConstraints",
|
||||||
|
"api_version": "security.openshift.io/v1",
|
||||||
|
}
|
||||||
sccs = self.kubernetes_facts(**params)
|
sccs = self.kubernetes_facts(**params)
|
||||||
if not sccs['api_found']:
|
if not sccs["api_found"]:
|
||||||
self.fail_json(msg=sccs['msg'])
|
self.fail_json(msg=sccs["msg"])
|
||||||
sccs = sccs.get('resources')
|
sccs = sccs.get("resources")
|
||||||
|
|
||||||
candidates = []
|
candidates = []
|
||||||
changed = False
|
changed = False
|
||||||
resource = self.find_resource(kind="SecurityContextConstraints", api_version="security.openshift.io/v1")
|
resource = self.find_resource(
|
||||||
|
kind="SecurityContextConstraints", api_version="security.openshift.io/v1"
|
||||||
|
)
|
||||||
for item in sccs:
|
for item in sccs:
|
||||||
subjects = item.get(key, [])
|
subjects = item.get(key, [])
|
||||||
retainedSubjects = [x for x in subjects if x not in ref_names]
|
retainedSubjects = [x for x in subjects if x not in ref_names]
|
||||||
if len(subjects) != len(retainedSubjects):
|
if len(subjects) != len(retainedSubjects):
|
||||||
candidates.append(item['metadata']['name'])
|
candidates.append(item["metadata"]["name"])
|
||||||
changed = True
|
changed = True
|
||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
upd_sec_ctx = item
|
upd_sec_ctx = item
|
||||||
@@ -164,94 +167,116 @@ class OpenShiftAdmPruneAuth(K8sAnsibleMixin):
|
|||||||
return candidates, changed
|
return candidates, changed
|
||||||
|
|
||||||
def auth_prune_roles(self):
|
def auth_prune_roles(self):
|
||||||
params = {'kind': 'Role', 'api_version': 'rbac.authorization.k8s.io/v1', 'namespace': self.params.get('namespace')}
|
params = {
|
||||||
for attr in ('name', 'label_selectors'):
|
"kind": "Role",
|
||||||
|
"api_version": "rbac.authorization.k8s.io/v1",
|
||||||
|
"namespace": self.params.get("namespace"),
|
||||||
|
}
|
||||||
|
for attr in ("name", "label_selectors"):
|
||||||
if self.params.get(attr):
|
if self.params.get(attr):
|
||||||
params[attr] = self.params.get(attr)
|
params[attr] = self.params.get(attr)
|
||||||
|
|
||||||
result = self.kubernetes_facts(**params)
|
result = self.kubernetes_facts(**params)
|
||||||
if not result['api_found']:
|
if not result["api_found"]:
|
||||||
self.fail_json(msg=result['msg'])
|
self.fail_json(msg=result["msg"])
|
||||||
|
|
||||||
roles = result.get('resources')
|
roles = result.get("resources")
|
||||||
if len(roles) == 0:
|
if len(roles) == 0:
|
||||||
self.exit_json(changed=False, msg="No candidate rolebinding to prune from namespace %s." % self.params.get('namespace'))
|
self.exit_json(
|
||||||
|
changed=False,
|
||||||
|
msg="No candidate rolebinding to prune from namespace %s."
|
||||||
|
% self.params.get("namespace"),
|
||||||
|
)
|
||||||
|
|
||||||
ref_roles = [(x['metadata']['namespace'], x['metadata']['name']) for x in roles]
|
ref_roles = [(x["metadata"]["namespace"], x["metadata"]["name"]) for x in roles]
|
||||||
candidates = self.prune_resource_binding(kind="RoleBinding",
|
candidates = self.prune_resource_binding(
|
||||||
api_version="rbac.authorization.k8s.io/v1",
|
kind="RoleBinding",
|
||||||
ref_kind="Role",
|
api_version="rbac.authorization.k8s.io/v1",
|
||||||
ref_namespace_names=ref_roles,
|
ref_kind="Role",
|
||||||
propagation_policy='Foreground')
|
ref_namespace_names=ref_roles,
|
||||||
|
propagation_policy="Foreground",
|
||||||
|
)
|
||||||
if len(candidates) == 0:
|
if len(candidates) == 0:
|
||||||
self.exit_json(changed=False, role_binding=candidates)
|
self.exit_json(changed=False, role_binding=candidates)
|
||||||
|
|
||||||
self.exit_json(changed=True, role_binding=candidates)
|
self.exit_json(changed=True, role_binding=candidates)
|
||||||
|
|
||||||
def auth_prune_clusterroles(self):
|
def auth_prune_clusterroles(self):
|
||||||
params = {'kind': 'ClusterRole', 'api_version': 'rbac.authorization.k8s.io/v1'}
|
params = {"kind": "ClusterRole", "api_version": "rbac.authorization.k8s.io/v1"}
|
||||||
for attr in ('name', 'label_selectors'):
|
for attr in ("name", "label_selectors"):
|
||||||
if self.params.get(attr):
|
if self.params.get(attr):
|
||||||
params[attr] = self.params.get(attr)
|
params[attr] = self.params.get(attr)
|
||||||
|
|
||||||
result = self.kubernetes_facts(**params)
|
result = self.kubernetes_facts(**params)
|
||||||
if not result['api_found']:
|
if not result["api_found"]:
|
||||||
self.fail_json(msg=result['msg'])
|
self.fail_json(msg=result["msg"])
|
||||||
|
|
||||||
clusterroles = result.get('resources')
|
clusterroles = result.get("resources")
|
||||||
if len(clusterroles) == 0:
|
if len(clusterroles) == 0:
|
||||||
self.exit_json(changed=False, msg="No clusterroles found matching input criteria.")
|
self.exit_json(
|
||||||
|
changed=False, msg="No clusterroles found matching input criteria."
|
||||||
|
)
|
||||||
|
|
||||||
ref_clusterroles = [(None, x['metadata']['name']) for x in clusterroles]
|
ref_clusterroles = [(None, x["metadata"]["name"]) for x in clusterroles]
|
||||||
|
|
||||||
# Prune ClusterRoleBinding
|
# Prune ClusterRoleBinding
|
||||||
candidates_cluster_binding = self.prune_resource_binding(kind="ClusterRoleBinding",
|
candidates_cluster_binding = self.prune_resource_binding(
|
||||||
api_version="rbac.authorization.k8s.io/v1",
|
kind="ClusterRoleBinding",
|
||||||
ref_kind=None,
|
api_version="rbac.authorization.k8s.io/v1",
|
||||||
ref_namespace_names=ref_clusterroles)
|
ref_kind=None,
|
||||||
|
ref_namespace_names=ref_clusterroles,
|
||||||
|
)
|
||||||
|
|
||||||
# Prune Role Binding
|
# Prune Role Binding
|
||||||
candidates_namespaced_binding = self.prune_resource_binding(kind="RoleBinding",
|
candidates_namespaced_binding = self.prune_resource_binding(
|
||||||
api_version="rbac.authorization.k8s.io/v1",
|
kind="RoleBinding",
|
||||||
ref_kind='ClusterRole',
|
api_version="rbac.authorization.k8s.io/v1",
|
||||||
ref_namespace_names=ref_clusterroles)
|
ref_kind="ClusterRole",
|
||||||
|
ref_namespace_names=ref_clusterroles,
|
||||||
|
)
|
||||||
|
|
||||||
self.exit_json(changed=True,
|
self.exit_json(
|
||||||
cluster_role_binding=candidates_cluster_binding,
|
changed=True,
|
||||||
role_binding=candidates_namespaced_binding)
|
cluster_role_binding=candidates_cluster_binding,
|
||||||
|
role_binding=candidates_namespaced_binding,
|
||||||
|
)
|
||||||
|
|
||||||
def list_groups(self, params=None):
|
def list_groups(self, params=None):
|
||||||
options = {'kind': 'Group', 'api_version': 'user.openshift.io/v1'}
|
options = {"kind": "Group", "api_version": "user.openshift.io/v1"}
|
||||||
if params:
|
if params:
|
||||||
for attr in ('name', 'label_selectors'):
|
for attr in ("name", "label_selectors"):
|
||||||
if params.get(attr):
|
if params.get(attr):
|
||||||
options[attr] = params.get(attr)
|
options[attr] = params.get(attr)
|
||||||
return self.kubernetes_facts(**options)
|
return self.kubernetes_facts(**options)
|
||||||
|
|
||||||
def auth_prune_users(self):
|
def auth_prune_users(self):
|
||||||
params = {'kind': 'User', 'api_version': 'user.openshift.io/v1'}
|
params = {"kind": "User", "api_version": "user.openshift.io/v1"}
|
||||||
for attr in ('name', 'label_selectors'):
|
for attr in ("name", "label_selectors"):
|
||||||
if self.params.get(attr):
|
if self.params.get(attr):
|
||||||
params[attr] = self.params.get(attr)
|
params[attr] = self.params.get(attr)
|
||||||
|
|
||||||
users = self.kubernetes_facts(**params)
|
users = self.kubernetes_facts(**params)
|
||||||
if len(users) == 0:
|
if len(users) == 0:
|
||||||
self.exit_json(changed=False, msg="No resource type 'User' found matching input criteria.")
|
self.exit_json(
|
||||||
|
changed=False,
|
||||||
|
msg="No resource type 'User' found matching input criteria.",
|
||||||
|
)
|
||||||
|
|
||||||
names = [x['metadata']['name'] for x in users]
|
names = [x["metadata"]["name"] for x in users]
|
||||||
changed = False
|
changed = False
|
||||||
# Remove the user role binding
|
# Remove the user role binding
|
||||||
rolebinding, changed_role = self.update_resource_binding(ref_kind="User",
|
rolebinding, changed_role = self.update_resource_binding(
|
||||||
ref_names=names,
|
ref_kind="User", ref_names=names, namespaced=True
|
||||||
namespaced=True)
|
)
|
||||||
changed = changed or changed_role
|
changed = changed or changed_role
|
||||||
# Remove the user cluster role binding
|
# Remove the user cluster role binding
|
||||||
clusterrolesbinding, changed_cr = self.update_resource_binding(ref_kind="User",
|
clusterrolesbinding, changed_cr = self.update_resource_binding(
|
||||||
ref_names=names)
|
ref_kind="User", ref_names=names
|
||||||
|
)
|
||||||
changed = changed or changed_cr
|
changed = changed or changed_cr
|
||||||
|
|
||||||
# Remove the user from security context constraints
|
# Remove the user from security context constraints
|
||||||
sccs, changed_sccs = self.update_security_context(names, 'users')
|
sccs, changed_sccs = self.update_security_context(names, "users")
|
||||||
changed = changed or changed_sccs
|
changed = changed or changed_sccs
|
||||||
|
|
||||||
# Remove the user from groups
|
# Remove the user from groups
|
||||||
@@ -259,14 +284,14 @@ class OpenShiftAdmPruneAuth(K8sAnsibleMixin):
|
|||||||
deleted_groups = []
|
deleted_groups = []
|
||||||
resource = self.find_resource(kind="Group", api_version="user.openshift.io/v1")
|
resource = self.find_resource(kind="Group", api_version="user.openshift.io/v1")
|
||||||
for grp in groups:
|
for grp in groups:
|
||||||
subjects = grp.get('users', [])
|
subjects = grp.get("users", [])
|
||||||
retainedSubjects = [x for x in subjects if x not in names]
|
retainedSubjects = [x for x in subjects if x not in names]
|
||||||
if len(subjects) != len(retainedSubjects):
|
if len(subjects) != len(retainedSubjects):
|
||||||
deleted_groups.append(grp['metadata']['name'])
|
deleted_groups.append(grp["metadata"]["name"])
|
||||||
changed = True
|
changed = True
|
||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
upd_group = grp
|
upd_group = grp
|
||||||
upd_group.update({'users': retainedSubjects})
|
upd_group.update({"users": retainedSubjects})
|
||||||
try:
|
try:
|
||||||
resource.apply(upd_group, namespace=None)
|
resource.apply(upd_group, namespace=None)
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
@@ -274,62 +299,82 @@ class OpenShiftAdmPruneAuth(K8sAnsibleMixin):
|
|||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
|
|
||||||
# Remove the user's OAuthClientAuthorizations
|
# Remove the user's OAuthClientAuthorizations
|
||||||
oauth = self.kubernetes_facts(kind='OAuthClientAuthorization', api_version='oauth.openshift.io/v1')
|
oauth = self.kubernetes_facts(
|
||||||
|
kind="OAuthClientAuthorization", api_version="oauth.openshift.io/v1"
|
||||||
|
)
|
||||||
deleted_auths = []
|
deleted_auths = []
|
||||||
resource = self.find_resource(kind="OAuthClientAuthorization", api_version="oauth.openshift.io/v1")
|
resource = self.find_resource(
|
||||||
|
kind="OAuthClientAuthorization", api_version="oauth.openshift.io/v1"
|
||||||
|
)
|
||||||
for authorization in oauth:
|
for authorization in oauth:
|
||||||
if authorization.get('userName', None) in names:
|
if authorization.get("userName", None) in names:
|
||||||
auth_name = authorization['metadata']['name']
|
auth_name = authorization["metadata"]["name"]
|
||||||
deleted_auths.append(auth_name)
|
deleted_auths.append(auth_name)
|
||||||
changed = True
|
changed = True
|
||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
try:
|
try:
|
||||||
resource.delete(name=auth_name, namespace=None, body=client.V1DeleteOptions())
|
resource.delete(
|
||||||
|
name=auth_name,
|
||||||
|
namespace=None,
|
||||||
|
body=client.V1DeleteOptions(),
|
||||||
|
)
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
msg = "Failed to delete OAuthClientAuthorization {name} due to: {msg}".format(name=auth_name, msg=exc.body)
|
msg = "Failed to delete OAuthClientAuthorization {name} due to: {msg}".format(
|
||||||
|
name=auth_name, msg=exc.body
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = "Failed to delete OAuthClientAuthorization {name} due to: {msg}".format(name=auth_name, msg=to_native(e))
|
msg = "Failed to delete OAuthClientAuthorization {name} due to: {msg}".format(
|
||||||
|
name=auth_name, msg=to_native(e)
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
|
|
||||||
self.exit_json(changed=changed,
|
self.exit_json(
|
||||||
cluster_role_binding=clusterrolesbinding,
|
changed=changed,
|
||||||
role_binding=rolebinding,
|
cluster_role_binding=clusterrolesbinding,
|
||||||
security_context_constraints=sccs,
|
role_binding=rolebinding,
|
||||||
authorization=deleted_auths,
|
security_context_constraints=sccs,
|
||||||
group=deleted_groups)
|
authorization=deleted_auths,
|
||||||
|
group=deleted_groups,
|
||||||
|
)
|
||||||
|
|
||||||
def auth_prune_groups(self):
|
def auth_prune_groups(self):
|
||||||
groups = self.list_groups(params=self.params)
|
groups = self.list_groups(params=self.params)
|
||||||
if len(groups) == 0:
|
if len(groups) == 0:
|
||||||
self.exit_json(changed=False, result="No resource type 'Group' found matching input criteria.")
|
self.exit_json(
|
||||||
|
changed=False,
|
||||||
|
result="No resource type 'Group' found matching input criteria.",
|
||||||
|
)
|
||||||
|
|
||||||
names = [x['metadata']['name'] for x in groups]
|
names = [x["metadata"]["name"] for x in groups]
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
# Remove the groups role binding
|
# Remove the groups role binding
|
||||||
rolebinding, changed_role = self.update_resource_binding(ref_kind="Group",
|
rolebinding, changed_role = self.update_resource_binding(
|
||||||
ref_names=names,
|
ref_kind="Group", ref_names=names, namespaced=True
|
||||||
namespaced=True)
|
)
|
||||||
changed = changed or changed_role
|
changed = changed or changed_role
|
||||||
# Remove the groups cluster role binding
|
# Remove the groups cluster role binding
|
||||||
clusterrolesbinding, changed_cr = self.update_resource_binding(ref_kind="Group",
|
clusterrolesbinding, changed_cr = self.update_resource_binding(
|
||||||
ref_names=names)
|
ref_kind="Group", ref_names=names
|
||||||
|
)
|
||||||
changed = changed or changed_cr
|
changed = changed or changed_cr
|
||||||
# Remove the groups security context constraints
|
# Remove the groups security context constraints
|
||||||
sccs, changed_sccs = self.update_security_context(names, 'groups')
|
sccs, changed_sccs = self.update_security_context(names, "groups")
|
||||||
changed = changed or changed_sccs
|
changed = changed or changed_sccs
|
||||||
|
|
||||||
self.exit_json(changed=changed,
|
self.exit_json(
|
||||||
cluster_role_binding=clusterrolesbinding,
|
changed=changed,
|
||||||
role_binding=rolebinding,
|
cluster_role_binding=clusterrolesbinding,
|
||||||
security_context_constraints=sccs)
|
role_binding=rolebinding,
|
||||||
|
security_context_constraints=sccs,
|
||||||
|
)
|
||||||
|
|
||||||
def execute_module(self):
|
def execute_module(self):
|
||||||
auth_prune = {
|
auth_prune = {
|
||||||
'roles': self.auth_prune_roles,
|
"roles": self.auth_prune_roles,
|
||||||
'clusterroles': self.auth_prune_clusterroles,
|
"clusterroles": self.auth_prune_clusterroles,
|
||||||
'users': self.auth_prune_users,
|
"users": self.auth_prune_users,
|
||||||
'groups': self.auth_prune_groups,
|
"groups": self.auth_prune_groups,
|
||||||
}
|
}
|
||||||
auth_prune[self.params.get('resource')]()
|
auth_prune[self.params.get("resource")]()
|
||||||
|
|||||||
@@ -1,23 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
import traceback
|
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
try:
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
AnsibleOpenshiftModule,
|
||||||
K8sAnsibleMixin,
|
)
|
||||||
get_api_client,
|
|
||||||
)
|
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes import client
|
from kubernetes import client
|
||||||
@@ -32,7 +25,9 @@ def get_deploymentconfig_for_replicationcontroller(replica_controller):
|
|||||||
# This is set on replication controller pod template by deployer controller.
|
# This is set on replication controller pod template by deployer controller.
|
||||||
DeploymentConfigAnnotation = "openshift.io/deployment-config.name"
|
DeploymentConfigAnnotation = "openshift.io/deployment-config.name"
|
||||||
try:
|
try:
|
||||||
deploymentconfig_name = replica_controller['metadata']['annotations'].get(DeploymentConfigAnnotation)
|
deploymentconfig_name = replica_controller["metadata"]["annotations"].get(
|
||||||
|
DeploymentConfigAnnotation
|
||||||
|
)
|
||||||
if deploymentconfig_name is None or deploymentconfig_name == "":
|
if deploymentconfig_name is None or deploymentconfig_name == "":
|
||||||
return None
|
return None
|
||||||
return deploymentconfig_name
|
return deploymentconfig_name
|
||||||
@@ -40,51 +35,42 @@ def get_deploymentconfig_for_replicationcontroller(replica_controller):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftAdmPruneDeployment(K8sAnsibleMixin):
|
class OpenShiftAdmPruneDeployment(AnsibleOpenshiftModule):
|
||||||
def __init__(self, module):
|
def __init__(self, **kwargs):
|
||||||
self.module = module
|
super(OpenShiftAdmPruneDeployment, self).__init__(**kwargs)
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.module.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception),
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftAdmPruneDeployment, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
|
|
||||||
def filter_replication_controller(self, replicacontrollers):
|
def filter_replication_controller(self, replicacontrollers):
|
||||||
def _deployment(obj):
|
def _deployment(obj):
|
||||||
return get_deploymentconfig_for_replicationcontroller(obj) is not None
|
return get_deploymentconfig_for_replicationcontroller(obj) is not None
|
||||||
|
|
||||||
def _zeroReplicaSize(obj):
|
def _zeroReplicaSize(obj):
|
||||||
return obj['spec']['replicas'] == 0 and obj['status']['replicas'] == 0
|
return obj["spec"]["replicas"] == 0 and obj["status"]["replicas"] == 0
|
||||||
|
|
||||||
def _complete_failed(obj):
|
def _complete_failed(obj):
|
||||||
DeploymentStatusAnnotation = "openshift.io/deployment.phase"
|
DeploymentStatusAnnotation = "openshift.io/deployment.phase"
|
||||||
try:
|
try:
|
||||||
# validate that replication controller status is either 'Complete' or 'Failed'
|
# validate that replication controller status is either 'Complete' or 'Failed'
|
||||||
deployment_phase = obj['metadata']['annotations'].get(DeploymentStatusAnnotation)
|
deployment_phase = obj["metadata"]["annotations"].get(
|
||||||
return deployment_phase in ('Failed', 'Complete')
|
DeploymentStatusAnnotation
|
||||||
|
)
|
||||||
|
return deployment_phase in ("Failed", "Complete")
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _younger(obj):
|
def _younger(obj):
|
||||||
creation_timestamp = datetime.strptime(obj['metadata']['creationTimestamp'], '%Y-%m-%dT%H:%M:%SZ')
|
creation_timestamp = datetime.strptime(
|
||||||
|
obj["metadata"]["creationTimestamp"], "%Y-%m-%dT%H:%M:%SZ"
|
||||||
|
)
|
||||||
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||||
age = (now - creation_timestamp).seconds / 60
|
age = (now - creation_timestamp).seconds / 60
|
||||||
return age > self.params['keep_younger_than']
|
return age > self.params["keep_younger_than"]
|
||||||
|
|
||||||
def _orphan(obj):
|
def _orphan(obj):
|
||||||
try:
|
try:
|
||||||
# verify if the deploymentconfig associated to the replication controller is still existing
|
# verify if the deploymentconfig associated to the replication controller is still existing
|
||||||
deploymentconfig_name = get_deploymentconfig_for_replicationcontroller(obj)
|
deploymentconfig_name = get_deploymentconfig_for_replicationcontroller(
|
||||||
|
obj
|
||||||
|
)
|
||||||
params = dict(
|
params = dict(
|
||||||
kind="DeploymentConfig",
|
kind="DeploymentConfig",
|
||||||
api_version="apps.openshift.io/v1",
|
api_version="apps.openshift.io/v1",
|
||||||
@@ -92,14 +78,14 @@ class OpenShiftAdmPruneDeployment(K8sAnsibleMixin):
|
|||||||
namespace=obj["metadata"]["name"],
|
namespace=obj["metadata"]["name"],
|
||||||
)
|
)
|
||||||
exists = self.kubernetes_facts(**params)
|
exists = self.kubernetes_facts(**params)
|
||||||
return not (exists.get['api_found'] and len(exists['resources']) > 0)
|
return not (exists.get["api_found"] and len(exists["resources"]) > 0)
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
predicates = [_deployment, _zeroReplicaSize, _complete_failed]
|
predicates = [_deployment, _zeroReplicaSize, _complete_failed]
|
||||||
if self.params['orphans']:
|
if self.params["orphans"]:
|
||||||
predicates.append(_orphan)
|
predicates.append(_orphan)
|
||||||
if self.params['keep_younger_than']:
|
if self.params["keep_younger_than"]:
|
||||||
predicates.append(_younger)
|
predicates.append(_younger)
|
||||||
|
|
||||||
results = replicacontrollers.copy()
|
results = replicacontrollers.copy()
|
||||||
@@ -107,10 +93,10 @@ class OpenShiftAdmPruneDeployment(K8sAnsibleMixin):
|
|||||||
results = filter(pred, results)
|
results = filter(pred, results)
|
||||||
return list(results)
|
return list(results)
|
||||||
|
|
||||||
def execute(self):
|
def execute_module(self):
|
||||||
# list replicationcontroller candidate for pruning
|
# list replicationcontroller candidate for pruning
|
||||||
kind = 'ReplicationController'
|
kind = "ReplicationController"
|
||||||
api_version = 'v1'
|
api_version = "v1"
|
||||||
resource = self.find_resource(kind=kind, api_version=api_version, fail=True)
|
resource = self.find_resource(kind=kind, api_version=api_version, fail=True)
|
||||||
|
|
||||||
# Get ReplicationController
|
# Get ReplicationController
|
||||||
@@ -126,7 +112,7 @@ class OpenShiftAdmPruneDeployment(K8sAnsibleMixin):
|
|||||||
self.exit_json(changed=False, replication_controllers=[])
|
self.exit_json(changed=False, replication_controllers=[])
|
||||||
|
|
||||||
changed = True
|
changed = True
|
||||||
delete_options = client.V1DeleteOptions(propagation_policy='Background')
|
delete_options = client.V1DeleteOptions(propagation_policy="Background")
|
||||||
replication_controllers = []
|
replication_controllers = []
|
||||||
for replica in candidates:
|
for replica in candidates:
|
||||||
try:
|
try:
|
||||||
@@ -134,12 +120,18 @@ class OpenShiftAdmPruneDeployment(K8sAnsibleMixin):
|
|||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
name = replica["metadata"]["name"]
|
name = replica["metadata"]["name"]
|
||||||
namespace = replica["metadata"]["namespace"]
|
namespace = replica["metadata"]["namespace"]
|
||||||
result = resource.delete(name=name, namespace=namespace, body=delete_options).to_dict()
|
result = resource.delete(
|
||||||
|
name=name, namespace=namespace, body=delete_options
|
||||||
|
).to_dict()
|
||||||
replication_controllers.append(result)
|
replication_controllers.append(result)
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
msg = "Failed to delete ReplicationController {namespace}/{name} due to: {msg}".format(namespace=namespace, name=name, msg=exc.body)
|
msg = "Failed to delete ReplicationController {namespace}/{name} due to: {msg}".format(
|
||||||
|
namespace=namespace, name=name, msg=exc.body
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = "Failed to delete ReplicationController {namespace}/{name} due to: {msg}".format(namespace=namespace, name=name, msg=to_native(e))
|
msg = "Failed to delete ReplicationController {namespace}/{name} due to: {msg}".format(
|
||||||
|
namespace=namespace, name=name, msg=to_native(e)
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
self.exit_json(changed=changed, replication_controllers=replication_controllers)
|
self.exit_json(changed=changed, replication_controllers=replication_controllers)
|
||||||
|
|||||||
@@ -1,26 +1,18 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
from datetime import datetime, timezone, timedelta
|
from datetime import datetime, timezone, timedelta
|
||||||
import traceback
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
from ansible.module_utils.parsing.convert_bool import boolean
|
from ansible.module_utils.parsing.convert_bool import boolean
|
||||||
from ansible.module_utils.six import iteritems
|
|
||||||
|
|
||||||
try:
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
AnsibleOpenshiftModule,
|
||||||
K8sAnsibleMixin,
|
)
|
||||||
get_api_client,
|
|
||||||
)
|
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_images_common import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_images_common import (
|
||||||
OpenShiftAnalyzeImageStream,
|
OpenShiftAnalyzeImageStream,
|
||||||
@@ -39,7 +31,7 @@ try:
|
|||||||
from kubernetes.dynamic.exceptions import (
|
from kubernetes.dynamic.exceptions import (
|
||||||
DynamicApiError,
|
DynamicApiError,
|
||||||
NotFoundError,
|
NotFoundError,
|
||||||
ApiException
|
ApiException,
|
||||||
)
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
@@ -76,18 +68,20 @@ def determine_host_registry(module, images, image_streams):
|
|||||||
managed_images = list(filter(_f_managed_images, images))
|
managed_images = list(filter(_f_managed_images, images))
|
||||||
|
|
||||||
# Be sure to pick up the newest managed image which should have an up to date information
|
# Be sure to pick up the newest managed image which should have an up to date information
|
||||||
sorted_images = sorted(managed_images,
|
sorted_images = sorted(
|
||||||
key=lambda x: x["metadata"]["creationTimestamp"],
|
managed_images, key=lambda x: x["metadata"]["creationTimestamp"], reverse=True
|
||||||
reverse=True)
|
)
|
||||||
docker_image_ref = ""
|
docker_image_ref = ""
|
||||||
if len(sorted_images) > 0:
|
if len(sorted_images) > 0:
|
||||||
docker_image_ref = sorted_images[0].get("dockerImageReference", "")
|
docker_image_ref = sorted_images[0].get("dockerImageReference", "")
|
||||||
else:
|
else:
|
||||||
# 2nd try to get the pull spec from any image stream
|
# 2nd try to get the pull spec from any image stream
|
||||||
# Sorting by creation timestamp may not get us up to date info. Modification time would be much
|
# Sorting by creation timestamp may not get us up to date info. Modification time would be much
|
||||||
sorted_image_streams = sorted(image_streams,
|
sorted_image_streams = sorted(
|
||||||
key=lambda x: x["metadata"]["creationTimestamp"],
|
image_streams,
|
||||||
reverse=True)
|
key=lambda x: x["metadata"]["creationTimestamp"],
|
||||||
|
reverse=True,
|
||||||
|
)
|
||||||
for i_stream in sorted_image_streams:
|
for i_stream in sorted_image_streams:
|
||||||
docker_image_ref = i_stream["status"].get("dockerImageRepository", "")
|
docker_image_ref = i_stream["status"].get("dockerImageRepository", "")
|
||||||
if len(docker_image_ref) > 0:
|
if len(docker_image_ref) > 0:
|
||||||
@@ -97,55 +91,28 @@ def determine_host_registry(module, images, image_streams):
|
|||||||
module.exit_json(changed=False, result="no managed image found")
|
module.exit_json(changed=False, result="no managed image found")
|
||||||
|
|
||||||
result, error = parse_docker_image_ref(docker_image_ref, module)
|
result, error = parse_docker_image_ref(docker_image_ref, module)
|
||||||
return result['hostname']
|
return result["hostname"]
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
class OpenShiftAdmPruneImages(AnsibleOpenshiftModule):
|
||||||
def __init__(self, module):
|
def __init__(self, **kwargs):
|
||||||
self.module = module
|
super(OpenShiftAdmPruneImages, self).__init__(**kwargs)
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception),
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftAdmPruneImages, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
try:
|
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
except DynamicApiError as e:
|
|
||||||
self.fail_json(
|
|
||||||
msg="Failed to get kubernetes client.",
|
|
||||||
reason=e.reason,
|
|
||||||
status=e.status,
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
self.fail_json(
|
|
||||||
msg="Failed to get kubernetes client.",
|
|
||||||
error=to_native(e)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.max_creation_timestamp = self.get_max_creation_timestamp()
|
self.max_creation_timestamp = self.get_max_creation_timestamp()
|
||||||
self._rest_client = None
|
self._rest_client = None
|
||||||
self.registryhost = self.params.get('registry_url')
|
self.registryhost = self.params.get("registry_url")
|
||||||
self.changed = False
|
self.changed = False
|
||||||
|
|
||||||
def list_objects(self):
|
def list_objects(self):
|
||||||
result = {}
|
result = {}
|
||||||
for kind, version in iteritems(ApiConfiguration):
|
for kind, version in ApiConfiguration.items():
|
||||||
namespace = None
|
namespace = None
|
||||||
if self.params.get("namespace") and kind.lower() == "imagestream":
|
if self.params.get("namespace") and kind.lower() == "imagestream":
|
||||||
namespace = self.params.get("namespace")
|
namespace = self.params.get("namespace")
|
||||||
try:
|
try:
|
||||||
result[kind] = self.kubernetes_facts(kind=kind,
|
result[kind] = self.kubernetes_facts(
|
||||||
api_version=version,
|
kind=kind, api_version=version, namespace=namespace
|
||||||
namespace=namespace).get('resources')
|
).get("resources")
|
||||||
except DynamicApiError as e:
|
except DynamicApiError as e:
|
||||||
self.fail_json(
|
self.fail_json(
|
||||||
msg="An error occurred while trying to list objects.",
|
msg="An error occurred while trying to list objects.",
|
||||||
@@ -155,7 +122,7 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail_json(
|
self.fail_json(
|
||||||
msg="An error occurred while trying to list objects.",
|
msg="An error occurred while trying to list objects.",
|
||||||
error=to_native(e)
|
error=to_native(e),
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -170,8 +137,8 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
def rest_client(self):
|
def rest_client(self):
|
||||||
if not self._rest_client:
|
if not self._rest_client:
|
||||||
configuration = copy.deepcopy(self.client.configuration)
|
configuration = copy.deepcopy(self.client.configuration)
|
||||||
validate_certs = self.params.get('registry_validate_certs')
|
validate_certs = self.params.get("registry_validate_certs")
|
||||||
ssl_ca_cert = self.params.get('registry_ca_cert')
|
ssl_ca_cert = self.params.get("registry_ca_cert")
|
||||||
if validate_certs is not None:
|
if validate_certs is not None:
|
||||||
configuration.verify_ssl = validate_certs
|
configuration.verify_ssl = validate_certs
|
||||||
if ssl_ca_cert is not None:
|
if ssl_ca_cert is not None:
|
||||||
@@ -182,7 +149,9 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
|
|
||||||
def delete_from_registry(self, url):
|
def delete_from_registry(self, url):
|
||||||
try:
|
try:
|
||||||
response = self.rest_client.DELETE(url=url, headers=self.client.configuration.api_key)
|
response = self.rest_client.DELETE(
|
||||||
|
url=url, headers=self.client.configuration.api_key
|
||||||
|
)
|
||||||
if response.status == 404:
|
if response.status == 404:
|
||||||
# Unable to delete layer
|
# Unable to delete layer
|
||||||
return None
|
return None
|
||||||
@@ -192,8 +161,9 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
if response.status != 202 and response.status != 204:
|
if response.status != 202 and response.status != 204:
|
||||||
self.fail_json(
|
self.fail_json(
|
||||||
msg="Delete URL {0}: Unexpected status code in response: {1}".format(
|
msg="Delete URL {0}: Unexpected status code in response: {1}".format(
|
||||||
response.status, url),
|
response.status, url
|
||||||
reason=response.reason
|
),
|
||||||
|
reason=response.reason,
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
except ApiException as e:
|
except ApiException as e:
|
||||||
@@ -237,12 +207,10 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
result = definition
|
result = definition
|
||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
try:
|
try:
|
||||||
result = self.client.request(
|
result = self.request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/apis/{api_version}/namespaces/{namespace}/imagestreams/{name}/status".format(
|
"/apis/{api_version}/namespaces/{namespace}/imagestreams/{name}/status".format(
|
||||||
api_version=api_version,
|
api_version=api_version, namespace=namespace, name=name
|
||||||
namespace=namespace,
|
|
||||||
name=name
|
|
||||||
),
|
),
|
||||||
body=definition,
|
body=definition,
|
||||||
content_type="application/json",
|
content_type="application/json",
|
||||||
@@ -273,11 +241,10 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
pass
|
pass
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
self.fail_json(
|
self.fail_json(
|
||||||
msg="Failed to delete object %s/%s due to: %s" % (
|
msg="Failed to delete object %s/%s due to: %s"
|
||||||
kind, name, exc.body
|
% (kind, name, exc.body),
|
||||||
),
|
|
||||||
reason=exc.reason,
|
reason=exc.reason,
|
||||||
status=exc.status
|
status=exc.status,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
existing = resource.get(name=name)
|
existing = resource.get(name=name)
|
||||||
@@ -321,9 +288,11 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if idx == 0:
|
if idx == 0:
|
||||||
istag = "%s/%s:%s" % (stream_namespace,
|
istag = "%s/%s:%s" % (
|
||||||
stream_name,
|
stream_namespace,
|
||||||
tag_event_list["tag"])
|
stream_name,
|
||||||
|
tag_event_list["tag"],
|
||||||
|
)
|
||||||
if istag in self.used_tags:
|
if istag in self.used_tags:
|
||||||
# keeping because tag is used
|
# keeping because tag is used
|
||||||
filtered_items.append(item)
|
filtered_items.append(item)
|
||||||
@@ -338,20 +307,20 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
|
|
||||||
image = self.image_mapping[item["image"]]
|
image = self.image_mapping[item["image"]]
|
||||||
# check prune over limit size
|
# check prune over limit size
|
||||||
if prune_over_size_limit and not self.exceeds_limits(stream_namespace, image):
|
if prune_over_size_limit and not self.exceeds_limits(
|
||||||
|
stream_namespace, image
|
||||||
|
):
|
||||||
filtered_items.append(item)
|
filtered_items.append(item)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
image_ref = "%s/%s@%s" % (stream_namespace,
|
image_ref = "%s/%s@%s" % (stream_namespace, stream_name, item["image"])
|
||||||
stream_name,
|
|
||||||
item["image"])
|
|
||||||
if image_ref in self.used_images:
|
if image_ref in self.used_images:
|
||||||
# keeping because tag is used
|
# keeping because tag is used
|
||||||
filtered_items.append(item)
|
filtered_items.append(item)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
images_to_delete.append(item["image"])
|
images_to_delete.append(item["image"])
|
||||||
if self.params.get('prune_registry'):
|
if self.params.get("prune_registry"):
|
||||||
manifests_to_delete.append(image["metadata"]["name"])
|
manifests_to_delete.append(image["metadata"]["name"])
|
||||||
path = stream_namespace + "/" + stream_name
|
path = stream_namespace + "/" + stream_name
|
||||||
image_blobs, err = get_image_blobs(image)
|
image_blobs, err = get_image_blobs(image)
|
||||||
@@ -361,21 +330,25 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
return filtered_items, manifests_to_delete, images_to_delete
|
return filtered_items, manifests_to_delete, images_to_delete
|
||||||
|
|
||||||
def prune_image_streams(self, stream):
|
def prune_image_streams(self, stream):
|
||||||
name = stream['metadata']['namespace'] + "/" + stream['metadata']['name']
|
name = stream["metadata"]["namespace"] + "/" + stream["metadata"]["name"]
|
||||||
if is_too_young_object(stream, self.max_creation_timestamp):
|
if is_too_young_object(stream, self.max_creation_timestamp):
|
||||||
# keeping all images because of image stream too young
|
# keeping all images because of image stream too young
|
||||||
return None, []
|
return None, []
|
||||||
facts = self.kubernetes_facts(kind="ImageStream",
|
facts = self.kubernetes_facts(
|
||||||
api_version=ApiConfiguration.get("ImageStream"),
|
kind="ImageStream",
|
||||||
name=stream["metadata"]["name"],
|
api_version=ApiConfiguration.get("ImageStream"),
|
||||||
namespace=stream["metadata"]["namespace"])
|
name=stream["metadata"]["name"],
|
||||||
image_stream = facts.get('resources')
|
namespace=stream["metadata"]["namespace"],
|
||||||
|
)
|
||||||
|
image_stream = facts.get("resources")
|
||||||
if len(image_stream) != 1:
|
if len(image_stream) != 1:
|
||||||
# skipping because it does not exist anymore
|
# skipping because it does not exist anymore
|
||||||
return None, []
|
return None, []
|
||||||
stream = image_stream[0]
|
stream = image_stream[0]
|
||||||
namespace = self.params.get("namespace")
|
namespace = self.params.get("namespace")
|
||||||
stream_to_update = not namespace or (stream["metadata"]["namespace"] == namespace)
|
stream_to_update = not namespace or (
|
||||||
|
stream["metadata"]["namespace"] == namespace
|
||||||
|
)
|
||||||
|
|
||||||
manifests_to_delete, images_to_delete = [], []
|
manifests_to_delete, images_to_delete = [], []
|
||||||
deleted_items = False
|
deleted_items = False
|
||||||
@@ -387,9 +360,9 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
(
|
(
|
||||||
filtered_tag_event,
|
filtered_tag_event,
|
||||||
tag_manifests_to_delete,
|
tag_manifests_to_delete,
|
||||||
tag_images_to_delete
|
tag_images_to_delete,
|
||||||
) = self.prune_image_stream_tag(stream, tag_event_list)
|
) = self.prune_image_stream_tag(stream, tag_event_list)
|
||||||
stream['status']['tags'][idx]['items'] = filtered_tag_event
|
stream["status"]["tags"][idx]["items"] = filtered_tag_event
|
||||||
manifests_to_delete += tag_manifests_to_delete
|
manifests_to_delete += tag_manifests_to_delete
|
||||||
images_to_delete += tag_images_to_delete
|
images_to_delete += tag_images_to_delete
|
||||||
deleted_items = deleted_items or (len(tag_images_to_delete) > 0)
|
deleted_items = deleted_items or (len(tag_images_to_delete) > 0)
|
||||||
@@ -397,11 +370,11 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
# Deleting tags without items
|
# Deleting tags without items
|
||||||
tags = []
|
tags = []
|
||||||
for tag in stream["status"].get("tags", []):
|
for tag in stream["status"].get("tags", []):
|
||||||
if tag['items'] is None or len(tag['items']) == 0:
|
if tag["items"] is None or len(tag["items"]) == 0:
|
||||||
continue
|
continue
|
||||||
tags.append(tag)
|
tags.append(tag)
|
||||||
|
|
||||||
stream['status']['tags'] = tags
|
stream["status"]["tags"] = tags
|
||||||
result = None
|
result = None
|
||||||
# Update ImageStream
|
# Update ImageStream
|
||||||
if stream_to_update:
|
if stream_to_update:
|
||||||
@@ -438,19 +411,23 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
|
|
||||||
def execute_module(self):
|
def execute_module(self):
|
||||||
resources = self.list_objects()
|
resources = self.list_objects()
|
||||||
if not self.check_mode and self.params.get('prune_registry'):
|
if not self.check_mode and self.params.get("prune_registry"):
|
||||||
if not self.registryhost:
|
if not self.registryhost:
|
||||||
self.registryhost = determine_host_registry(self.module, resources['Image'], resources['ImageStream'])
|
self.registryhost = determine_host_registry(
|
||||||
|
self.module, resources["Image"], resources["ImageStream"]
|
||||||
|
)
|
||||||
# validate that host has a scheme
|
# validate that host has a scheme
|
||||||
if "://" not in self.registryhost:
|
if "://" not in self.registryhost:
|
||||||
self.registryhost = "https://" + self.registryhost
|
self.registryhost = "https://" + self.registryhost
|
||||||
# Analyze Image Streams
|
# Analyze Image Streams
|
||||||
analyze_ref = OpenShiftAnalyzeImageStream(
|
analyze_ref = OpenShiftAnalyzeImageStream(
|
||||||
ignore_invalid_refs=self.params.get('ignore_invalid_refs'),
|
ignore_invalid_refs=self.params.get("ignore_invalid_refs"),
|
||||||
max_creation_timestamp=self.max_creation_timestamp,
|
max_creation_timestamp=self.max_creation_timestamp,
|
||||||
module=self.module
|
module=self.module,
|
||||||
|
)
|
||||||
|
self.used_tags, self.used_images, error = analyze_ref.analyze_image_stream(
|
||||||
|
resources
|
||||||
)
|
)
|
||||||
self.used_tags, self.used_images, error = analyze_ref.analyze_image_stream(resources)
|
|
||||||
if error:
|
if error:
|
||||||
self.fail_json(msg=error)
|
self.fail_json(msg=error)
|
||||||
|
|
||||||
@@ -471,16 +448,20 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
updated_image_streams = []
|
updated_image_streams = []
|
||||||
deleted_tags_images = []
|
deleted_tags_images = []
|
||||||
updated_is_mapping = {}
|
updated_is_mapping = {}
|
||||||
for stream in resources['ImageStream']:
|
for stream in resources["ImageStream"]:
|
||||||
result, images_to_delete = self.prune_image_streams(stream)
|
result, images_to_delete = self.prune_image_streams(stream)
|
||||||
if result:
|
if result:
|
||||||
updated_is_mapping[result["metadata"]["namespace"] + "/" + result["metadata"]["name"]] = result
|
updated_is_mapping[
|
||||||
|
result["metadata"]["namespace"] + "/" + result["metadata"]["name"]
|
||||||
|
] = result
|
||||||
updated_image_streams.append(result)
|
updated_image_streams.append(result)
|
||||||
deleted_tags_images += images_to_delete
|
deleted_tags_images += images_to_delete
|
||||||
|
|
||||||
# Create a list with images referenced on image stream
|
# Create a list with images referenced on image stream
|
||||||
self.referenced_images = []
|
self.referenced_images = []
|
||||||
for item in self.kubernetes_facts(kind="ImageStream", api_version="image.openshift.io/v1")["resources"]:
|
for item in self.kubernetes_facts(
|
||||||
|
kind="ImageStream", api_version="image.openshift.io/v1"
|
||||||
|
)["resources"]:
|
||||||
name = "%s/%s" % (item["metadata"]["namespace"], item["metadata"]["name"])
|
name = "%s/%s" % (item["metadata"]["namespace"], item["metadata"]["name"])
|
||||||
if name in updated_is_mapping:
|
if name in updated_is_mapping:
|
||||||
item = updated_is_mapping[name]
|
item = updated_is_mapping[name]
|
||||||
@@ -489,7 +470,7 @@ class OpenShiftAdmPruneImages(K8sAnsibleMixin):
|
|||||||
|
|
||||||
# Stage 2: delete images
|
# Stage 2: delete images
|
||||||
images = []
|
images = []
|
||||||
images_to_delete = [x["metadata"]["name"] for x in resources['Image']]
|
images_to_delete = [x["metadata"]["name"] for x in resources["Image"]]
|
||||||
if self.params.get("namespace") is not None:
|
if self.params.get("namespace") is not None:
|
||||||
# When namespace is defined, prune only images that were referenced by ImageStream
|
# When namespace is defined, prune only images that were referenced by ImageStream
|
||||||
# from the corresponding namespace
|
# from the corresponding namespace
|
||||||
|
|||||||
@@ -0,0 +1,424 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
from datetime import datetime, timezone, timedelta
|
||||||
|
import time
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
|
AnsibleOpenshiftModule,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from kubernetes.dynamic.exceptions import DynamicApiError
|
||||||
|
except ImportError as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class OpenShiftBuilds(AnsibleOpenshiftModule):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(OpenShiftBuilds, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
def get_build_config(self, name, namespace):
|
||||||
|
params = dict(
|
||||||
|
kind="BuildConfig",
|
||||||
|
api_version="build.openshift.io/v1",
|
||||||
|
name=name,
|
||||||
|
namespace=namespace,
|
||||||
|
)
|
||||||
|
result = self.kubernetes_facts(**params)
|
||||||
|
return result["resources"]
|
||||||
|
|
||||||
|
def clone_build(self, name, namespace, request):
|
||||||
|
try:
|
||||||
|
result = self.request(
|
||||||
|
method="POST",
|
||||||
|
path="/apis/build.openshift.io/v1/namespaces/{namespace}/builds/{name}/clone".format(
|
||||||
|
namespace=namespace, name=name
|
||||||
|
),
|
||||||
|
body=request,
|
||||||
|
content_type="application/json",
|
||||||
|
)
|
||||||
|
return result.to_dict()
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
msg = "Failed to clone Build %s/%s due to: %s" % (namespace, name, exc.body)
|
||||||
|
self.fail_json(msg=msg, status=exc.status, reason=exc.reason)
|
||||||
|
except Exception as e:
|
||||||
|
msg = "Failed to clone Build %s/%s due to: %s" % (
|
||||||
|
namespace,
|
||||||
|
name,
|
||||||
|
to_native(e),
|
||||||
|
)
|
||||||
|
self.fail_json(msg=msg, error=to_native(e), exception=e)
|
||||||
|
|
||||||
|
def instantiate_build_config(self, name, namespace, request):
|
||||||
|
try:
|
||||||
|
result = self.request(
|
||||||
|
method="POST",
|
||||||
|
path="/apis/build.openshift.io/v1/namespaces/{namespace}/buildconfigs/{name}/instantiate".format(
|
||||||
|
namespace=namespace, name=name
|
||||||
|
),
|
||||||
|
body=request,
|
||||||
|
content_type="application/json",
|
||||||
|
)
|
||||||
|
return result.to_dict()
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
msg = "Failed to instantiate BuildConfig %s/%s due to: %s" % (
|
||||||
|
namespace,
|
||||||
|
name,
|
||||||
|
exc.body,
|
||||||
|
)
|
||||||
|
self.fail_json(msg=msg, status=exc.status, reason=exc.reason)
|
||||||
|
except Exception as e:
|
||||||
|
msg = "Failed to instantiate BuildConfig %s/%s due to: %s" % (
|
||||||
|
namespace,
|
||||||
|
name,
|
||||||
|
to_native(e),
|
||||||
|
)
|
||||||
|
self.fail_json(msg=msg, error=to_native(e), exception=e)
|
||||||
|
|
||||||
|
def start_build(self):
|
||||||
|
result = None
|
||||||
|
name = self.params.get("build_config_name")
|
||||||
|
if not name:
|
||||||
|
name = self.params.get("build_name")
|
||||||
|
|
||||||
|
build_request = {
|
||||||
|
"kind": "BuildRequest",
|
||||||
|
"apiVersion": "build.openshift.io/v1",
|
||||||
|
"metadata": {"name": name},
|
||||||
|
"triggeredBy": [{"message": "Manually triggered"}],
|
||||||
|
}
|
||||||
|
|
||||||
|
# Overrides incremental
|
||||||
|
incremental = self.params.get("incremental")
|
||||||
|
if incremental is not None:
|
||||||
|
build_request.update(
|
||||||
|
{"sourceStrategyOptions": {"incremental": incremental}}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Environment variable
|
||||||
|
if self.params.get("env_vars"):
|
||||||
|
build_request.update({"env": self.params.get("env_vars")})
|
||||||
|
|
||||||
|
# Docker strategy option
|
||||||
|
if self.params.get("build_args"):
|
||||||
|
build_request.update(
|
||||||
|
{
|
||||||
|
"dockerStrategyOptions": {
|
||||||
|
"buildArgs": self.params.get("build_args")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# caching option
|
||||||
|
no_cache = self.params.get("no_cache")
|
||||||
|
if no_cache is not None:
|
||||||
|
build_request.update(
|
||||||
|
{
|
||||||
|
"dockerStrategyOptions": {"noCache": no_cache},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# commit
|
||||||
|
if self.params.get("commit"):
|
||||||
|
build_request.update(
|
||||||
|
{"revision": {"git": {"commit": self.params.get("commit")}}}
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.params.get("build_config_name"):
|
||||||
|
# Instantiate Build from Build config
|
||||||
|
result = self.instantiate_build_config(
|
||||||
|
name=self.params.get("build_config_name"),
|
||||||
|
namespace=self.params.get("namespace"),
|
||||||
|
request=build_request,
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Re-run Build
|
||||||
|
result = self.clone_build(
|
||||||
|
name=self.params.get("build_name"),
|
||||||
|
namespace=self.params.get("namespace"),
|
||||||
|
request=build_request,
|
||||||
|
)
|
||||||
|
|
||||||
|
if result and self.params.get("wait"):
|
||||||
|
start = datetime.now()
|
||||||
|
|
||||||
|
def _total_wait_time():
|
||||||
|
return (datetime.now() - start).seconds
|
||||||
|
|
||||||
|
wait_timeout = self.params.get("wait_timeout")
|
||||||
|
wait_sleep = self.params.get("wait_sleep")
|
||||||
|
last_status_phase = None
|
||||||
|
while _total_wait_time() < wait_timeout:
|
||||||
|
params = dict(
|
||||||
|
kind=result["kind"],
|
||||||
|
api_version=result["apiVersion"],
|
||||||
|
name=result["metadata"]["name"],
|
||||||
|
namespace=result["metadata"]["namespace"],
|
||||||
|
)
|
||||||
|
facts = self.kubernetes_facts(**params)
|
||||||
|
if len(facts["resources"]) > 0:
|
||||||
|
last_status_phase = facts["resources"][0]["status"]["phase"]
|
||||||
|
if last_status_phase == "Complete":
|
||||||
|
result = facts["resources"][0]
|
||||||
|
break
|
||||||
|
elif last_status_phase in ("Cancelled", "Error", "Failed"):
|
||||||
|
self.fail_json(
|
||||||
|
msg="Unexpected status for Build %s/%s: %s"
|
||||||
|
% (
|
||||||
|
result["metadata"]["name"],
|
||||||
|
result["metadata"]["namespace"],
|
||||||
|
last_status_phase,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
time.sleep(wait_sleep)
|
||||||
|
|
||||||
|
if last_status_phase != "Complete":
|
||||||
|
name = result["metadata"]["name"]
|
||||||
|
namespace = result["metadata"]["namespace"]
|
||||||
|
msg = (
|
||||||
|
"Build %s/%s has not complete after %d second(s),"
|
||||||
|
"current status is %s"
|
||||||
|
% (namespace, name, wait_timeout, last_status_phase)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.fail_json(msg=msg)
|
||||||
|
|
||||||
|
result = [result] if result else []
|
||||||
|
self.exit_json(changed=True, builds=result)
|
||||||
|
|
||||||
|
def cancel_build(self, restart):
|
||||||
|
kind = "Build"
|
||||||
|
api_version = "build.openshift.io/v1"
|
||||||
|
|
||||||
|
namespace = self.params.get("namespace")
|
||||||
|
phases = ["new", "pending", "running"]
|
||||||
|
build_phases = self.params.get("build_phases", [])
|
||||||
|
if build_phases:
|
||||||
|
phases = [p.lower() for p in build_phases]
|
||||||
|
|
||||||
|
names = []
|
||||||
|
if self.params.get("build_name"):
|
||||||
|
names.append(self.params.get("build_name"))
|
||||||
|
else:
|
||||||
|
build_config = self.params.get("build_config_name")
|
||||||
|
# list all builds from namespace
|
||||||
|
params = dict(kind=kind, api_version=api_version, namespace=namespace)
|
||||||
|
resources = self.kubernetes_facts(**params).get("resources", [])
|
||||||
|
|
||||||
|
def _filter_builds(build):
|
||||||
|
config = (
|
||||||
|
build["metadata"]
|
||||||
|
.get("labels", {})
|
||||||
|
.get("openshift.io/build-config.name")
|
||||||
|
)
|
||||||
|
return build_config is None or (
|
||||||
|
build_config is not None and config in build_config
|
||||||
|
)
|
||||||
|
|
||||||
|
for item in list(filter(_filter_builds, resources)):
|
||||||
|
name = item["metadata"]["name"]
|
||||||
|
if name not in names:
|
||||||
|
names.append(name)
|
||||||
|
|
||||||
|
if len(names) == 0:
|
||||||
|
self.exit_json(
|
||||||
|
changed=False, msg="No Build found from namespace %s" % namespace
|
||||||
|
)
|
||||||
|
|
||||||
|
warning = []
|
||||||
|
builds_to_cancel = []
|
||||||
|
for name in names:
|
||||||
|
params = dict(
|
||||||
|
kind=kind, api_version=api_version, name=name, namespace=namespace
|
||||||
|
)
|
||||||
|
|
||||||
|
resource = self.kubernetes_facts(**params).get("resources", [])
|
||||||
|
if len(resource) == 0:
|
||||||
|
warning.append("Build %s/%s not found" % (namespace, name))
|
||||||
|
continue
|
||||||
|
|
||||||
|
resource = resource[0]
|
||||||
|
phase = resource["status"].get("phase").lower()
|
||||||
|
|
||||||
|
# Build status.phase is matching the requested state and is not completed
|
||||||
|
if phase in phases:
|
||||||
|
builds_to_cancel.append(resource)
|
||||||
|
else:
|
||||||
|
warning.append(
|
||||||
|
"build %s/%s is not in expected phase, found %s"
|
||||||
|
% (namespace, name, phase)
|
||||||
|
)
|
||||||
|
|
||||||
|
changed = False
|
||||||
|
result = []
|
||||||
|
for build in builds_to_cancel:
|
||||||
|
# Set cancelled to true
|
||||||
|
build["status"]["cancelled"] = True
|
||||||
|
name = build["metadata"]["name"]
|
||||||
|
changed = True
|
||||||
|
try:
|
||||||
|
content_type = "application/json"
|
||||||
|
cancelled_build = self.request(
|
||||||
|
"PUT",
|
||||||
|
"/apis/build.openshift.io/v1/namespaces/{0}/builds/{1}".format(
|
||||||
|
namespace, name
|
||||||
|
),
|
||||||
|
body=build,
|
||||||
|
content_type=content_type,
|
||||||
|
).to_dict()
|
||||||
|
result.append(cancelled_build)
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
self.fail_json(
|
||||||
|
msg="Failed to cancel Build %s/%s due to: %s"
|
||||||
|
% (namespace, name, exc),
|
||||||
|
reason=exc.reason,
|
||||||
|
status=exc.status,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
self.fail_json(
|
||||||
|
msg="Failed to cancel Build %s/%s due to: %s" % (namespace, name, e)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Make sure the build phase is really cancelled.
|
||||||
|
def _wait_until_cancelled(build, wait_timeout, wait_sleep):
|
||||||
|
start = datetime.now()
|
||||||
|
last_phase = None
|
||||||
|
name = build["metadata"]["name"]
|
||||||
|
while (datetime.now() - start).seconds < wait_timeout:
|
||||||
|
params = dict(
|
||||||
|
kind=kind, api_version=api_version, name=name, namespace=namespace
|
||||||
|
)
|
||||||
|
resource = self.kubernetes_facts(**params).get("resources", [])
|
||||||
|
if len(resource) == 0:
|
||||||
|
return None, "Build %s/%s not found" % (namespace, name)
|
||||||
|
resource = resource[0]
|
||||||
|
last_phase = resource["status"]["phase"]
|
||||||
|
if last_phase == "Cancelled":
|
||||||
|
return resource, None
|
||||||
|
time.sleep(wait_sleep)
|
||||||
|
return (
|
||||||
|
None,
|
||||||
|
"Build %s/%s is not cancelled as expected, current state is %s"
|
||||||
|
% (namespace, name, last_phase),
|
||||||
|
)
|
||||||
|
|
||||||
|
if result and self.params.get("wait"):
|
||||||
|
wait_timeout = self.params.get("wait_timeout")
|
||||||
|
wait_sleep = self.params.get("wait_sleep")
|
||||||
|
|
||||||
|
wait_result = []
|
||||||
|
for build in result:
|
||||||
|
ret, err = _wait_until_cancelled(build, wait_timeout, wait_sleep)
|
||||||
|
if err:
|
||||||
|
self.exit_json(msg=err)
|
||||||
|
wait_result.append(ret)
|
||||||
|
result = wait_result
|
||||||
|
|
||||||
|
if restart:
|
||||||
|
self.start_build()
|
||||||
|
|
||||||
|
self.exit_json(builds=result, changed=changed)
|
||||||
|
|
||||||
|
def execute_module(self):
|
||||||
|
state = self.params.get("state")
|
||||||
|
if state == "started":
|
||||||
|
self.start_build()
|
||||||
|
else:
|
||||||
|
restart = bool(state == "restarted")
|
||||||
|
self.cancel_build(restart=restart)
|
||||||
|
|
||||||
|
|
||||||
|
class OpenShiftPruneBuilds(OpenShiftBuilds):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(OpenShiftPruneBuilds, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
def execute_module(self):
|
||||||
|
# list replicationcontroller candidate for pruning
|
||||||
|
kind = "Build"
|
||||||
|
api_version = "build.openshift.io/v1"
|
||||||
|
resource = self.find_resource(kind=kind, api_version=api_version, fail=True)
|
||||||
|
|
||||||
|
self.max_creation_timestamp = None
|
||||||
|
keep_younger_than = self.params.get("keep_younger_than")
|
||||||
|
if keep_younger_than:
|
||||||
|
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||||
|
self.max_creation_timestamp = now - timedelta(minutes=keep_younger_than)
|
||||||
|
|
||||||
|
def _prunable_build(build):
|
||||||
|
return build["status"]["phase"] in (
|
||||||
|
"Complete",
|
||||||
|
"Failed",
|
||||||
|
"Error",
|
||||||
|
"Cancelled",
|
||||||
|
)
|
||||||
|
|
||||||
|
def _orphan_build(build):
|
||||||
|
if not _prunable_build(build):
|
||||||
|
return False
|
||||||
|
|
||||||
|
config = build["status"].get("config", None)
|
||||||
|
if not config:
|
||||||
|
return True
|
||||||
|
build_config = self.get_build_config(config["name"], config["namespace"])
|
||||||
|
return len(build_config) == 0
|
||||||
|
|
||||||
|
def _younger_build(build):
|
||||||
|
if not self.max_creation_timestamp:
|
||||||
|
return False
|
||||||
|
creation_timestamp = datetime.strptime(
|
||||||
|
build["metadata"]["creationTimestamp"], "%Y-%m-%dT%H:%M:%SZ"
|
||||||
|
)
|
||||||
|
return creation_timestamp < self.max_creation_timestamp
|
||||||
|
|
||||||
|
predicates = [
|
||||||
|
_prunable_build,
|
||||||
|
]
|
||||||
|
if self.params.get("orphans"):
|
||||||
|
predicates.append(_orphan_build)
|
||||||
|
if self.max_creation_timestamp:
|
||||||
|
predicates.append(_younger_build)
|
||||||
|
|
||||||
|
# Get ReplicationController
|
||||||
|
params = dict(
|
||||||
|
kind=kind,
|
||||||
|
api_version=api_version,
|
||||||
|
namespace=self.params.get("namespace"),
|
||||||
|
)
|
||||||
|
result = self.kubernetes_facts(**params)
|
||||||
|
candidates = result["resources"]
|
||||||
|
for pred in predicates:
|
||||||
|
candidates = list(filter(pred, candidates))
|
||||||
|
|
||||||
|
if self.check_mode:
|
||||||
|
changed = len(candidates) > 0
|
||||||
|
self.exit_json(changed=changed, builds=candidates)
|
||||||
|
|
||||||
|
changed = False
|
||||||
|
for build in candidates:
|
||||||
|
changed = True
|
||||||
|
try:
|
||||||
|
name = build["metadata"]["name"]
|
||||||
|
namespace = build["metadata"]["namespace"]
|
||||||
|
resource.delete(name=name, namespace=namespace, body={})
|
||||||
|
except DynamicApiError as exc:
|
||||||
|
msg = "Failed to delete Build %s/%s due to: %s" % (
|
||||||
|
namespace,
|
||||||
|
name,
|
||||||
|
exc.body,
|
||||||
|
)
|
||||||
|
self.fail_json(msg=msg, status=exc.status, reason=exc.reason)
|
||||||
|
except Exception as e:
|
||||||
|
msg = "Failed to delete Build %s/%s due to: %s" % (
|
||||||
|
namespace,
|
||||||
|
name,
|
||||||
|
to_native(e),
|
||||||
|
)
|
||||||
|
self.fail_json(msg=msg, error=to_native(e), exception=e)
|
||||||
|
self.exit_json(changed=changed, builds=candidates)
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
from abc import abstractmethod
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import (
|
||||||
|
get_api_client,
|
||||||
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.core import (
|
||||||
|
AnsibleK8SModule,
|
||||||
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.service import (
|
||||||
|
K8sService,
|
||||||
|
diff_objects,
|
||||||
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.runner import (
|
||||||
|
perform_action,
|
||||||
|
validate,
|
||||||
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.resource import (
|
||||||
|
create_definitions,
|
||||||
|
merge_params,
|
||||||
|
flatten_list_kind,
|
||||||
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions import (
|
||||||
|
CoreException,
|
||||||
|
)
|
||||||
|
|
||||||
|
HAS_KUBERNETES_COLLECTION = True
|
||||||
|
k8s_collection_import_exception = None
|
||||||
|
K8S_COLLECTION_ERROR = None
|
||||||
|
except ImportError as e:
|
||||||
|
HAS_KUBERNETES_COLLECTION = False
|
||||||
|
k8s_collection_import_exception = e
|
||||||
|
K8S_COLLECTION_ERROR = traceback.format_exc()
|
||||||
|
|
||||||
|
|
||||||
|
class AnsibleOpenshiftModule(AnsibleK8SModule):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(AnsibleOpenshiftModule, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
self.client = get_api_client(module=self)
|
||||||
|
self.fail = self.fail_json
|
||||||
|
|
||||||
|
self.svc = K8sService(self.client, self._module)
|
||||||
|
self.find_resource = self.svc.find_resource
|
||||||
|
self.kubernetes_facts = self.svc.find
|
||||||
|
|
||||||
|
if not HAS_KUBERNETES_COLLECTION:
|
||||||
|
self.fail_json(
|
||||||
|
msg="The kubernetes.core collection must be installed",
|
||||||
|
exception=K8S_COLLECTION_ERROR,
|
||||||
|
error=to_native(k8s_collection_import_exception),
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def module(self):
|
||||||
|
return self._module
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def execute_module(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def request(self, *args, **kwargs):
|
||||||
|
return self.client.client.request(*args, **kwargs)
|
||||||
|
|
||||||
|
def set_resource_definitions(self):
|
||||||
|
self.resource_definitions = create_definitions(self.params)
|
||||||
|
|
||||||
|
def perform_action(self, definition, params):
|
||||||
|
return perform_action(self.svc, definition, params)
|
||||||
|
|
||||||
|
def validate(self, definition):
|
||||||
|
validate(self.client, self, definition)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def merge_params(definition, params):
|
||||||
|
return merge_params(definition, params)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def flatten_list_kind(definition, params):
|
||||||
|
return flatten_list_kind(definition, params)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def diff_objects(existing, new):
|
||||||
|
return diff_objects(existing, new)
|
||||||
|
|
||||||
|
def run_module(self):
|
||||||
|
try:
|
||||||
|
self.execute_module()
|
||||||
|
except CoreException as e:
|
||||||
|
self.fail_from_exception(e)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import re
|
import re
|
||||||
@@ -23,62 +24,68 @@ def convert_storage_to_bytes(value):
|
|||||||
|
|
||||||
|
|
||||||
def is_valid_digest(digest):
|
def is_valid_digest(digest):
|
||||||
|
|
||||||
digest_algorithm_size = dict(
|
digest_algorithm_size = dict(
|
||||||
sha256=64, sha384=96, sha512=128,
|
sha256=64,
|
||||||
|
sha384=96,
|
||||||
|
sha512=128,
|
||||||
)
|
)
|
||||||
|
|
||||||
m = re.match(r'[a-zA-Z0-9-_+.]+:[a-fA-F0-9]+', digest)
|
m = re.match(r"[a-zA-Z0-9-_+.]+:[a-fA-F0-9]+", digest)
|
||||||
if not m:
|
if not m:
|
||||||
return "Docker digest does not match expected format %s" % digest
|
return "Docker digest does not match expected format %s" % digest
|
||||||
|
|
||||||
idx = digest.find(':')
|
idx = digest.find(":")
|
||||||
# case: "sha256:" with no hex.
|
# case: "sha256:" with no hex.
|
||||||
if idx < 0 or idx == (len(digest) - 1):
|
if idx < 0 or idx == (len(digest) - 1):
|
||||||
return "Invalid docker digest %s, no hex value define" % digest
|
return "Invalid docker digest %s, no hex value define" % digest
|
||||||
|
|
||||||
algorithm = digest[:idx]
|
algorithm = digest[:idx]
|
||||||
if algorithm not in digest_algorithm_size:
|
if algorithm not in digest_algorithm_size:
|
||||||
return "Unsupported digest algorithm value %s for digest %s" % (algorithm, digest)
|
return "Unsupported digest algorithm value %s for digest %s" % (
|
||||||
|
algorithm,
|
||||||
|
digest,
|
||||||
|
)
|
||||||
|
|
||||||
hex_value = digest[idx + 1:]
|
hex_value = digest[idx + 1:] # fmt: skip
|
||||||
if len(hex_value) != digest_algorithm_size.get(algorithm):
|
if len(hex_value) != digest_algorithm_size.get(algorithm):
|
||||||
return "Invalid length for digest hex expected %d found %d (digest is %s)" % (
|
return "Invalid length for digest hex expected %d found %d (digest is %s)" % (
|
||||||
digest_algorithm_size.get(algorithm), len(hex_value), digest
|
digest_algorithm_size.get(algorithm),
|
||||||
|
len(hex_value),
|
||||||
|
digest,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_docker_image_ref(image_ref, module=None):
|
def parse_docker_image_ref(image_ref, module=None):
|
||||||
"""
|
"""
|
||||||
Docker Grammar Reference
|
Docker Grammar Reference
|
||||||
Reference => name [ ":" tag ] [ "@" digest ]
|
Reference => name [ ":" tag ] [ "@" digest ]
|
||||||
name => [hostname '/'] component ['/' component]*
|
name => [hostname '/'] component ['/' component]*
|
||||||
hostname => hostcomponent ['.' hostcomponent]* [':' port-number]
|
hostname => hostcomponent ['.' hostcomponent]* [':' port-number]
|
||||||
hostcomponent => /([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])/
|
hostcomponent => /([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])/
|
||||||
port-number => /[0-9]+/
|
port-number => /[0-9]+/
|
||||||
component => alpha-numeric [separator alpha-numeric]*
|
component => alpha-numeric [separator alpha-numeric]*
|
||||||
alpha-numeric => /[a-z0-9]+/
|
alpha-numeric => /[a-z0-9]+/
|
||||||
separator => /[_.]|__|[-]*/
|
separator => /[_.]|__|[-]*/
|
||||||
"""
|
"""
|
||||||
idx = image_ref.find("/")
|
idx = image_ref.find("/")
|
||||||
|
|
||||||
def _contains_any(src, values):
|
def _contains_any(src, values):
|
||||||
return any(x in src for x in values)
|
return any(x in src for x in values)
|
||||||
|
|
||||||
result = {
|
result = {"tag": None, "digest": None}
|
||||||
"tag": None, "digest": None
|
|
||||||
}
|
|
||||||
default_domain = "docker.io"
|
default_domain = "docker.io"
|
||||||
if idx < 0 or (not _contains_any(image_ref[:idx], ":.") and image_ref[:idx] != "localhost"):
|
if idx < 0 or (
|
||||||
|
not _contains_any(image_ref[:idx], ":.") and image_ref[:idx] != "localhost"
|
||||||
|
):
|
||||||
result["hostname"], remainder = default_domain, image_ref
|
result["hostname"], remainder = default_domain, image_ref
|
||||||
else:
|
else:
|
||||||
result["hostname"], remainder = image_ref[:idx], image_ref[idx + 1:]
|
result["hostname"], remainder = image_ref[:idx], image_ref[idx + 1:] # fmt: skip
|
||||||
|
|
||||||
# Parse remainder information
|
# Parse remainder information
|
||||||
idx = remainder.find("@")
|
idx = remainder.find("@")
|
||||||
if idx > 0 and len(remainder) > (idx + 1):
|
if idx > 0 and len(remainder) > (idx + 1):
|
||||||
# docker image reference with digest
|
# docker image reference with digest
|
||||||
component, result["digest"] = remainder[:idx], remainder[idx + 1:]
|
component, result["digest"] = remainder[:idx], remainder[idx + 1:] # fmt: skip
|
||||||
err = is_valid_digest(result["digest"])
|
err = is_valid_digest(result["digest"])
|
||||||
if err:
|
if err:
|
||||||
if module:
|
if module:
|
||||||
@@ -88,7 +95,7 @@ def parse_docker_image_ref(image_ref, module=None):
|
|||||||
idx = remainder.find(":")
|
idx = remainder.find(":")
|
||||||
if idx > 0 and len(remainder) > (idx + 1):
|
if idx > 0 and len(remainder) > (idx + 1):
|
||||||
# docker image reference with tag
|
# docker image reference with tag
|
||||||
component, result["tag"] = remainder[:idx], remainder[idx + 1:]
|
component, result["tag"] = remainder[:idx], remainder[idx + 1:] # fmt: skip
|
||||||
else:
|
else:
|
||||||
# name only
|
# name only
|
||||||
component = remainder
|
component = remainder
|
||||||
@@ -96,8 +103,6 @@ def parse_docker_image_ref(image_ref, module=None):
|
|||||||
namespace = None
|
namespace = None
|
||||||
if len(v) > 1:
|
if len(v) > 1:
|
||||||
namespace = v[0]
|
namespace = v[0]
|
||||||
result.update({
|
result.update({"namespace": namespace, "name": v[-1]})
|
||||||
"namespace": namespace, "name": v[-1]
|
|
||||||
})
|
|
||||||
|
|
||||||
return result, None
|
return result, None
|
||||||
|
|||||||
@@ -3,16 +3,15 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
import traceback
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (K8sAnsibleMixin, get_api_client)
|
|
||||||
from ansible.module_utils.parsing.convert_bool import boolean
|
from ansible.module_utils.parsing.convert_bool import boolean
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
from ansible.module_utils.basic import missing_required_lib
|
from ansible.module_utils.basic import missing_required_lib
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_ldap import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_ldap import (
|
||||||
@@ -20,26 +19,21 @@ from ansible_collections.community.okd.plugins.module_utils.openshift_ldap impor
|
|||||||
ldap_split_host_port,
|
ldap_split_host_port,
|
||||||
OpenshiftLDAPRFC2307,
|
OpenshiftLDAPRFC2307,
|
||||||
OpenshiftLDAPActiveDirectory,
|
OpenshiftLDAPActiveDirectory,
|
||||||
OpenshiftLDAPAugmentedActiveDirectory
|
OpenshiftLDAPAugmentedActiveDirectory,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ldap
|
import ldap
|
||||||
|
|
||||||
HAS_PYTHON_LDAP = True
|
HAS_PYTHON_LDAP = True
|
||||||
|
PYTHON_LDAP_ERROR = None
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
HAS_PYTHON_LDAP = False
|
HAS_PYTHON_LDAP = False
|
||||||
PYTHON_LDAP_ERROR = e
|
PYTHON_LDAP_ERROR = e
|
||||||
|
|
||||||
try:
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
AnsibleOpenshiftModule,
|
||||||
K8sAnsibleMixin,
|
)
|
||||||
get_api_client,
|
|
||||||
)
|
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes.dynamic.exceptions import DynamicApiError
|
from kubernetes.dynamic.exceptions import DynamicApiError
|
||||||
@@ -53,7 +47,9 @@ LDAP_OPENSHIFT_UID_ANNOTATION = "openshift.io/ldap.uid"
|
|||||||
LDAP_OPENSHIFT_SYNCTIME_ANNOTATION = "openshift.io/ldap.sync-time"
|
LDAP_OPENSHIFT_SYNCTIME_ANNOTATION = "openshift.io/ldap.sync-time"
|
||||||
|
|
||||||
|
|
||||||
def connect_to_ldap(module, server_uri, bind_dn=None, bind_pw=None, insecure=True, ca_file=None):
|
def connect_to_ldap(
|
||||||
|
module, server_uri, bind_dn=None, bind_pw=None, insecure=True, ca_file=None
|
||||||
|
):
|
||||||
if insecure:
|
if insecure:
|
||||||
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
||||||
elif ca_file:
|
elif ca_file:
|
||||||
@@ -65,27 +61,36 @@ def connect_to_ldap(module, server_uri, bind_dn=None, bind_pw=None, insecure=Tru
|
|||||||
connection.simple_bind_s(bind_dn, bind_pw)
|
connection.simple_bind_s(bind_dn, bind_pw)
|
||||||
return connection
|
return connection
|
||||||
except ldap.LDAPError as e:
|
except ldap.LDAPError as e:
|
||||||
module.fail_json(msg="Cannot bind to the LDAP server '{0}' due to: {1}".format(server_uri, e))
|
module.fail_json(
|
||||||
|
msg="Cannot bind to the LDAP server '{0}' due to: {1}".format(server_uri, e)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_group_annotation(definition, host_ip):
|
def validate_group_annotation(definition, host_ip):
|
||||||
name = definition['metadata']['name']
|
name = definition["metadata"]["name"]
|
||||||
# Validate LDAP URL Annotation
|
# Validate LDAP URL Annotation
|
||||||
annotate_url = definition['metadata'].get('annotations', {}).get(LDAP_OPENSHIFT_URL_ANNOTATION)
|
annotate_url = (
|
||||||
|
definition["metadata"].get("annotations", {}).get(LDAP_OPENSHIFT_URL_ANNOTATION)
|
||||||
|
)
|
||||||
if host_ip:
|
if host_ip:
|
||||||
if not annotate_url:
|
if not annotate_url:
|
||||||
return "group '{0}' marked as having been synced did not have an '{1}' annotation".format(name, LDAP_OPENSHIFT_URL_ANNOTATION)
|
return "group '{0}' marked as having been synced did not have an '{1}' annotation".format(
|
||||||
|
name, LDAP_OPENSHIFT_URL_ANNOTATION
|
||||||
|
)
|
||||||
elif annotate_url != host_ip:
|
elif annotate_url != host_ip:
|
||||||
return "group '{0}' was not synchronized from: '{1}'".format(name, host_ip)
|
return "group '{0}' was not synchronized from: '{1}'".format(name, host_ip)
|
||||||
# Validate LDAP UID Annotation
|
# Validate LDAP UID Annotation
|
||||||
annotate_uid = definition['metadata']['annotations'].get(LDAP_OPENSHIFT_UID_ANNOTATION)
|
annotate_uid = definition["metadata"]["annotations"].get(
|
||||||
|
LDAP_OPENSHIFT_UID_ANNOTATION
|
||||||
|
)
|
||||||
if not annotate_uid:
|
if not annotate_uid:
|
||||||
return "group '{0}' marked as having been synced did not have an '{1}' annotation".format(name, LDAP_OPENSHIFT_UID_ANNOTATION)
|
return "group '{0}' marked as having been synced did not have an '{1}' annotation".format(
|
||||||
|
name, LDAP_OPENSHIFT_UID_ANNOTATION
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class OpenshiftLDAPGroups(object):
|
class OpenshiftLDAPGroups(object):
|
||||||
|
|
||||||
kind = "Group"
|
kind = "Group"
|
||||||
version = "user.openshift.io/v1"
|
version = "user.openshift.io/v1"
|
||||||
|
|
||||||
@@ -97,11 +102,7 @@ class OpenshiftLDAPGroups(object):
|
|||||||
@property
|
@property
|
||||||
def k8s_group_api(self):
|
def k8s_group_api(self):
|
||||||
if not self.__group_api:
|
if not self.__group_api:
|
||||||
params = dict(
|
params = dict(kind=self.kind, api_version=self.version, fail=True)
|
||||||
kind=self.kind,
|
|
||||||
api_version=self.version,
|
|
||||||
fail=True
|
|
||||||
)
|
|
||||||
self.__group_api = self.module.find_resource(**params)
|
self.__group_api = self.module.find_resource(**params)
|
||||||
return self.__group_api
|
return self.__group_api
|
||||||
|
|
||||||
@@ -148,16 +149,26 @@ class OpenshiftLDAPGroups(object):
|
|||||||
|
|
||||||
if missing:
|
if missing:
|
||||||
self.module.fail_json(
|
self.module.fail_json(
|
||||||
msg="The following groups were not found: %s" % ''.join(missing)
|
msg="The following groups were not found: %s" % "".join(missing)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
label_selector = "%s=%s" % (LDAP_OPENSHIFT_HOST_LABEL, host)
|
label_selector = "%s=%s" % (LDAP_OPENSHIFT_HOST_LABEL, host)
|
||||||
resources = self.get_group_info(label_selectors=[label_selector], return_list=True)
|
resources = self.get_group_info(
|
||||||
|
label_selectors=[label_selector], return_list=True
|
||||||
|
)
|
||||||
if not resources:
|
if not resources:
|
||||||
return None, "Unable to find Group matching label selector '%s'" % label_selector
|
return (
|
||||||
|
None,
|
||||||
|
"Unable to find Group matching label selector '%s'"
|
||||||
|
% label_selector,
|
||||||
|
)
|
||||||
groups = resources
|
groups = resources
|
||||||
if deny_groups:
|
if deny_groups:
|
||||||
groups = [item for item in groups if item["metadata"]["name"] not in deny_groups]
|
groups = [
|
||||||
|
item
|
||||||
|
for item in groups
|
||||||
|
if item["metadata"]["name"] not in deny_groups
|
||||||
|
]
|
||||||
|
|
||||||
uids = []
|
uids = []
|
||||||
for grp in groups:
|
for grp in groups:
|
||||||
@@ -165,7 +176,9 @@ class OpenshiftLDAPGroups(object):
|
|||||||
if err and allow_groups:
|
if err and allow_groups:
|
||||||
# We raise an error for group part of the allow_group not matching LDAP sync criteria
|
# We raise an error for group part of the allow_group not matching LDAP sync criteria
|
||||||
return None, err
|
return None, err
|
||||||
group_uid = grp['metadata']['annotations'].get(LDAP_OPENSHIFT_UID_ANNOTATION)
|
group_uid = grp["metadata"]["annotations"].get(
|
||||||
|
LDAP_OPENSHIFT_UID_ANNOTATION
|
||||||
|
)
|
||||||
self.cache[group_uid] = grp
|
self.cache[group_uid] = grp
|
||||||
uids.append(group_uid)
|
uids.append(group_uid)
|
||||||
return uids, None
|
return uids, None
|
||||||
@@ -183,38 +196,65 @@ class OpenshiftLDAPGroups(object):
|
|||||||
"kind": "Group",
|
"kind": "Group",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"name": group_name,
|
"name": group_name,
|
||||||
"labels": {
|
"labels": {LDAP_OPENSHIFT_HOST_LABEL: self.module.host},
|
||||||
LDAP_OPENSHIFT_HOST_LABEL: self.module.host
|
|
||||||
},
|
|
||||||
"annotations": {
|
"annotations": {
|
||||||
LDAP_OPENSHIFT_URL_ANNOTATION: self.module.netlocation,
|
LDAP_OPENSHIFT_URL_ANNOTATION: self.module.netlocation,
|
||||||
LDAP_OPENSHIFT_UID_ANNOTATION: group_uid,
|
LDAP_OPENSHIFT_UID_ANNOTATION: group_uid,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Make sure we aren't taking over an OpenShift group that is already related to a different LDAP group
|
# Make sure we aren't taking over an OpenShift group that is already related to a different LDAP group
|
||||||
ldaphost_label = group["metadata"].get("labels", {}).get(LDAP_OPENSHIFT_HOST_LABEL)
|
ldaphost_label = (
|
||||||
|
group["metadata"].get("labels", {}).get(LDAP_OPENSHIFT_HOST_LABEL)
|
||||||
|
)
|
||||||
if not ldaphost_label or ldaphost_label != self.module.host:
|
if not ldaphost_label or ldaphost_label != self.module.host:
|
||||||
return None, "Group %s: %s label did not match sync host: wanted %s, got %s" % (
|
return (
|
||||||
group_name, LDAP_OPENSHIFT_HOST_LABEL, self.module.host, ldaphost_label
|
None,
|
||||||
|
"Group %s: %s label did not match sync host: wanted %s, got %s"
|
||||||
|
% (
|
||||||
|
group_name,
|
||||||
|
LDAP_OPENSHIFT_HOST_LABEL,
|
||||||
|
self.module.host,
|
||||||
|
ldaphost_label,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
ldapurl_annotation = group["metadata"].get("annotations", {}).get(LDAP_OPENSHIFT_URL_ANNOTATION)
|
ldapurl_annotation = (
|
||||||
|
group["metadata"].get("annotations", {}).get(LDAP_OPENSHIFT_URL_ANNOTATION)
|
||||||
|
)
|
||||||
if not ldapurl_annotation or ldapurl_annotation != self.module.netlocation:
|
if not ldapurl_annotation or ldapurl_annotation != self.module.netlocation:
|
||||||
return None, "Group %s: %s annotation did not match sync host: wanted %s, got %s" % (
|
return (
|
||||||
group_name, LDAP_OPENSHIFT_URL_ANNOTATION, self.module.netlocation, ldapurl_annotation
|
None,
|
||||||
|
"Group %s: %s annotation did not match sync host: wanted %s, got %s"
|
||||||
|
% (
|
||||||
|
group_name,
|
||||||
|
LDAP_OPENSHIFT_URL_ANNOTATION,
|
||||||
|
self.module.netlocation,
|
||||||
|
ldapurl_annotation,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
ldapuid_annotation = group["metadata"].get("annotations", {}).get(LDAP_OPENSHIFT_UID_ANNOTATION)
|
ldapuid_annotation = (
|
||||||
|
group["metadata"].get("annotations", {}).get(LDAP_OPENSHIFT_UID_ANNOTATION)
|
||||||
|
)
|
||||||
if not ldapuid_annotation or ldapuid_annotation != group_uid:
|
if not ldapuid_annotation or ldapuid_annotation != group_uid:
|
||||||
return None, "Group %s: %s annotation did not match LDAP UID: wanted %s, got %s" % (
|
return (
|
||||||
group_name, LDAP_OPENSHIFT_UID_ANNOTATION, group_uid, ldapuid_annotation
|
None,
|
||||||
|
"Group %s: %s annotation did not match LDAP UID: wanted %s, got %s"
|
||||||
|
% (
|
||||||
|
group_name,
|
||||||
|
LDAP_OPENSHIFT_UID_ANNOTATION,
|
||||||
|
group_uid,
|
||||||
|
ldapuid_annotation,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Overwrite Group Users data
|
# Overwrite Group Users data
|
||||||
group["users"] = usernames
|
group["users"] = usernames
|
||||||
group["metadata"]["annotations"][LDAP_OPENSHIFT_SYNCTIME_ANNOTATION] = datetime.now().isoformat()
|
group["metadata"]["annotations"][
|
||||||
|
LDAP_OPENSHIFT_SYNCTIME_ANNOTATION
|
||||||
|
] = datetime.now().isoformat()
|
||||||
return group, None
|
return group, None
|
||||||
|
|
||||||
def create_openshift_groups(self, groups: list):
|
def create_openshift_groups(self, groups: list):
|
||||||
@@ -225,17 +265,22 @@ class OpenshiftLDAPGroups(object):
|
|||||||
name = definition["metadata"]["name"]
|
name = definition["metadata"]["name"]
|
||||||
existing = self.get_group_info(name=name)
|
existing = self.get_group_info(name=name)
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
|
method = "patch" if existing else "create"
|
||||||
try:
|
try:
|
||||||
if existing:
|
if existing:
|
||||||
method = 'patch'
|
|
||||||
definition = self.k8s_group_api.patch(definition).to_dict()
|
definition = self.k8s_group_api.patch(definition).to_dict()
|
||||||
else:
|
else:
|
||||||
method = 'create'
|
|
||||||
definition = self.k8s_group_api.create(definition).to_dict()
|
definition = self.k8s_group_api.create(definition).to_dict()
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
self.module.fail_json(msg="Failed to %s Group '%s' due to: %s" % (method, name, exc.body))
|
self.module.fail_json(
|
||||||
|
msg="Failed to %s Group '%s' due to: %s"
|
||||||
|
% (method, name, exc.body)
|
||||||
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.module.fail_json(msg="Failed to %s Group '%s' due to: %s" % (method, name, to_native(exc)))
|
self.module.fail_json(
|
||||||
|
msg="Failed to %s Group '%s' due to: %s"
|
||||||
|
% (method, name, to_native(exc))
|
||||||
|
)
|
||||||
equals = False
|
equals = False
|
||||||
if existing:
|
if existing:
|
||||||
equals, diff = self.module.diff_objects(existing, definition)
|
equals, diff = self.module.diff_objects(existing, definition)
|
||||||
@@ -245,47 +290,28 @@ class OpenshiftLDAPGroups(object):
|
|||||||
return results, diffs, changed
|
return results, diffs, changed
|
||||||
|
|
||||||
def delete_openshift_group(self, name: str):
|
def delete_openshift_group(self, name: str):
|
||||||
result = dict(
|
result = dict(kind=self.kind, apiVersion=self.version, metadata=dict(name=name))
|
||||||
kind=self.kind,
|
|
||||||
apiVersion=self.version,
|
|
||||||
metadata=dict(
|
|
||||||
name=name
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
try:
|
try:
|
||||||
result = self.k8s_group_api.delete(name=name).to_dict()
|
result = self.k8s_group_api.delete(name=name).to_dict()
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
self.module.fail_json(msg="Failed to delete Group '{0}' due to: {1}".format(name, exc.body))
|
self.module.fail_json(
|
||||||
|
msg="Failed to delete Group '{0}' due to: {1}".format(
|
||||||
|
name, exc.body
|
||||||
|
)
|
||||||
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.module.fail_json(msg="Failed to delete Group '{0}' due to: {1}".format(name, to_native(exc)))
|
self.module.fail_json(
|
||||||
|
msg="Failed to delete Group '{0}' due to: {1}".format(
|
||||||
|
name, to_native(exc)
|
||||||
|
)
|
||||||
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class OpenshiftGroupsSync(K8sAnsibleMixin):
|
class OpenshiftGroupsSync(AnsibleOpenshiftModule):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
def __init__(self, module):
|
super(OpenshiftGroupsSync, self).__init__(**kwargs)
|
||||||
|
|
||||||
self.module = module
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.module.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception),
|
|
||||||
)
|
|
||||||
|
|
||||||
if not HAS_PYTHON_LDAP:
|
|
||||||
self.fail_json(
|
|
||||||
msg=missing_required_lib('python-ldap'), error=to_native(PYTHON_LDAP_ERROR)
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenshiftGroupsSync, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
|
|
||||||
self.__k8s_group_api = None
|
self.__k8s_group_api = None
|
||||||
self.__ldap_connection = None
|
self.__ldap_connection = None
|
||||||
self.host = None
|
self.host = None
|
||||||
@@ -294,14 +320,16 @@ class OpenshiftGroupsSync(K8sAnsibleMixin):
|
|||||||
self.scheme = None
|
self.scheme = None
|
||||||
self.config = self.params.get("sync_config")
|
self.config = self.params.get("sync_config")
|
||||||
|
|
||||||
|
if not HAS_PYTHON_LDAP:
|
||||||
|
self.fail_json(
|
||||||
|
msg=missing_required_lib("python-ldap"),
|
||||||
|
error=to_native(PYTHON_LDAP_ERROR),
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def k8s_group_api(self):
|
def k8s_group_api(self):
|
||||||
if not self.__k8s_group_api:
|
if not self.__k8s_group_api:
|
||||||
params = dict(
|
params = dict(kind="Group", api_version="user.openshift.io/v1", fail=True)
|
||||||
kind="Group",
|
|
||||||
api_version="user.openshift.io/v1",
|
|
||||||
fail=True
|
|
||||||
)
|
|
||||||
self.__k8s_group_api = self.find_resource(**params)
|
self.__k8s_group_api = self.find_resource(**params)
|
||||||
return self.__k8s_group_api
|
return self.__k8s_group_api
|
||||||
|
|
||||||
@@ -315,11 +343,11 @@ class OpenshiftGroupsSync(K8sAnsibleMixin):
|
|||||||
# Create connection object
|
# Create connection object
|
||||||
params = dict(
|
params = dict(
|
||||||
module=self,
|
module=self,
|
||||||
server_uri=self.config.get('url'),
|
server_uri=self.config.get("url"),
|
||||||
bind_dn=self.config.get('bindDN'),
|
bind_dn=self.config.get("bindDN"),
|
||||||
bind_pw=self.config.get('bindPassword'),
|
bind_pw=self.config.get("bindPassword"),
|
||||||
insecure=boolean(self.config.get('insecure')),
|
insecure=boolean(self.config.get("insecure")),
|
||||||
ca_file=self.config.get('ca')
|
ca_file=self.config.get("ca"),
|
||||||
)
|
)
|
||||||
self.__ldap_connection = connect_to_ldap(**params)
|
self.__ldap_connection = connect_to_ldap(**params)
|
||||||
return self.__ldap_connection
|
return self.__ldap_connection
|
||||||
@@ -351,7 +379,6 @@ class OpenshiftGroupsSync(K8sAnsibleMixin):
|
|||||||
return syncer
|
return syncer
|
||||||
|
|
||||||
def synchronize(self):
|
def synchronize(self):
|
||||||
|
|
||||||
sync_group_type = self.module.params.get("type")
|
sync_group_type = self.module.params.get("type")
|
||||||
|
|
||||||
groups_uids = []
|
groups_uids = []
|
||||||
@@ -389,7 +416,8 @@ class OpenshiftGroupsSync(K8sAnsibleMixin):
|
|||||||
name, err = syncer.get_username_for_entry(entry)
|
name, err = syncer.get_username_for_entry(entry)
|
||||||
if err:
|
if err:
|
||||||
self.exit_json(
|
self.exit_json(
|
||||||
msg="Unable to determine username for entry %s: %s" % (entry, err)
|
msg="Unable to determine username for entry %s: %s"
|
||||||
|
% (entry, err)
|
||||||
)
|
)
|
||||||
if isinstance(name, list):
|
if isinstance(name, list):
|
||||||
usernames.extend(name)
|
usernames.extend(name)
|
||||||
@@ -404,13 +432,17 @@ class OpenshiftGroupsSync(K8sAnsibleMixin):
|
|||||||
self.exit_json(msg=err)
|
self.exit_json(msg=err)
|
||||||
|
|
||||||
# Make Openshift group
|
# Make Openshift group
|
||||||
group, err = ldap_openshift_group.make_openshift_group(uid, group_name, usernames)
|
group, err = ldap_openshift_group.make_openshift_group(
|
||||||
|
uid, group_name, usernames
|
||||||
|
)
|
||||||
if err:
|
if err:
|
||||||
self.fail_json(msg=err)
|
self.fail_json(msg=err)
|
||||||
openshift_groups.append(group)
|
openshift_groups.append(group)
|
||||||
|
|
||||||
# Create Openshift Groups
|
# Create Openshift Groups
|
||||||
results, diffs, changed = ldap_openshift_group.create_openshift_groups(openshift_groups)
|
results, diffs, changed = ldap_openshift_group.create_openshift_groups(
|
||||||
|
openshift_groups
|
||||||
|
)
|
||||||
self.module.exit_json(changed=True, groups=results)
|
self.module.exit_json(changed=True, groups=results)
|
||||||
|
|
||||||
def prune(self):
|
def prune(self):
|
||||||
@@ -428,7 +460,10 @@ class OpenshiftGroupsSync(K8sAnsibleMixin):
|
|||||||
# Check if LDAP group exist
|
# Check if LDAP group exist
|
||||||
exists, err = syncer.is_ldapgroup_exists(uid)
|
exists, err = syncer.is_ldapgroup_exists(uid)
|
||||||
if err:
|
if err:
|
||||||
msg = "Error determining LDAP group existence for group %s: %s" % (uid, err)
|
msg = "Error determining LDAP group existence for group %s: %s" % (
|
||||||
|
uid,
|
||||||
|
err,
|
||||||
|
)
|
||||||
self.module.fail_json(msg=msg)
|
self.module.fail_json(msg=msg)
|
||||||
|
|
||||||
if exists:
|
if exists:
|
||||||
@@ -453,14 +488,22 @@ class OpenshiftGroupsSync(K8sAnsibleMixin):
|
|||||||
self.fail_json(msg="Invalid LDAP Sync config: %s" % error)
|
self.fail_json(msg="Invalid LDAP Sync config: %s" % error)
|
||||||
|
|
||||||
# Split host/port
|
# Split host/port
|
||||||
if self.config.get('url'):
|
if self.config.get("url"):
|
||||||
result, error = ldap_split_host_port(self.config.get('url'))
|
result, error = ldap_split_host_port(self.config.get("url"))
|
||||||
if error:
|
if error:
|
||||||
self.fail_json(msg="Failed to parse url='{0}': {1}".format(self.config.get('url'), error))
|
self.fail_json(
|
||||||
self.netlocation, self.host, self.port = result["netlocation"], result["host"], result["port"]
|
msg="Failed to parse url='{0}': {1}".format(
|
||||||
|
self.config.get("url"), error
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.netlocation, self.host, self.port = (
|
||||||
|
result["netlocation"],
|
||||||
|
result["host"],
|
||||||
|
result["port"],
|
||||||
|
)
|
||||||
self.scheme = result["scheme"]
|
self.scheme = result["scheme"]
|
||||||
|
|
||||||
if self.params.get('state') == 'present':
|
if self.params.get("state") == "present":
|
||||||
self.synchronize()
|
self.synchronize()
|
||||||
else:
|
else:
|
||||||
self.prune()
|
self.prune()
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_docker_image import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_docker_image import (
|
||||||
parse_docker_image_ref,
|
parse_docker_image_ref,
|
||||||
)
|
)
|
||||||
from ansible.module_utils.six import iteritems
|
|
||||||
|
|
||||||
|
|
||||||
def get_image_blobs(image):
|
def get_image_blobs(image):
|
||||||
blobs = [layer["image"] for layer in image["dockerImageLayers"]]
|
blobs = [layer["image"] for layer in image["dockerImageLayers"] if "image" in layer]
|
||||||
docker_image_metadata = image.get("dockerImageMetadata")
|
docker_image_metadata = image.get("dockerImageMetadata")
|
||||||
if not docker_image_metadata:
|
if not docker_image_metadata:
|
||||||
return blobs, "failed to read metadata for image %s" % image["metadata"]["name"]
|
return blobs, "failed to read metadata for image %s" % image["metadata"]["name"]
|
||||||
media_type_manifest = (
|
media_type_manifest = (
|
||||||
"application/vnd.docker.distribution.manifest.v2+json",
|
"application/vnd.docker.distribution.manifest.v2+json",
|
||||||
"application/vnd.oci.image.manifest.v1+json"
|
"application/vnd.oci.image.manifest.v1+json",
|
||||||
)
|
)
|
||||||
media_type_has_config = image['dockerImageManifestMediaType'] in media_type_manifest
|
media_type_has_config = image["dockerImageManifestMediaType"] in media_type_manifest
|
||||||
docker_image_id = docker_image_metadata.get("Id")
|
docker_image_id = docker_image_metadata.get("Id")
|
||||||
if media_type_has_config and docker_image_id and len(docker_image_id) > 0:
|
if media_type_has_config and docker_image_id and len(docker_image_id) > 0:
|
||||||
blobs.append(docker_image_id)
|
blobs.append(docker_image_id)
|
||||||
@@ -29,19 +29,18 @@ def get_image_blobs(image):
|
|||||||
def is_created_after(creation_timestamp, max_creation_timestamp):
|
def is_created_after(creation_timestamp, max_creation_timestamp):
|
||||||
if not max_creation_timestamp:
|
if not max_creation_timestamp:
|
||||||
return False
|
return False
|
||||||
creationTimestamp = datetime.strptime(creation_timestamp, '%Y-%m-%dT%H:%M:%SZ')
|
creationTimestamp = datetime.strptime(creation_timestamp, "%Y-%m-%dT%H:%M:%SZ")
|
||||||
return creationTimestamp > max_creation_timestamp
|
return creationTimestamp > max_creation_timestamp
|
||||||
|
|
||||||
|
|
||||||
def is_too_young_object(obj, max_creation_timestamp):
|
def is_too_young_object(obj, max_creation_timestamp):
|
||||||
return is_created_after(obj['metadata']['creationTimestamp'],
|
return is_created_after(
|
||||||
max_creation_timestamp)
|
obj["metadata"]["creationTimestamp"], max_creation_timestamp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftAnalyzeImageStream(object):
|
class OpenShiftAnalyzeImageStream(object):
|
||||||
|
|
||||||
def __init__(self, ignore_invalid_refs, max_creation_timestamp, module):
|
def __init__(self, ignore_invalid_refs, max_creation_timestamp, module):
|
||||||
|
|
||||||
self.max_creationTimestamp = max_creation_timestamp
|
self.max_creationTimestamp = max_creation_timestamp
|
||||||
self.used_tags = {}
|
self.used_tags = {}
|
||||||
self.used_images = {}
|
self.used_images = {}
|
||||||
@@ -53,32 +52,34 @@ class OpenShiftAnalyzeImageStream(object):
|
|||||||
if error:
|
if error:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
if len(result['hostname']) == 0 or len(result['namespace']) == 0:
|
if not result["hostname"] or not result["namespace"]:
|
||||||
# image reference does not match hostname/namespace/name pattern - skipping
|
# image reference does not match hostname/namespace/name pattern - skipping
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not result['digest']:
|
if not result["digest"]:
|
||||||
# Attempt to dereference istag. Since we cannot be sure whether the reference refers to the
|
# Attempt to dereference istag. Since we cannot be sure whether the reference refers to the
|
||||||
# integrated registry or not, we ignore the host part completely. As a consequence, we may keep
|
# integrated registry or not, we ignore the host part completely. As a consequence, we may keep
|
||||||
# image otherwise sentenced for a removal just because its pull spec accidentally matches one of
|
# image otherwise sentenced for a removal just because its pull spec accidentally matches one of
|
||||||
# our imagestreamtags.
|
# our imagestreamtags.
|
||||||
|
|
||||||
# set the tag if empty
|
# set the tag if empty
|
||||||
if result['tag'] == "":
|
if result["tag"] == "":
|
||||||
result['tag'] = 'latest'
|
result["tag"] = "latest"
|
||||||
key = "%s/%s:%s" % (result['namespace'], result['name'], result['tag'])
|
key = "%s/%s:%s" % (result["namespace"], result["name"], result["tag"])
|
||||||
if key not in self.used_tags:
|
if key not in self.used_tags:
|
||||||
self.used_tags[key] = []
|
self.used_tags[key] = []
|
||||||
self.used_tags[key].append(referrer)
|
self.used_tags[key].append(referrer)
|
||||||
else:
|
else:
|
||||||
key = "%s/%s@%s" % (result['namespace'], result['name'], result['digest'])
|
key = "%s/%s@%s" % (result["namespace"], result["name"], result["digest"])
|
||||||
if key not in self.used_images:
|
if key not in self.used_images:
|
||||||
self.used_images[key] = []
|
self.used_images[key] = []
|
||||||
self.used_images[key].append(referrer)
|
self.used_images[key].append(referrer)
|
||||||
|
|
||||||
def analyze_refs_from_pod_spec(self, podSpec, referrer):
|
def analyze_refs_from_pod_spec(self, podSpec, referrer):
|
||||||
for container in podSpec.get('initContainers', []) + podSpec.get('containers', []):
|
for container in podSpec.get("initContainers", []) + podSpec.get(
|
||||||
image = container.get('image')
|
"containers", []
|
||||||
|
):
|
||||||
|
image = container.get("image")
|
||||||
if len(image.strip()) == 0:
|
if len(image.strip()) == 0:
|
||||||
# Ignoring container because it has no reference to image
|
# Ignoring container because it has no reference to image
|
||||||
continue
|
continue
|
||||||
@@ -93,29 +94,35 @@ class OpenShiftAnalyzeImageStream(object):
|
|||||||
# pending or running. Additionally, it has to be at least as old as the minimum
|
# pending or running. Additionally, it has to be at least as old as the minimum
|
||||||
# age threshold defined by the algorithm.
|
# age threshold defined by the algorithm.
|
||||||
too_young = is_too_young_object(pod, self.max_creationTimestamp)
|
too_young = is_too_young_object(pod, self.max_creationTimestamp)
|
||||||
if pod['status']['phase'] not in ("Running", "Pending") and too_young:
|
if pod["status"]["phase"] not in ("Running", "Pending") and too_young:
|
||||||
continue
|
continue
|
||||||
referrer = {
|
referrer = {
|
||||||
"kind": pod["kind"],
|
"kind": pod["kind"],
|
||||||
"namespace": pod["metadata"]["namespace"],
|
"namespace": pod["metadata"]["namespace"],
|
||||||
"name": pod["metadata"]["name"],
|
"name": pod["metadata"]["name"],
|
||||||
}
|
}
|
||||||
err = self.analyze_refs_from_pod_spec(pod['spec'], referrer)
|
err = self.analyze_refs_from_pod_spec(pod["spec"], referrer)
|
||||||
if err:
|
if err:
|
||||||
return err
|
return err
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def analyze_refs_pod_creators(self, resources):
|
def analyze_refs_pod_creators(self, resources):
|
||||||
keys = (
|
keys = (
|
||||||
"ReplicationController", "DeploymentConfig", "DaemonSet",
|
"ReplicationController",
|
||||||
"Deployment", "ReplicaSet", "StatefulSet", "Job", "CronJob"
|
"DeploymentConfig",
|
||||||
|
"DaemonSet",
|
||||||
|
"Deployment",
|
||||||
|
"ReplicaSet",
|
||||||
|
"StatefulSet",
|
||||||
|
"Job",
|
||||||
|
"CronJob",
|
||||||
)
|
)
|
||||||
|
|
||||||
for k, objects in iteritems(resources):
|
for k, objects in resources.items():
|
||||||
if k not in keys:
|
if k not in keys:
|
||||||
continue
|
continue
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
if k == 'CronJob':
|
if k == "CronJob":
|
||||||
spec = obj["spec"]["jobTemplate"]["spec"]["template"]["spec"]
|
spec = obj["spec"]["jobTemplate"]["spec"]["template"]["spec"]
|
||||||
else:
|
else:
|
||||||
spec = obj["spec"]["template"]["spec"]
|
spec = obj["spec"]["template"]["spec"]
|
||||||
@@ -132,75 +139,89 @@ class OpenShiftAnalyzeImageStream(object):
|
|||||||
def analyze_refs_from_strategy(self, build_strategy, namespace, referrer):
|
def analyze_refs_from_strategy(self, build_strategy, namespace, referrer):
|
||||||
# Determine 'from' reference
|
# Determine 'from' reference
|
||||||
def _determine_source_strategy():
|
def _determine_source_strategy():
|
||||||
for src in ('sourceStrategy', 'dockerStrategy', 'customStrategy'):
|
for src in ("sourceStrategy", "dockerStrategy", "customStrategy"):
|
||||||
strategy = build_strategy.get(src)
|
strategy = build_strategy.get(src)
|
||||||
if strategy:
|
if strategy:
|
||||||
return strategy.get('from')
|
return strategy.get("from")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _parse_image_stream_image_name(name):
|
def _parse_image_stream_image_name(name):
|
||||||
v = name.split('@')
|
v = name.split("@")
|
||||||
if len(v) != 2:
|
if len(v) != 2:
|
||||||
return None, None, "expected exactly one @ in the isimage name %s" % name
|
return (
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"expected exactly one @ in the isimage name %s" % name,
|
||||||
|
)
|
||||||
name = v[0]
|
name = v[0]
|
||||||
tag = v[1]
|
tag = v[1]
|
||||||
if len(name) == 0 or len(tag) == 0:
|
if len(name) == 0 or len(tag) == 0:
|
||||||
return None, None, "image stream image name %s must have a name and ID" % name
|
return (
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"image stream image name %s must have a name and ID" % name,
|
||||||
|
)
|
||||||
return name, tag, None
|
return name, tag, None
|
||||||
|
|
||||||
def _parse_image_stream_tag_name(name):
|
def _parse_image_stream_tag_name(name):
|
||||||
if "@" in name:
|
if "@" in name:
|
||||||
return None, None, "%s is an image stream image, not an image stream tag" % name
|
return (
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"%s is an image stream image, not an image stream tag" % name,
|
||||||
|
)
|
||||||
v = name.split(":")
|
v = name.split(":")
|
||||||
if len(v) != 2:
|
if len(v) != 2:
|
||||||
return None, None, "expected exactly one : delimiter in the istag %s" % name
|
return (
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"expected exactly one : delimiter in the istag %s" % name,
|
||||||
|
)
|
||||||
name = v[0]
|
name = v[0]
|
||||||
tag = v[1]
|
tag = v[1]
|
||||||
if len(name) == 0 or len(tag) == 0:
|
if len(name) == 0 or len(tag) == 0:
|
||||||
return None, None, "image stream tag name %s must have a name and a tag" % name
|
return (
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"image stream tag name %s must have a name and a tag" % name,
|
||||||
|
)
|
||||||
return name, tag, None
|
return name, tag, None
|
||||||
|
|
||||||
from_strategy = _determine_source_strategy()
|
from_strategy = _determine_source_strategy()
|
||||||
if not from_strategy:
|
if from_strategy:
|
||||||
# Build strategy not found
|
if from_strategy.get("kind") == "DockerImage":
|
||||||
return
|
docker_image_ref = from_strategy.get("name").strip()
|
||||||
|
if len(docker_image_ref) > 0:
|
||||||
if from_strategy.get('kind') == "DockerImage":
|
err = self.analyze_reference_image(docker_image_ref, referrer)
|
||||||
docker_image_ref = from_strategy.get('name').strip()
|
elif from_strategy.get("kind") == "ImageStreamImage":
|
||||||
if len(docker_image_ref) > 0:
|
name, tag, error = _parse_image_stream_image_name(
|
||||||
err = self.analyze_reference_image(docker_image_ref, referrer)
|
from_strategy.get("name")
|
||||||
|
)
|
||||||
elif from_strategy.get('kind') == "ImageStreamImage":
|
if error:
|
||||||
name, tag, error = _parse_image_stream_image_name(from_strategy.get('name'))
|
if not self.ignore_invalid_refs:
|
||||||
if error:
|
return error
|
||||||
if not self.ignore_invalid_refs:
|
else:
|
||||||
return error
|
namespace = from_strategy.get("namespace") or namespace
|
||||||
else:
|
self.used_images.append(
|
||||||
namespace = from_strategy.get('namespace') or namespace
|
{"namespace": namespace, "name": name, "tag": tag}
|
||||||
self.used_images.append({
|
)
|
||||||
'namespace': namespace,
|
elif from_strategy.get("kind") == "ImageStreamTag":
|
||||||
'name': name,
|
name, tag, error = _parse_image_stream_tag_name(
|
||||||
'tag': tag
|
from_strategy.get("name")
|
||||||
})
|
)
|
||||||
elif from_strategy.get('kind') == "ImageStreamTag":
|
if error:
|
||||||
name, tag, error = _parse_image_stream_tag_name(from_strategy.get('name'))
|
if not self.ignore_invalid_refs:
|
||||||
if error:
|
return error
|
||||||
if not self.ignore_invalid_refs:
|
else:
|
||||||
return error
|
namespace = from_strategy.get("namespace") or namespace
|
||||||
else:
|
self.used_tags.append(
|
||||||
namespace = from_strategy.get('namespace') or namespace
|
{"namespace": namespace, "name": name, "tag": tag}
|
||||||
self.used_tags.append({
|
)
|
||||||
'namespace': namespace,
|
|
||||||
'name': name,
|
|
||||||
'tag': tag
|
|
||||||
})
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
def analyze_refs_from_build_strategy(self, resources):
|
def analyze_refs_from_build_strategy(self, resources):
|
||||||
# Json Path is always spec.strategy
|
# Json Path is always spec.strategy
|
||||||
keys = ("BuildConfig", "Build")
|
keys = ("BuildConfig", "Build")
|
||||||
for k, objects in iteritems(resources):
|
for k, objects in resources.items():
|
||||||
if k not in keys:
|
if k not in keys:
|
||||||
continue
|
continue
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
@@ -209,16 +230,20 @@ class OpenShiftAnalyzeImageStream(object):
|
|||||||
"namespace": obj["metadata"]["namespace"],
|
"namespace": obj["metadata"]["namespace"],
|
||||||
"name": obj["metadata"]["name"],
|
"name": obj["metadata"]["name"],
|
||||||
}
|
}
|
||||||
error = self.analyze_refs_from_strategy(obj['spec']['strategy'],
|
error = self.analyze_refs_from_strategy(
|
||||||
obj['metadata']['namespace'],
|
obj["spec"]["strategy"], obj["metadata"]["namespace"], referrer
|
||||||
referrer)
|
)
|
||||||
if not error:
|
if error is not None:
|
||||||
return "%s/%s/%s: %s" % (referrer["kind"], referrer["namespace"], referrer["name"], error)
|
return "%s/%s/%s: %s" % (
|
||||||
|
referrer["kind"],
|
||||||
|
referrer["namespace"],
|
||||||
|
referrer["name"],
|
||||||
|
error,
|
||||||
|
)
|
||||||
|
|
||||||
def analyze_image_stream(self, resources):
|
def analyze_image_stream(self, resources):
|
||||||
|
|
||||||
# Analyze image reference from Pods
|
# Analyze image reference from Pods
|
||||||
error = self.analyze_refs_from_pods(resources['Pod'])
|
error = self.analyze_refs_from_pods(resources["Pod"])
|
||||||
if error:
|
if error:
|
||||||
return None, None, error
|
return None, None, error
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import traceback
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
|
||||||
from ansible.module_utils.parsing.convert_bool import boolean
|
from ansible.module_utils.parsing.convert_bool import boolean
|
||||||
from ansible.module_utils.six import string_types
|
|
||||||
|
|
||||||
try:
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
AnsibleOpenshiftModule,
|
||||||
K8sAnsibleMixin,
|
)
|
||||||
get_api_client,
|
|
||||||
)
|
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes.dynamic.exceptions import DynamicApiError
|
from kubernetes.dynamic.exceptions import DynamicApiError
|
||||||
@@ -53,10 +44,17 @@ def follow_imagestream_tag_reference(stream, tag):
|
|||||||
return name, tag, len(parts) == 2
|
return name, tag, len(parts) == 2
|
||||||
|
|
||||||
content = []
|
content = []
|
||||||
err_cross_stream_ref = "tag %s points to an imagestreamtag from another ImageStream" % tag
|
err_cross_stream_ref = (
|
||||||
|
"tag %s points to an imagestreamtag from another ImageStream" % tag
|
||||||
|
)
|
||||||
while True:
|
while True:
|
||||||
if tag in content:
|
if tag in content:
|
||||||
return tag, None, multiple, "tag %s on the image stream is a reference to same tag" % tag
|
return (
|
||||||
|
tag,
|
||||||
|
None,
|
||||||
|
multiple,
|
||||||
|
"tag %s on the image stream is a reference to same tag" % tag,
|
||||||
|
)
|
||||||
content.append(tag)
|
content.append(tag)
|
||||||
tag_ref = _imagestream_has_tag()
|
tag_ref = _imagestream_has_tag()
|
||||||
if not tag_ref:
|
if not tag_ref:
|
||||||
@@ -65,7 +63,10 @@ def follow_imagestream_tag_reference(stream, tag):
|
|||||||
if not tag_ref.get("from") or tag_ref["from"]["kind"] != "ImageStreamTag":
|
if not tag_ref.get("from") or tag_ref["from"]["kind"] != "ImageStreamTag":
|
||||||
return tag, tag_ref, multiple, None
|
return tag, tag_ref, multiple, None
|
||||||
|
|
||||||
if tag_ref["from"]["namespace"] != "" and tag_ref["from"]["namespace"] != stream["metadata"]["namespace"]:
|
if (
|
||||||
|
tag_ref["from"]["namespace"] != ""
|
||||||
|
and tag_ref["from"]["namespace"] != stream["metadata"]["namespace"]
|
||||||
|
):
|
||||||
return tag, None, multiple, err_cross_stream_ref
|
return tag, None, multiple, err_cross_stream_ref
|
||||||
|
|
||||||
# The reference needs to be followed with two format patterns:
|
# The reference needs to be followed with two format patterns:
|
||||||
@@ -73,7 +74,12 @@ def follow_imagestream_tag_reference(stream, tag):
|
|||||||
if ":" in tag_ref["from"]["name"]:
|
if ":" in tag_ref["from"]["name"]:
|
||||||
name, tagref, result = _imagestream_split_tag(tag_ref["from"]["name"])
|
name, tagref, result = _imagestream_split_tag(tag_ref["from"]["name"])
|
||||||
if not result:
|
if not result:
|
||||||
return tag, None, multiple, "tag %s points to an invalid imagestreamtag" % tag
|
return (
|
||||||
|
tag,
|
||||||
|
None,
|
||||||
|
multiple,
|
||||||
|
"tag %s points to an invalid imagestreamtag" % tag,
|
||||||
|
)
|
||||||
if name != stream["metadata"]["namespace"]:
|
if name != stream["metadata"]["namespace"]:
|
||||||
# anotheris:sometag - this should not happen.
|
# anotheris:sometag - this should not happen.
|
||||||
return tag, None, multiple, err_cross_stream_ref
|
return tag, None, multiple, err_cross_stream_ref
|
||||||
@@ -84,27 +90,12 @@ def follow_imagestream_tag_reference(stream, tag):
|
|||||||
multiple = True
|
multiple = True
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftImportImage(K8sAnsibleMixin):
|
class OpenShiftImportImage(AnsibleOpenshiftModule):
|
||||||
def __init__(self, module):
|
def __init__(self, **kwargs):
|
||||||
self.module = module
|
super(OpenShiftImportImage, self).__init__(**kwargs)
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception),
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftImportImage, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
|
|
||||||
self._rest_client = None
|
self._rest_client = None
|
||||||
self.registryhost = self.params.get('registry_url')
|
self.registryhost = self.params.get("registry_url")
|
||||||
self.changed = False
|
self.changed = False
|
||||||
|
|
||||||
ref_policy = self.params.get("reference_policy")
|
ref_policy = self.params.get("reference_policy")
|
||||||
@@ -114,9 +105,7 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
elif ref_policy == "local":
|
elif ref_policy == "local":
|
||||||
ref_policy_type = "Local"
|
ref_policy_type = "Local"
|
||||||
|
|
||||||
self.ref_policy = {
|
self.ref_policy = {"type": ref_policy_type}
|
||||||
"type": ref_policy_type
|
|
||||||
}
|
|
||||||
|
|
||||||
self.validate_certs = self.params.get("validate_registry_certs")
|
self.validate_certs = self.params.get("validate_registry_certs")
|
||||||
self.cluster_resources = {}
|
self.cluster_resources = {}
|
||||||
@@ -128,15 +117,15 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"name": stream["metadata"]["name"],
|
"name": stream["metadata"]["name"],
|
||||||
"namespace": stream["metadata"]["namespace"],
|
"namespace": stream["metadata"]["namespace"],
|
||||||
"resourceVersion": stream["metadata"].get("resourceVersion")
|
"resourceVersion": stream["metadata"].get("resourceVersion"),
|
||||||
},
|
},
|
||||||
"spec": {
|
"spec": {"import": True},
|
||||||
"import": True
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
annotations = stream.get("annotations", {})
|
annotations = stream.get("annotations", {})
|
||||||
insecure = boolean(annotations.get("openshift.io/image.insecureRepository", True))
|
insecure = boolean(
|
||||||
|
annotations.get("openshift.io/image.insecureRepository", True)
|
||||||
|
)
|
||||||
if self.validate_certs is not None:
|
if self.validate_certs is not None:
|
||||||
insecure = not self.validate_certs
|
insecure = not self.validate_certs
|
||||||
return isi, insecure
|
return isi, insecure
|
||||||
@@ -150,7 +139,7 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
},
|
},
|
||||||
"importPolicy": {
|
"importPolicy": {
|
||||||
"insecure": insecure,
|
"insecure": insecure,
|
||||||
"scheduled": self.params.get("scheduled")
|
"scheduled": self.params.get("scheduled"),
|
||||||
},
|
},
|
||||||
"referencePolicy": self.ref_policy,
|
"referencePolicy": self.ref_policy,
|
||||||
}
|
}
|
||||||
@@ -173,26 +162,23 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
scheduled = scheduled or old_tag["importPolicy"].get("scheduled")
|
scheduled = scheduled or old_tag["importPolicy"].get("scheduled")
|
||||||
|
|
||||||
images = isi["spec"].get("images", [])
|
images = isi["spec"].get("images", [])
|
||||||
images.append({
|
images.append(
|
||||||
"from": {
|
{
|
||||||
"kind": "DockerImage",
|
"from": {
|
||||||
"name": tags.get(k),
|
"kind": "DockerImage",
|
||||||
},
|
"name": tags.get(k),
|
||||||
"to": {
|
},
|
||||||
"name": k
|
"to": {"name": k},
|
||||||
},
|
"importPolicy": {"insecure": insecure, "scheduled": scheduled},
|
||||||
"importPolicy": {
|
"referencePolicy": self.ref_policy,
|
||||||
"insecure": insecure,
|
}
|
||||||
"scheduled": scheduled
|
)
|
||||||
},
|
|
||||||
"referencePolicy": self.ref_policy,
|
|
||||||
})
|
|
||||||
isi["spec"]["images"] = images
|
isi["spec"]["images"] = images
|
||||||
return isi
|
return isi
|
||||||
|
|
||||||
def create_image_stream(self, ref):
|
def create_image_stream(self, ref):
|
||||||
"""
|
"""
|
||||||
Create new ImageStream and accompanying ImageStreamImport
|
Create new ImageStream and accompanying ImageStreamImport
|
||||||
"""
|
"""
|
||||||
source = self.params.get("source")
|
source = self.params.get("source")
|
||||||
if not source:
|
if not source:
|
||||||
@@ -207,27 +193,20 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
if self.params.get("all") and not ref["tag"]:
|
if self.params.get("all") and not ref["tag"]:
|
||||||
spec = dict(
|
spec = dict(dockerImageRepository=source)
|
||||||
dockerImageRepository=source
|
|
||||||
)
|
|
||||||
isi = self.create_image_stream_import_all(stream, source)
|
isi = self.create_image_stream_import_all(stream, source)
|
||||||
else:
|
else:
|
||||||
spec = dict(
|
spec = dict(
|
||||||
tags=[
|
tags=[
|
||||||
{
|
{
|
||||||
"from": {
|
"from": {"kind": "DockerImage", "name": source},
|
||||||
"kind": "DockerImage",
|
"referencePolicy": self.ref_policy,
|
||||||
"name": source
|
|
||||||
},
|
|
||||||
"referencePolicy": self.ref_policy
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
tags = {ref["tag"]: source}
|
tags = {ref["tag"]: source}
|
||||||
isi = self.create_image_stream_import_tags(stream, tags)
|
isi = self.create_image_stream_import_tags(stream, tags)
|
||||||
stream.update(
|
stream.update(dict(spec=spec))
|
||||||
dict(spec=spec)
|
|
||||||
)
|
|
||||||
return stream, isi
|
return stream, isi
|
||||||
|
|
||||||
def import_all(self, istream):
|
def import_all(self, istream):
|
||||||
@@ -244,8 +223,9 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
if t.get("from") and t["from"].get("kind") == "DockerImage":
|
if t.get("from") and t["from"].get("kind") == "DockerImage":
|
||||||
tags[t.get("name")] = t["from"].get("name")
|
tags[t.get("name")] = t["from"].get("name")
|
||||||
if tags == {}:
|
if tags == {}:
|
||||||
msg = "image stream %s/%s does not have tags pointing to external container images" % (
|
msg = (
|
||||||
stream["metadata"]["namespace"], stream["metadata"]["name"]
|
"image stream %s/%s does not have tags pointing to external container images"
|
||||||
|
% (stream["metadata"]["namespace"], stream["metadata"]["name"])
|
||||||
)
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
isi = self.create_image_stream_import_tags(stream, tags)
|
isi = self.create_image_stream_import_tags(stream, tags)
|
||||||
@@ -260,7 +240,9 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
source = self.params.get("source")
|
source = self.params.get("source")
|
||||||
|
|
||||||
# Follow any referential tags to the destination
|
# Follow any referential tags to the destination
|
||||||
final_tag, existing, multiple, err = follow_imagestream_tag_reference(stream, tag)
|
final_tag, existing, multiple, err = follow_imagestream_tag_reference(
|
||||||
|
stream, tag
|
||||||
|
)
|
||||||
if err:
|
if err:
|
||||||
if err == err_stream_not_found_ref:
|
if err == err_stream_not_found_ref:
|
||||||
# Create a new tag
|
# Create a new tag
|
||||||
@@ -269,7 +251,10 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
# if the from is still empty this means there's no such tag defined
|
# if the from is still empty this means there's no such tag defined
|
||||||
# nor we can't create any from .spec.dockerImageRepository
|
# nor we can't create any from .spec.dockerImageRepository
|
||||||
if not source:
|
if not source:
|
||||||
msg = "the tag %s does not exist on the image stream - choose an existing tag to import" % tag
|
msg = (
|
||||||
|
"the tag %s does not exist on the image stream - choose an existing tag to import"
|
||||||
|
% tag
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
existing = {
|
existing = {
|
||||||
"from": {
|
"from": {
|
||||||
@@ -281,13 +266,21 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
self.fail_json(msg=err)
|
self.fail_json(msg=err)
|
||||||
else:
|
else:
|
||||||
# Disallow re-importing anything other than DockerImage
|
# Disallow re-importing anything other than DockerImage
|
||||||
if existing.get("from", {}) and existing["from"].get("kind") != "DockerImage":
|
if (
|
||||||
|
existing.get("from", {})
|
||||||
|
and existing["from"].get("kind") != "DockerImage"
|
||||||
|
):
|
||||||
msg = "tag {tag} points to existing {kind}/={name}, it cannot be re-imported.".format(
|
msg = "tag {tag} points to existing {kind}/={name}, it cannot be re-imported.".format(
|
||||||
tag=tag, kind=existing["from"]["kind"], name=existing["from"]["name"]
|
tag=tag,
|
||||||
|
kind=existing["from"]["kind"],
|
||||||
|
name=existing["from"]["name"],
|
||||||
)
|
)
|
||||||
# disallow changing an existing tag
|
# disallow changing an existing tag
|
||||||
if not existing.get("from", {}):
|
if not existing.get("from", {}):
|
||||||
msg = "tag %s already exists - you cannot change the source using this module." % tag
|
msg = (
|
||||||
|
"tag %s already exists - you cannot change the source using this module."
|
||||||
|
% tag
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
if source and source != existing["from"]["name"]:
|
if source and source != existing["from"]["name"]:
|
||||||
if multiple:
|
if multiple:
|
||||||
@@ -295,7 +288,10 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
tag, final_tag, existing["from"]["name"]
|
tag, final_tag, existing["from"]["name"]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
msg = "the tag %s points to %s you cannot change the source using this module." % (tag, final_tag)
|
msg = (
|
||||||
|
"the tag %s points to %s you cannot change the source using this module."
|
||||||
|
% (tag, final_tag)
|
||||||
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
|
|
||||||
# Set the target item to import
|
# Set the target item to import
|
||||||
@@ -333,13 +329,13 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
kind=kind,
|
kind=kind,
|
||||||
api_version=api_version,
|
api_version=api_version,
|
||||||
name=ref.get("name"),
|
name=ref.get("name"),
|
||||||
namespace=self.params.get("namespace")
|
namespace=self.params.get("namespace"),
|
||||||
)
|
)
|
||||||
result = self.kubernetes_facts(**params)
|
result = self.kubernetes_facts(**params)
|
||||||
if not result["api_found"]:
|
if not result["api_found"]:
|
||||||
msg = 'Failed to find API for resource with apiVersion "{0}" and kind "{1}"'.format(
|
msg = 'Failed to find API for resource with apiVersion "{0}" and kind "{1}"'.format(
|
||||||
api_version, kind
|
api_version, kind
|
||||||
),
|
)
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
imagestream = None
|
imagestream = None
|
||||||
if len(result["resources"]) > 0:
|
if len(result["resources"]) > 0:
|
||||||
@@ -359,7 +355,9 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
def parse_image_reference(self, image_ref):
|
def parse_image_reference(self, image_ref):
|
||||||
result, err = parse_docker_image_ref(image_ref, self.module)
|
result, err = parse_docker_image_ref(image_ref, self.module)
|
||||||
if result.get("digest"):
|
if result.get("digest"):
|
||||||
self.fail_json(msg="Cannot import by ID, error with definition: %s" % image_ref)
|
self.fail_json(
|
||||||
|
msg="Cannot import by ID, error with definition: %s" % image_ref
|
||||||
|
)
|
||||||
tag = result.get("tag") or None
|
tag = result.get("tag") or None
|
||||||
if not self.params.get("all") and not tag:
|
if not self.params.get("all") and not tag:
|
||||||
tag = "latest"
|
tag = "latest"
|
||||||
@@ -369,10 +367,9 @@ class OpenShiftImportImage(K8sAnsibleMixin):
|
|||||||
return dict(name=result.get("name"), tag=tag, source=image_ref)
|
return dict(name=result.get("name"), tag=tag, source=image_ref)
|
||||||
|
|
||||||
def execute_module(self):
|
def execute_module(self):
|
||||||
|
|
||||||
names = []
|
names = []
|
||||||
name = self.params.get("name")
|
name = self.params.get("name")
|
||||||
if isinstance(name, string_types):
|
if isinstance(name, str):
|
||||||
names.append(name)
|
names.append(name)
|
||||||
elif isinstance(name, list):
|
elif isinstance(name, list):
|
||||||
names = name
|
names = name
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +12,6 @@ import os
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
from ansible.module_utils.parsing.convert_bool import boolean
|
from ansible.module_utils.parsing.convert_bool import boolean
|
||||||
from ansible.module_utils.six import iteritems
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ldap
|
import ldap
|
||||||
@@ -24,109 +24,119 @@ LDAP_SEARCH_OUT_OF_SCOPE_ERROR = "trying to search by DN for an entry that exist
|
|||||||
|
|
||||||
def validate_ldap_sync_config(config):
|
def validate_ldap_sync_config(config):
|
||||||
# Validate url
|
# Validate url
|
||||||
url = config.get('url')
|
url = config.get("url")
|
||||||
if not url:
|
if not url:
|
||||||
return "url should be non empty attribute."
|
return "url should be non empty attribute."
|
||||||
|
|
||||||
# Make sure bindDN and bindPassword are both set, or both unset
|
# Make sure bindDN and bindPassword are both set, or both unset
|
||||||
bind_dn = config.get('bindDN', "")
|
bind_dn = config.get("bindDN", "")
|
||||||
bind_password = config.get('bindPassword', "")
|
bind_password = config.get("bindPassword", "")
|
||||||
if (len(bind_dn) == 0) != (len(bind_password) == 0):
|
if (len(bind_dn) == 0) != (len(bind_password) == 0):
|
||||||
return "bindDN and bindPassword must both be specified, or both be empty."
|
return "bindDN and bindPassword must both be specified, or both be empty."
|
||||||
|
|
||||||
insecure = boolean(config.get('insecure'))
|
insecure = boolean(config.get("insecure"))
|
||||||
ca_file = config.get('ca')
|
ca_file = config.get("ca")
|
||||||
if insecure:
|
if insecure:
|
||||||
if url.startswith('ldaps://'):
|
if url.startswith("ldaps://"):
|
||||||
return "Cannot use ldaps scheme with insecure=true."
|
return "Cannot use ldaps scheme with insecure=true."
|
||||||
if ca_file:
|
if ca_file:
|
||||||
return "Cannot specify a ca with insecure=true."
|
return "Cannot specify a ca with insecure=true."
|
||||||
elif ca_file and not os.path.isfile(ca_file):
|
elif ca_file and not os.path.isfile(ca_file):
|
||||||
return "could not read ca file: {0}.".format(ca_file)
|
return "could not read ca file: {0}.".format(ca_file)
|
||||||
|
|
||||||
nameMapping = config.get('groupUIDNameMapping', {})
|
nameMapping = config.get("groupUIDNameMapping", {})
|
||||||
for k, v in iteritems(nameMapping):
|
for k, v in nameMapping.items():
|
||||||
if len(k) == 0 or len(v) == 0:
|
if len(k) == 0 or len(v) == 0:
|
||||||
return "groupUIDNameMapping has empty key or value"
|
return "groupUIDNameMapping has empty key or value"
|
||||||
|
|
||||||
schemas = []
|
schemas = []
|
||||||
schema_list = ('rfc2307', 'activeDirectory', 'augmentedActiveDirectory')
|
schema_list = ("rfc2307", "activeDirectory", "augmentedActiveDirectory")
|
||||||
for schema in schema_list:
|
for schema in schema_list:
|
||||||
if schema in config:
|
if schema in config:
|
||||||
schemas.append(schema)
|
schemas.append(schema)
|
||||||
|
|
||||||
if len(schemas) == 0:
|
if len(schemas) == 0:
|
||||||
return "No schema-specific config was provided, should be one of %s" % schema_list
|
return (
|
||||||
|
"No schema-specific config was provided, should be one of %s"
|
||||||
|
% ", ".join(schema_list)
|
||||||
|
)
|
||||||
if len(schemas) > 1:
|
if len(schemas) > 1:
|
||||||
return "Exactly one schema-specific config is required; found (%d) %s" % (len(schemas), ','.join(schemas))
|
return "Exactly one schema-specific config is required; found (%d) %s" % (
|
||||||
|
len(schemas),
|
||||||
|
",".join(schemas),
|
||||||
|
)
|
||||||
|
|
||||||
if schemas[0] == 'rfc2307':
|
if schemas[0] == "rfc2307":
|
||||||
return validate_RFC2307(config.get("rfc2307"))
|
return validate_RFC2307(config.get("rfc2307"))
|
||||||
elif schemas[0] == 'activeDirectory':
|
elif schemas[0] == "activeDirectory":
|
||||||
return validate_ActiveDirectory(config.get("activeDirectory"))
|
return validate_ActiveDirectory(config.get("activeDirectory"))
|
||||||
elif schemas[0] == 'augmentedActiveDirectory':
|
elif schemas[0] == "augmentedActiveDirectory":
|
||||||
return validate_AugmentedActiveDirectory(config.get("augmentedActiveDirectory"))
|
return validate_AugmentedActiveDirectory(config.get("augmentedActiveDirectory"))
|
||||||
|
|
||||||
|
|
||||||
def validate_ldap_query(qry, isDNOnly=False):
|
def validate_ldap_query(qry, isDNOnly=False):
|
||||||
|
|
||||||
# validate query scope
|
# validate query scope
|
||||||
scope = qry.get('scope')
|
scope = qry.get("scope")
|
||||||
if scope and scope not in ("", "sub", "one", "base"):
|
if scope and scope not in ("", "sub", "one", "base"):
|
||||||
return "invalid scope %s" % scope
|
return "invalid scope %s" % scope
|
||||||
|
|
||||||
# validate deref aliases
|
# validate deref aliases
|
||||||
derefAlias = qry.get('derefAliases')
|
derefAlias = qry.get("derefAliases")
|
||||||
if derefAlias and derefAlias not in ("never", "search", "base", "always"):
|
if derefAlias and derefAlias not in ("never", "search", "base", "always"):
|
||||||
return "not a valid LDAP alias dereferncing behavior: %s", derefAlias
|
return "not a valid LDAP alias dereferncing behavior: %s", derefAlias
|
||||||
|
|
||||||
# validate timeout
|
# validate timeout
|
||||||
timeout = qry.get('timeout')
|
timeout = qry.get("timeout")
|
||||||
if timeout and float(timeout) < 0:
|
if timeout and float(timeout) < 0:
|
||||||
return "timeout must be equal to or greater than zero"
|
return "timeout must be equal to or greater than zero"
|
||||||
|
|
||||||
# Validate DN only
|
# Validate DN only
|
||||||
qry_filter = qry.get('filter', "")
|
qry_filter = qry.get("filter", "")
|
||||||
if isDNOnly:
|
if isDNOnly:
|
||||||
if len(qry_filter) > 0:
|
if len(qry_filter) > 0:
|
||||||
return 'cannot specify a filter when using "dn" as the UID attribute'
|
return 'cannot specify a filter when using "dn" as the UID attribute'
|
||||||
else:
|
else:
|
||||||
# validate filter
|
# validate filter
|
||||||
if len(qry_filter) == 0 or qry_filter[0] != '(':
|
if len(qry_filter) == 0 or qry_filter[0] != "(":
|
||||||
return "filter does not start with an '('"
|
return "filter does not start with an '('"
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def validate_RFC2307(config):
|
def validate_RFC2307(config):
|
||||||
qry = config.get('groupsQuery')
|
qry = config.get("groupsQuery")
|
||||||
if not qry or not isinstance(qry, dict):
|
if not qry or not isinstance(qry, dict):
|
||||||
return "RFC2307: groupsQuery requires a dictionary"
|
return "RFC2307: groupsQuery requires a dictionary"
|
||||||
error = validate_ldap_query(qry)
|
error = validate_ldap_query(qry)
|
||||||
if not error:
|
if not error:
|
||||||
return error
|
return error
|
||||||
for field in ('groupUIDAttribute', 'groupNameAttributes', 'groupMembershipAttributes',
|
for field in (
|
||||||
'userUIDAttribute', 'userNameAttributes'):
|
"groupUIDAttribute",
|
||||||
|
"groupNameAttributes",
|
||||||
|
"groupMembershipAttributes",
|
||||||
|
"userUIDAttribute",
|
||||||
|
"userNameAttributes",
|
||||||
|
):
|
||||||
value = config.get(field)
|
value = config.get(field)
|
||||||
if not value:
|
if not value:
|
||||||
return "RFC2307: {0} is required.".format(field)
|
return "RFC2307: {0} is required.".format(field)
|
||||||
|
|
||||||
users_qry = config.get('usersQuery')
|
users_qry = config.get("usersQuery")
|
||||||
if not users_qry or not isinstance(users_qry, dict):
|
if not users_qry or not isinstance(users_qry, dict):
|
||||||
return "RFC2307: usersQuery requires a dictionary"
|
return "RFC2307: usersQuery requires a dictionary"
|
||||||
|
|
||||||
isUserDNOnly = (config.get('userUIDAttribute').strip() == 'dn')
|
isUserDNOnly = config.get("userUIDAttribute").strip() == "dn"
|
||||||
return validate_ldap_query(users_qry, isDNOnly=isUserDNOnly)
|
return validate_ldap_query(users_qry, isDNOnly=isUserDNOnly)
|
||||||
|
|
||||||
|
|
||||||
def validate_ActiveDirectory(config, label="ActiveDirectory"):
|
def validate_ActiveDirectory(config, label="ActiveDirectory"):
|
||||||
users_qry = config.get('usersQuery')
|
users_qry = config.get("usersQuery")
|
||||||
if not users_qry or not isinstance(users_qry, dict):
|
if not users_qry or not isinstance(users_qry, dict):
|
||||||
return "{0}: usersQuery requires as dictionnary".format(label)
|
return "{0}: usersQuery requires as dictionnary".format(label)
|
||||||
error = validate_ldap_query(users_qry)
|
error = validate_ldap_query(users_qry)
|
||||||
if not error:
|
if not error:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
for field in ('userNameAttributes', 'groupMembershipAttributes'):
|
for field in ("userNameAttributes", "groupMembershipAttributes"):
|
||||||
value = config.get(field)
|
value = config.get(field)
|
||||||
if not value:
|
if not value:
|
||||||
return "{0}: {1} is required.".format(field, label)
|
return "{0}: {1} is required.".format(field, label)
|
||||||
@@ -138,24 +148,24 @@ def validate_AugmentedActiveDirectory(config):
|
|||||||
error = validate_ActiveDirectory(config, label="AugmentedActiveDirectory")
|
error = validate_ActiveDirectory(config, label="AugmentedActiveDirectory")
|
||||||
if not error:
|
if not error:
|
||||||
return error
|
return error
|
||||||
for field in ('groupUIDAttribute', 'groupNameAttributes'):
|
for field in ("groupUIDAttribute", "groupNameAttributes"):
|
||||||
value = config.get(field)
|
value = config.get(field)
|
||||||
if not value:
|
if not value:
|
||||||
return "AugmentedActiveDirectory: {0} is required".format(field)
|
return "AugmentedActiveDirectory: {0} is required".format(field)
|
||||||
groups_qry = config.get('groupsQuery')
|
groups_qry = config.get("groupsQuery")
|
||||||
if not groups_qry or not isinstance(groups_qry, dict):
|
if not groups_qry or not isinstance(groups_qry, dict):
|
||||||
return "AugmentedActiveDirectory: groupsQuery requires as dictionnary."
|
return "AugmentedActiveDirectory: groupsQuery requires as dictionnary."
|
||||||
|
|
||||||
isGroupDNOnly = (config.get('groupUIDAttribute').strip() == 'dn')
|
isGroupDNOnly = config.get("groupUIDAttribute").strip() == "dn"
|
||||||
return validate_ldap_query(groups_qry, isDNOnly=isGroupDNOnly)
|
return validate_ldap_query(groups_qry, isDNOnly=isGroupDNOnly)
|
||||||
|
|
||||||
|
|
||||||
def determine_ldap_scope(scope):
|
def determine_ldap_scope(scope):
|
||||||
if scope in ("", "sub"):
|
if scope in ("", "sub"):
|
||||||
return ldap.SCOPE_SUBTREE
|
return ldap.SCOPE_SUBTREE
|
||||||
elif scope == 'base':
|
elif scope == "base":
|
||||||
return ldap.SCOPE_BASE
|
return ldap.SCOPE_BASE
|
||||||
elif scope == 'one':
|
elif scope == "one":
|
||||||
return ldap.SCOPE_ONELEVEL
|
return ldap.SCOPE_ONELEVEL
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -175,28 +185,28 @@ def determine_deref_aliases(derefAlias):
|
|||||||
|
|
||||||
def openshift_ldap_build_base_query(config):
|
def openshift_ldap_build_base_query(config):
|
||||||
qry = {}
|
qry = {}
|
||||||
if config.get('baseDN'):
|
if config.get("baseDN"):
|
||||||
qry['base'] = config.get('baseDN')
|
qry["base"] = config.get("baseDN")
|
||||||
|
|
||||||
scope = determine_ldap_scope(config.get('scope'))
|
scope = determine_ldap_scope(config.get("scope"))
|
||||||
if scope:
|
if scope:
|
||||||
qry['scope'] = scope
|
qry["scope"] = scope
|
||||||
|
|
||||||
pageSize = config.get('pageSize')
|
pageSize = config.get("pageSize")
|
||||||
if pageSize and int(pageSize) > 0:
|
if pageSize and int(pageSize) > 0:
|
||||||
qry['sizelimit'] = int(pageSize)
|
qry["sizelimit"] = int(pageSize)
|
||||||
|
|
||||||
timeout = config.get('timeout')
|
timeout = config.get("timeout")
|
||||||
if timeout and int(timeout) > 0:
|
if timeout and int(timeout) > 0:
|
||||||
qry['timeout'] = int(timeout)
|
qry["timeout"] = int(timeout)
|
||||||
|
|
||||||
filter = config.get('filter')
|
filter = config.get("filter")
|
||||||
if filter:
|
if filter:
|
||||||
qry['filterstr'] = filter
|
qry["filterstr"] = filter
|
||||||
|
|
||||||
derefAlias = determine_deref_aliases(config.get('derefAliases'))
|
derefAlias = determine_deref_aliases(config.get("derefAliases"))
|
||||||
if derefAlias:
|
if derefAlias:
|
||||||
qry['derefAlias'] = derefAlias
|
qry["derefAlias"] = derefAlias
|
||||||
return qry
|
return qry
|
||||||
|
|
||||||
|
|
||||||
@@ -205,32 +215,30 @@ def openshift_ldap_get_attribute_for_entry(entry, attribute):
|
|||||||
if isinstance(attribute, list):
|
if isinstance(attribute, list):
|
||||||
attributes = attribute
|
attributes = attribute
|
||||||
for k in attributes:
|
for k in attributes:
|
||||||
if k.lower() == 'dn':
|
if k.lower() == "dn":
|
||||||
return entry[0]
|
return entry[0]
|
||||||
v = entry[1].get(k, None)
|
v = entry[1].get(k, None)
|
||||||
if v:
|
if v:
|
||||||
if isinstance(v, list):
|
if isinstance(v, list):
|
||||||
result = []
|
result = []
|
||||||
for x in v:
|
for x in v:
|
||||||
if hasattr(x, 'decode'):
|
if hasattr(x, "decode"):
|
||||||
result.append(x.decode('utf-8'))
|
result.append(x.decode("utf-8"))
|
||||||
else:
|
else:
|
||||||
result.append(x)
|
result.append(x)
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
return v.decode('utf-8') if hasattr(v, 'decode') else v
|
return v.decode("utf-8") if hasattr(v, "decode") else v
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def ldap_split_host_port(hostport):
|
def ldap_split_host_port(hostport):
|
||||||
"""
|
"""
|
||||||
ldap_split_host_port splits a network address of the form "host:port",
|
ldap_split_host_port splits a network address of the form "host:port",
|
||||||
"host%zone:port", "[host]:port" or "[host%zone]:port" into host or
|
"host%zone:port", "[host]:port" or "[host%zone]:port" into host or
|
||||||
host%zone and port.
|
host%zone and port.
|
||||||
"""
|
"""
|
||||||
result = dict(
|
result = dict(scheme=None, netlocation=None, host=None, port=None)
|
||||||
scheme=None, netlocation=None, host=None, port=None
|
|
||||||
)
|
|
||||||
if not hostport:
|
if not hostport:
|
||||||
return result, None
|
return result, None
|
||||||
|
|
||||||
@@ -240,10 +248,10 @@ def ldap_split_host_port(hostport):
|
|||||||
if "://" in hostport:
|
if "://" in hostport:
|
||||||
idx = hostport.find(scheme_l)
|
idx = hostport.find(scheme_l)
|
||||||
result["scheme"] = hostport[:idx]
|
result["scheme"] = hostport[:idx]
|
||||||
netlocation = hostport[idx + len(scheme_l):]
|
netlocation = hostport[idx + len(scheme_l):] # fmt: skip
|
||||||
result["netlocation"] = netlocation
|
result["netlocation"] = netlocation
|
||||||
|
|
||||||
if netlocation[-1] == ']':
|
if netlocation[-1] == "]":
|
||||||
# ipv6 literal (with no port)
|
# ipv6 literal (with no port)
|
||||||
result["host"] = netlocation
|
result["host"] = netlocation
|
||||||
|
|
||||||
@@ -259,21 +267,32 @@ def ldap_split_host_port(hostport):
|
|||||||
|
|
||||||
def openshift_ldap_query_for_entries(connection, qry, unique_entry=True):
|
def openshift_ldap_query_for_entries(connection, qry, unique_entry=True):
|
||||||
# set deref alias (TODO: need to set a default value to reset for each transaction)
|
# set deref alias (TODO: need to set a default value to reset for each transaction)
|
||||||
derefAlias = qry.pop('derefAlias', None)
|
derefAlias = qry.pop("derefAlias", None)
|
||||||
if derefAlias:
|
if derefAlias:
|
||||||
ldap.set_option(ldap.OPT_DEREF, derefAlias)
|
ldap.set_option(ldap.OPT_DEREF, derefAlias)
|
||||||
try:
|
try:
|
||||||
result = connection.search_ext_s(**qry)
|
result = connection.search_ext_s(**qry)
|
||||||
if not result or len(result) == 0:
|
if not result or len(result) == 0:
|
||||||
return None, "Entry not found for base='{0}' and filter='{1}'".format(qry['base'], qry['filterstr'])
|
return None, "Entry not found for base='{0}' and filter='{1}'".format(
|
||||||
|
qry["base"], qry["filterstr"]
|
||||||
|
)
|
||||||
if len(result) > 1 and unique_entry:
|
if len(result) > 1 and unique_entry:
|
||||||
if qry.get('scope') == ldap.SCOPE_BASE:
|
if qry.get("scope") == ldap.SCOPE_BASE:
|
||||||
return None, "multiple entries found matching dn={0}: {1}".format(qry['base'], result)
|
return None, "multiple entries found matching dn={0}: {1}".format(
|
||||||
|
qry["base"], result
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return None, "multiple entries found matching filter {0}: {1}".format(qry['filterstr'], result)
|
return None, "multiple entries found matching filter {0}: {1}".format(
|
||||||
|
qry["filterstr"], result
|
||||||
|
)
|
||||||
return result, None
|
return result, None
|
||||||
except ldap.NO_SUCH_OBJECT:
|
except ldap.NO_SUCH_OBJECT:
|
||||||
return None, "search for entry with base dn='{0}' refers to a non-existent entry".format(qry['base'])
|
return (
|
||||||
|
None,
|
||||||
|
"search for entry with base dn='{0}' refers to a non-existent entry".format(
|
||||||
|
qry["base"]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def openshift_equal_dn_objects(dn_obj, other_dn_obj):
|
def openshift_equal_dn_objects(dn_obj, other_dn_obj):
|
||||||
@@ -303,7 +322,9 @@ def openshift_ancestorof_dn(dn, other):
|
|||||||
if len(dn_obj) >= len(other_dn_obj):
|
if len(dn_obj) >= len(other_dn_obj):
|
||||||
return False
|
return False
|
||||||
# Take the last attribute from the other DN to compare against
|
# Take the last attribute from the other DN to compare against
|
||||||
return openshift_equal_dn_objects(dn_obj, other_dn_obj[len(other_dn_obj) - len(dn_obj):])
|
return openshift_equal_dn_objects(
|
||||||
|
dn_obj, other_dn_obj[len(other_dn_obj) - len(dn_obj):] # fmt: skip
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OpenshiftLDAPQueryOnAttribute(object):
|
class OpenshiftLDAPQueryOnAttribute(object):
|
||||||
@@ -324,33 +345,38 @@ class OpenshiftLDAPQueryOnAttribute(object):
|
|||||||
output = []
|
output = []
|
||||||
hex_string = "0123456789abcdef"
|
hex_string = "0123456789abcdef"
|
||||||
for c in buffer:
|
for c in buffer:
|
||||||
if ord(c) > 0x7f or c in ('(', ')', '\\', '*') or c == 0:
|
if ord(c) > 0x7F or c in ("(", ")", "\\", "*") or c == 0:
|
||||||
first = ord(c) >> 4
|
first = ord(c) >> 4
|
||||||
second = ord(c) & 0xf
|
second = ord(c) & 0xF
|
||||||
output += ['\\', hex_string[first], hex_string[second]]
|
output += ["\\", hex_string[first], hex_string[second]]
|
||||||
else:
|
else:
|
||||||
output.append(c)
|
output.append(c)
|
||||||
return ''.join(output)
|
return "".join(output)
|
||||||
|
|
||||||
def build_request(self, ldapuid, attributes):
|
def build_request(self, ldapuid, attributes):
|
||||||
params = copy.deepcopy(self.qry)
|
params = copy.deepcopy(self.qry)
|
||||||
if self.query_attribute.lower() == 'dn':
|
if self.query_attribute.lower() == "dn":
|
||||||
if ldapuid:
|
if ldapuid:
|
||||||
if not openshift_equal_dn(ldapuid, params['base']) and not openshift_ancestorof_dn(params['base'], ldapuid):
|
if not openshift_equal_dn(
|
||||||
|
ldapuid, params["base"]
|
||||||
|
) and not openshift_ancestorof_dn(params["base"], ldapuid):
|
||||||
return None, LDAP_SEARCH_OUT_OF_SCOPE_ERROR
|
return None, LDAP_SEARCH_OUT_OF_SCOPE_ERROR
|
||||||
params['base'] = ldapuid
|
params["base"] = ldapuid
|
||||||
params['scope'] = ldap.SCOPE_BASE
|
params["scope"] = ldap.SCOPE_BASE
|
||||||
# filter that returns all values
|
# filter that returns all values
|
||||||
params['filterstr'] = "(objectClass=*)"
|
params["filterstr"] = "(objectClass=*)"
|
||||||
params['attrlist'] = attributes
|
params["attrlist"] = attributes
|
||||||
else:
|
else:
|
||||||
# Builds the query containing a filter that conjoins the common filter given
|
# Builds the query containing a filter that conjoins the common filter given
|
||||||
# in the configuration with the specific attribute filter for which the attribute value is given
|
# in the configuration with the specific attribute filter for which the attribute value is given
|
||||||
specificFilter = "%s=%s" % (self.escape_filter(self.query_attribute), self.escape_filter(ldapuid))
|
specificFilter = "%s=%s" % (
|
||||||
qry_filter = params.get('filterstr', None)
|
self.escape_filter(self.query_attribute),
|
||||||
|
self.escape_filter(ldapuid),
|
||||||
|
)
|
||||||
|
qry_filter = params.get("filterstr", None)
|
||||||
if qry_filter:
|
if qry_filter:
|
||||||
params['filterstr'] = "(&%s(%s))" % (qry_filter, specificFilter)
|
params["filterstr"] = "(&%s(%s))" % (qry_filter, specificFilter)
|
||||||
params['attrlist'] = attributes
|
params["attrlist"] = attributes
|
||||||
return params, None
|
return params, None
|
||||||
|
|
||||||
def ldap_search(self, connection, ldapuid, required_attributes, unique_entry=True):
|
def ldap_search(self, connection, ldapuid, required_attributes, unique_entry=True):
|
||||||
@@ -358,21 +384,29 @@ class OpenshiftLDAPQueryOnAttribute(object):
|
|||||||
if error:
|
if error:
|
||||||
return None, error
|
return None, error
|
||||||
# set deref alias (TODO: need to set a default value to reset for each transaction)
|
# set deref alias (TODO: need to set a default value to reset for each transaction)
|
||||||
derefAlias = query.pop('derefAlias', None)
|
derefAlias = query.pop("derefAlias", None)
|
||||||
if derefAlias:
|
if derefAlias:
|
||||||
ldap.set_option(ldap.OPT_DEREF, derefAlias)
|
ldap.set_option(ldap.OPT_DEREF, derefAlias)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = connection.search_ext_s(**query)
|
result = connection.search_ext_s(**query)
|
||||||
if not result or len(result) == 0:
|
if not result or len(result) == 0:
|
||||||
return None, "Entry not found for base='{0}' and filter='{1}'".format(query['base'], query['filterstr'])
|
return None, "Entry not found for base='{0}' and filter='{1}'".format(
|
||||||
|
query["base"], query["filterstr"]
|
||||||
|
)
|
||||||
if unique_entry:
|
if unique_entry:
|
||||||
if len(result) > 1:
|
if len(result) > 1:
|
||||||
return None, "Multiple Entries found matching search criteria: %s (%s)" % (query, result)
|
return (
|
||||||
|
None,
|
||||||
|
"Multiple Entries found matching search criteria: %s (%s)"
|
||||||
|
% (query, result),
|
||||||
|
)
|
||||||
result = result[0]
|
result = result[0]
|
||||||
return result, None
|
return result, None
|
||||||
except ldap.NO_SUCH_OBJECT:
|
except ldap.NO_SUCH_OBJECT:
|
||||||
return None, "Entry not found for base='{0}' and filter='{1}'".format(query['base'], query['filterstr'])
|
return None, "Entry not found for base='{0}' and filter='{1}'".format(
|
||||||
|
query["base"], query["filterstr"]
|
||||||
|
)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
return None, "Request %s failed due to: %s" % (query, err)
|
return None, "Request %s failed due to: %s" % (query, err)
|
||||||
|
|
||||||
@@ -384,30 +418,43 @@ class OpenshiftLDAPQuery(object):
|
|||||||
|
|
||||||
def build_request(self, attributes):
|
def build_request(self, attributes):
|
||||||
params = copy.deepcopy(self.qry)
|
params = copy.deepcopy(self.qry)
|
||||||
params['attrlist'] = attributes
|
params["attrlist"] = attributes
|
||||||
return params
|
return params
|
||||||
|
|
||||||
def ldap_search(self, connection, required_attributes):
|
def ldap_search(self, connection, required_attributes):
|
||||||
query = self.build_request(required_attributes)
|
query = self.build_request(required_attributes)
|
||||||
# set deref alias (TODO: need to set a default value to reset for each transaction)
|
# set deref alias (TODO: need to set a default value to reset for each transaction)
|
||||||
derefAlias = query.pop('derefAlias', None)
|
derefAlias = query.pop("derefAlias", None)
|
||||||
if derefAlias:
|
if derefAlias:
|
||||||
ldap.set_option(ldap.OPT_DEREF, derefAlias)
|
ldap.set_option(ldap.OPT_DEREF, derefAlias)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = connection.search_ext_s(**query)
|
result = connection.search_ext_s(**query)
|
||||||
if not result or len(result) == 0:
|
if not result or len(result) == 0:
|
||||||
return None, "Entry not found for base='{0}' and filter='{1}'".format(query['base'], query['filterstr'])
|
return None, "Entry not found for base='{0}' and filter='{1}'".format(
|
||||||
|
query["base"], query["filterstr"]
|
||||||
|
)
|
||||||
return result, None
|
return result, None
|
||||||
except ldap.NO_SUCH_OBJECT:
|
except ldap.NO_SUCH_OBJECT:
|
||||||
return None, "search for entry with base dn='{0}' refers to a non-existent entry".format(query['base'])
|
return (
|
||||||
|
None,
|
||||||
|
"search for entry with base dn='{0}' refers to a non-existent entry".format(
|
||||||
|
query["base"]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OpenshiftLDAPInterface(object):
|
class OpenshiftLDAPInterface(object):
|
||||||
|
def __init__(
|
||||||
def __init__(self, connection, groupQuery, groupNameAttributes, groupMembershipAttributes,
|
self,
|
||||||
userQuery, userNameAttributes, config):
|
connection,
|
||||||
|
groupQuery,
|
||||||
|
groupNameAttributes,
|
||||||
|
groupMembershipAttributes,
|
||||||
|
userQuery,
|
||||||
|
userNameAttributes,
|
||||||
|
config,
|
||||||
|
):
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
self.groupQuery = copy.deepcopy(groupQuery)
|
self.groupQuery = copy.deepcopy(groupQuery)
|
||||||
self.groupNameAttributes = groupNameAttributes
|
self.groupNameAttributes = groupNameAttributes
|
||||||
@@ -416,8 +463,12 @@ class OpenshiftLDAPInterface(object):
|
|||||||
self.userNameAttributes = userNameAttributes
|
self.userNameAttributes = userNameAttributes
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
self.tolerate_not_found = boolean(config.get('tolerateMemberNotFoundErrors', False))
|
self.tolerate_not_found = boolean(
|
||||||
self.tolerate_out_of_scope = boolean(config.get('tolerateMemberOutOfScopeErrors', False))
|
config.get("tolerateMemberNotFoundErrors", False)
|
||||||
|
)
|
||||||
|
self.tolerate_out_of_scope = boolean(
|
||||||
|
config.get("tolerateMemberOutOfScopeErrors", False)
|
||||||
|
)
|
||||||
|
|
||||||
self.required_group_attributes = [self.groupQuery.query_attribute]
|
self.required_group_attributes = [self.groupQuery.query_attribute]
|
||||||
for x in self.groupNameAttributes + self.groupMembershipAttributes:
|
for x in self.groupNameAttributes + self.groupMembershipAttributes:
|
||||||
@@ -434,13 +485,15 @@ class OpenshiftLDAPInterface(object):
|
|||||||
|
|
||||||
def get_group_entry(self, uid):
|
def get_group_entry(self, uid):
|
||||||
"""
|
"""
|
||||||
get_group_entry returns an LDAP group entry for the given group UID by searching the internal cache
|
get_group_entry returns an LDAP group entry for the given group UID by searching the internal cache
|
||||||
of the LDAPInterface first, then sending an LDAP query if the cache did not contain the entry.
|
of the LDAPInterface first, then sending an LDAP query if the cache did not contain the entry.
|
||||||
"""
|
"""
|
||||||
if uid in self.cached_groups:
|
if uid in self.cached_groups:
|
||||||
return self.cached_groups.get(uid), None
|
return self.cached_groups.get(uid), None
|
||||||
|
|
||||||
group, err = self.groupQuery.ldap_search(self.connection, uid, self.required_group_attributes)
|
group, err = self.groupQuery.ldap_search(
|
||||||
|
self.connection, uid, self.required_group_attributes
|
||||||
|
)
|
||||||
if err:
|
if err:
|
||||||
return None, err
|
return None, err
|
||||||
self.cached_groups[uid] = group
|
self.cached_groups[uid] = group
|
||||||
@@ -448,13 +501,15 @@ class OpenshiftLDAPInterface(object):
|
|||||||
|
|
||||||
def get_user_entry(self, uid):
|
def get_user_entry(self, uid):
|
||||||
"""
|
"""
|
||||||
get_user_entry returns an LDAP group entry for the given user UID by searching the internal cache
|
get_user_entry returns an LDAP group entry for the given user UID by searching the internal cache
|
||||||
of the LDAPInterface first, then sending an LDAP query if the cache did not contain the entry.
|
of the LDAPInterface first, then sending an LDAP query if the cache did not contain the entry.
|
||||||
"""
|
"""
|
||||||
if uid in self.cached_users:
|
if uid in self.cached_users:
|
||||||
return self.cached_users.get(uid), None
|
return self.cached_users.get(uid), None
|
||||||
|
|
||||||
entry, err = self.userQuery.ldap_search(self.connection, uid, self.required_user_attributes)
|
entry, err = self.userQuery.ldap_search(
|
||||||
|
self.connection, uid, self.required_user_attributes
|
||||||
|
)
|
||||||
if err:
|
if err:
|
||||||
return None, err
|
return None, err
|
||||||
self.cached_users[uid] = entry
|
self.cached_users[uid] = entry
|
||||||
@@ -466,19 +521,19 @@ class OpenshiftLDAPInterface(object):
|
|||||||
|
|
||||||
def list_groups(self):
|
def list_groups(self):
|
||||||
group_qry = copy.deepcopy(self.groupQuery.qry)
|
group_qry = copy.deepcopy(self.groupQuery.qry)
|
||||||
group_qry['attrlist'] = self.required_group_attributes
|
group_qry["attrlist"] = self.required_group_attributes
|
||||||
|
|
||||||
groups, err = openshift_ldap_query_for_entries(
|
groups, err = openshift_ldap_query_for_entries(
|
||||||
connection=self.connection,
|
connection=self.connection, qry=group_qry, unique_entry=False
|
||||||
qry=group_qry,
|
|
||||||
unique_entry=False
|
|
||||||
)
|
)
|
||||||
if err:
|
if err:
|
||||||
return None, err
|
return None, err
|
||||||
|
|
||||||
group_uids = []
|
group_uids = []
|
||||||
for entry in groups:
|
for entry in groups:
|
||||||
uid = openshift_ldap_get_attribute_for_entry(entry, self.groupQuery.query_attribute)
|
uid = openshift_ldap_get_attribute_for_entry(
|
||||||
|
entry, self.groupQuery.query_attribute
|
||||||
|
)
|
||||||
if not uid:
|
if not uid:
|
||||||
return None, "Unable to find LDAP group uid for entry %s" % entry
|
return None, "Unable to find LDAP group uid for entry %s" % entry
|
||||||
self.cached_groups[uid] = entry
|
self.cached_groups[uid] = entry
|
||||||
@@ -487,7 +542,7 @@ class OpenshiftLDAPInterface(object):
|
|||||||
|
|
||||||
def extract_members(self, uid):
|
def extract_members(self, uid):
|
||||||
"""
|
"""
|
||||||
returns the LDAP member entries for a group specified with a ldapGroupUID
|
returns the LDAP member entries for a group specified with a ldapGroupUID
|
||||||
"""
|
"""
|
||||||
# Get group entry from LDAP
|
# Get group entry from LDAP
|
||||||
group, err = self.get_group_entry(uid)
|
group, err = self.get_group_entry(uid)
|
||||||
@@ -514,39 +569,46 @@ class OpenshiftLDAPInterface(object):
|
|||||||
|
|
||||||
|
|
||||||
class OpenshiftLDAPRFC2307(object):
|
class OpenshiftLDAPRFC2307(object):
|
||||||
|
|
||||||
def __init__(self, config, ldap_connection):
|
def __init__(self, config, ldap_connection):
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.ldap_interface = self.create_ldap_interface(ldap_connection)
|
self.ldap_interface = self.create_ldap_interface(ldap_connection)
|
||||||
|
|
||||||
def create_ldap_interface(self, connection):
|
def create_ldap_interface(self, connection):
|
||||||
segment = self.config.get("rfc2307")
|
segment = self.config.get("rfc2307")
|
||||||
groups_base_qry = openshift_ldap_build_base_query(segment['groupsQuery'])
|
groups_base_qry = openshift_ldap_build_base_query(segment["groupsQuery"])
|
||||||
users_base_qry = openshift_ldap_build_base_query(segment['usersQuery'])
|
users_base_qry = openshift_ldap_build_base_query(segment["usersQuery"])
|
||||||
|
|
||||||
groups_query = OpenshiftLDAPQueryOnAttribute(groups_base_qry, segment['groupUIDAttribute'])
|
groups_query = OpenshiftLDAPQueryOnAttribute(
|
||||||
users_query = OpenshiftLDAPQueryOnAttribute(users_base_qry, segment['userUIDAttribute'])
|
groups_base_qry, segment["groupUIDAttribute"]
|
||||||
|
)
|
||||||
|
users_query = OpenshiftLDAPQueryOnAttribute(
|
||||||
|
users_base_qry, segment["userUIDAttribute"]
|
||||||
|
)
|
||||||
|
|
||||||
params = dict(
|
params = dict(
|
||||||
connection=connection,
|
connection=connection,
|
||||||
groupQuery=groups_query,
|
groupQuery=groups_query,
|
||||||
groupNameAttributes=segment['groupNameAttributes'],
|
groupNameAttributes=segment["groupNameAttributes"],
|
||||||
groupMembershipAttributes=segment['groupMembershipAttributes'],
|
groupMembershipAttributes=segment["groupMembershipAttributes"],
|
||||||
userQuery=users_query,
|
userQuery=users_query,
|
||||||
userNameAttributes=segment['userNameAttributes'],
|
userNameAttributes=segment["userNameAttributes"],
|
||||||
config=segment
|
config=segment,
|
||||||
)
|
)
|
||||||
return OpenshiftLDAPInterface(**params)
|
return OpenshiftLDAPInterface(**params)
|
||||||
|
|
||||||
def get_username_for_entry(self, entry):
|
def get_username_for_entry(self, entry):
|
||||||
username = openshift_ldap_get_attribute_for_entry(entry, self.ldap_interface.userNameAttributes)
|
username = openshift_ldap_get_attribute_for_entry(
|
||||||
|
entry, self.ldap_interface.userNameAttributes
|
||||||
|
)
|
||||||
if not username:
|
if not username:
|
||||||
return None, "The user entry (%s) does not map to a OpenShift User name with the given mapping" % entry
|
return (
|
||||||
|
None,
|
||||||
|
"The user entry (%s) does not map to a OpenShift User name with the given mapping"
|
||||||
|
% entry,
|
||||||
|
)
|
||||||
return username, None
|
return username, None
|
||||||
|
|
||||||
def get_group_name_for_uid(self, uid):
|
def get_group_name_for_uid(self, uid):
|
||||||
|
|
||||||
# Get name from User defined mapping
|
# Get name from User defined mapping
|
||||||
groupuid_name_mapping = self.config.get("groupUIDNameMapping")
|
groupuid_name_mapping = self.config.get("groupUIDNameMapping")
|
||||||
if groupuid_name_mapping and uid in groupuid_name_mapping:
|
if groupuid_name_mapping and uid in groupuid_name_mapping:
|
||||||
@@ -555,10 +617,13 @@ class OpenshiftLDAPRFC2307(object):
|
|||||||
group, err = self.ldap_interface.get_group_entry(uid)
|
group, err = self.ldap_interface.get_group_entry(uid)
|
||||||
if err:
|
if err:
|
||||||
return None, err
|
return None, err
|
||||||
group_name = openshift_ldap_get_attribute_for_entry(group, self.ldap_interface.groupNameAttributes)
|
group_name = openshift_ldap_get_attribute_for_entry(
|
||||||
|
group, self.ldap_interface.groupNameAttributes
|
||||||
|
)
|
||||||
if not group_name:
|
if not group_name:
|
||||||
error = "The group entry (%s) does not map to an OpenShift Group name with the given name attribute (%s)" % (
|
error = (
|
||||||
group, self.ldap_interface.groupNameAttributes
|
"The group entry (%s) does not map to an OpenShift Group name with the given name attribute (%s)"
|
||||||
|
% (group, self.ldap_interface.groupNameAttributes)
|
||||||
)
|
)
|
||||||
return None, error
|
return None, error
|
||||||
if isinstance(group_name, list):
|
if isinstance(group_name, list):
|
||||||
@@ -570,7 +635,11 @@ class OpenshiftLDAPRFC2307(object):
|
|||||||
def is_ldapgroup_exists(self, uid):
|
def is_ldapgroup_exists(self, uid):
|
||||||
group, err = self.ldap_interface.get_group_entry(uid)
|
group, err = self.ldap_interface.get_group_entry(uid)
|
||||||
if err:
|
if err:
|
||||||
if err == LDAP_SEARCH_OUT_OF_SCOPE_ERROR or err.startswith("Entry not found") or "non-existent entry" in err:
|
if (
|
||||||
|
err == LDAP_SEARCH_OUT_OF_SCOPE_ERROR
|
||||||
|
or err.startswith("Entry not found")
|
||||||
|
or "non-existent entry" in err
|
||||||
|
):
|
||||||
return False, None
|
return False, None
|
||||||
return False, err
|
return False, err
|
||||||
if group:
|
if group:
|
||||||
@@ -585,7 +654,6 @@ class OpenshiftLDAPRFC2307(object):
|
|||||||
|
|
||||||
|
|
||||||
class OpenshiftLDAP_ADInterface(object):
|
class OpenshiftLDAP_ADInterface(object):
|
||||||
|
|
||||||
def __init__(self, connection, user_query, group_member_attr, user_name_attr):
|
def __init__(self, connection, user_query, group_member_attr, user_name_attr):
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
self.userQuery = user_query
|
self.userQuery = user_query
|
||||||
@@ -609,7 +677,9 @@ class OpenshiftLDAP_ADInterface(object):
|
|||||||
def populate_cache(self):
|
def populate_cache(self):
|
||||||
if not self.cache_populated:
|
if not self.cache_populated:
|
||||||
self.cache_populated = True
|
self.cache_populated = True
|
||||||
entries, err = self.userQuery.ldap_search(self.connection, self.required_user_attributes)
|
entries, err = self.userQuery.ldap_search(
|
||||||
|
self.connection, self.required_user_attributes
|
||||||
|
)
|
||||||
if err:
|
if err:
|
||||||
return err
|
return err
|
||||||
|
|
||||||
@@ -645,7 +715,9 @@ class OpenshiftLDAP_ADInterface(object):
|
|||||||
users_in_group = []
|
users_in_group = []
|
||||||
for attr in self.groupMembershipAttributes:
|
for attr in self.groupMembershipAttributes:
|
||||||
query_on_attribute = OpenshiftLDAPQueryOnAttribute(self.userQuery.qry, attr)
|
query_on_attribute = OpenshiftLDAPQueryOnAttribute(self.userQuery.qry, attr)
|
||||||
entries, error = query_on_attribute.ldap_search(self.connection, uid, self.required_user_attributes, unique_entry=False)
|
entries, error = query_on_attribute.ldap_search(
|
||||||
|
self.connection, uid, self.required_user_attributes, unique_entry=False
|
||||||
|
)
|
||||||
if error and "not found" not in error:
|
if error and "not found" not in error:
|
||||||
return None, error
|
return None, error
|
||||||
if not entries:
|
if not entries:
|
||||||
@@ -660,15 +732,13 @@ class OpenshiftLDAP_ADInterface(object):
|
|||||||
|
|
||||||
|
|
||||||
class OpenshiftLDAPActiveDirectory(object):
|
class OpenshiftLDAPActiveDirectory(object):
|
||||||
|
|
||||||
def __init__(self, config, ldap_connection):
|
def __init__(self, config, ldap_connection):
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.ldap_interface = self.create_ldap_interface(ldap_connection)
|
self.ldap_interface = self.create_ldap_interface(ldap_connection)
|
||||||
|
|
||||||
def create_ldap_interface(self, connection):
|
def create_ldap_interface(self, connection):
|
||||||
segment = self.config.get("activeDirectory")
|
segment = self.config.get("activeDirectory")
|
||||||
base_query = openshift_ldap_build_base_query(segment['usersQuery'])
|
base_query = openshift_ldap_build_base_query(segment["usersQuery"])
|
||||||
user_query = OpenshiftLDAPQuery(base_query)
|
user_query = OpenshiftLDAPQuery(base_query)
|
||||||
|
|
||||||
return OpenshiftLDAP_ADInterface(
|
return OpenshiftLDAP_ADInterface(
|
||||||
@@ -679,9 +749,15 @@ class OpenshiftLDAPActiveDirectory(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_username_for_entry(self, entry):
|
def get_username_for_entry(self, entry):
|
||||||
username = openshift_ldap_get_attribute_for_entry(entry, self.ldap_interface.userNameAttributes)
|
username = openshift_ldap_get_attribute_for_entry(
|
||||||
|
entry, self.ldap_interface.userNameAttributes
|
||||||
|
)
|
||||||
if not username:
|
if not username:
|
||||||
return None, "The user entry (%s) does not map to a OpenShift User name with the given mapping" % entry
|
return (
|
||||||
|
None,
|
||||||
|
"The user entry (%s) does not map to a OpenShift User name with the given mapping"
|
||||||
|
% entry,
|
||||||
|
)
|
||||||
return username, None
|
return username, None
|
||||||
|
|
||||||
def get_group_name_for_uid(self, uid):
|
def get_group_name_for_uid(self, uid):
|
||||||
@@ -702,8 +778,15 @@ class OpenshiftLDAPActiveDirectory(object):
|
|||||||
|
|
||||||
|
|
||||||
class OpenshiftLDAP_AugmentedADInterface(OpenshiftLDAP_ADInterface):
|
class OpenshiftLDAP_AugmentedADInterface(OpenshiftLDAP_ADInterface):
|
||||||
|
def __init__(
|
||||||
def __init__(self, connection, user_query, group_member_attr, user_name_attr, group_qry, group_name_attr):
|
self,
|
||||||
|
connection,
|
||||||
|
user_query,
|
||||||
|
group_member_attr,
|
||||||
|
user_name_attr,
|
||||||
|
group_qry,
|
||||||
|
group_name_attr,
|
||||||
|
):
|
||||||
super(OpenshiftLDAP_AugmentedADInterface, self).__init__(
|
super(OpenshiftLDAP_AugmentedADInterface, self).__init__(
|
||||||
connection, user_query, group_member_attr, user_name_attr
|
connection, user_query, group_member_attr, user_name_attr
|
||||||
)
|
)
|
||||||
@@ -719,13 +802,15 @@ class OpenshiftLDAP_AugmentedADInterface(OpenshiftLDAP_ADInterface):
|
|||||||
|
|
||||||
def get_group_entry(self, uid):
|
def get_group_entry(self, uid):
|
||||||
"""
|
"""
|
||||||
get_group_entry returns an LDAP group entry for the given group UID by searching the internal cache
|
get_group_entry returns an LDAP group entry for the given group UID by searching the internal cache
|
||||||
of the LDAPInterface first, then sending an LDAP query if the cache did not contain the entry.
|
of the LDAPInterface first, then sending an LDAP query if the cache did not contain the entry.
|
||||||
"""
|
"""
|
||||||
if uid in self.cached_groups:
|
if uid in self.cached_groups:
|
||||||
return self.cached_groups.get(uid), None
|
return self.cached_groups.get(uid), None
|
||||||
|
|
||||||
group, err = self.groupQuery.ldap_search(self.connection, uid, self.required_group_attributes)
|
group, err = self.groupQuery.ldap_search(
|
||||||
|
self.connection, uid, self.required_group_attributes
|
||||||
|
)
|
||||||
if err:
|
if err:
|
||||||
return None, err
|
return None, err
|
||||||
self.cached_groups[uid] = group
|
self.cached_groups[uid] = group
|
||||||
@@ -750,19 +835,19 @@ class OpenshiftLDAP_AugmentedADInterface(OpenshiftLDAP_ADInterface):
|
|||||||
|
|
||||||
|
|
||||||
class OpenshiftLDAPAugmentedActiveDirectory(OpenshiftLDAPRFC2307):
|
class OpenshiftLDAPAugmentedActiveDirectory(OpenshiftLDAPRFC2307):
|
||||||
|
|
||||||
def __init__(self, config, ldap_connection):
|
def __init__(self, config, ldap_connection):
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.ldap_interface = self.create_ldap_interface(ldap_connection)
|
self.ldap_interface = self.create_ldap_interface(ldap_connection)
|
||||||
|
|
||||||
def create_ldap_interface(self, connection):
|
def create_ldap_interface(self, connection):
|
||||||
segment = self.config.get("augmentedActiveDirectory")
|
segment = self.config.get("augmentedActiveDirectory")
|
||||||
user_base_query = openshift_ldap_build_base_query(segment['usersQuery'])
|
user_base_query = openshift_ldap_build_base_query(segment["usersQuery"])
|
||||||
groups_base_qry = openshift_ldap_build_base_query(segment['groupsQuery'])
|
groups_base_qry = openshift_ldap_build_base_query(segment["groupsQuery"])
|
||||||
|
|
||||||
user_query = OpenshiftLDAPQuery(user_base_query)
|
user_query = OpenshiftLDAPQuery(user_base_query)
|
||||||
groups_query = OpenshiftLDAPQueryOnAttribute(groups_base_qry, segment['groupUIDAttribute'])
|
groups_query = OpenshiftLDAPQueryOnAttribute(
|
||||||
|
groups_base_qry, segment["groupUIDAttribute"]
|
||||||
|
)
|
||||||
|
|
||||||
return OpenshiftLDAP_AugmentedADInterface(
|
return OpenshiftLDAP_AugmentedADInterface(
|
||||||
connection=connection,
|
connection=connection,
|
||||||
@@ -770,7 +855,7 @@ class OpenshiftLDAPAugmentedActiveDirectory(OpenshiftLDAPRFC2307):
|
|||||||
group_member_attr=segment["groupMembershipAttributes"],
|
group_member_attr=segment["groupMembershipAttributes"],
|
||||||
user_name_attr=segment["userNameAttributes"],
|
user_name_attr=segment["userNameAttributes"],
|
||||||
group_qry=groups_query,
|
group_qry=groups_query,
|
||||||
group_name_attr=segment["groupNameAttributes"]
|
group_name_attr=segment["groupNameAttributes"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def is_ldapgroup_exists(self, uid):
|
def is_ldapgroup_exists(self, uid):
|
||||||
|
|||||||
@@ -1,50 +1,26 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import traceback
|
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
K8sAnsibleMixin,
|
|
||||||
get_api_client,
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
|
AnsibleOpenshiftModule,
|
||||||
)
|
)
|
||||||
from ansible.module_utils._text import to_native
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError
|
from kubernetes.dynamic.exceptions import DynamicApiError
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
try:
|
|
||||||
from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftProcess(K8sAnsibleMixin):
|
class OpenShiftProcess(AnsibleOpenshiftModule):
|
||||||
def __init__(self, module):
|
def __init__(self, **kwargs):
|
||||||
self.module = module
|
super(OpenShiftProcess, self).__init__(**kwargs)
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.module.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception),
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftProcess, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
|
|
||||||
def execute_module(self):
|
def execute_module(self):
|
||||||
v1_templates = self.find_resource(
|
v1_templates = self.find_resource(
|
||||||
@@ -74,7 +50,7 @@ class OpenShiftProcess(K8sAnsibleMixin):
|
|||||||
template = None
|
template = None
|
||||||
|
|
||||||
if src or definition:
|
if src or definition:
|
||||||
self.set_resource_definitions(self.module)
|
self.set_resource_definitions()
|
||||||
if len(self.resource_definitions) < 1:
|
if len(self.resource_definitions) < 1:
|
||||||
self.fail_json(
|
self.fail_json(
|
||||||
"Unable to load a Template resource from src or resource_definition"
|
"Unable to load a Template resource from src or resource_definition"
|
||||||
@@ -99,7 +75,7 @@ class OpenShiftProcess(K8sAnsibleMixin):
|
|||||||
reason=exc.reason,
|
reason=exc.reason,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.module.fail_json(
|
self.fail_json(
|
||||||
msg="Failed to retrieve Template with name '{0}' in namespace '{1}': {2}".format(
|
msg="Failed to retrieve Template with name '{0}' in namespace '{1}': {2}".format(
|
||||||
name, namespace, to_native(exc)
|
name, namespace, to_native(exc)
|
||||||
),
|
),
|
||||||
@@ -132,7 +108,7 @@ class OpenShiftProcess(K8sAnsibleMixin):
|
|||||||
reason=exc.reason,
|
reason=exc.reason,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.module.fail_json(
|
self.fail_json(
|
||||||
msg="Server failed to render the Template: {0}".format(to_native(exc)),
|
msg="Server failed to render the Template: {0}".format(to_native(exc)),
|
||||||
error="",
|
error="",
|
||||||
status="",
|
status="",
|
||||||
@@ -144,16 +120,38 @@ class OpenShiftProcess(K8sAnsibleMixin):
|
|||||||
result["resources"] = response["objects"]
|
result["resources"] = response["objects"]
|
||||||
|
|
||||||
if state != "rendered":
|
if state != "rendered":
|
||||||
self.resource_definitions = response["objects"]
|
self.create_resources(response["objects"])
|
||||||
self.kind = self.api_version = self.name = None
|
|
||||||
self.namespace = self.params.get("namespace_target")
|
|
||||||
self.append_hash = False
|
|
||||||
self.apply = False
|
|
||||||
self.params["validate"] = None
|
|
||||||
self.params["merge_type"] = None
|
|
||||||
super(OpenShiftProcess, self).execute_module()
|
|
||||||
|
|
||||||
self.module.exit_json(**result)
|
self.exit_json(**result)
|
||||||
|
|
||||||
|
def create_resources(self, definitions):
|
||||||
|
params = {"namespace": self.params.get("namespace_target")}
|
||||||
|
|
||||||
|
self.params["apply"] = False
|
||||||
|
self.params["validate"] = None
|
||||||
|
|
||||||
|
changed = False
|
||||||
|
results = []
|
||||||
|
|
||||||
|
flattened_definitions = []
|
||||||
|
for definition in definitions:
|
||||||
|
if definition is None:
|
||||||
|
continue
|
||||||
|
kind = definition.get("kind")
|
||||||
|
if kind and kind.endswith("List"):
|
||||||
|
flattened_definitions.extend(self.flatten_list_kind(definition, params))
|
||||||
|
else:
|
||||||
|
flattened_definitions.append(self.merge_params(definition, params))
|
||||||
|
|
||||||
|
for definition in flattened_definitions:
|
||||||
|
result = self.perform_action(definition, self.params)
|
||||||
|
changed = changed or result["changed"]
|
||||||
|
results.append(result)
|
||||||
|
|
||||||
|
if len(results) == 1:
|
||||||
|
self.exit_json(**results[0])
|
||||||
|
|
||||||
|
self.exit_json(**{"changed": changed, "result": {"results": results}})
|
||||||
|
|
||||||
def update_template_param(self, template, k, v):
|
def update_template_param(self, template, k, v):
|
||||||
for i, param in enumerate(template["parameters"]):
|
for i, param in enumerate(template["parameters"]):
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
|
AnsibleOpenshiftModule,
|
||||||
try:
|
)
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
|
||||||
K8sAnsibleMixin,
|
|
||||||
get_api_client,
|
|
||||||
)
|
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_docker_image import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_docker_image import (
|
||||||
parse_docker_image_ref,
|
parse_docker_image_ref,
|
||||||
@@ -26,43 +18,25 @@ from ansible_collections.community.okd.plugins.module_utils.openshift_docker_ima
|
|||||||
try:
|
try:
|
||||||
from requests import request
|
from requests import request
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
|
|
||||||
HAS_REQUESTS_MODULE = True
|
HAS_REQUESTS_MODULE = True
|
||||||
|
requests_import_exception = None
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
HAS_REQUESTS_MODULE = False
|
HAS_REQUESTS_MODULE = False
|
||||||
requests_import_exception = e
|
requests_import_exception = e
|
||||||
REQUESTS_MODULE_ERROR = traceback.format_exc()
|
REQUESTS_MODULE_ERROR = traceback.format_exc()
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftRegistry(K8sAnsibleMixin):
|
class OpenShiftRegistry(AnsibleOpenshiftModule):
|
||||||
def __init__(self, module):
|
def __init__(self, **kwargs):
|
||||||
self.module = module
|
super(OpenShiftRegistry, self).__init__(**kwargs)
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception),
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftRegistry, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
|
|
||||||
self.check = self.params.get("check")
|
self.check = self.params.get("check")
|
||||||
|
|
||||||
def list_image_streams(self, namespace=None):
|
def list_image_streams(self, namespace=None):
|
||||||
kind = "ImageStream"
|
kind = "ImageStream"
|
||||||
api_version = "image.openshift.io/v1"
|
api_version = "image.openshift.io/v1"
|
||||||
|
|
||||||
params = dict(
|
params = dict(kind=kind, api_version=api_version, namespace=namespace)
|
||||||
kind=kind,
|
|
||||||
api_version=api_version,
|
|
||||||
namespace=namespace
|
|
||||||
)
|
|
||||||
result = self.kubernetes_facts(**params)
|
result = self.kubernetes_facts(**params)
|
||||||
imagestream = []
|
imagestream = []
|
||||||
if len(result["resources"]) > 0:
|
if len(result["resources"]) > 0:
|
||||||
@@ -70,7 +44,6 @@ class OpenShiftRegistry(K8sAnsibleMixin):
|
|||||||
return imagestream
|
return imagestream
|
||||||
|
|
||||||
def find_registry_info(self):
|
def find_registry_info(self):
|
||||||
|
|
||||||
def _determine_registry(image_stream):
|
def _determine_registry(image_stream):
|
||||||
public, internal = None, None
|
public, internal = None, None
|
||||||
docker_repo = image_stream["status"].get("publicDockerImageRepository")
|
docker_repo = image_stream["status"].get("publicDockerImageRepository")
|
||||||
@@ -98,39 +71,46 @@ class OpenShiftRegistry(K8sAnsibleMixin):
|
|||||||
self.fail_json(msg="The integrated registry has not been configured")
|
self.fail_json(msg="The integrated registry has not been configured")
|
||||||
return internal, public
|
return internal, public
|
||||||
|
|
||||||
self.fail_json(msg="No Image Streams could be located to retrieve registry info.")
|
self.fail_json(
|
||||||
|
msg="No Image Streams could be located to retrieve registry info."
|
||||||
|
)
|
||||||
|
|
||||||
def info(self):
|
def execute_module(self):
|
||||||
result = {}
|
result = {}
|
||||||
result["internal_hostname"], result["public_hostname"] = self.find_registry_info()
|
(
|
||||||
|
result["internal_hostname"],
|
||||||
|
result["public_hostname"],
|
||||||
|
) = self.find_registry_info()
|
||||||
|
|
||||||
if self.check:
|
if self.check:
|
||||||
public_registry = result["public_hostname"]
|
public_registry = result["public_hostname"]
|
||||||
if not public_registry:
|
if not public_registry:
|
||||||
result["check"] = dict(
|
result["check"] = dict(
|
||||||
reached=False,
|
reached=False, msg="Registry does not have a public hostname."
|
||||||
msg="Registry does not have a public hostname."
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
headers = {
|
headers = {"Content-Type": "application/json"}
|
||||||
'Content-Type': 'application/json'
|
params = {"method": "GET", "verify": False}
|
||||||
}
|
|
||||||
params = {
|
|
||||||
'method': 'GET',
|
|
||||||
'verify': False
|
|
||||||
}
|
|
||||||
if self.client.configuration.api_key:
|
if self.client.configuration.api_key:
|
||||||
headers.update(self.client.configuration.api_key)
|
headers.update(self.client.configuration.api_key)
|
||||||
elif self.client.configuration.username and self.client.configuration.password:
|
elif (
|
||||||
|
self.client.configuration.username
|
||||||
|
and self.client.configuration.password
|
||||||
|
):
|
||||||
if not HAS_REQUESTS_MODULE:
|
if not HAS_REQUESTS_MODULE:
|
||||||
result["check"] = dict(
|
result["check"] = dict(
|
||||||
reached=False,
|
reached=False,
|
||||||
msg="The requests python package is missing, try `pip install requests`",
|
msg="The requests python package is missing, try `pip install requests`",
|
||||||
error=requests_import_exception
|
error=requests_import_exception,
|
||||||
)
|
)
|
||||||
self.exit_json(**result)
|
self.exit_json(**result)
|
||||||
params.update(
|
params.update(
|
||||||
dict(auth=HTTPBasicAuth(self.client.configuration.username, self.client.configuration.password))
|
dict(
|
||||||
|
auth=HTTPBasicAuth(
|
||||||
|
self.client.configuration.username,
|
||||||
|
self.client.configuration.password,
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# verify ssl
|
# verify ssl
|
||||||
@@ -138,23 +118,20 @@ class OpenShiftRegistry(K8sAnsibleMixin):
|
|||||||
if len(host.scheme) == 0:
|
if len(host.scheme) == 0:
|
||||||
registry_url = "https://" + public_registry
|
registry_url = "https://" + public_registry
|
||||||
|
|
||||||
if registry_url.startswith("https://") and self.client.configuration.ssl_ca_cert:
|
if (
|
||||||
params.update(
|
registry_url.startswith("https://")
|
||||||
dict(verify=self.client.configuration.ssl_ca_cert)
|
and self.client.configuration.ssl_ca_cert
|
||||||
)
|
):
|
||||||
params.update(
|
params.update(dict(verify=self.client.configuration.ssl_ca_cert))
|
||||||
dict(headers=headers)
|
params.update(dict(headers=headers))
|
||||||
)
|
|
||||||
last_bad_status, last_bad_reason = None, None
|
last_bad_status, last_bad_reason = None, None
|
||||||
for path in ("/", "/healthz"):
|
for path in ("/", "/healthz"):
|
||||||
params.update(
|
params.update(dict(url=registry_url + path))
|
||||||
dict(url=registry_url + path)
|
|
||||||
)
|
|
||||||
response = request(**params)
|
response = request(**params)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
result["check"] = dict(
|
result["check"] = dict(
|
||||||
reached=True,
|
reached=True,
|
||||||
msg="The local client can contact the integrated registry."
|
msg="The local client can contact the integrated registry.",
|
||||||
)
|
)
|
||||||
self.exit_json(**result)
|
self.exit_json(**result)
|
||||||
last_bad_reason = response.reason
|
last_bad_reason = response.reason
|
||||||
@@ -162,9 +139,8 @@ class OpenShiftRegistry(K8sAnsibleMixin):
|
|||||||
|
|
||||||
result["check"] = dict(
|
result["check"] = dict(
|
||||||
reached=False,
|
reached=False,
|
||||||
msg="Unable to contact the integrated registry using local client. Status=%d, Reason=%s" % (
|
msg="Unable to contact the integrated registry using local client. Status=%d, Reason=%s"
|
||||||
last_bad_status, last_bad_reason
|
% (last_bad_status, last_bad_reason),
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.exit_json(**result)
|
self.exit_json(**result)
|
||||||
|
|||||||
+60
-47
@@ -10,7 +10,7 @@ from __future__ import absolute_import, division, print_function
|
|||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
module: k8s
|
module: k8s
|
||||||
|
|
||||||
@@ -64,9 +64,8 @@ options:
|
|||||||
- Defaults to C(['strategic-merge', 'merge']), which is ideal for using the same parameters
|
- Defaults to C(['strategic-merge', 'merge']), which is ideal for using the same parameters
|
||||||
on resource kinds that combine Custom Resources and built-in resources.
|
on resource kinds that combine Custom Resources and built-in resources.
|
||||||
- mutually exclusive with C(apply)
|
- mutually exclusive with C(apply)
|
||||||
- I(merge_type=json) is deprecated and will be removed in version 3.0.0. Please use M(kubernetes.core.k8s_json_patch) instead.
|
- I(merge_type=json) has been removed in version 4.0.0. Please use M(kubernetes.core.k8s_json_patch) instead.
|
||||||
choices:
|
choices:
|
||||||
- json
|
|
||||||
- merge
|
- merge
|
||||||
- strategic-merge
|
- strategic-merge
|
||||||
type: list
|
type: list
|
||||||
@@ -84,7 +83,7 @@ options:
|
|||||||
type: str
|
type: str
|
||||||
strict:
|
strict:
|
||||||
description: whether to fail when passing unexpected properties
|
description: whether to fail when passing unexpected properties
|
||||||
default: True
|
default: true
|
||||||
type: bool
|
type: bool
|
||||||
type: dict
|
type: dict
|
||||||
append_hash:
|
append_hash:
|
||||||
@@ -135,16 +134,25 @@ options:
|
|||||||
- Whether to continue on creation/deletion errors when multiple resources are defined.
|
- Whether to continue on creation/deletion errors when multiple resources are defined.
|
||||||
- This has no effect on the validation step which is controlled by the C(validate.fail_on_error) parameter.
|
- This has no effect on the validation step which is controlled by the C(validate.fail_on_error) parameter.
|
||||||
type: bool
|
type: bool
|
||||||
default: False
|
default: false
|
||||||
version_added: 2.0.0
|
version_added: 2.0.0
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.6"
|
- "python >= 3.6"
|
||||||
- "kubernetes >= 12.0.0"
|
- "kubernetes >= 12.0.0"
|
||||||
- "PyYAML >= 3.11"
|
- "PyYAML >= 3.11"
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
- name: Create an OCP project
|
||||||
|
community.okd.k8s:
|
||||||
|
state: present
|
||||||
|
resource_definition:
|
||||||
|
apiVersion: project.openshift.io/v1
|
||||||
|
kind: Project
|
||||||
|
metadata:
|
||||||
|
name: testing
|
||||||
|
|
||||||
EXAMPLES = r'''
|
|
||||||
- name: Create a k8s namespace
|
- name: Create a k8s namespace
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
name: testing
|
name: testing
|
||||||
@@ -169,10 +177,10 @@ EXAMPLES = r'''
|
|||||||
app: galaxy
|
app: galaxy
|
||||||
service: web
|
service: web
|
||||||
ports:
|
ports:
|
||||||
- protocol: TCP
|
- protocol: TCP
|
||||||
targetPort: 8000
|
targetPort: 8000
|
||||||
name: port-8000-tcp
|
name: port-8000-tcp
|
||||||
port: 8000
|
port: 8000
|
||||||
|
|
||||||
- name: Remove an existing Service object
|
- name: Remove an existing Service object
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
@@ -206,18 +214,18 @@ EXAMPLES = r'''
|
|||||||
state: present
|
state: present
|
||||||
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
||||||
validate:
|
validate:
|
||||||
fail_on_error: yes
|
fail_on_error: true
|
||||||
|
|
||||||
- name: warn on validation errors, check for unexpected properties
|
- name: warn on validation errors, check for unexpected properties
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
state: present
|
state: present
|
||||||
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
definition: "{{ lookup('template', '/testing/deployment.yml') | from_yaml }}"
|
||||||
validate:
|
validate:
|
||||||
fail_on_error: no
|
fail_on_error: false
|
||||||
strict: yes
|
strict: true
|
||||||
'''
|
"""
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
result:
|
result:
|
||||||
description:
|
description:
|
||||||
- The created, patched, or otherwise present object. Will be empty in the case of a deletion.
|
- The created, patched, or otherwise present object. Will be empty in the case of a deletion.
|
||||||
@@ -254,26 +262,26 @@ result:
|
|||||||
type: int
|
type: int
|
||||||
sample: 48
|
sample: 48
|
||||||
error:
|
error:
|
||||||
description: error while trying to create/delete the object.
|
description: Error while trying to create/delete the object.
|
||||||
returned: error
|
returned: error
|
||||||
type: complex
|
type: complex
|
||||||
'''
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
try:
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
|
|
||||||
except ImportError:
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
NAME_ARG_SPEC, RESOURCE_ARG_SPEC, AUTH_ARG_SPEC, WAIT_ARG_SPEC, DELETE_OPTS_ARG_SPEC)
|
NAME_ARG_SPEC,
|
||||||
|
RESOURCE_ARG_SPEC,
|
||||||
|
AUTH_ARG_SPEC,
|
||||||
|
WAIT_ARG_SPEC,
|
||||||
|
DELETE_OPTS_ARG_SPEC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_spec():
|
def validate_spec():
|
||||||
return dict(
|
return dict(
|
||||||
fail_on_error=dict(type='bool'),
|
fail_on_error=dict(type="bool"),
|
||||||
version=dict(),
|
version=dict(),
|
||||||
strict=dict(type='bool', default=True)
|
strict=dict(type="bool", default=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -283,36 +291,41 @@ def argspec():
|
|||||||
argument_spec.update(RESOURCE_ARG_SPEC)
|
argument_spec.update(RESOURCE_ARG_SPEC)
|
||||||
argument_spec.update(AUTH_ARG_SPEC)
|
argument_spec.update(AUTH_ARG_SPEC)
|
||||||
argument_spec.update(WAIT_ARG_SPEC)
|
argument_spec.update(WAIT_ARG_SPEC)
|
||||||
argument_spec['merge_type'] = dict(type='list', elements='str', choices=['json', 'merge', 'strategic-merge'])
|
argument_spec["merge_type"] = dict(
|
||||||
argument_spec['validate'] = dict(type='dict', default=None, options=validate_spec())
|
type="list", elements="str", choices=["merge", "strategic-merge"]
|
||||||
argument_spec['append_hash'] = dict(type='bool', default=False)
|
)
|
||||||
argument_spec['apply'] = dict(type='bool', default=False)
|
argument_spec["validate"] = dict(type="dict", default=None, options=validate_spec())
|
||||||
argument_spec['template'] = dict(type='raw', default=None)
|
argument_spec["append_hash"] = dict(type="bool", default=False)
|
||||||
argument_spec['delete_options'] = dict(type='dict', default=None, options=DELETE_OPTS_ARG_SPEC)
|
argument_spec["apply"] = dict(type="bool", default=False)
|
||||||
argument_spec['continue_on_error'] = dict(type='bool', default=False)
|
argument_spec["template"] = dict(type="raw", default=None)
|
||||||
argument_spec['state'] = dict(default='present', choices=['present', 'absent', 'patched'])
|
argument_spec["delete_options"] = dict(
|
||||||
argument_spec['force'] = dict(type='bool', default=False)
|
type="dict", default=None, options=DELETE_OPTS_ARG_SPEC
|
||||||
|
)
|
||||||
|
argument_spec["continue_on_error"] = dict(type="bool", default=False)
|
||||||
|
argument_spec["state"] = dict(
|
||||||
|
default="present", choices=["present", "absent", "patched"]
|
||||||
|
)
|
||||||
|
argument_spec["force"] = dict(type="bool", default=False)
|
||||||
return argument_spec
|
return argument_spec
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
mutually_exclusive = [
|
mutually_exclusive = [
|
||||||
('resource_definition', 'src'),
|
("resource_definition", "src"),
|
||||||
('merge_type', 'apply'),
|
("merge_type", "apply"),
|
||||||
('template', 'resource_definition'),
|
("template", "resource_definition"),
|
||||||
('template', 'src'),
|
("template", "src"),
|
||||||
]
|
]
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec=argspec(), supports_check_mode=True, mutually_exclusive=mutually_exclusive)
|
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.k8s import OKDRawModule
|
from ansible_collections.community.okd.plugins.module_utils.k8s import OKDRawModule
|
||||||
okdraw_module = OKDRawModule(module)
|
|
||||||
|
|
||||||
# remove_aliases from kubernetes.core's common requires the argspec attribute. Ideally, it should
|
module = OKDRawModule(
|
||||||
# read that throught the module class, but we cannot change that.
|
argument_spec=argspec(),
|
||||||
okdraw_module.argspec = argspec()
|
supports_check_mode=True,
|
||||||
okdraw_module.execute_module()
|
mutually_exclusive=mutually_exclusive,
|
||||||
|
)
|
||||||
|
module.run_module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ options:
|
|||||||
aliases:
|
aliases:
|
||||||
- config
|
- config
|
||||||
- src
|
- src
|
||||||
required: True
|
required: true
|
||||||
deny_groups:
|
deny_groups:
|
||||||
description:
|
description:
|
||||||
- Denied groups, could be openshift group name or LDAP group dn value.
|
- Denied groups, could be openshift group name or LDAP group dn value.
|
||||||
@@ -60,6 +60,7 @@ options:
|
|||||||
- The elements specified in this list will override the ones specified in C(allow_groups).
|
- The elements specified in this list will override the ones specified in C(allow_groups).
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
|
default: []
|
||||||
allow_groups:
|
allow_groups:
|
||||||
description:
|
description:
|
||||||
- Allowed groups, could be openshift group name or LDAP group dn value.
|
- Allowed groups, could be openshift group name or LDAP group dn value.
|
||||||
@@ -67,6 +68,7 @@ options:
|
|||||||
like I(cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat).
|
like I(cn=developers,ou=groups,ou=rfc2307,dc=ansible,dc=redhat).
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
|
default: []
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- python >= 3.6
|
- python >= 3.6
|
||||||
@@ -94,31 +96,31 @@ EXAMPLES = r"""
|
|||||||
- name: Sync all groups from an LDAP server
|
- name: Sync all groups from an LDAP server
|
||||||
openshift_adm_groups_sync:
|
openshift_adm_groups_sync:
|
||||||
src:
|
src:
|
||||||
kind: LDAPSyncConfig
|
kind: LDAPSyncConfig
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
url: ldap://localhost:1390
|
url: ldap://localhost:1390
|
||||||
insecure: true
|
insecure: true
|
||||||
bindDN: cn=admin,dc=example,dc=org
|
bindDN: cn=admin,dc=example,dc=org
|
||||||
bindPassword: adminpassword
|
bindPassword: adminpassword
|
||||||
rfc2307:
|
rfc2307:
|
||||||
groupsQuery:
|
groupsQuery:
|
||||||
baseDN: "cn=admins,ou=groups,dc=example,dc=org"
|
baseDN: "cn=admins,ou=groups,dc=example,dc=org"
|
||||||
scope: sub
|
scope: sub
|
||||||
derefAliases: never
|
derefAliases: never
|
||||||
filter: (objectClass=*)
|
filter: (objectClass=*)
|
||||||
pageSize: 0
|
pageSize: 0
|
||||||
groupUIDAttribute: dn
|
groupUIDAttribute: dn
|
||||||
groupNameAttributes: [ cn ]
|
groupNameAttributes: [cn]
|
||||||
groupMembershipAttributes: [ member ]
|
groupMembershipAttributes: [member]
|
||||||
usersQuery:
|
usersQuery:
|
||||||
baseDN: "ou=users,dc=example,dc=org"
|
baseDN: "ou=users,dc=example,dc=org"
|
||||||
scope: sub
|
scope: sub
|
||||||
derefAliases: never
|
derefAliases: never
|
||||||
pageSize: 0
|
pageSize: 0
|
||||||
userUIDAttribute: dn
|
userUIDAttribute: dn
|
||||||
userNameAttributes: [ mail ]
|
userNameAttributes: [mail]
|
||||||
tolerateMemberNotFoundErrors: true
|
tolerateMemberNotFoundErrors: true
|
||||||
tolerateMemberOutOfScopeErrors: true
|
tolerateMemberOutOfScopeErrors: true
|
||||||
|
|
||||||
# Sync all groups except the ones from the deny_groups from an LDAP server
|
# Sync all groups except the ones from the deny_groups from an LDAP server
|
||||||
- name: Sync all groups from an LDAP server using deny_groups
|
- name: Sync all groups from an LDAP server using deny_groups
|
||||||
@@ -190,39 +192,36 @@ builds:
|
|||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import traceback
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC
|
AUTH_ARG_SPEC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def argument_spec():
|
def argument_spec():
|
||||||
args = copy.deepcopy(AUTH_ARG_SPEC)
|
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||||
args.update(
|
args.update(
|
||||||
dict(
|
dict(
|
||||||
state=dict(type='str', choices=['absent', 'present'], default='present'),
|
state=dict(type="str", choices=["absent", "present"], default="present"),
|
||||||
type=dict(type='str', choices=['ldap', 'openshift'], default='ldap'),
|
type=dict(type="str", choices=["ldap", "openshift"], default="ldap"),
|
||||||
sync_config=dict(type='dict', aliases=['config', 'src'], required=True),
|
sync_config=dict(type="dict", aliases=["config", "src"], required=True),
|
||||||
deny_groups=dict(type='list', elements='str', default=[]),
|
deny_groups=dict(type="list", elements="str", default=[]),
|
||||||
allow_groups=dict(type='list', elements='str', default=[]),
|
allow_groups=dict(type="list", elements="str", default=[]),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=argument_spec(), supports_check_mode=True)
|
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_groups import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_groups import (
|
||||||
OpenshiftGroupsSync
|
OpenshiftGroupsSync,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
module = OpenshiftGroupsSync(
|
||||||
openshift_groups = OpenshiftGroupsSync(module)
|
argument_spec=argument_spec(), supports_check_mode=True
|
||||||
openshift_groups.execute_module()
|
)
|
||||||
except Exception as e:
|
module.run_module()
|
||||||
module.fail_json(msg=str(e), exception=traceback.format_exc())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ requirements:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = r"""
|
EXAMPLES = r"""
|
||||||
- name: Migrate TemplateInstances in namespace=test
|
- name: Migrate TemplateInstances in namespace=test
|
||||||
community.okd.openshift_adm_migrate_template_instances:
|
community.okd.openshift_adm_migrate_template_instances:
|
||||||
namespace: test
|
namespace: test
|
||||||
register: _result
|
register: _result
|
||||||
|
|
||||||
- name: Migrate TemplateInstances in all namespaces
|
- name: Migrate TemplateInstances in all namespaces
|
||||||
community.okd.openshift_adm_migrate_template_instances:
|
community.okd.openshift_adm_migrate_template_instances:
|
||||||
register: _result
|
register: _result
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN = r"""
|
RETURN = r"""
|
||||||
@@ -233,31 +233,22 @@ result:
|
|||||||
"""
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import traceback
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
|
AnsibleOpenshiftModule,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from kubernetes.dynamic.exceptions import DynamicApiError
|
from kubernetes.dynamic.exceptions import DynamicApiError
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
AUTH_ARG_SPEC,
|
AUTH_ARG_SPEC,
|
||||||
WAIT_ARG_SPEC,
|
WAIT_ARG_SPEC,
|
||||||
)
|
)
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
|
||||||
K8sAnsibleMixin,
|
|
||||||
get_api_client,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
transforms = {
|
transforms = {
|
||||||
"Build": "build.openshift.io/v1",
|
"Build": "build.openshift.io/v1",
|
||||||
"BuildConfig": "build.openshift.io/v1",
|
"BuildConfig": "build.openshift.io/v1",
|
||||||
@@ -266,24 +257,9 @@ transforms = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftMigrateTemplateInstances(K8sAnsibleMixin):
|
class OpenShiftMigrateTemplateInstances(AnsibleOpenshiftModule):
|
||||||
def __init__(self, module):
|
def __init__(self, **kwargs):
|
||||||
self.module = module
|
super(OpenShiftMigrateTemplateInstances, self).__init__(**kwargs)
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
self.exit_json = self.module.exit_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.module.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception),
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftMigrateTemplateInstances, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
|
|
||||||
def patch_template_instance(self, resource, templateinstance):
|
def patch_template_instance(self, resource, templateinstance):
|
||||||
result = None
|
result = None
|
||||||
@@ -291,7 +267,7 @@ class OpenShiftMigrateTemplateInstances(K8sAnsibleMixin):
|
|||||||
try:
|
try:
|
||||||
result = resource.status.patch(templateinstance)
|
result = resource.status.patch(templateinstance)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.module.fail_json(
|
self.fail_json(
|
||||||
msg="Failed to migrate TemplateInstance {0} due to: {1}".format(
|
msg="Failed to migrate TemplateInstance {0} due to: {1}".format(
|
||||||
templateinstance["metadata"]["name"], to_native(exc)
|
templateinstance["metadata"]["name"], to_native(exc)
|
||||||
)
|
)
|
||||||
@@ -319,9 +295,9 @@ class OpenShiftMigrateTemplateInstances(K8sAnsibleMixin):
|
|||||||
object_type in transforms.keys()
|
object_type in transforms.keys()
|
||||||
and obj["ref"].get("apiVersion") != transforms[object_type]
|
and obj["ref"].get("apiVersion") != transforms[object_type]
|
||||||
):
|
):
|
||||||
ti_elem["status"]["objects"][i]["ref"][
|
ti_elem["status"]["objects"][i]["ref"]["apiVersion"] = (
|
||||||
"apiVersion"
|
transforms[object_type]
|
||||||
] = transforms[object_type]
|
)
|
||||||
ti_to_be_migrated.append(ti_elem)
|
ti_to_be_migrated.append(ti_elem)
|
||||||
|
|
||||||
return ti_to_be_migrated
|
return ti_to_be_migrated
|
||||||
@@ -349,7 +325,7 @@ class OpenShiftMigrateTemplateInstances(K8sAnsibleMixin):
|
|||||||
reason=exc.reason,
|
reason=exc.reason,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.module.fail_json(
|
self.fail_json(
|
||||||
msg="Failed to retrieve TemplateInstances in namespace '{0}': {1}".format(
|
msg="Failed to retrieve TemplateInstances in namespace '{0}': {1}".format(
|
||||||
namespace, to_native(exc)
|
namespace, to_native(exc)
|
||||||
),
|
),
|
||||||
@@ -365,9 +341,7 @@ class OpenShiftMigrateTemplateInstances(K8sAnsibleMixin):
|
|||||||
|
|
||||||
if ti_to_be_migrated:
|
if ti_to_be_migrated:
|
||||||
if self.check_mode:
|
if self.check_mode:
|
||||||
self.module.exit_json(
|
self.exit_json(**{"changed": True, "result": ti_to_be_migrated})
|
||||||
**{"changed": True, "result": ti_to_be_migrated}
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
for ti_elem in ti_to_be_migrated:
|
for ti_elem in ti_to_be_migrated:
|
||||||
results["result"].append(
|
results["result"].append(
|
||||||
@@ -375,7 +349,7 @@ class OpenShiftMigrateTemplateInstances(K8sAnsibleMixin):
|
|||||||
)
|
)
|
||||||
results["changed"] = True
|
results["changed"] = True
|
||||||
|
|
||||||
self.module.exit_json(**results)
|
self.exit_json(**results)
|
||||||
|
|
||||||
|
|
||||||
def argspec():
|
def argspec():
|
||||||
@@ -389,10 +363,10 @@ def argspec():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = argspec()
|
argument_spec = argspec()
|
||||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
module = OpenShiftMigrateTemplateInstances(
|
||||||
openshift_process = OpenShiftMigrateTemplateInstances(module)
|
argument_spec=argument_spec, supports_check_mode=True
|
||||||
openshift_process.argspec = argument_spec
|
)
|
||||||
openshift_process.execute_module()
|
module.run_module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
module: openshift_adm_prune_auth
|
module: openshift_adm_prune_auth
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ options:
|
|||||||
- users
|
- users
|
||||||
- groups
|
- groups
|
||||||
type: str
|
type: str
|
||||||
required: True
|
required: true
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Use to specify an object name to remove.
|
- Use to specify an object name to remove.
|
||||||
@@ -58,9 +59,9 @@ options:
|
|||||||
requirements:
|
requirements:
|
||||||
- python >= 3.6
|
- python >= 3.6
|
||||||
- kubernetes >= 12.0.0
|
- kubernetes >= 12.0.0
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r"""
|
||||||
- name: Prune all roles from default namespace
|
- name: Prune all roles from default namespace
|
||||||
openshift_adm_prune_auth:
|
openshift_adm_prune_auth:
|
||||||
resource: roles
|
resource: roles
|
||||||
@@ -72,10 +73,10 @@ EXAMPLES = r'''
|
|||||||
namespace: testing
|
namespace: testing
|
||||||
label_selectors:
|
label_selectors:
|
||||||
- phase=production
|
- phase=production
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
cluster_role_binding:
|
cluster_role_binding:
|
||||||
type: list
|
type: list
|
||||||
description: list of cluster role binding deleted.
|
description: list of cluster role binding deleted.
|
||||||
@@ -96,40 +97,45 @@ group:
|
|||||||
type: list
|
type: list
|
||||||
description: list of Security Context Constraints deleted.
|
description: list of Security Context Constraints deleted.
|
||||||
returned: I(resource=users)
|
returned: I(resource=users)
|
||||||
'''
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC
|
AUTH_ARG_SPEC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def argument_spec():
|
def argument_spec():
|
||||||
args = copy.deepcopy(AUTH_ARG_SPEC)
|
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||||
args.update(
|
args.update(
|
||||||
dict(
|
dict(
|
||||||
resource=dict(type='str', required=True, choices=['roles', 'clusterroles', 'users', 'groups']),
|
resource=dict(
|
||||||
namespace=dict(type='str'),
|
type="str",
|
||||||
name=dict(type='str'),
|
required=True,
|
||||||
label_selectors=dict(type='list', elements='str'),
|
choices=["roles", "clusterroles", "users", "groups"],
|
||||||
|
),
|
||||||
|
namespace=dict(type="str"),
|
||||||
|
name=dict(type="str"),
|
||||||
|
label_selectors=dict(type="list", elements="str"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=argument_spec(),
|
|
||||||
mutually_exclusive=[("name", "label_selectors")],
|
|
||||||
supports_check_mode=True)
|
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_adm_prune_auth import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_adm_prune_auth import (
|
||||||
OpenShiftAdmPruneAuth)
|
OpenShiftAdmPruneAuth,
|
||||||
|
)
|
||||||
|
|
||||||
adm_prune_auth = OpenShiftAdmPruneAuth(module)
|
module = OpenShiftAdmPruneAuth(
|
||||||
adm_prune_auth.argspec = argument_spec
|
argument_spec=argument_spec(),
|
||||||
adm_prune_auth.execute_module()
|
mutually_exclusive=[("name", "label_selectors")],
|
||||||
|
supports_check_mode=True,
|
||||||
|
)
|
||||||
|
module.run_module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright (c) 2021, Red Hat
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
# STARTREMOVE (downstream)
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
|
module: openshift_adm_prune_builds
|
||||||
|
|
||||||
|
short_description: Prune old completed and failed builds
|
||||||
|
|
||||||
|
version_added: "2.3.0"
|
||||||
|
|
||||||
|
author:
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
|
|
||||||
|
description:
|
||||||
|
- This module allow administrators to delete old completed and failed builds.
|
||||||
|
- Analogous to C(oc adm prune builds).
|
||||||
|
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- kubernetes.core.k8s_auth_options
|
||||||
|
|
||||||
|
options:
|
||||||
|
namespace:
|
||||||
|
description:
|
||||||
|
- Use to specify namespace for builds to be deleted.
|
||||||
|
type: str
|
||||||
|
keep_younger_than:
|
||||||
|
description:
|
||||||
|
- Specify the minimum age (in minutes) of a Build for it to be considered a candidate for pruning.
|
||||||
|
type: int
|
||||||
|
orphans:
|
||||||
|
description:
|
||||||
|
- If C(true), prune all builds whose associated BuildConfig no longer exists and whose status is
|
||||||
|
complete, failed, error, or cancelled.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
|
||||||
|
requirements:
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
# Run deleting older completed and failed builds and also including
|
||||||
|
# all builds whose associated BuildConfig no longer exists
|
||||||
|
- name: Run delete orphan Builds
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
orphans: true
|
||||||
|
|
||||||
|
# Run deleting older completed and failed builds keep younger than 2hours
|
||||||
|
- name: Run delete builds, keep younger than 2h
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
keep_younger_than: 120
|
||||||
|
|
||||||
|
# Run deleting builds from specific namespace
|
||||||
|
- name: Run delete builds from namespace
|
||||||
|
community.okd.openshift_adm_prune_builds:
|
||||||
|
namespace: testing_namespace
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
builds:
|
||||||
|
description:
|
||||||
|
- The builds that were deleted
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
api_version:
|
||||||
|
description: The versioned schema of this representation of an object.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
kind:
|
||||||
|
description: Represents the REST resource this object represents.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
metadata:
|
||||||
|
description: Standard object metadata. Includes name, namespace, annotations, labels, etc.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
spec:
|
||||||
|
description: Specific attributes of the object. Will vary based on the I(api_version) and I(kind).
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
status:
|
||||||
|
description: Current status details for the object.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
"""
|
||||||
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
|
AUTH_ARG_SPEC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def argument_spec():
|
||||||
|
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||||
|
args.update(
|
||||||
|
dict(
|
||||||
|
namespace=dict(type="str"),
|
||||||
|
keep_younger_than=dict(type="int"),
|
||||||
|
orphans=dict(type="bool", default=False),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
from ansible_collections.community.okd.plugins.module_utils.openshift_builds import (
|
||||||
|
OpenShiftPruneBuilds,
|
||||||
|
)
|
||||||
|
|
||||||
|
module = OpenShiftPruneBuilds(
|
||||||
|
argument_spec=argument_spec(), supports_check_mode=True
|
||||||
|
)
|
||||||
|
module.run_module()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -5,10 +5,11 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
module: openshift_adm_prune_deployments
|
module: openshift_adm_prune_deployments
|
||||||
|
|
||||||
@@ -40,38 +41,39 @@ options:
|
|||||||
- If C(true), prune all deployments where the associated DeploymentConfig no longer exists,
|
- If C(true), prune all deployments where the associated DeploymentConfig no longer exists,
|
||||||
the status is complete or failed, and the replica size is C(0).
|
the status is complete or failed, and the replica size is C(0).
|
||||||
type: bool
|
type: bool
|
||||||
default: False
|
default: false
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- python >= 3.6
|
- python >= 3.6
|
||||||
- kubernetes >= 12.0.0
|
- kubernetes >= 12.0.0
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r"""
|
||||||
- name: Prune Deployments from testing namespace
|
- name: Prune Deployments from testing namespace
|
||||||
community.okd.openshift_adm_prune_deployments:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
namespace: testing
|
namespace: testing
|
||||||
|
|
||||||
- name: Prune orphans deployments, keep younger than 2hours
|
- name: Prune orphans deployments, keep younger than 2hours
|
||||||
community.okd.openshift_adm_prune_deployments:
|
community.okd.openshift_adm_prune_deployments:
|
||||||
orphans: True
|
orphans: true
|
||||||
keep_younger_than: 120
|
keep_younger_than: 120
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
replication_controllers:
|
replication_controllers:
|
||||||
type: list
|
type: list
|
||||||
description: list of replication controllers candidate for pruning.
|
description: list of replication controllers candidate for pruning.
|
||||||
returned: always
|
returned: always
|
||||||
'''
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
try:
|
try:
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
|
AUTH_ARG_SPEC,
|
||||||
|
)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -80,23 +82,28 @@ def argument_spec():
|
|||||||
args = copy.deepcopy(AUTH_ARG_SPEC)
|
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||||
args.update(
|
args.update(
|
||||||
dict(
|
dict(
|
||||||
namespace=dict(type='str',),
|
namespace=dict(
|
||||||
keep_younger_than=dict(type='int',),
|
type="str",
|
||||||
orphans=dict(type='bool', default=False),
|
),
|
||||||
|
keep_younger_than=dict(
|
||||||
|
type="int",
|
||||||
|
),
|
||||||
|
orphans=dict(type="bool", default=False),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=argument_spec(), supports_check_mode=True)
|
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_adm_prune_deployments import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_adm_prune_deployments import (
|
||||||
OpenShiftAdmPruneDeployment)
|
OpenShiftAdmPruneDeployment,
|
||||||
|
)
|
||||||
|
|
||||||
adm_prune_deployments = OpenShiftAdmPruneDeployment(module)
|
module = OpenShiftAdmPruneDeployment(
|
||||||
adm_prune_deployments.execute()
|
argument_spec=argument_spec(), supports_check_mode=True
|
||||||
|
)
|
||||||
|
module.run_module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
module: openshift_adm_prune_images
|
module: openshift_adm_prune_images
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ options:
|
|||||||
- Include images that were imported from external registries as candidates for pruning.
|
- Include images that were imported from external registries as candidates for pruning.
|
||||||
- If pruned, all the mirrored objects associated with them will also be removed from the integrated registry.
|
- If pruned, all the mirrored objects associated with them will also be removed from the integrated registry.
|
||||||
type: bool
|
type: bool
|
||||||
default: True
|
default: true
|
||||||
keep_younger_than:
|
keep_younger_than:
|
||||||
description:
|
description:
|
||||||
- Specify the minimum age (in minutes) of an image and its referrers for it to be considered a candidate for pruning.
|
- Specify the minimum age (in minutes) of an image and its referrers for it to be considered a candidate for pruning.
|
||||||
@@ -49,7 +50,7 @@ options:
|
|||||||
- Specify if images which are exceeding LimitRanges specified in the same namespace,
|
- Specify if images which are exceeding LimitRanges specified in the same namespace,
|
||||||
should be considered for pruning.
|
should be considered for pruning.
|
||||||
type: bool
|
type: bool
|
||||||
default: False
|
default: false
|
||||||
registry_url:
|
registry_url:
|
||||||
description:
|
description:
|
||||||
- The address to use when contacting the registry, instead of using the default value.
|
- The address to use when contacting the registry, instead of using the default value.
|
||||||
@@ -69,24 +70,24 @@ options:
|
|||||||
type: bool
|
type: bool
|
||||||
prune_registry:
|
prune_registry:
|
||||||
description:
|
description:
|
||||||
- If set to I(False), the prune operation will clean up image API objects, but
|
- If set to I(false), the prune operation will clean up image API objects, but
|
||||||
none of the associated content in the registry is removed.
|
none of the associated content in the registry is removed.
|
||||||
type: bool
|
type: bool
|
||||||
default: True
|
default: true
|
||||||
ignore_invalid_refs:
|
ignore_invalid_refs:
|
||||||
description:
|
description:
|
||||||
- If set to I(True), the pruning process will ignore all errors while parsing image references.
|
- If set to I(true), the pruning process will ignore all errors while parsing image references.
|
||||||
- This means that the pruning process will ignore the intended connection between the object and the referenced image.
|
- This means that the pruning process will ignore the intended connection between the object and the referenced image.
|
||||||
- As a result an image may be incorrectly deleted as unused.
|
- As a result an image may be incorrectly deleted as unused.
|
||||||
type: bool
|
type: bool
|
||||||
default: False
|
default: false
|
||||||
requirements:
|
requirements:
|
||||||
- python >= 3.6
|
- python >= 3.6
|
||||||
- kubernetes >= 12.0.0
|
- kubernetes >= 12.0.0
|
||||||
- docker-image-py
|
- docker-image-py
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r"""
|
||||||
# Prune if only images and their referrers were more than an hour old
|
# Prune if only images and their referrers were more than an hour old
|
||||||
- name: Prune image with referrer been more than an hour old
|
- name: Prune image with referrer been more than an hour old
|
||||||
community.okd.openshift_adm_prune_images:
|
community.okd.openshift_adm_prune_images:
|
||||||
@@ -102,10 +103,10 @@ EXAMPLES = r'''
|
|||||||
community.okd.openshift_adm_prune_images:
|
community.okd.openshift_adm_prune_images:
|
||||||
registry_url: http://registry.example.org
|
registry_url: http://registry.example.org
|
||||||
registry_validate_certs: false
|
registry_validate_certs: false
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
updated_image_streams:
|
updated_image_streams:
|
||||||
description:
|
description:
|
||||||
- The images streams updated.
|
- The images streams updated.
|
||||||
@@ -275,43 +276,44 @@ deleted_images:
|
|||||||
},
|
},
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
'''
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC
|
AUTH_ARG_SPEC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def argument_spec():
|
def argument_spec():
|
||||||
args = copy.deepcopy(AUTH_ARG_SPEC)
|
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||||
args.update(
|
args.update(
|
||||||
dict(
|
dict(
|
||||||
namespace=dict(type='str'),
|
namespace=dict(type="str"),
|
||||||
all_images=dict(type='bool', default=True),
|
all_images=dict(type="bool", default=True),
|
||||||
keep_younger_than=dict(type='int'),
|
keep_younger_than=dict(type="int"),
|
||||||
prune_over_size_limit=dict(type='bool', default=False),
|
prune_over_size_limit=dict(type="bool", default=False),
|
||||||
registry_url=dict(type='str'),
|
registry_url=dict(type="str"),
|
||||||
registry_validate_certs=dict(type='bool'),
|
registry_validate_certs=dict(type="bool"),
|
||||||
registry_ca_cert=dict(type='path'),
|
registry_ca_cert=dict(type="path"),
|
||||||
prune_registry=dict(type='bool', default=True),
|
prune_registry=dict(type="bool", default=True),
|
||||||
ignore_invalid_refs=dict(type='bool', default=False),
|
ignore_invalid_refs=dict(type="bool", default=False),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=argument_spec(), supports_check_mode=True)
|
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_adm_prune_images import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_adm_prune_images import (
|
||||||
OpenShiftAdmPruneImages)
|
OpenShiftAdmPruneImages,
|
||||||
|
)
|
||||||
|
|
||||||
adm_prune_images = OpenShiftAdmPruneImages(module)
|
module = OpenShiftAdmPruneImages(
|
||||||
adm_prune_images.argspec = argument_spec()
|
argument_spec=argument_spec(), supports_check_mode=True
|
||||||
adm_prune_images.execute_module()
|
)
|
||||||
|
module.run_module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
+166
-100
@@ -5,9 +5,10 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
module: openshift_auth
|
module: openshift_auth
|
||||||
|
|
||||||
@@ -74,46 +75,49 @@ requirements:
|
|||||||
- urllib3
|
- urllib3
|
||||||
- requests
|
- requests
|
||||||
- requests-oauthlib
|
- requests-oauthlib
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r"""
|
||||||
- hosts: localhost
|
- name: Example Playbook
|
||||||
|
hosts: localhost
|
||||||
module_defaults:
|
module_defaults:
|
||||||
group/k8s:
|
group/community.okd.okd:
|
||||||
host: https://k8s.example.com/
|
host: https://k8s.example.com/
|
||||||
ca_cert: ca.pem
|
ca_cert: ca.pem
|
||||||
tasks:
|
tasks:
|
||||||
- block:
|
- name: Authenticate to OpenShift cluster and gell a list of all pods from any namespace
|
||||||
# It's good practice to store login credentials in a secure vault and not
|
block:
|
||||||
# directly in playbooks.
|
# It's good practice to store login credentials in a secure vault and not
|
||||||
- include_vars: openshift_passwords.yml
|
# directly in playbooks.
|
||||||
|
- name: Include 'openshift_passwords.yml'
|
||||||
|
ansible.builtin.include_vars: openshift_passwords.yml
|
||||||
|
|
||||||
- name: Log in (obtain access token)
|
- name: Log in (obtain access token)
|
||||||
community.okd.openshift_auth:
|
community.okd.openshift_auth:
|
||||||
username: admin
|
username: admin
|
||||||
password: "{{ openshift_admin_password }}"
|
password: "{{ openshift_admin_password }}"
|
||||||
register: openshift_auth_results
|
register: openshift_auth_results
|
||||||
|
|
||||||
# Previous task provides the token/api_key, while all other parameters
|
# Previous task provides the token/api_key, while all other parameters
|
||||||
# are taken from module_defaults
|
# are taken from module_defaults
|
||||||
- name: Get a list of all pods from any namespace
|
- name: Get a list of all pods from any namespace
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
||||||
kind: Pod
|
kind: Pod
|
||||||
register: pod_list
|
register: pod_list
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: If login succeeded, try to log out (revoke access token)
|
- name: If login succeeded, try to log out (revoke access token)
|
||||||
when: openshift_auth_results.openshift_auth.api_key is defined
|
when: openshift_auth_results.openshift_auth.api_key is defined
|
||||||
community.okd.openshift_auth:
|
community.okd.openshift_auth:
|
||||||
state: absent
|
state: absent
|
||||||
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
|
||||||
'''
|
"""
|
||||||
|
|
||||||
# Returned value names need to match k8s modules parameter names, to make it
|
# Returned value names need to match k8s modules parameter names, to make it
|
||||||
# easy to pass returned values of openshift_auth to other k8s modules.
|
# easy to pass returned values of openshift_auth to other k8s modules.
|
||||||
# Discussion: https://github.com/ansible/ansible/pull/50807#discussion_r248827899
|
# Discussion: https://github.com/ansible/ansible/pull/50807#discussion_r248827899
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
openshift_auth:
|
openshift_auth:
|
||||||
description: OpenShift authentication facts.
|
description: OpenShift authentication facts.
|
||||||
returned: success
|
returned: success
|
||||||
@@ -164,93 +168,119 @@ k8s_auth:
|
|||||||
description: Username for authenticating with the API server.
|
description: Username for authenticating with the API server.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.six.moves.urllib_parse import urlparse, parse_qs, urlencode
|
from urllib.parse import urlparse, parse_qs, urlencode, urljoin
|
||||||
from urllib.parse import urljoin
|
|
||||||
|
from base64 import urlsafe_b64encode
|
||||||
|
import hashlib
|
||||||
|
|
||||||
# 3rd party imports
|
# 3rd party imports
|
||||||
try:
|
try:
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
HAS_REQUESTS = True
|
HAS_REQUESTS = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_REQUESTS = False
|
HAS_REQUESTS = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from requests_oauthlib import OAuth2Session
|
from requests_oauthlib import OAuth2Session
|
||||||
|
|
||||||
HAS_REQUESTS_OAUTH = True
|
HAS_REQUESTS_OAUTH = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_REQUESTS_OAUTH = False
|
HAS_REQUESTS_OAUTH = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib3.util import make_headers
|
from urllib3.util import make_headers
|
||||||
|
|
||||||
HAS_URLLIB3 = True
|
HAS_URLLIB3 = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_URLLIB3 = False
|
HAS_URLLIB3 = False
|
||||||
|
|
||||||
|
|
||||||
K8S_AUTH_ARG_SPEC = {
|
K8S_AUTH_ARG_SPEC = {
|
||||||
'state': {
|
"state": {
|
||||||
'default': 'present',
|
"default": "present",
|
||||||
'choices': ['present', 'absent'],
|
"choices": ["present", "absent"],
|
||||||
},
|
},
|
||||||
'host': {'required': True},
|
"host": {"required": True},
|
||||||
'username': {},
|
"username": {},
|
||||||
'password': {'no_log': True},
|
"password": {"no_log": True},
|
||||||
'ca_cert': {'type': 'path', 'aliases': ['ssl_ca_cert']},
|
"ca_cert": {"type": "path", "aliases": ["ssl_ca_cert"]},
|
||||||
'validate_certs': {
|
"validate_certs": {"type": "bool", "default": True, "aliases": ["verify_ssl"]},
|
||||||
'type': 'bool',
|
"api_key": {"no_log": True},
|
||||||
'default': True,
|
|
||||||
'aliases': ['verify_ssl']
|
|
||||||
},
|
|
||||||
'api_key': {'no_log': True},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_oauthaccesstoken_objectname_from_token(token_name):
|
||||||
|
"""
|
||||||
|
openshift convert the access token to an OAuthAccessToken resource name using the algorithm
|
||||||
|
https://github.com/openshift/console/blob/9f352ba49f82ad693a72d0d35709961428b43b93/pkg/server/server.go#L609-L613
|
||||||
|
"""
|
||||||
|
|
||||||
|
sha256Prefix = "sha256~"
|
||||||
|
if token_name.startswith(sha256Prefix):
|
||||||
|
content = token_name[len(sha256Prefix) :]
|
||||||
|
else:
|
||||||
|
content = token_name
|
||||||
|
b64encoded = urlsafe_b64encode(hashlib.sha256(content.encode()).digest()).rstrip(
|
||||||
|
b"="
|
||||||
|
)
|
||||||
|
return sha256Prefix + b64encoded.decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftAuthModule(AnsibleModule):
|
class OpenShiftAuthModule(AnsibleModule):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
AnsibleModule.__init__(
|
AnsibleModule.__init__(
|
||||||
self,
|
self,
|
||||||
argument_spec=K8S_AUTH_ARG_SPEC,
|
argument_spec=K8S_AUTH_ARG_SPEC,
|
||||||
required_if=[
|
required_if=[
|
||||||
('state', 'present', ['username', 'password']),
|
("state", "present", ["username", "password"]),
|
||||||
('state', 'absent', ['api_key']),
|
("state", "absent", ["api_key"]),
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
if not HAS_REQUESTS:
|
if not HAS_REQUESTS:
|
||||||
self.fail("This module requires the python 'requests' package. Try `pip install requests`.")
|
self.fail(
|
||||||
|
"This module requires the python 'requests' package. Try `pip install requests`."
|
||||||
|
)
|
||||||
|
|
||||||
if not HAS_REQUESTS_OAUTH:
|
if not HAS_REQUESTS_OAUTH:
|
||||||
self.fail("This module requires the python 'requests-oauthlib' package. Try `pip install requests-oauthlib`.")
|
self.fail(
|
||||||
|
"This module requires the python 'requests-oauthlib' package. Try `pip install requests-oauthlib`."
|
||||||
|
)
|
||||||
|
|
||||||
if not HAS_URLLIB3:
|
if not HAS_URLLIB3:
|
||||||
self.fail("This module requires the python 'urllib3' package. Try `pip install urllib3`.")
|
self.fail(
|
||||||
|
"This module requires the python 'urllib3' package. Try `pip install urllib3`."
|
||||||
|
)
|
||||||
|
|
||||||
def execute_module(self):
|
def execute_module(self):
|
||||||
state = self.params.get('state')
|
state = self.params.get("state")
|
||||||
verify_ssl = self.params.get('validate_certs')
|
verify_ssl = self.params.get("validate_certs")
|
||||||
ssl_ca_cert = self.params.get('ca_cert')
|
ssl_ca_cert = self.params.get("ca_cert")
|
||||||
|
|
||||||
self.auth_username = self.params.get('username')
|
self.auth_username = self.params.get("username")
|
||||||
self.auth_password = self.params.get('password')
|
self.auth_password = self.params.get("password")
|
||||||
self.auth_api_key = self.params.get('api_key')
|
self.auth_api_key = self.params.get("api_key")
|
||||||
self.con_host = self.params.get('host')
|
self.con_host = self.params.get("host")
|
||||||
|
|
||||||
# python-requests takes either a bool or a path to a ca file as the 'verify' param
|
# python-requests takes either a bool or a path to a ca file as the 'verify' param
|
||||||
if verify_ssl and ssl_ca_cert:
|
if verify_ssl and ssl_ca_cert:
|
||||||
self.con_verify_ca = ssl_ca_cert # path
|
self.con_verify_ca = ssl_ca_cert # path
|
||||||
else:
|
else:
|
||||||
self.con_verify_ca = verify_ssl # bool
|
self.con_verify_ca = verify_ssl # bool
|
||||||
|
|
||||||
# Get needed info to access authorization APIs
|
# Get needed info to access authorization APIs
|
||||||
self.openshift_discover()
|
self.openshift_discover()
|
||||||
|
|
||||||
if state == 'present':
|
changed = False
|
||||||
|
result = dict()
|
||||||
|
if state == "present":
|
||||||
new_api_key = self.openshift_login()
|
new_api_key = self.openshift_login()
|
||||||
result = dict(
|
result = dict(
|
||||||
host=self.con_host,
|
host=self.con_host,
|
||||||
@@ -260,87 +290,123 @@ class OpenShiftAuthModule(AnsibleModule):
|
|||||||
username=self.auth_username,
|
username=self.auth_username,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.openshift_logout()
|
changed = self.openshift_logout()
|
||||||
result = dict()
|
|
||||||
|
|
||||||
# return k8s_auth as well for backwards compatibility
|
# return k8s_auth as well for backwards compatibility
|
||||||
self.exit_json(changed=False, openshift_auth=result, k8s_auth=result)
|
self.exit_json(changed=changed, openshift_auth=result, k8s_auth=result)
|
||||||
|
|
||||||
def openshift_discover(self):
|
def openshift_discover(self):
|
||||||
url = urljoin(self.con_host, '.well-known/oauth-authorization-server')
|
url = urljoin(self.con_host, ".well-known/oauth-authorization-server")
|
||||||
ret = requests.get(url, verify=self.con_verify_ca)
|
ret = requests.get(url, verify=self.con_verify_ca)
|
||||||
|
|
||||||
if ret.status_code != 200:
|
if ret.status_code != 200:
|
||||||
self.fail_request("Couldn't find OpenShift's OAuth API", method='GET', url=url,
|
self.fail_request(
|
||||||
reason=ret.reason, status_code=ret.status_code)
|
"Couldn't find OpenShift's OAuth API",
|
||||||
|
method="GET",
|
||||||
|
url=url,
|
||||||
|
reason=ret.reason,
|
||||||
|
status_code=ret.status_code,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
oauth_info = ret.json()
|
oauth_info = ret.json()
|
||||||
|
|
||||||
self.openshift_auth_endpoint = oauth_info['authorization_endpoint']
|
self.openshift_auth_endpoint = oauth_info["authorization_endpoint"]
|
||||||
self.openshift_token_endpoint = oauth_info['token_endpoint']
|
self.openshift_token_endpoint = oauth_info["token_endpoint"]
|
||||||
except Exception:
|
except Exception:
|
||||||
self.fail_json(msg="Something went wrong discovering OpenShift OAuth details.",
|
self.fail_json(
|
||||||
exception=traceback.format_exc())
|
msg="Something went wrong discovering OpenShift OAuth details.",
|
||||||
|
exception=traceback.format_exc(),
|
||||||
|
)
|
||||||
|
|
||||||
def openshift_login(self):
|
def openshift_login(self):
|
||||||
os_oauth = OAuth2Session(client_id='openshift-challenging-client')
|
os_oauth = OAuth2Session(client_id="openshift-challenging-client")
|
||||||
authorization_url, state = os_oauth.authorization_url(self.openshift_auth_endpoint,
|
authorization_url, state = os_oauth.authorization_url(
|
||||||
state="1", code_challenge_method='S256')
|
self.openshift_auth_endpoint, state="1", code_challenge_method="S256"
|
||||||
auth_headers = make_headers(basic_auth='{0}:{1}'.format(self.auth_username, self.auth_password))
|
)
|
||||||
|
auth_headers = make_headers(
|
||||||
|
basic_auth="{0}:{1}".format(self.auth_username, self.auth_password)
|
||||||
|
)
|
||||||
|
|
||||||
# Request authorization code using basic auth credentials
|
# Request authorization code using basic auth credentials
|
||||||
ret = os_oauth.get(
|
ret = os_oauth.get(
|
||||||
authorization_url,
|
authorization_url,
|
||||||
headers={'X-Csrf-Token': state, 'authorization': auth_headers.get('authorization')},
|
headers={
|
||||||
|
"X-Csrf-Token": state,
|
||||||
|
"authorization": auth_headers.get("authorization"),
|
||||||
|
},
|
||||||
verify=self.con_verify_ca,
|
verify=self.con_verify_ca,
|
||||||
allow_redirects=False
|
allow_redirects=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
if ret.status_code != 302:
|
if ret.status_code != 302:
|
||||||
self.fail_request("Authorization failed.", method='GET', url=authorization_url,
|
self.fail_request(
|
||||||
reason=ret.reason, status_code=ret.status_code)
|
"Authorization failed.",
|
||||||
|
method="GET",
|
||||||
|
url=authorization_url,
|
||||||
|
reason=ret.reason,
|
||||||
|
status_code=ret.status_code,
|
||||||
|
)
|
||||||
|
|
||||||
# In here we have `code` and `state`, I think `code` is the important one
|
# In here we have `code` and `state`, I think `code` is the important one
|
||||||
qwargs = {}
|
qwargs = {}
|
||||||
for k, v in parse_qs(urlparse(ret.headers['Location']).query).items():
|
for k, v in parse_qs(urlparse(ret.headers["Location"]).query).items():
|
||||||
qwargs[k] = v[0]
|
qwargs[k] = v[0]
|
||||||
qwargs['grant_type'] = 'authorization_code'
|
qwargs["grant_type"] = "authorization_code"
|
||||||
|
|
||||||
# Using authorization code given to us in the Location header of the previous request, request a token
|
# Using authorization code given to us in the Location header of the previous request, request a token
|
||||||
ret = os_oauth.post(
|
ret = os_oauth.post(
|
||||||
self.openshift_token_endpoint,
|
self.openshift_token_endpoint,
|
||||||
headers={
|
headers={
|
||||||
'Accept': 'application/json',
|
"Accept": "application/json",
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
# This is just base64 encoded 'openshift-challenging-client:'
|
# This is just base64 encoded 'openshift-challenging-client:'
|
||||||
'Authorization': 'Basic b3BlbnNoaWZ0LWNoYWxsZW5naW5nLWNsaWVudDo='
|
"Authorization": "Basic b3BlbnNoaWZ0LWNoYWxsZW5naW5nLWNsaWVudDo=",
|
||||||
},
|
},
|
||||||
data=urlencode(qwargs),
|
data=urlencode(qwargs),
|
||||||
verify=self.con_verify_ca
|
verify=self.con_verify_ca,
|
||||||
)
|
)
|
||||||
|
|
||||||
if ret.status_code != 200:
|
if ret.status_code != 200:
|
||||||
self.fail_request("Failed to obtain an authorization token.", method='POST',
|
self.fail_request(
|
||||||
url=self.openshift_token_endpoint,
|
"Failed to obtain an authorization token.",
|
||||||
reason=ret.reason, status_code=ret.status_code)
|
method="POST",
|
||||||
|
url=self.openshift_token_endpoint,
|
||||||
|
reason=ret.reason,
|
||||||
|
status_code=ret.status_code,
|
||||||
|
)
|
||||||
|
|
||||||
return ret.json()['access_token']
|
return ret.json()["access_token"]
|
||||||
|
|
||||||
def openshift_logout(self):
|
def openshift_logout(self):
|
||||||
url = '{0}/apis/oauth.openshift.io/v1/oauthaccesstokens/{1}'.format(self.con_host, self.auth_api_key)
|
name = get_oauthaccesstoken_objectname_from_token(self.auth_api_key)
|
||||||
headers = {
|
headers = {
|
||||||
'Accept': 'application/json',
|
"Accept": "application/json",
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
'Authorization': 'Bearer {0}'.format(self.auth_api_key)
|
"Authorization": "Bearer {0}".format(self.auth_api_key),
|
||||||
}
|
|
||||||
json = {
|
|
||||||
"apiVersion": "oauth.openshift.io/v1",
|
|
||||||
"kind": "DeleteOptions"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requests.delete(url, headers=headers, json=json, verify=self.con_verify_ca)
|
url = "{0}/apis/oauth.openshift.io/v1/useroauthaccesstokens/{1}".format(
|
||||||
# Ignore errors, the token will time out eventually anyway
|
self.con_host, name
|
||||||
|
)
|
||||||
|
json = {
|
||||||
|
"apiVersion": "oauth.openshift.io/v1",
|
||||||
|
"kind": "DeleteOptions",
|
||||||
|
"gracePeriodSeconds": 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = requests.delete(
|
||||||
|
url, json=json, verify=self.con_verify_ca, headers=headers
|
||||||
|
)
|
||||||
|
if ret.status_code != 200:
|
||||||
|
self.fail_json(
|
||||||
|
msg="Couldn't delete user oauth access token '{0}' due to: {1}".format(
|
||||||
|
name, ret.json().get("message")
|
||||||
|
),
|
||||||
|
status_code=ret.status_code,
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def fail(self, msg=None):
|
def fail(self, msg=None):
|
||||||
self.fail_json(msg=msg)
|
self.fail_json(msg=msg)
|
||||||
@@ -348,7 +414,7 @@ class OpenShiftAuthModule(AnsibleModule):
|
|||||||
def fail_request(self, msg, **kwargs):
|
def fail_request(self, msg, **kwargs):
|
||||||
req_info = {}
|
req_info = {}
|
||||||
for k, v in kwargs.items():
|
for k, v in kwargs.items():
|
||||||
req_info['req_' + k] = v
|
req_info["req_" + k] = v
|
||||||
self.fail_json(msg=msg, **req_info)
|
self.fail_json(msg=msg, **req_info)
|
||||||
|
|
||||||
|
|
||||||
@@ -360,5 +426,5 @@ def main():
|
|||||||
module.fail_json(msg=str(e), exception=traceback.format_exc())
|
module.fail_json(msg=str(e), exception=traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -0,0 +1,272 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright (c) 2021, Red Hat
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
# STARTREMOVE (downstream)
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
|
module: openshift_build
|
||||||
|
|
||||||
|
short_description: Start a new build or Cancel running, pending, or new builds.
|
||||||
|
|
||||||
|
version_added: "2.3.0"
|
||||||
|
|
||||||
|
author:
|
||||||
|
- Aubin Bikouo (@abikouo)
|
||||||
|
|
||||||
|
description:
|
||||||
|
- This module starts a new build from the provided build config or build name.
|
||||||
|
- This module also cancel a new, pending or running build by requesting a graceful shutdown of the build.
|
||||||
|
There may be a delay between requesting the build and the time the build is terminated.
|
||||||
|
- This can also restart a new build when the current is cancelled.
|
||||||
|
- Analogous to C(oc cancel-build) and C(oc start-build).
|
||||||
|
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- kubernetes.core.k8s_auth_options
|
||||||
|
|
||||||
|
options:
|
||||||
|
state:
|
||||||
|
description:
|
||||||
|
- Determines if a Build should be started ,cancelled or restarted.
|
||||||
|
- When set to C(restarted) a new build will be created after the current build is cancelled.
|
||||||
|
choices:
|
||||||
|
- started
|
||||||
|
- cancelled
|
||||||
|
- restarted
|
||||||
|
default: started
|
||||||
|
type: str
|
||||||
|
build_name:
|
||||||
|
description:
|
||||||
|
- Specify the name of a build which should be re-run.
|
||||||
|
- Mutually exclusive with parameter I(build_config_name).
|
||||||
|
type: str
|
||||||
|
build_config_name:
|
||||||
|
description:
|
||||||
|
- Specify the name of a build config from which a new build will be run.
|
||||||
|
- Mutually exclusive with parameter I(build_name).
|
||||||
|
type: str
|
||||||
|
namespace:
|
||||||
|
description:
|
||||||
|
- Specify the namespace for the build or the build config.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
build_args:
|
||||||
|
description:
|
||||||
|
- Specify a list of key-value pair to pass to Docker during the build.
|
||||||
|
type: list
|
||||||
|
elements: dict
|
||||||
|
suboptions:
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- docker build argument name.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
value:
|
||||||
|
description:
|
||||||
|
- docker build argument value.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
commit:
|
||||||
|
description:
|
||||||
|
- Specify the source code commit identifier the build should use;
|
||||||
|
requires a build based on a Git repository.
|
||||||
|
type: str
|
||||||
|
env_vars:
|
||||||
|
description:
|
||||||
|
- Specify a list of key-value pair for an environment variable to set for the build container.
|
||||||
|
type: list
|
||||||
|
elements: dict
|
||||||
|
suboptions:
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- Environment variable name.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
value:
|
||||||
|
description:
|
||||||
|
- Environment variable value.
|
||||||
|
type: str
|
||||||
|
required: true
|
||||||
|
incremental:
|
||||||
|
description:
|
||||||
|
- Overrides the incremental setting in a source-strategy build, ignored if not specified.
|
||||||
|
type: bool
|
||||||
|
no_cache:
|
||||||
|
description:
|
||||||
|
- Overrides the noCache setting in a docker-strategy build, ignored if not specified.
|
||||||
|
type: bool
|
||||||
|
wait:
|
||||||
|
description:
|
||||||
|
- When C(state=started), specify whether to wait for a build to complete
|
||||||
|
and exit with a non-zero return code if the build fails.
|
||||||
|
- When I(state=cancelled), specify whether to wait for a build phase to be Cancelled.
|
||||||
|
default: false
|
||||||
|
type: bool
|
||||||
|
wait_sleep:
|
||||||
|
description:
|
||||||
|
- Number of seconds to sleep between checks.
|
||||||
|
- Ignored if C(wait=false).
|
||||||
|
default: 5
|
||||||
|
type: int
|
||||||
|
wait_timeout:
|
||||||
|
description:
|
||||||
|
- How long in seconds to wait for a build to complete.
|
||||||
|
- Ignored if C(wait=false).
|
||||||
|
default: 120
|
||||||
|
type: int
|
||||||
|
build_phases:
|
||||||
|
description:
|
||||||
|
- List of state for build to cancel.
|
||||||
|
- Ignored when C(state=started).
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
choices:
|
||||||
|
- New
|
||||||
|
- Pending
|
||||||
|
- Running
|
||||||
|
default: []
|
||||||
|
|
||||||
|
requirements:
|
||||||
|
- python >= 3.6
|
||||||
|
- kubernetes >= 12.0.0
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
# Starts build from build config default/hello-world
|
||||||
|
- name: Starts build from build config
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: default
|
||||||
|
build_config_name: hello-world
|
||||||
|
|
||||||
|
# Starts build from a previous build "default/hello-world-1"
|
||||||
|
- name: Starts build from a previous build
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: default
|
||||||
|
build_name: hello-world-1
|
||||||
|
|
||||||
|
# Cancel the build with the given name
|
||||||
|
- name: Cancel build from default namespace
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "default"
|
||||||
|
build_name: ruby-build-1
|
||||||
|
state: cancelled
|
||||||
|
|
||||||
|
# Cancel the named build and create a new one with the same parameters
|
||||||
|
- name: Cancel build from default namespace and create a new one
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "default"
|
||||||
|
build_name: ruby-build-1
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
# Cancel all builds created from 'ruby-build' build configuration that are in 'new' state
|
||||||
|
- name: Cancel build from default namespace and create a new one
|
||||||
|
community.okd.openshift_build:
|
||||||
|
namespace: "default"
|
||||||
|
build_config_name: ruby-build
|
||||||
|
build_phases:
|
||||||
|
- New
|
||||||
|
state: cancelled
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
builds:
|
||||||
|
description:
|
||||||
|
- The builds that were started/cancelled.
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains:
|
||||||
|
api_version:
|
||||||
|
description: The versioned schema of this representation of an object.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
kind:
|
||||||
|
description: Represents the REST resource this object represents.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
metadata:
|
||||||
|
description: Standard object metadata. Includes name, namespace, annotations, labels, etc.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
spec:
|
||||||
|
description: Specific attributes of the build.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
status:
|
||||||
|
description: Current status details for the object.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
"""
|
||||||
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
|
AUTH_ARG_SPEC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def argument_spec():
|
||||||
|
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||||
|
|
||||||
|
args_options = dict(
|
||||||
|
name=dict(type="str", required=True), value=dict(type="str", required=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
args.update(
|
||||||
|
dict(
|
||||||
|
state=dict(
|
||||||
|
type="str",
|
||||||
|
choices=["started", "cancelled", "restarted"],
|
||||||
|
default="started",
|
||||||
|
),
|
||||||
|
build_args=dict(type="list", elements="dict", options=args_options),
|
||||||
|
commit=dict(type="str"),
|
||||||
|
env_vars=dict(type="list", elements="dict", options=args_options),
|
||||||
|
build_name=dict(type="str"),
|
||||||
|
build_config_name=dict(type="str"),
|
||||||
|
namespace=dict(type="str", required=True),
|
||||||
|
incremental=dict(type="bool"),
|
||||||
|
no_cache=dict(type="bool"),
|
||||||
|
wait=dict(type="bool", default=False),
|
||||||
|
wait_sleep=dict(type="int", default=5),
|
||||||
|
wait_timeout=dict(type="int", default=120),
|
||||||
|
build_phases=dict(
|
||||||
|
type="list",
|
||||||
|
elements="str",
|
||||||
|
default=[],
|
||||||
|
choices=["New", "Pending", "Running"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
mutually_exclusive = [
|
||||||
|
("build_name", "build_config_name"),
|
||||||
|
]
|
||||||
|
from ansible_collections.community.okd.plugins.module_utils.openshift_builds import (
|
||||||
|
OpenShiftBuilds,
|
||||||
|
)
|
||||||
|
|
||||||
|
module = OpenShiftBuilds(
|
||||||
|
argument_spec=argument_spec(),
|
||||||
|
mutually_exclusive=mutually_exclusive,
|
||||||
|
required_one_of=[
|
||||||
|
[
|
||||||
|
"build_name",
|
||||||
|
"build_config_name",
|
||||||
|
]
|
||||||
|
],
|
||||||
|
)
|
||||||
|
module.run_module()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -5,10 +5,11 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
module: openshift_import_image
|
module: openshift_import_image
|
||||||
|
|
||||||
@@ -35,18 +36,18 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Use to specify namespace for image stream to create/update.
|
- Use to specify namespace for image stream to create/update.
|
||||||
type: str
|
type: str
|
||||||
required: True
|
required: true
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Image stream to import tag into.
|
- Image stream to import tag into.
|
||||||
- This can be provided as a list of images streams or a single value.
|
- This can be provided as a list of images streams or a single value.
|
||||||
type: raw
|
type: raw
|
||||||
required: True
|
required: true
|
||||||
all:
|
all:
|
||||||
description:
|
description:
|
||||||
- If set to I(true), import all tags from the provided source on creation or if C(source) is specified.
|
- If set to I(true), import all tags from the provided source on creation or if C(source) is specified.
|
||||||
type: bool
|
type: bool
|
||||||
default: False
|
default: false
|
||||||
validate_registry_certs:
|
validate_registry_certs:
|
||||||
description:
|
description:
|
||||||
- If set to I(true), allow importing from registries that have invalid HTTPS certificates.
|
- If set to I(true), allow importing from registries that have invalid HTTPS certificates.
|
||||||
@@ -64,7 +65,7 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Set each imported Docker image to be periodically imported from a remote repository.
|
- Set each imported Docker image to be periodically imported from a remote repository.
|
||||||
type: bool
|
type: bool
|
||||||
default: False
|
default: false
|
||||||
source:
|
source:
|
||||||
description:
|
description:
|
||||||
- A Docker image repository to import images from.
|
- A Docker image repository to import images from.
|
||||||
@@ -75,9 +76,9 @@ requirements:
|
|||||||
- python >= 3.6
|
- python >= 3.6
|
||||||
- kubernetes >= 12.0.0
|
- kubernetes >= 12.0.0
|
||||||
- docker-image-py
|
- docker-image-py
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r"""
|
||||||
# Import tag latest into a new image stream.
|
# Import tag latest into a new image stream.
|
||||||
- name: Import tag latest into new image stream
|
- name: Import tag latest into new image stream
|
||||||
community.okd.openshift_import_image:
|
community.okd.openshift_import_image:
|
||||||
@@ -122,10 +123,10 @@ EXAMPLES = r'''
|
|||||||
- mystream3
|
- mystream3
|
||||||
source: registry.io/repo/image:latest
|
source: registry.io/repo/image:latest
|
||||||
all: true
|
all: true
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
result:
|
result:
|
||||||
description:
|
description:
|
||||||
- List with all ImageStreamImport that have been created.
|
- List with all ImageStreamImport that have been created.
|
||||||
@@ -153,44 +154,44 @@ result:
|
|||||||
description: Current status details for the object.
|
description: Current status details for the object.
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
'''
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC
|
AUTH_ARG_SPEC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def argument_spec():
|
def argument_spec():
|
||||||
args = copy.deepcopy(AUTH_ARG_SPEC)
|
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||||
args.update(
|
args.update(
|
||||||
dict(
|
dict(
|
||||||
namespace=dict(type='str', required=True),
|
namespace=dict(type="str", required=True),
|
||||||
name=dict(type='raw', required=True),
|
name=dict(type="raw", required=True),
|
||||||
all=dict(type='bool', default=False),
|
all=dict(type="bool", default=False),
|
||||||
validate_registry_certs=dict(type='bool'),
|
validate_registry_certs=dict(type="bool"),
|
||||||
reference_policy=dict(type='str', choices=["source", "local"], default="source"),
|
reference_policy=dict(
|
||||||
scheduled=dict(type='bool', default=False),
|
type="str", choices=["source", "local"], default="source"
|
||||||
source=dict(type='str'),
|
),
|
||||||
|
scheduled=dict(type="bool", default=False),
|
||||||
|
source=dict(type="str"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
from ansible_collections.community.okd.plugins.module_utils.openshift_import_image import (
|
||||||
argument_spec=argument_spec(),
|
OpenShiftImportImage,
|
||||||
supports_check_mode=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_import_image import (
|
module = OpenShiftImportImage(
|
||||||
OpenShiftImportImage)
|
argument_spec=argument_spec(), supports_check_mode=True
|
||||||
|
)
|
||||||
import_image = OpenShiftImportImage(module)
|
module.run_module()
|
||||||
import_image.argspec = argument_spec()
|
|
||||||
import_image.execute_module()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# Copyright (c) 2020-2021, Red Hat
|
# Copyright (c) 2020-2021, Red Hat
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
module: openshift_process
|
module: openshift_process
|
||||||
|
|
||||||
short_description: Process an OpenShift template.openshift.io/v1 Template
|
short_description: Process an OpenShift template.openshift.io/v1 Template
|
||||||
@@ -49,6 +50,7 @@ options:
|
|||||||
description:
|
description:
|
||||||
- The namespace that resources should be created, updated, or deleted in.
|
- The namespace that resources should be created, updated, or deleted in.
|
||||||
- Only used when I(state) is present or absent.
|
- Only used when I(state) is present or absent.
|
||||||
|
type: str
|
||||||
parameters:
|
parameters:
|
||||||
description:
|
description:
|
||||||
- 'A set of key: value pairs that will be used to set/override values in the Template.'
|
- 'A set of key: value pairs that will be used to set/override values in the Template.'
|
||||||
@@ -70,9 +72,9 @@ options:
|
|||||||
type: str
|
type: str
|
||||||
default: rendered
|
default: rendered
|
||||||
choices: [ absent, present, rendered ]
|
choices: [ absent, present, rendered ]
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r"""
|
||||||
- name: Process a template in the cluster
|
- name: Process a template in the cluster
|
||||||
community.okd.openshift_process:
|
community.okd.openshift_process:
|
||||||
name: nginx-example
|
name: nginx-example
|
||||||
@@ -87,8 +89,8 @@ EXAMPLES = r'''
|
|||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
namespace: default
|
namespace: default
|
||||||
definition: '{{ item }}'
|
definition: '{{ item }}'
|
||||||
wait: yes
|
wait: true
|
||||||
apply: yes
|
apply: true
|
||||||
loop: '{{ result.resources }}'
|
loop: '{{ result.resources }}'
|
||||||
|
|
||||||
- name: Process a template with parameters from an env file and create the resources
|
- name: Process a template with parameters from an env file and create the resources
|
||||||
@@ -98,7 +100,7 @@ EXAMPLES = r'''
|
|||||||
namespace_target: default
|
namespace_target: default
|
||||||
parameter_file: 'files/nginx.env'
|
parameter_file: 'files/nginx.env'
|
||||||
state: present
|
state: present
|
||||||
wait: yes
|
wait: true
|
||||||
|
|
||||||
- name: Process a local template and create the resources
|
- name: Process a local template and create the resources
|
||||||
community.okd.openshift_process:
|
community.okd.openshift_process:
|
||||||
@@ -113,10 +115,10 @@ EXAMPLES = r'''
|
|||||||
parameter_file: files/example.env
|
parameter_file: files/example.env
|
||||||
namespace_target: default
|
namespace_target: default
|
||||||
state: absent
|
state: absent
|
||||||
wait: yes
|
wait: true
|
||||||
'''
|
"""
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
result:
|
result:
|
||||||
description:
|
description:
|
||||||
- The created, patched, or otherwise present object. Will be empty in the case of a deletion.
|
- The created, patched, or otherwise present object. Will be empty in the case of a deletion.
|
||||||
@@ -200,16 +202,13 @@ resources:
|
|||||||
conditions:
|
conditions:
|
||||||
type: complex
|
type: complex
|
||||||
description: Array of status conditions for the object. Not guaranteed to be present
|
description: Array of status conditions for the object. Not guaranteed to be present
|
||||||
'''
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
try:
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
|
|
||||||
except ImportError:
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
AUTH_ARG_SPEC, RESOURCE_ARG_SPEC, WAIT_ARG_SPEC
|
AUTH_ARG_SPEC,
|
||||||
|
RESOURCE_ARG_SPEC,
|
||||||
|
WAIT_ARG_SPEC,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -218,29 +217,26 @@ def argspec():
|
|||||||
argument_spec.update(AUTH_ARG_SPEC)
|
argument_spec.update(AUTH_ARG_SPEC)
|
||||||
argument_spec.update(WAIT_ARG_SPEC)
|
argument_spec.update(WAIT_ARG_SPEC)
|
||||||
argument_spec.update(RESOURCE_ARG_SPEC)
|
argument_spec.update(RESOURCE_ARG_SPEC)
|
||||||
argument_spec['state'] = dict(type='str', default='rendered', choices=['present', 'absent', 'rendered'])
|
argument_spec["state"] = dict(
|
||||||
argument_spec['namespace'] = dict(type='str')
|
type="str", default="rendered", choices=["present", "absent", "rendered"]
|
||||||
argument_spec['namespace_target'] = dict(type='str')
|
)
|
||||||
argument_spec['parameters'] = dict(type='dict')
|
argument_spec["namespace"] = dict(type="str")
|
||||||
argument_spec['name'] = dict(type='str')
|
argument_spec["namespace_target"] = dict(type="str")
|
||||||
argument_spec['parameter_file'] = dict(type='str')
|
argument_spec["parameters"] = dict(type="dict")
|
||||||
|
argument_spec["name"] = dict(type="str")
|
||||||
|
argument_spec["parameter_file"] = dict(type="str")
|
||||||
|
|
||||||
return argument_spec
|
return argument_spec
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = argspec()
|
|
||||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_process import (
|
from ansible_collections.community.okd.plugins.module_utils.openshift_process import (
|
||||||
OpenShiftProcess)
|
OpenShiftProcess,
|
||||||
|
)
|
||||||
|
|
||||||
openshift_process = OpenShiftProcess(module)
|
module = OpenShiftProcess(argument_spec=argspec(), supports_check_mode=True)
|
||||||
# remove_aliases from kubernetes.core's common requires the argspec attribute. Ideally, it should
|
module.run_module()
|
||||||
# read that throught the module class, but we cannot change that.
|
|
||||||
openshift_process.argspec = argument_spec
|
|
||||||
openshift_process.execute_module()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
|
|
||||||
module: openshift_registry_info
|
module: openshift_registry_info
|
||||||
|
|
||||||
@@ -34,15 +35,15 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Attempt to contact the integrated registry using local client.
|
- Attempt to contact the integrated registry using local client.
|
||||||
type: bool
|
type: bool
|
||||||
default: False
|
default: false
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- python >= 3.6
|
- python >= 3.6
|
||||||
- kubernetes >= 12.0.0
|
- kubernetes >= 12.0.0
|
||||||
- docker-image-py
|
- docker-image-py
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r"""
|
||||||
# Get registry information
|
# Get registry information
|
||||||
- name: Read integrated registry information
|
- name: Read integrated registry information
|
||||||
community.okd.openshift_registry_info:
|
community.okd.openshift_registry_info:
|
||||||
@@ -50,11 +51,11 @@ EXAMPLES = r'''
|
|||||||
# Read registry integrated information and attempt to contact using local client.
|
# Read registry integrated information and attempt to contact using local client.
|
||||||
- name: Attempt to contact integrated registry using local client
|
- name: Attempt to contact integrated registry using local client
|
||||||
community.okd.openshift_registry_info:
|
community.okd.openshift_registry_info:
|
||||||
check: yes
|
check: true
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
internal_hostname:
|
internal_hostname:
|
||||||
description:
|
description:
|
||||||
- The internal registry hostname.
|
- The internal registry hostname.
|
||||||
@@ -79,38 +80,30 @@ check:
|
|||||||
description: message describing the ping operation.
|
description: message describing the ping operation.
|
||||||
returned: always
|
returned: always
|
||||||
type: str
|
type: str
|
||||||
'''
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC
|
AUTH_ARG_SPEC,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def argument_spec():
|
def argument_spec():
|
||||||
args = copy.deepcopy(AUTH_ARG_SPEC)
|
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||||
args.update(
|
args.update(dict(check=dict(type="bool", default=False)))
|
||||||
dict(
|
|
||||||
check=dict(type='bool', default=False)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
from ansible_collections.community.okd.plugins.module_utils.openshift_registry import (
|
||||||
argument_spec=argument_spec(),
|
OpenShiftRegistry,
|
||||||
supports_check_mode=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from ansible_collections.community.okd.plugins.module_utils.openshift_registry import (
|
module = OpenShiftRegistry(argument_spec=argument_spec(), supports_check_mode=True)
|
||||||
OpenShiftRegistry)
|
module.run_module()
|
||||||
|
|
||||||
registry = OpenShiftRegistry(module)
|
|
||||||
registry.argspec = argument_spec()
|
|
||||||
registry.info()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
+191
-148
@@ -9,7 +9,7 @@ from __future__ import absolute_import, division, print_function
|
|||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
# STARTREMOVE (downstream)
|
# STARTREMOVE (downstream)
|
||||||
DOCUMENTATION = r'''
|
DOCUMENTATION = r"""
|
||||||
module: openshift_route
|
module: openshift_route
|
||||||
|
|
||||||
short_description: Expose a Service as an OpenShift Route.
|
short_description: Expose a Service as an OpenShift Route.
|
||||||
@@ -133,9 +133,9 @@ options:
|
|||||||
- insecure
|
- insecure
|
||||||
default: insecure
|
default: insecure
|
||||||
type: str
|
type: str
|
||||||
'''
|
"""
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r"""
|
||||||
- name: Create hello-world deployment
|
- name: Create hello-world deployment
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
definition:
|
definition:
|
||||||
@@ -155,10 +155,10 @@ EXAMPLES = r'''
|
|||||||
app: hello-kubernetes
|
app: hello-kubernetes
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: hello-kubernetes
|
- name: hello-kubernetes
|
||||||
image: paulbouwer/hello-kubernetes:1.8
|
image: paulbouwer/hello-kubernetes:1.8
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
|
||||||
- name: Create Service for the hello-world deployment
|
- name: Create Service for the hello-world deployment
|
||||||
community.okd.k8s:
|
community.okd.k8s:
|
||||||
@@ -170,8 +170,8 @@ EXAMPLES = r'''
|
|||||||
namespace: default
|
namespace: default
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- port: 80
|
- port: 80
|
||||||
targetPort: 8080
|
targetPort: 8080
|
||||||
selector:
|
selector:
|
||||||
app: hello-kubernetes
|
app: hello-kubernetes
|
||||||
|
|
||||||
@@ -183,9 +183,9 @@ EXAMPLES = r'''
|
|||||||
annotations:
|
annotations:
|
||||||
haproxy.router.openshift.io/balance: roundrobin
|
haproxy.router.openshift.io/balance: roundrobin
|
||||||
register: route
|
register: route
|
||||||
'''
|
"""
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r"""
|
||||||
result:
|
result:
|
||||||
description:
|
description:
|
||||||
- The Route object that was created or updated. Will be empty in the case of deletion.
|
- The Route object that was created or updated. Will be empty in the case of deletion.
|
||||||
@@ -303,29 +303,31 @@ duration:
|
|||||||
returned: when C(wait) is true
|
returned: when C(wait) is true
|
||||||
type: int
|
type: int
|
||||||
sample: 48
|
sample: 48
|
||||||
'''
|
"""
|
||||||
# ENDREMOVE (downstream)
|
# ENDREMOVE (downstream)
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import traceback
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
|
from ansible_collections.community.okd.plugins.module_utils.openshift_common import (
|
||||||
|
AnsibleOpenshiftModule,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import AnsibleModule
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.runner import (
|
||||||
except ImportError:
|
perform_action,
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
)
|
||||||
from ansible.module_utils._text import to_native
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.waiter import (
|
||||||
|
Waiter,
|
||||||
try:
|
)
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin, get_api_client
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
AUTH_ARG_SPEC, WAIT_ARG_SPEC, COMMON_ARG_SPEC
|
AUTH_ARG_SPEC,
|
||||||
|
WAIT_ARG_SPEC,
|
||||||
|
COMMON_ARG_SPEC,
|
||||||
)
|
)
|
||||||
HAS_KUBERNETES_COLLECTION = True
|
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
HAS_KUBERNETES_COLLECTION = False
|
pass
|
||||||
k8s_collection_import_exception = e
|
|
||||||
K8S_COLLECTION_ERROR = traceback.format_exc()
|
|
||||||
K8sAnsibleMixin = object
|
|
||||||
AUTH_ARG_SPEC = WAIT_ARG_SPEC = COMMON_ARG_SPEC = {}
|
AUTH_ARG_SPEC = WAIT_ARG_SPEC = COMMON_ARG_SPEC = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -334,33 +336,17 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class OpenShiftRoute(K8sAnsibleMixin):
|
class OpenShiftRoute(AnsibleOpenshiftModule):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.module = AnsibleModule(
|
super(OpenShiftRoute, self).__init__(
|
||||||
argument_spec=self.argspec,
|
argument_spec=self.argspec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
self.fail_json = self.module.fail_json
|
|
||||||
|
|
||||||
if not HAS_KUBERNETES_COLLECTION:
|
|
||||||
self.module.fail_json(
|
|
||||||
msg="The kubernetes.core collection must be installed",
|
|
||||||
exception=K8S_COLLECTION_ERROR,
|
|
||||||
error=to_native(k8s_collection_import_exception)
|
|
||||||
)
|
|
||||||
|
|
||||||
super(OpenShiftRoute, self).__init__(self.module)
|
|
||||||
|
|
||||||
self.params = self.module.params
|
|
||||||
# TODO: should probably make it so that at least some of these aren't required for perform_action to work
|
|
||||||
# Or at least explicitly pass them in
|
|
||||||
self.append_hash = False
|
self.append_hash = False
|
||||||
self.apply = False
|
self.apply = False
|
||||||
self.check_mode = self.module.check_mode
|
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
self.params['merge_type'] = None
|
self.params["merge_type"] = None
|
||||||
self.client = get_api_client(self.module)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def argspec(self):
|
def argspec(self):
|
||||||
@@ -368,81 +354,95 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
spec.update(copy.deepcopy(WAIT_ARG_SPEC))
|
spec.update(copy.deepcopy(WAIT_ARG_SPEC))
|
||||||
spec.update(copy.deepcopy(COMMON_ARG_SPEC))
|
spec.update(copy.deepcopy(COMMON_ARG_SPEC))
|
||||||
|
|
||||||
spec['service'] = dict(type='str', aliases=['svc'])
|
spec["service"] = dict(type="str", aliases=["svc"])
|
||||||
spec['namespace'] = dict(required=True, type='str')
|
spec["namespace"] = dict(required=True, type="str")
|
||||||
spec['labels'] = dict(type='dict')
|
spec["labels"] = dict(type="dict")
|
||||||
spec['name'] = dict(type='str')
|
spec["name"] = dict(type="str")
|
||||||
spec['hostname'] = dict(type='str')
|
spec["hostname"] = dict(type="str")
|
||||||
spec['path'] = dict(type='str')
|
spec["path"] = dict(type="str")
|
||||||
spec['wildcard_policy'] = dict(choices=['Subdomain'], type='str')
|
spec["wildcard_policy"] = dict(choices=["Subdomain"], type="str")
|
||||||
spec['port'] = dict(type='str')
|
spec["port"] = dict(type="str")
|
||||||
spec['tls'] = dict(type='dict', options=dict(
|
spec["tls"] = dict(
|
||||||
ca_certificate=dict(type='str'),
|
type="dict",
|
||||||
certificate=dict(type='str'),
|
options=dict(
|
||||||
destination_ca_certificate=dict(type='str'),
|
ca_certificate=dict(type="str"),
|
||||||
key=dict(type='str', no_log=False),
|
certificate=dict(type="str"),
|
||||||
insecure_policy=dict(type='str', choices=['allow', 'redirect', 'disallow'], default='disallow'),
|
destination_ca_certificate=dict(type="str"),
|
||||||
))
|
key=dict(type="str", no_log=False),
|
||||||
spec['termination'] = dict(choices=['edge', 'passthrough', 'reencrypt', 'insecure'], default='insecure')
|
insecure_policy=dict(
|
||||||
spec['annotations'] = dict(type='dict')
|
type="str",
|
||||||
|
choices=["allow", "redirect", "disallow"],
|
||||||
|
default="disallow",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
spec["termination"] = dict(
|
||||||
|
choices=["edge", "passthrough", "reencrypt", "insecure"], default="insecure"
|
||||||
|
)
|
||||||
|
spec["annotations"] = dict(type="dict")
|
||||||
|
|
||||||
return spec
|
return spec
|
||||||
|
|
||||||
def execute_module(self):
|
def execute_module(self):
|
||||||
v1_routes = self.find_resource('Route', 'route.openshift.io/v1', fail=True)
|
service_name = self.params.get("service")
|
||||||
|
namespace = self.params["namespace"]
|
||||||
service_name = self.params.get('service')
|
termination_type = self.params.get("termination")
|
||||||
namespace = self.params['namespace']
|
if termination_type == "insecure":
|
||||||
termination_type = self.params.get('termination')
|
|
||||||
if termination_type == 'insecure':
|
|
||||||
termination_type = None
|
termination_type = None
|
||||||
state = self.params.get('state')
|
state = self.params.get("state")
|
||||||
|
|
||||||
if state != 'absent' and not service_name:
|
if state != "absent" and not service_name:
|
||||||
self.fail_json("If 'state' is not 'absent' then 'service' must be provided")
|
self.fail_json("If 'state' is not 'absent' then 'service' must be provided")
|
||||||
|
|
||||||
# We need to do something a little wonky to wait if the user doesn't supply a custom condition
|
# We need to do something a little wonky to wait if the user doesn't supply a custom condition
|
||||||
custom_wait = self.params.get('wait') and not self.params.get('wait_condition') and state != 'absent'
|
custom_wait = (
|
||||||
|
self.params.get("wait")
|
||||||
|
and not self.params.get("wait_condition")
|
||||||
|
and state != "absent"
|
||||||
|
)
|
||||||
if custom_wait:
|
if custom_wait:
|
||||||
# Don't use default wait logic in perform_action
|
# Don't use default wait logic in perform_action
|
||||||
self.params['wait'] = False
|
self.params["wait"] = False
|
||||||
|
|
||||||
route_name = self.params.get('name') or service_name
|
route_name = self.params.get("name") or service_name
|
||||||
labels = self.params.get('labels')
|
labels = self.params.get("labels")
|
||||||
hostname = self.params.get('hostname')
|
hostname = self.params.get("hostname")
|
||||||
path = self.params.get('path')
|
path = self.params.get("path")
|
||||||
wildcard_policy = self.params.get('wildcard_policy')
|
wildcard_policy = self.params.get("wildcard_policy")
|
||||||
port = self.params.get('port')
|
port = self.params.get("port")
|
||||||
annotations = self.params.get('annotations')
|
annotations = self.params.get("annotations")
|
||||||
|
|
||||||
if termination_type and self.params.get('tls'):
|
if termination_type and self.params.get("tls"):
|
||||||
tls_ca_cert = self.params['tls'].get('ca_certificate')
|
tls_ca_cert = self.params["tls"].get("ca_certificate")
|
||||||
tls_cert = self.params['tls'].get('certificate')
|
tls_cert = self.params["tls"].get("certificate")
|
||||||
tls_dest_ca_cert = self.params['tls'].get('destination_ca_certificate')
|
tls_dest_ca_cert = self.params["tls"].get("destination_ca_certificate")
|
||||||
tls_key = self.params['tls'].get('key')
|
tls_key = self.params["tls"].get("key")
|
||||||
tls_insecure_policy = self.params['tls'].get('insecure_policy')
|
tls_insecure_policy = self.params["tls"].get("insecure_policy")
|
||||||
if tls_insecure_policy == 'disallow':
|
if tls_insecure_policy == "disallow":
|
||||||
tls_insecure_policy = None
|
tls_insecure_policy = None
|
||||||
else:
|
else:
|
||||||
tls_ca_cert = tls_cert = tls_dest_ca_cert = tls_key = tls_insecure_policy = None
|
tls_ca_cert = tls_cert = tls_dest_ca_cert = tls_key = (
|
||||||
|
tls_insecure_policy
|
||||||
|
) = None
|
||||||
|
|
||||||
route = {
|
route = {
|
||||||
'apiVersion': 'route.openshift.io/v1',
|
"apiVersion": "route.openshift.io/v1",
|
||||||
'kind': 'Route',
|
"kind": "Route",
|
||||||
'metadata': {
|
"metadata": {
|
||||||
'name': route_name,
|
"name": route_name,
|
||||||
'namespace': namespace,
|
"namespace": namespace,
|
||||||
'labels': labels,
|
"labels": labels,
|
||||||
},
|
},
|
||||||
'spec': {}
|
"spec": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
if annotations:
|
if annotations:
|
||||||
route['metadata']['annotations'] = annotations
|
route["metadata"]["annotations"] = annotations
|
||||||
|
|
||||||
if state != 'absent':
|
if state != "absent":
|
||||||
route['spec'] = self.build_route_spec(
|
route["spec"] = self.build_route_spec(
|
||||||
service_name, namespace,
|
service_name,
|
||||||
|
namespace,
|
||||||
port=port,
|
port=port,
|
||||||
wildcard_policy=wildcard_policy,
|
wildcard_policy=wildcard_policy,
|
||||||
hostname=hostname,
|
hostname=hostname,
|
||||||
@@ -455,78 +455,121 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
tls_dest_ca_cert=tls_dest_ca_cert,
|
tls_dest_ca_cert=tls_dest_ca_cert,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = self.perform_action(v1_routes, route)
|
result = perform_action(self.svc, route, self.params)
|
||||||
timeout = self.params.get('wait_timeout')
|
timeout = self.params.get("wait_timeout")
|
||||||
sleep = self.params.get('wait_sleep')
|
sleep = self.params.get("wait_sleep")
|
||||||
if custom_wait:
|
if custom_wait:
|
||||||
success, result['result'], result['duration'] = self._wait_for(v1_routes, route_name, namespace, wait_predicate, sleep, timeout, state)
|
v1_routes = self.find_resource("Route", "route.openshift.io/v1", fail=True)
|
||||||
|
waiter = Waiter(self.client, v1_routes, wait_predicate)
|
||||||
|
success, result["result"], result["duration"] = waiter.wait(
|
||||||
|
timeout=timeout, sleep=sleep, name=route_name, namespace=namespace
|
||||||
|
)
|
||||||
|
|
||||||
self.module.exit_json(**result)
|
self.exit_json(**result)
|
||||||
|
|
||||||
def build_route_spec(self, service_name, namespace, port=None, wildcard_policy=None, hostname=None, path=None, termination_type=None,
|
def build_route_spec(
|
||||||
tls_insecure_policy=None, tls_ca_cert=None, tls_cert=None, tls_key=None, tls_dest_ca_cert=None):
|
self,
|
||||||
v1_services = self.find_resource('Service', 'v1', fail=True)
|
service_name,
|
||||||
|
namespace,
|
||||||
|
port=None,
|
||||||
|
wildcard_policy=None,
|
||||||
|
hostname=None,
|
||||||
|
path=None,
|
||||||
|
termination_type=None,
|
||||||
|
tls_insecure_policy=None,
|
||||||
|
tls_ca_cert=None,
|
||||||
|
tls_cert=None,
|
||||||
|
tls_key=None,
|
||||||
|
tls_dest_ca_cert=None,
|
||||||
|
):
|
||||||
|
v1_services = self.find_resource("Service", "v1", fail=True)
|
||||||
try:
|
try:
|
||||||
target_service = v1_services.get(name=service_name, namespace=namespace)
|
target_service = v1_services.get(name=service_name, namespace=namespace)
|
||||||
except NotFoundError:
|
except NotFoundError:
|
||||||
if not port:
|
if not port:
|
||||||
self.module.fail_json(msg="You need to provide the 'port' argument when exposing a non-existent service")
|
self.fail_json(
|
||||||
|
msg="You need to provide the 'port' argument when exposing a non-existent service"
|
||||||
|
)
|
||||||
target_service = None
|
target_service = None
|
||||||
except DynamicApiError as exc:
|
except DynamicApiError as exc:
|
||||||
self.module.fail_json(msg='Failed to retrieve service to be exposed: {0}'.format(exc.body),
|
self.fail_json(
|
||||||
error=exc.status, status=exc.status, reason=exc.reason)
|
msg="Failed to retrieve service to be exposed: {0}".format(exc.body),
|
||||||
|
error=exc.status,
|
||||||
|
status=exc.status,
|
||||||
|
reason=exc.reason,
|
||||||
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.module.fail_json(msg='Failed to retrieve service to be exposed: {0}'.format(to_native(exc)),
|
self.fail_json(
|
||||||
error='', status='', reason='')
|
msg="Failed to retrieve service to be exposed: {0}".format(
|
||||||
|
to_native(exc)
|
||||||
|
),
|
||||||
|
error="",
|
||||||
|
status="",
|
||||||
|
reason="",
|
||||||
|
)
|
||||||
|
|
||||||
route_spec = {
|
route_spec = {
|
||||||
'tls': {},
|
"tls": {},
|
||||||
'to': {
|
"to": {
|
||||||
'kind': 'Service',
|
"kind": "Service",
|
||||||
'name': service_name,
|
"name": service_name,
|
||||||
},
|
},
|
||||||
'port': {
|
"port": {
|
||||||
'targetPort': self.set_port(target_service, port),
|
"targetPort": self.set_port(target_service, port),
|
||||||
},
|
},
|
||||||
'wildcardPolicy': wildcard_policy
|
"wildcardPolicy": wildcard_policy,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Want to conditionally add these so we don't overwrite what is automically added when nothing is provided
|
# Want to conditionally add these so we don't overwrite what is automically added when nothing is provided
|
||||||
if termination_type:
|
if termination_type:
|
||||||
route_spec['tls'] = dict(termination=termination_type.capitalize())
|
route_spec["tls"] = dict(termination=termination_type.capitalize())
|
||||||
if tls_insecure_policy:
|
if tls_insecure_policy:
|
||||||
if termination_type == 'edge':
|
if termination_type == "edge":
|
||||||
route_spec['tls']['insecureEdgeTerminationPolicy'] = tls_insecure_policy.capitalize()
|
route_spec["tls"][
|
||||||
elif termination_type == 'passthrough':
|
"insecureEdgeTerminationPolicy"
|
||||||
if tls_insecure_policy != 'redirect':
|
] = tls_insecure_policy.capitalize()
|
||||||
self.module.fail_json("'redirect' is the only supported insecureEdgeTerminationPolicy for passthrough routes")
|
elif termination_type == "passthrough":
|
||||||
route_spec['tls']['insecureEdgeTerminationPolicy'] = tls_insecure_policy.capitalize()
|
if tls_insecure_policy != "redirect":
|
||||||
elif termination_type == 'reencrypt':
|
self.fail_json(
|
||||||
self.module.fail_json("'tls.insecure_policy' is not supported with reencrypt routes")
|
"'redirect' is the only supported insecureEdgeTerminationPolicy for passthrough routes"
|
||||||
|
)
|
||||||
|
route_spec["tls"][
|
||||||
|
"insecureEdgeTerminationPolicy"
|
||||||
|
] = tls_insecure_policy.capitalize()
|
||||||
|
elif termination_type == "reencrypt":
|
||||||
|
self.fail_json(
|
||||||
|
"'tls.insecure_policy' is not supported with reencrypt routes"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
route_spec['tls']['insecureEdgeTerminationPolicy'] = None
|
route_spec["tls"]["insecureEdgeTerminationPolicy"] = None
|
||||||
if tls_ca_cert:
|
if tls_ca_cert:
|
||||||
if termination_type == 'passthrough':
|
if termination_type == "passthrough":
|
||||||
self.module.fail_json("'tls.ca_certificate' is not supported with passthrough routes")
|
self.fail_json(
|
||||||
route_spec['tls']['caCertificate'] = tls_ca_cert
|
"'tls.ca_certificate' is not supported with passthrough routes"
|
||||||
|
)
|
||||||
|
route_spec["tls"]["caCertificate"] = tls_ca_cert
|
||||||
if tls_cert:
|
if tls_cert:
|
||||||
if termination_type == 'passthrough':
|
if termination_type == "passthrough":
|
||||||
self.module.fail_json("'tls.certificate' is not supported with passthrough routes")
|
self.fail_json(
|
||||||
route_spec['tls']['certificate'] = tls_cert
|
"'tls.certificate' is not supported with passthrough routes"
|
||||||
|
)
|
||||||
|
route_spec["tls"]["certificate"] = tls_cert
|
||||||
if tls_key:
|
if tls_key:
|
||||||
if termination_type == 'passthrough':
|
if termination_type == "passthrough":
|
||||||
self.module.fail_json("'tls.key' is not supported with passthrough routes")
|
self.fail_json("'tls.key' is not supported with passthrough routes")
|
||||||
route_spec['tls']['key'] = tls_key
|
route_spec["tls"]["key"] = tls_key
|
||||||
if tls_dest_ca_cert:
|
if tls_dest_ca_cert:
|
||||||
if termination_type != 'reencrypt':
|
if termination_type != "reencrypt":
|
||||||
self.module.fail_json("'destination_certificate' is only valid for reencrypt routes")
|
self.fail_json(
|
||||||
route_spec['tls']['destinationCACertificate'] = tls_dest_ca_cert
|
"'destination_certificate' is only valid for reencrypt routes"
|
||||||
|
)
|
||||||
|
route_spec["tls"]["destinationCACertificate"] = tls_dest_ca_cert
|
||||||
else:
|
else:
|
||||||
route_spec['tls'] = None
|
route_spec["tls"] = None
|
||||||
if hostname:
|
if hostname:
|
||||||
route_spec['host'] = hostname
|
route_spec["host"] = hostname
|
||||||
if path:
|
if path:
|
||||||
route_spec['path'] = path
|
route_spec["path"] = path
|
||||||
|
|
||||||
return route_spec
|
return route_spec
|
||||||
|
|
||||||
@@ -534,7 +577,7 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
if port_arg:
|
if port_arg:
|
||||||
return port_arg
|
return port_arg
|
||||||
for p in service.spec.ports:
|
for p in service.spec.ports:
|
||||||
if p.protocol == 'TCP':
|
if p.protocol == "TCP":
|
||||||
if p.name is not None:
|
if p.name is not None:
|
||||||
return p.name
|
return p.name
|
||||||
return p.targetPort
|
return p.targetPort
|
||||||
@@ -542,10 +585,10 @@ class OpenShiftRoute(K8sAnsibleMixin):
|
|||||||
|
|
||||||
|
|
||||||
def wait_predicate(route):
|
def wait_predicate(route):
|
||||||
if not(route.status and route.status.ingress):
|
if not (route.status and route.status.ingress):
|
||||||
return False
|
return False
|
||||||
for ingress in route.status.ingress:
|
for ingress in route.status.ingress:
|
||||||
match = [x for x in ingress.conditions if x.type == 'Admitted']
|
match = [x for x in ingress.conditions if x.type == "Admitted"]
|
||||||
if not match:
|
if not match:
|
||||||
return False
|
return False
|
||||||
match = match[0]
|
match = match[0]
|
||||||
@@ -555,8 +598,8 @@ def wait_predicate(route):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
OpenShiftRoute().execute_module()
|
OpenShiftRoute().run_module()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
|
---
|
||||||
collections:
|
collections:
|
||||||
- name: kubernetes.core
|
- name: kubernetes.core
|
||||||
version: '>=2.1.0,<2.3.0'
|
version: '>=3.0.0'
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
coverage==4.5.4
|
coverage==4.5.4
|
||||||
pytest
|
pytest
|
||||||
pytest-xdist
|
pytest-xdist
|
||||||
|
pytest-forked
|
||||||
|
pytest-ansible
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
modules:
|
||||||
|
python_requires: ">=3.9"
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
||||||
plugins/modules/k8s.py validate-modules:return-syntax-error
|
plugins/modules/k8s.py validate-modules:return-syntax-error
|
||||||
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
plugins/modules/openshift_process.py validate-modules:parameter-type-not-in-doc
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user