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

Implement tk delete functionality. #313

Merged
merged 4 commits into from
Jul 6, 2020
Merged

Implement tk delete functionality. #313

merged 4 commits into from
Jul 6, 2020

Conversation

mplzik
Copy link
Contributor

@mplzik mplzik commented Jul 6, 2020

This can be used to tear down a tanka environment. When doing tk delete, tanka will generate all manifests for an environment and remove
them from kubernetes cluster.

This is a safer variant of the one-liner mentioned at #155

@mplzik mplzik requested a review from sh0rez July 6, 2020 14:54
@mplzik mplzik marked this pull request as ready for review July 6, 2020 14:54
This can be used to tear down a tanka environment. When doing `tk
delete`, tanka will generate all manifests for an environment and remove
them from kubernetes cluster.

This is a safer variant of the one-liner mentioned at #155

Signed-off-by: Milan Plzik <[email protected]>
@mplzik mplzik force-pushed the mplzik/tanka-delete branch from 06629ab to 56191be Compare July 6, 2020 14:56
pkg/tanka/workflow.go Outdated Show resolved Hide resolved
pkg/tanka/workflow.go Outdated Show resolved Hide resolved
pkg/tanka/workflow.go Outdated Show resolved Hide resolved
mplzik added 2 commits July 6, 2020 18:32
Signed-off-by: Milan Plzik <[email protected]>
In order to avoid cascading objects deletions on server side, we need
to sort the object in an order reverse to the one used fpr Apply(). This
is best done directly in kube.Delete(), making the rest of tanka
codebase agnostic to generated object ordering.

Signed-off-by: Milan Plzik <[email protected]>
pkg/tanka/workflow.go Show resolved Hide resolved
pkg/tanka/tanka.go Outdated Show resolved Hide resolved
Comment on lines +14 to +18
for i := 0; i < len(state)/2; i++ {
t := state[i]
state[i] = state[len(state)-1-i]
state[len(state)-1-i] = t
}
Copy link
Member

Choose a reason for hiding this comment

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

While this is recommended in SliceTricks, I just discovered there is sort.Reverse which can be used as long as the type implements sort.Interface.

We could consider whether it's worth moving most of the sort logic from process to manifest, and have manifest.List implement the interface, so that you could sort.Sort(manifest.List{}) and also sort.Reverse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a look at sort.Reverse and it looked like a lot of bureaucracy. If we migrated from sort.SliceStable, it might be a bit more worthwhile, but I'm not sure if it's that intuitive in this case; e.g. the sorting criterion is non-trivial. I'd give it a go in a separate PR, since this is an internal cleanup, not a user-visible feature.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah thought about doing that. The slice would then know how to sort itself, allowing us to use sort.Stable and sort.Reverse on it

Copy link
Member

Choose a reason for hiding this comment

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

We can do that, but I agree it's minor internal cleanup

cmd/tk/workflow.go Outdated Show resolved Hide resolved
- check `err` for diff
- remove DeleteOpts
- fix documentation for `--force`

Signed-off-by: Milan Plzik <[email protected]>
Copy link
Member

@sh0rez sh0rez left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Comment on lines +14 to +18
for i := 0; i < len(state)/2; i++ {
t := state[i]
state[i] = state[len(state)-1-i]
state[len(state)-1-i] = t
}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah thought about doing that. The slice would then know how to sort itself, allowing us to use sort.Stable and sort.Reverse on it

Comment on lines +14 to +18
for i := 0; i < len(state)/2; i++ {
t := state[i]
state[i] = state[len(state)-1-i]
state[len(state)-1-i] = t
}
Copy link
Member

Choose a reason for hiding this comment

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

We can do that, but I agree it's minor internal cleanup

@sh0rez sh0rez merged commit ed6e1e5 into master Jul 6, 2020
@sh0rez sh0rez deleted the mplzik/tanka-delete branch July 6, 2020 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants