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

452: handle delete strategy for inoperable resources #468

Merged
merged 6 commits into from
Apr 11, 2022

Conversation

kumaritanushree
Copy link
Contributor

@kumaritanushree kumaritanushree commented Mar 25, 2022

Why this PR and what it is doing
Issue was: Inoperable resources like default namespace are not allowed to delete which was throwing error on kapp delete.
Solution: For all inoperable resources kapp will orphaned the requested resource instead of trying to delete.

TODO:

  • Manual testing for the changes
  • Add e2e test case

NOTE: If you feel there should be more resources in the list please suggest.

@vrabbi
Copy link

vrabbi commented Apr 3, 2022

i think this list should also include the namespaces:
kube-system
kube-public
kube-node-lease

these are all default namespaces in a cluster and as such should be treated i believe the same as the default namespace in terms of deletion strategy behavior

@kumaritanushree kumaritanushree marked this pull request as ready for review April 4, 2022 08:55
@kumaritanushree
Copy link
Contributor Author

i think this list should also include the namespaces: kube-system kube-public kube-node-lease

these are all default namespaces in a cluster and as such should be treated i believe the same as the default namespace in terms of deletion strategy behavior

Updated the list as suggested. Thanks @vrabbi

res := c.change.ExistingResource()

for _, r := range inoperableResourceList {
strings.EqualFold(r.Name, res.Name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EqualFold do the non case-sensitive comparison of two strings. Which I found better than converting strings in one case and then compare.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have decide3d to go ahead with matching Group and Kind. We can change the values to have capital case (i.e. "Namespace") as that is always the case and go ahead with simply checking for equality

Copy link
Contributor

@100mik 100mik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some thoughts 🤔
will take a closer look at the test as it is slightly diferent for what we have for the orphaning test.

res := c.change.ExistingResource()

for _, r := range inoperableResourceList {
strings.EqualFold(r.Name, res.Name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have decide3d to go ahead with matching Group and Kind. We can change the values to have capital case (i.e. "Namespace") as that is always the case and go ahead with simply checking for equality

Name string
}

// if any new reource will encountered which kapp can not delete and required to orphaned then resource info will be added here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: (just trying to make it a bit clearer)

Suggested change
// if any new reource will encountered which kapp can not delete and required to orphaned then resource info will be added here.
// List of resources use the "orphan" delete strategy implicitly as they cannot be deleted by end users

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -32,10 +33,40 @@ type DeleteChange struct {
identifiedResources ctlres.IdentifiedResources
}

type uniqueResourceRef struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we change this to "inoperableResourceRef" as we are loosely matching it without being strict about versions now? It is also not being used anywhere else.
(Others might have other ideas as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the suggestion and updated the same. thanks

pkg/kapp/clusterapply/delete_change.go Show resolved Hide resolved

for _, r := range inoperableResourceList {
strings.EqualFold(r.Name, res.Name())
if strings.EqualFold(r.Name, res.Name()) && strings.EqualFold(r.Kind, res.GroupKind().Kind) && strings.EqualFold(r.Group, res.GroupKind().Group) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As renu pointed out, I do not think we should do a match which ignores cases here if we have decided on using Group-Kinds to match as they are always the same.

kind: Namespace
metadata:
name: default

Copy link
Contributor

@100mik 100mik Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we do not need this empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

@100mik
Copy link
Contributor

100mik commented Apr 4, 2022

The failing lint should be fixed by #470

@@ -122,3 +157,14 @@ func descMessage(res ctlres.Resource) []string {
}
return []string{}
}

func (c DeleteChange) isInoperableResource() bool {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No need of new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Copy link
Contributor

@100mik 100mik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

I see that there is an extra case (one more the orphaned test)
But I believe it addresses two cases, one where the GVR of the resource being deleted is available and the other when it is not.

I am fine with having this 🚀


res := c.change.ExistingResource()
for _, r := range inoperableResourceList {
if r.Name == res.Name() && r.Kind == res.GroupKind().Kind && r.Group == res.GroupKind().Group {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is a trick:

if r == inoperableResourceRef{Name: res.Name(), GroupKind: res.GroupKind()} {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@rohitagg2020
Copy link
Contributor

LGTM

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

Successfully merging this pull request may close these issues.

Allow kapp delete even if default namespace was part of the application configuration
8 participants