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: handles cleanup by using owner ref and cleanup hook #4

Merged
merged 8 commits into from
Jul 14, 2023

Conversation

bartoszmajsak
Copy link

OssmResourceTracker

A cluster-scoped resource for tracking objects created by OSSM installer. Primarily used as owner reference for resources created across namespaces so that they can be garbage collected by Kubernetes when they are not needed anymore.

Cleanup funcs

OSSM Installer keeps a chain of functions that will be invoked during the cleanup phase. Right now it includes:

  • deletion of OssmResourceTracker so the owned resources will be garbage collected on KfDef deletion
    • this included ConfigMaps, EnvoyFilters and so on - essentially every ns-scoped resource created by the installer
  • deletion of OAuth client. This is needed even though it also has OwnerReferences pointing to the tracker resource. OAuth client is also a cluster-scoped resource so it won't be garbage collected.
  • removal of token volume from Istio ingress
  • removal of extAuthzProvider

With this in place, subsequent deployments of KfDef wouldn't result in OAuth flow failed error which is caused by misaligned secrets between filter and client.

Those cleanup functions are invoked by a hook in Delete phase of KfDef operator.

Open points

  • we are not restoring everything yet. For example, settings such as IOR or auto-injection are not rolled back. We could use OssmTrackerResource (we might want to change its name btw ;)) to keep old values in a .spec and use it to restore on deletion.
  • code need a bit more polish
  • we need tests :)

It is a cluster-scoped resource for tracking objects created by Ossm plugin.
Primarily used as owner reference for resources created across namespaces
so that they can be garbage collected by Kubernetes when they are not needed anymore.
- adds cleanup hook for Delete phase of KfDef operator
- moves k8s_utils code to ossm package to keep it in one place for future extraction of the logic
main.go Show resolved Hide resolved
Comment on lines +31 to +38
objectMeta.SetOwnerReferences([]metav1.OwnerReference{
{
APIVersion: o.tracker.APIVersion,
Kind: o.tracker.Kind,
Name: o.tracker.Name,
UID: o.tracker.UID,
},
})
Copy link
Author

Choose a reason for hiding this comment

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

Note to self: we have it in multiple places - worth extracting

Copy link
Author

Choose a reason for hiding this comment

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

Duplicated by purpose - we want to have our code self-contained and thus we should minimize coupling with other parts of the current operator as much as possible. Another benefit is that now we can refactor it to our liking, as I think we don't need all of the logic from the original k8s_utils.go

Copy link

@cam-garrison cam-garrison left a comment

Choose a reason for hiding this comment

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

Nice :) excited to have cleanup working.

}

gvr := schema.GroupVersionResource{
Group: "ossm.plugins.kubeflow.org",

Choose a reason for hiding this comment

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

noting this Group as something to potentially change in future based on our call

@cam-garrison cam-garrison merged commit d5995af into kf_ossm_plugin Jul 14, 2023
bartoszmajsak added a commit that referenced this pull request Sep 6, 2023
* feat: introduces OssmResourceTracker resource

It is a cluster-scoped resource for tracking objects created by Ossm plugin.
Primarily used as owner reference for resources created across namespaces
so that they can be garbage collected by Kubernetes when they are not needed anymore.

* feat: uses OssmResourceTracker to cleanup owned resources

- adds cleanup hook for Delete phase of KfDef operator
- moves k8s_utils code to ossm package to keep it in one place for future extraction of the logic

* chore: renames plugin to OssmInstaller

* chore: moves cleanup logic to single file

* feat: handles token volume removal in SMCP

* chore: adds plugin name as extra key-value to logger

* feat: removes extAuthzProvider on deletion

* chore: minor naming fixes
bartoszmajsak added a commit that referenced this pull request Sep 6, 2023
* feat: introduces OssmResourceTracker resource

It is a cluster-scoped resource for tracking objects created by Ossm plugin.
Primarily used as owner reference for resources created across namespaces
so that they can be garbage collected by Kubernetes when they are not needed anymore.

* feat: uses OssmResourceTracker to cleanup owned resources

- adds cleanup hook for Delete phase of KfDef operator
- moves k8s_utils code to ossm package to keep it in one place for future extraction of the logic

* chore: renames plugin to OssmInstaller

* chore: moves cleanup logic to single file

* feat: handles token volume removal in SMCP

* chore: adds plugin name as extra key-value to logger

* feat: removes extAuthzProvider on deletion

* chore: minor naming fixes
@bartoszmajsak bartoszmajsak deleted the resources_cleanup branch October 4, 2023 04:45
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