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

Commit

Permalink
Apply Ketan's suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Claire McGinty <[email protected]>
  • Loading branch information
clairemcginty committed Sep 9, 2021
1 parent ed5a657 commit 1080290
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions go/tasks/pluginmachinery/k8s/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,67 +92,79 @@ type Plugin interface {
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 overriden 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.
// 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)
return AbortBehavior {
Patch: &patchOperation,
DeleteOnErr: deleteOnErr,
}
}

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

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

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

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

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

0 comments on commit 1080290

Please sign in to comment.