-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Delete kubernetes resources from yaml files , solves #940 #1392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete kubernetes resources from yaml files , solves #940 #1392
Conversation
test_portforward_raw is flaky, we have an issue to track fixing it. closing to trigger CI |
@yliaog: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/reopen |
@yliaog: Reopened this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @yliaog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is mostly duplicates from create_from_yaml, better to refactor it into a common file, then have create_from_yaml, and delete_from_yaml share the common util, instead of having duplicates between them.
@@ -0,0 +1,146 @@ | |||
# Copyright 2018 The Kubernetes Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/2018/2021/
kubernetes/utils/delete_from_yaml.py
Outdated
|
||
def delete_from_yaml(k8s_client, yaml_file, verbose=False, | ||
namespace="default", **kwargs): | ||
"""Input: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to describe what the function does before the Input:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay will modify and push
k8s_client: an ApiClient object, initialized with the client args. | ||
verbose: If True, print confirmation from the create action. | ||
Default is False. | ||
namespace: string. Contains the namespace to create all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/create/delete/
Default is False. | ||
namespace: string. Contains the namespace to create all | ||
resources inside. The namespace must preexist otherwise | ||
the resource creation will fail. If the API object in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/creation/deletion/ ?
the resource creation will fail. If the API object in | ||
the yaml file already contains a namespace definition | ||
this parameter has no effect. | ||
Available parameters for creating <kind>: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/creating/deleting/
should not be persisted. An invalid or unrecognized dryRun | ||
directive will result in an error response and no further | ||
processing of the request. | ||
Valid values are: - All: all dry run stages will be processed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns:?
does it return anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it does not return anything , just deletes the resource
kubernetes/utils/delete_from_yaml.py
Outdated
failures = [] | ||
for yml_document in yml_document_all: | ||
try: | ||
# call delete from dict function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment above is not very useful
|
||
|
||
def delete_from_dict(k8s_client, yml_document, verbose, | ||
namespace="default", **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comments about what it does, Input, Returns etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure will do
kubernetes/utils/delete_from_yaml.py
Outdated
except client.rest.ApiException as api_exception: | ||
api_exceptions.append(api_exception) | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why extra blank line?
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: DiptoChakrabarty The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
hey since this is solving the issue of #940 deleting resources using yaml maintainers can this be merged pleased |
it is mostly duplicates from create_from_yaml, better to refactor it into a common file, then have create_from_yaml, and delete_from_yaml share the common util. |
Can this not be a new issue as this PR is solving the issue of deleting using yamls feature and a common file would be a new enhancement |
@DiptoChakrabarty -- I agree with @yliaog. It's better to address the duplication of logic in this PR itself. I wouldn't say that deduplication of logic is a new enhancement. |
Okay I am working on it |
I made a new file operate_from_yaml which has both the create and delete features as requested. Please tell me if I have to add anything more in it. |
b9de90f
to
58d6b0c
Compare
hey I have rebased it |
Hi, any plans to merge this and release it? |
Hey @reviewers can you please review this and tell what I have to do next or any suggestions |
/remove-lifecycle rotten |
|
||
def delete_k8s_object(k8s_api, yml_document, kind, **kwargs): | ||
|
||
if hasattr(k8s_api, "create_namespaced_{0}".format(kind)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "create_namespaceD_{0}" here intentional? Should it not be "delete_namespaced_{0}"?
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Any update? |
/reopen |
@dofmind: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
This feature would definitely be very welcome! Please reopen! |
Any plans to finish this? It would be quite useful. |
@DiptoChakrabarty @roycaihw is this PR still on the table? |
Jup it would be very nice to have! |
Why this PR has not been merged? It would be nice to have this feature. Thank you! |
/reopen |
@jamesjallorina: You can't reopen an issue/PR unless you authored it or you are a collaborator. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Anyway, I was able to use the author's implementation. Just create a package (e.g kubernetes_workaround) and copy the changes, no need to do some extra tweaking. Thanks! |
Will this feature ever be supported? It has been requested numerous times over the past three years, seems like a logical counterpart to |
Seconding this. Without the mirrored ability to tear down resources the |
…l by DiptoChakrabarty) and update to latest
…l by DiptoChakrabarty) and update to latest Revive PR kubernetes-client#1392: Implement delete_from_yaml, solves kubernetes-client#940 (original by DiptoChakrabarty) and update to latest
…date to latest (original by DiptoChakrabarty) - Implement delete_from_yaml functionality - Combine create_from_yaml and delete_from_yaml into yaml_processor, preserving existing signatures for create
…date to latest (original by @DiptoChakrabarty) - Implement delete_from_yaml functionality - Combine create_from_yaml and delete_from_yaml into yaml_processor, preserving existing signatures for create
This is a method to delete kubernetes resources using the yaml files . It is similar to the method create_from_yaml but for deleting kubernetes resources .
It can be used to any type pf resource deployment , pod , service etc.
Fixes #940
create_from_yaml creates kubernetes objects like deployments,serivces,ingress etc from the given yml files , the delete_from_yaml method can be used to remove/delete those objects from the same yml files in the given cluster for any namespace