The Wayback Machine - https://web.archive.org/web/20200912174236/https://github.com/kubernetes-client/python/pull/1197
Skip to content
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 from yaml #1197

Open
wants to merge 31 commits into
base: master
from

Conversation

@DiptoChakrabarty
Copy link

DiptoChakrabarty commented Jul 7, 2020

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

Resolved issue for tests failing for python2.7

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

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 7, 2020

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please log a ticket with the Linux Foundation Helpdesk: https://support.linuxfoundation.org/
  • Should you encounter any issues with the Linux Foundation Helpdesk, send a message to the backup e-mail support address at: [email protected]

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. I understand the commands that are listed here.

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 7, 2020

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: DiptoChakrabarty
To complete the pull request process, please assign yliaog
You can assign the PR to them by writing /assign @yliaog in a comment when ready.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 7, 2020

Welcome @DiptoChakrabarty!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot requested review from roycaihw and yliaog Jul 7, 2020
@k8s-ci-robot k8s-ci-robot added the size/L label Jul 7, 2020
@MoShitrit
Copy link
Member

MoShitrit commented Jul 8, 2020

Hey @DiptoChakrabarty
Thanks for your PR!
Looks like you need to sign the CLA, can you please follow these instructions and sign?

@DiptoChakrabarty
Copy link
Author

DiptoChakrabarty commented Jul 8, 2020

Hey @DiptoChakrabarty
Thanks for your PR!
Looks like you need to sign the CLA, can you please follow these instructions and sign?

Yes I have done it

@DiptoChakrabarty
Copy link
Author

DiptoChakrabarty commented Jul 13, 2020

HI @roycaihw , @yliaog can you please review this PR

print(msg)


class FailToCreateError(Exception):

This comment has been minimized.

@yliaog

yliaog Jul 13, 2020

Contributor

should it be FailToDeleteError?

# convert group name from DNS subdomain format to
# python class name convention
group = "".join(word.capitalize() for word in group.split('.'))
group = "".join(word.capitalize() for word in group.split('.'))

This comment has been minimized.

@yliaog

yliaog Jul 13, 2020

Contributor

looks the two lines above are the same?

This comment has been minimized.

@DiptoChakrabarty

DiptoChakrabarty Jul 13, 2020

Author

Yes resolving these small issues

from kubernetes import client


def delete_from_yaml(

This comment has been minimized.

@yliaog

yliaog Jul 13, 2020

Contributor

overall, what is the difference between this and create_from_yaml? could you please list the differences in the PR description? is it possible to reuse to avoid dups?

This comment has been minimized.

@DiptoChakrabarty

DiptoChakrabarty Jul 13, 2020

Author

Yes I will do it

This comment has been minimized.

@DiptoChakrabarty

DiptoChakrabarty Jul 28, 2020

Author

I have written the difference between the methods create_from_yaml and delete_from_yaml editing the PR description and also fixed the issues as stated earlier.

DiptoChakrabarty and others added 13 commits Jul 13, 2020
Signed-off-by: Nabarun Pal <[email protected]>
Reference: OpenAPITools/openapi-generator#5377

Signed-off-by: Nabarun Pal <[email protected]>
The upstream 1.16 API moved ahead due to [patch releases](https://github.com/kubernetes/sig-release/blob/master/releases/patch-releases.md).

The logs are gathered from the upstream [CHANGELOG](https://raw.githubusercontent.com/kubernetes/kubernetes/master/CHANGELOG/CHANGELOG-1.16.md).

Signed-off-by: Nabarun Pal <[email protected]>
Reference:
- [#866](#866)
- [#959](#959)

Signed-off-by: Nabarun Pal <[email protected]>
Reference: #974

Signed-off-by: Nabarun Pal <[email protected]>
The implementation and tests were already picked up by the upstream OpenAPI
generator [here](OpenAPITools/openapi-generator#5094).
Patching in the tests here for correctness and clarity.

Reference: #1073

Signed-off-by: Nabarun Pal <[email protected]>
Signed-off-by: Nabarun Pal <[email protected]>
Signed-off-by: Nabarun Pal <[email protected]>
Update from 49ec06096ebc4e092c1ebc2291bf18ccaac935af to fb86b8acb66830b098c691fa14f4e6edbf9f7317

Signed-off-by: Nabarun Pal <[email protected]>
Signed-off-by: Nabarun Pal <[email protected]>
The changes have been listed in the CHANGELOG and linked to the
respective milestone pull requests.

Signed-off-by: Nabarun Pal <[email protected]>
Update OpenAPI generator and the client
palnabarun and others added 2 commits Jul 20, 2020
There has been no API changes between 1.16.11 and 1.16.14

Signed-off-by: Nabarun Pal <[email protected]>
Update upstream version to 1.16.14
@@ -0,0 +1,146 @@
import re

This comment has been minimized.

@roycaihw

roycaihw Jul 30, 2020

Member

please add copyright boilerplate

This comment has been minimized.

@DiptoChakrabarty

DiptoChakrabarty Aug 17, 2020

Author

sure Ill add the boilerplate and try writing the tests

This comment has been minimized.

@DiptoChakrabarty

DiptoChakrabarty Aug 24, 2020

Author

added the boilerplate and added tests also modifying delete_from_dict function

this parameter has no effect.
Available parameters for creating <kind>:
:param async_req bool
:param bool include_uninitialized: If true, partially initialized

This comment has been minimized.

@roycaihw

roycaihw Jul 30, 2020

Member

the initializer feature has been removed

API object (i.e. List, Service, etc).
Input:
k8s_client: an ApiClient object, initialized with the client args.
data: a dictionary holding valid kubernetes objects

This comment has been minimized.

@roycaihw

roycaihw Jul 30, 2020

Member

the comment doesn't match the parameter

This comment has been minimized.

@DiptoChakrabarty

DiptoChakrabarty Aug 31, 2020

Author

changed the comment with correct parameter

name = yml_document["metadata"]["name"]
#call function to delete from namespace
res = getattr(k8s_api,"delete_namespaced_{}".format(kind))(
name=name,body=client.V1DeleteOptions(propagation_policy="Foreground", grace_period_seconds=5),**kwargs)

This comment has been minimized.

@roycaihw

roycaihw Jul 30, 2020

Member

if we want to achieve parity with kubectl delete -f, we should probably use Background policy by default with a Cascade option: https://github.com/kubernetes/kubernetes/blob/0c642b6ef01071219b9b9e34ad6d89cb9b4b1971/staging/src/k8s.io/kubectl/pkg/cmd/delete/delete.go#L304-L308

This comment has been minimized.

@DiptoChakrabarty

DiptoChakrabarty Aug 31, 2020

Author

have updated this to use background policy

name = yml_document["metadata"]["name"]
kwargs.pop('namespace', None)
res = getattr(k8s_api,"delete_{}".format(kind))(
name=name,body=client.V1DeleteOptions(propagation_policy="Foreground", grace_period_seconds=5),**kwargs)

This comment has been minimized.

@roycaihw

roycaihw Jul 30, 2020

Member

A 200 response from a delete request doesn't guarantee the resource being deleted. We should wait until the resource is no longer visible from the server.

This comment has been minimized.

@DiptoChakrabarty

DiptoChakrabarty Sep 4, 2020

Author

How should the e2e tests work for objects being deleted , after deletion if they are search (the object) it gets timed out resulting in an error ,however in the create_from_yaml tests in the end all resources are being deleted using multiple separate commands could we delete those using the delete_from_yaml method and that would be sufficient?

This comment has been minimized.

This comment has been minimized.

@yliaog

yliaog Sep 7, 2020

Contributor

in e2e, after delete, try listing the object again, if it does not exist anymore, it means the object is successfully deleted.

greed42 and others added 2 commits Jul 30, 2020
To get auth plugin support for client certificates, ref. kubernetes-client/python-base#205
Update python base
@psikka1
Copy link

psikka1 commented Aug 4, 2020

@DiptoChakrabarty @roycaihw - Does the API support non-namespaced resources such as ClusterRole? I am failing to delete the cluster role with this error -

line 115, in delete_from_yaml_single_item
    if getattr(k8s_api, "delete_namespaced_{}".format(kind)):
AttributeError: 'RbacAuthorizationV1Api' object has no attribute 'delete_namespaced_cluster_role'

I feel they should also be supported. Same seems to be the case with create_from_yaml.
Another likely bug I noticed was that when the yaml doc has a blank item, this fails.

...
---

---
...
...

Adding a check
if yml_document:
before this line would do the job.

@k8s-ci-robot k8s-ci-robot added size/XXL and removed size/L labels Aug 24, 2020
@yliaog
Copy link
Contributor

yliaog commented Sep 7, 2020

this PR has 2151 files changed, please rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

8 participants
You can’t perform that action at this time.