Commit Graph

48 Commits

Author SHA1 Message Date
abikouo
3c36b6fa0f k8s support diff mode (#146)
* support diff mode for k8s module

* Update and rename 145-k8s-add-support-diff-mode.yml to 146-k8s-add-support-diff-mode.yml

* Update 146-k8s-add-support-diff-mode.yml

* Update changelogs/fragments/146-k8s-add-support-diff-mode.yml

Co-authored-by: Mike Graves <mgraves@redhat.com>

* update k8s_scale and k8s_json_patch

* diff for k8s_scale  and k8s_json_patch

Co-authored-by: Mike Graves <mgraves@redhat.com>
2021-07-21 14:29:28 +02:00
Abhijeet Kasurde
5fb3ecbb50 common: import k8sdynamicclient directly (#163) 2021-07-09 10:02:35 +05:30
Mike Graves
15799b2dd5 Check that auth value is not None (#151)
* Check that auth value is not None

The previous check for truth prevented the verify_ssl param from being
set to false, thus forcing ssl verfication in every case.

* Add changelog fragment

* Fix linting
2021-06-24 12:15:27 -04:00
abikouo
46494a18bd Revert "k8s ability to wait on arbitrary property (#105)" (#133)
This reverts commit 4ccb15d4ad.
2021-06-15 14:32:21 +02:00
abikouo
4ccb15d4ad k8s ability to wait on arbitrary property (#105)
* missing implementation of jsonpath library

* not tested

* sanity

* save

* updates

* Update args_common.py

* lint validation

* fix

* Update k8s.py

* attribute should match for all

* select wait

* Revert "select wait"

This reverts commit a20a1f6f01.

* sanity

* Update molecule/default/tasks/waiter.yml

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>

* Update jsonpath_extractor.py

* Update k8s_wait_options.py

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-06-15 10:44:26 +02:00
Mike Graves
5b5777d202 Split JSON patch out into a new module (#99)
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-05-24 18:05:48 +05:30
Mike Graves
0bbc9ca999 Account for updated pods when waiting on DaemonSet (#102)
* Account for updated pods when waiting on DaemonSet

The exising logic that's used to determine when a DaemonSet is ready
fails to account for the fact that a RollingUpdate first kills the pod
and then creates a new one. Simply checking if the
desiredNumberScheduled equals the numberReady will succeed in cases
when the old pod takes time to shut down, and would report that the new
Deployment is ready despite the fact that the old pod has not been
replaced, yet.

* Add changelog fragment
2021-05-19 09:29:22 -04:00
abikouo
192cae1507 k8s - patch existing resource (#90)
* patch only

* add changelogs

* Rename 89-k8s-add-parameter-patch_only.yml to 90-k8s-add-parameter-patch_only.yml

* Update 90-k8s-add-parameter-patch_only.yml

* patch_only parameter changed to state=patched

* Update 90-k8s-add-parameter-patch_only.yml

* Update plugins/modules/k8s.py

Co-authored-by: Fabian von Feilitzsch <fabian@fabianism.us>

* Update molecule/default/tasks/patched.yml

Co-authored-by: John Mazzitelli <mazz@redhat.com>

* Update molecule/default/tasks/patched.yml

Co-authored-by: John Mazzitelli <mazz@redhat.com>

* sanity issue

Co-authored-by: Fabian von Feilitzsch <fabian@fabianism.us>
Co-authored-by: John Mazzitelli <mazz@redhat.com>
2021-05-19 11:03:11 +02:00
Mike Graves
01a0815e56 Replace openshift client with kubernetes client (#96)
* Replace openshift client with kubernetes client

This commit primarily just removes mentions of openshift from the docs
and updates the requirements. Most of the work to replace the client has
been done through the following commits:

edc48ee577
c214376cac
48c5170018
2b6a989cf9

* Add changelog fragment

* Update changelogs/fragments/96-replace-openshift-client.yaml

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>

* Update plugins/modules/k8s.py

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>

* Update plugins/modules/k8s_info.py

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>

* Update plugins/modules/k8s_service.py

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>

* Bump minimum kubernetes version to 12.0.0

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-05-06 14:44:17 -04:00
Mike Graves
2b6a989cf9 Replicate base resource for lists functionality (#89)
* Replicate base resource for lists functionality

This replicates specific functionality from the openshift client to more
reliably retrieve the base resource from a resource list.

* Add changelog fragment
2021-05-05 10:09:22 -04:00
abikouo
963aa3fbe6 support merge_type`json` (#83)
Fixes #54
2021-04-28 09:06:43 -04:00
abikouo
d29f8c1eb7 add option proxy_headers for k8s modules (#58)
* add option proxy_headers for k8s modules

* Update and rename 50-add-support-for-proxy_headers-on-authentication to 58-add-support-for-proxy_headers-on-authentication.yaml

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-04-28 08:44:57 +02:00
Mike Graves
8b2d39d6d2 Fix client regression from turbo mode refactor (#79)
* Fix client regression from turbo mode refactor

The turbo mode refactoring introduced a regression where the kubernetes
client can fail to find the kubeconfig. This happens because
get_api_client is called twice and the second time it is called without
the module being passed as an argument. Without this, the configuration
will use defaults. This will be a problem if the user has specified a
location for the kubeconfig that's different from default, for example.

* Add tests
2021-04-22 15:13:38 -04:00
Alina Buzachis
48c5170018 Replicate apply method in the DynamicClient (#45)
* * Replicate apply method in the DynamicClient

Signed-off-by: Alina Buzachis <abuzachis@redhat.com>

* * Add changelog fragment

Signed-off-by: Alina Buzachis <abuzachis@redhat.com>
2021-04-22 14:58:53 -04:00
abikouo
361061c727 k8s loop flattening for template argument (#49)
* repo migration

* Update and rename 411-k8s-loop-flattening-and-continue_on_error.yaml to 49-k8s-loop-flattening-and-continue_on_error.yaml

* Update plugins/modules/k8s.py

Co-authored-by: Mike Graves <mgraves@redhat.com>

* split into multiple lines

* linting

* Update .gitignore

* Update template.yml

* merge

* Update template.yml

* deep copy environment

* deepcopy

* lint

* remove useless comment

* multiple definition

* tests update

* jmespath

* Update ci.yml

* Update template.yml

Co-authored-by: Mike Graves <mgraves@redhat.com>
2021-04-22 19:28:07 +02:00
Alina Buzachis
c214376cac Add cache_file parameter for DynamicClient (#46) 2021-04-21 09:57:52 +05:30
Abhijeet Kasurde
a5a850d1da Remove KubernetesAnsibleModule class (#70)
Co-authored-by: Mike Graves <mgraves@redhat.com>
2021-04-20 21:02:59 +05:30
Alina Buzachis
edc48ee577 Add configmap/secret hash functionality (#48)
* * * Add configmap/secret hash functionality

Signed-off-by: Alina Buzachis <abuzachis@redhat.com>

* * Add changelog fragment

Signed-off-by: Alina Buzachis <abuzachis@redhat.com>
2021-04-20 08:27:25 -04:00
Abhijeet Kasurde
cc10268adf k8s inventory - remove trailing slashes from hostname (#63)
When the user provides a hostname with trailing slashes like
https://localhost:6443/, the openshift library fails to
enumerate the APIs from the given cluster.

This fix removes any extra trailing slashes before sending it
to the openshift DynamicClient.

Fixes: #52

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-04-20 13:15:29 +05:30
Mike Graves
ba586a8ed8 Rename from community.kubernetes to kubernetes.core (#6)
* Rename from community.kubernetes to kubernetes.core

This goes through and renames community.kubernetes to kubernetes.core.
Most of this was generated from the downstream build script that was
used on the community repository, plus whatever hand edits I could find
that were needed.

The downstream build and test process has also been removed as this
repository is now the downstream repository.

* Fix CONTRIBUTING.md
2021-04-08 08:48:27 -04:00
Abhijeet Kasurde
c9157ce713 k8s: fix get_api_client usage in inventory plugin (#395)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-03-26 14:36:47 -04:00
Gonéri Le Bouder
39660dd40e refactoring for ansible_module.turbo integration (#313)
* refactoring for ansible_module.turbo integration

This refactoring prepares the integration of `ansible_module.turbo`

- Delay the loading of `common.py`, move the shared structure in
  `args_common`.
- Avoid the use of one single object per module, this to increase the
  amount of Python structure that we can cache.
- Cache the Kubernetes client.

See: https://github.com/ansible-collections/community.kubernetes/pull/270

Co-authored-by: Jill Rouleau <jill.rouleau@bespokess.com>
2021-03-16 17:16:18 -04:00
Mike Graves
9f7b6fb3ff Honor wait_timeout in k8s_info for missing resource (#360)
* Honor wait in k8s_info for missing resource

The wait logic in the k8s_info module immediately returns when no
resources are found, regardless whether a wait_timeout has been
specified. This expands the logic to wait when a name has been provided.
The case this is specifically meant to address is when querying for a
resource that is indirectly created by another resource, for example, a
pod created by a deployment or an operator.

The existing logic in every other case should remain as it was before.
This means if a query might return more than one resource--all pods with
some label, for example--the module will return immediately if no pods
are found, even if a wait_timeout has been provided.

* Add changelog fragment
2021-02-16 10:19:22 -07:00
Mike Graves
b26afc3518 Fix Secret check_mode (#343)
When adding a Secret and using stringData, check_mode will always show
changes. An existing resource fetched from Kubernetes will have the
stringData already base64 encoded and merged into the data attribute.
This change performs the base64 encoding and merging with the provided
definition to more accurately represent the current state of the
cluster.

This change only affects check_mode. When making any changes to the
cluster the stringData is passed along as provided in the definition.

Closes #282.
2021-01-14 11:05:11 -05:00
Mike Graves
a9b8cc68d5 Add support for configuring garbage collection (#334)
* Add support for configuring garbage collection

This surfaces deleteOptions functionality in a top-level delete_options
parameter.

* Add changelog fragment

* Remove kind and apiVersion from delete_options

* Add release version to docs
2021-01-12 14:17:18 -05:00
Abhijeet Kasurde
9059f2c526 k8s: Handle ValueError raised (#330) 2021-01-12 21:38:58 +05:30
Abhijeet Kasurde
549dd262d2 Loosen strictness for boolean (#326) 2020-12-08 20:01:44 +05:30
Fabian von Feilitzsch
2474ef1b2c k8s_info now outputs whether the api was found (#308) 2020-11-30 10:26:54 +05:30
Gonéri Le Bouder
8f14bf6c46 The type of wait_condition.status is str (#310)
The `wait_condition.status` key is a string.

- Use actually string in the documentation
- Use core's `boolean()` method to convert the value internally to
  boolean
2020-11-25 13:01:38 -06:00
jaydesl
aad4696f20 Fix default configuration getter in client v12.0.0 (#276)
Fixes #273
2020-10-22 15:41:51 -04:00
Fabian von Feilitzsch
0f3fef927e SelfSubjectAccessReviews now work with the k8s module (#237)
* SelfSubjectAccessReviews now work with the k8s module
2020-09-28 12:20:01 -04:00
Abhijeet Kasurde
f03d2ce243 k8s_info: Add support for wait (#235)
Fixes: #18
2020-09-28 10:52:00 +05:30
Abhijeet Kasurde
308956b313 Replace KubernetesRawModule class (#231)
* Migrate from KubernetesRawModule to K8sAnsibleMixin
* Modified k8s.py
* Modified k8s_service.py

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-09-19 09:54:40 +05:30
Abhijeet Kasurde
51cadb7150 Replace KubernetesAnsibleModule class with dummy class (#227)
* Make an AnsibleMixin parent class for every module
* Replace KubernetesAnsibleModule class with dummy class
* Modified k8s_log
* k8s_exec refactor
* k8s_info refactor
* k8s_service refactor
* k8s_scale refactor
* Fix integration tests
* Add a warning about the deprecation of KubernetesAnsibleModule
* Add a dummy class for backward compatibility

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-09-16 20:35:05 +05:30
Fabian von Feilitzsch
28dcf76cfb Merge pull request #228 from fabianvf/ignore-diff-with-warning
Do not mark task as changed when diff is irrelevant
2020-09-15 14:42:08 -04:00
Fabian von Feilitzsch
571406ce47 Merge pull request #224 from Akasurde/handle_exc
handle exception raised due to DynamicClient
2020-09-15 14:40:59 -04:00
Fabian von Feilitzsch
0afe40e657 Do not mark task as changed when diff is irrelevant
When the diff contains changes only to the fields `metadata.generation`
or `metadata.resourceVersion`, do not mark the task as changed. Instead,
   emit a warning highlighting that the API itself may not be
   idempotent, but that there was no meaningful difference between the
   desired and actual state of the resource.
2020-09-14 15:51:08 -04:00
Abhijeet Kasurde
527859c9cd Refactor module_utils (#223)
Moved a bunch of common things to module_utils.
2020-09-08 20:37:16 +05:30
Abhijeet Kasurde
ffb7032dc2 handle exception raised due to DynamicClient
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-09-07 19:03:28 +05:30
Abhijeet Kasurde
16059a8111 k8s_*: Group argument_spec accroding to usage (#199)
Partially fix #36

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-08-26 19:48:07 +05:30
Abhijeet Kasurde
3004c8d3f0 Handle invalid kubeconfig parsing error (#119)
Provide message to user about invalid or empty kubeconfig
by handling exception raised by kubernetes Python API

Fixes: #90

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-06-16 11:03:08 +05:30
Jeff Geerling
0e92889d34 Merge pull request #123 from willthames/flake8
Flake8
2020-06-15 12:34:46 -05:00
Will Thames
43ae9664fc W504 Move binary operator to start of line from end of line
PEP8 prefers binary operators at the start of a line
https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
2020-06-09 19:00:21 +10:00
Will Thames
4b7db6f7f9 Use improved kubernetes diffs where possible
Use information from strategic merges to improve
the quality of diffs, particularly for list items
(order no longer important, and adding/removing an
item from a list just shows that item in the diff,
not the whole list)
2020-06-08 19:35:59 +10:00
Will Thames
beebe98ce6 Fix scale wait and add tests
Move wait logic out of raw and into common and use that
logic in scale

Fix a few broken wait condition cases highlighted by scaling
up and down

Move scale-related tests into dedicated test task file

Additional service related tests
2020-05-22 12:39:43 +10:00
Fabrice Rabaute
5cb93f16b6 k8s: persist refreshed tokens
When the ansible k8s module is refreshing the tokens from the local kube
config, it should save those token to the kube config file.

If this is not done, this might break the next kube client call as the
token in the local kube config file is not valid anymore and refreshing
can fail.

This commit is adding an env var K8S_AUTH_PERSIST_CONFIG that can be
used to set this flag to true (default is false, same as current
behavior).
2020-03-12 13:50:43 -05:00
Jeff Geerling
49fe926bb4 Issue #2, Issue #5: Migrate doc_fragments, fix missing types in docs. 2020-01-30 15:28:30 -06:00
Jeff Geerling
d94dd72ae6 Issue #1, Issue #2: Move more content into collection, fix tests. 2020-01-30 13:51:43 -06:00