Skip to content

Commit

Permalink
add composable PluginCleanupPolicy (flyteorg#1345) (flyteorg#203)
Browse files Browse the repository at this point in the history
* add composable PluginCleanupPolicy

Signed-off-by: Claire McGinty <[email protected]>

* fix generated mocks

Signed-off-by: Claire McGinty <[email protected]>

* use PluginAbortOverride in PluginProperties

Signed-off-by: Claire McGinty <[email protected]>

* Update go/tasks/pluginmachinery/k8s/plugin.go

Co-authored-by: Haytham Abuelfutuh <[email protected]>
Signed-off-by: Claire McGinty <[email protected]>

* add custom constructors for AbortBehavior

Signed-off-by: Claire McGinty <[email protected]>

* Apply Ketan's suggestions

Signed-off-by: Claire McGinty <[email protected]>

* Apply suggestions from code review

Co-authored-by: Haytham Abuelfutuh <[email protected]>
Signed-off-by: Claire McGinty <[email protected]>

* lint/goimports

Signed-off-by: Claire McGinty <[email protected]>

Co-authored-by: Haytham Abuelfutuh <[email protected]>
  • Loading branch information
clairemcginty and EngHabu authored Sep 9, 2021
1 parent 280d2dd commit bd6c1b6
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
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
}

// An optional interface a Plugin can implement to override its default OnAbort finalizer (deletion of the underlying resource).
type PluginAbortOverride interface {
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,
}
}

0 comments on commit bd6c1b6

Please sign in to comment.