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

feat: Prune old resources #251

Merged
merged 9 commits into from
Apr 20, 2020
Merged

feat: Prune old resources #251

merged 9 commits into from
Apr 20, 2020

Conversation

sh0rez
Copy link
Member

@sh0rez sh0rez commented Apr 3, 2020

Implements a mechanism that allows to remove previously created resources that are no longer present in the Jsonnet code, based on internal discussion and tips from @anguslees (thanks!)

Process:

  1. Automatically labels all resources with tanka.dev/environment: <env-name>
  2. Use tk prune to remove old ones
  3. Fetches all metadata.uid of currently present objects
  4. Fetches all objects that hold our label
  5. Shows diff and prompts for confirm
  6. Removes all objects having an unknown UID

Design doc: https://docs.google.com/document/d/1R3_dvXRb2d46GJTb3PQT3hfx2q5sy-ixifSGaWwDM8M

Fixes #88

/cc @malcolmholmes @captncraig @mplzik

@sh0rez sh0rez added kind/feature Something new should be added component/kubernetes Working with Kubernetes clusters labels Apr 3, 2020
@sh0rez sh0rez self-assigned this Apr 3, 2020
sh0rez added 4 commits April 4, 2020 22:58
Queries the required data a lot faster, by using kubectl more
efficiently (one call vs a call for each kind).

Can be possibly improved even further by running in parallel.
Adds a `tk prune` command, that does what it promises. Prune is
functionally complete now.
@sh0rez sh0rez changed the title WIP feat(prune): find old resources feat(prune): find old resources Apr 6, 2020
@sh0rez sh0rez changed the title feat(prune): find old resources feat: Prune old resources Apr 6, 2020
@sh0rez sh0rez requested review from rfratto and woodsaj April 6, 2020 20:52
pkg/kubernetes/apply.go Outdated Show resolved Hide resolved
Copy link

@anguslees anguslees left a comment

Choose a reason for hiding this comment

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

(otherwise lgtm, fwiw)

pkg/kubernetes/apply.go Outdated Show resolved Hide resolved
@sh0rez sh0rez requested a review from woodsaj April 8, 2020 08:59
pkg/kubernetes/reconcile.go Outdated Show resolved Hide resolved
@sh0rez sh0rez requested a review from woodsaj April 8, 2020 20:30
Copy link
Contributor

@malcolmholmes malcolmholmes left a comment

Choose a reason for hiding this comment

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

Looked through code (there's a lot of changes!)
In one test environment, set injectLabels and saw it create labels.
Duplicated a service, and created it. Saw label added.
Removed service from jsonnet. tk apply said no changes. tk prune swiftly went through steps, then offered me a diff showing the service that was to be removed.
It then removed it.
Looks good to me.

@sh0rez sh0rez merged commit 7c78c8f into master Apr 20, 2020
@sh0rez sh0rez deleted the prune-uid branch April 20, 2020 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/kubernetes Working with Kubernetes clusters kind/feature Something new should be added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pruning resources
5 participants