Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

add composable PluginCleanupPolicy (flyteorg/flyte#1345) #203

Merged
merged 8 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions go/tasks/pluginmachinery/k8s/mocks/plugin_abort_override.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions go/tasks/pluginmachinery/k8s/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,72 @@ type Plugin interface {
// Properties desired by the plugin
GetProperties() PluginProperties
EngHabu marked this conversation as resolved.
Show resolved Hide resolved
}

// An optional interface a Plugin can implement to override its default OnAbort finalizer (deletion of the underlying resource).
type PluginAbortOverride interface {
clairemcginty marked this conversation as resolved.
Show resolved Hide resolved
OnAbort(ctx context.Context, tCtx pluginsCore.TaskExecutionContext, resource client.Object) (behavior AbortBehavior, err error)
}

// Defines the overridden OnAbort behavior. The resource (by default, the underlying resource, although this
// can be overridden) can be either patched, updated, or deleted.
type AbortBehavior struct {
// Optional override to the default k8s Resource being acted on.
Resource client.Object
DeleteResource bool
Update *UpdateResourceOperation
Patch *PatchResourceOperation
// Determines whether to delete the Resource if the specified operations return an error
DeleteOnErr bool
}

// Defines a Patch operation on a Resource
type PatchResourceOperation struct {
Patch client.Patch
Options []client.PatchOption
}

// Defines an Update operation on a Resource
type UpdateResourceOperation struct {
Options []client.UpdateOption
}

// AbortBehavior that patches the default resource
func AbortBehaviorPatchDefaultResource(patchOperation PatchResourceOperation, deleteOnErr bool) AbortBehavior {
return AbortBehaviorPatch(patchOperation, deleteOnErr, nil)
}

// AbortBehavior that patches the specified resource
func AbortBehaviorPatch(patchOperation PatchResourceOperation, deleteOnErr bool, resource client.Object) AbortBehavior {
return AbortBehavior{
Resource: resource,
Patch: &patchOperation,
DeleteOnErr: deleteOnErr,
}
}

// AbortBehavior that updates the default resource
func AbortBehaviorUpdateDefaultResource(updateOperation UpdateResourceOperation, deleteOnErr bool) AbortBehavior {
return AbortBehaviorUpdate(updateOperation, deleteOnErr, nil)
}

// AbortBehavior that updates the specified resource
func AbortBehaviorUpdate(updateOperation UpdateResourceOperation, deleteOnErr bool, resource client.Object) AbortBehavior {
return AbortBehavior{
Resource: resource,
Update: &updateOperation,
DeleteOnErr: deleteOnErr,
}
}

// AbortBehavior that deletes the default resource
func AbortBehaviorDeleteDefaultResource() AbortBehavior {
return AbortBehaviorDelete(nil)
}

// AbortBehavior that deletes the specified resource
func AbortBehaviorDelete(resource client.Object) AbortBehavior {
return AbortBehavior{
Resource: resource,
DeleteResource: true,
}
}