diff --git a/pkg/config/resource.go b/pkg/config/resource.go index 59180b47b..f9e7b60c8 100644 --- a/pkg/config/resource.go +++ b/pkg/config/resource.go @@ -75,6 +75,9 @@ type ResourceConfig struct { // operation `notImplemented`. Custom read function allows the // reconciler's progression. ReadOperation *ReadOperationsConfig `json:"find_operation,omitempty"` + //DeleteOperation contains instructions for the code generator to generate + // Go code for the delete operation for the resource. + DeleteOperation *DeleteOperationsConfig `json:"delete_operation,omitempty"` // Reconcile describes options for controlling the reconciliation // logic for a particular resource. Reconcile *ReconcileConfig `json:"reconcile,omitempty"` @@ -347,6 +350,15 @@ type ReadOperationsConfig struct { CustomMethodName string `json:"custom_method_name"` } +// DeleteOperationsConfig contains instructions for the code generator to handle +// custom delete operations for service APIs that have resources that have +// difficult-to-standardize delete operations. +type DeleteOperationsConfig struct { + // CustomMethodName is a string for the method name to replace the + // sdkDelete() method implementation for this resource + CustomMethodName string `json:"custom_method_name"` +} + // AdditionalColumnConfig can be used to specify additional printer columns to be included // in a Resource's output from kubectl. type AdditionalColumnConfig struct { @@ -685,6 +697,19 @@ func (c *Config) GetCustomFindMethodName(resourceName string) string { return "" } +func (c *Config) GetCustomDeleteMethodName(resourceName string) string { + if c == nil { + return "" + } + rConfig, found := c.Resources[resourceName] + if found { + if rConfig.DeleteOperation != nil { + return rConfig.DeleteOperation.CustomMethodName + } + } + return "" +} + // GetAllRenames returns all of the CRD's field renames observed in the generator config // for a given map of operations. func (c *Config) GetAllRenames( diff --git a/pkg/generate/ack/controller.go b/pkg/generate/ack/controller.go index 9788b50d6..259adbebc 100644 --- a/pkg/generate/ack/controller.go +++ b/pkg/generate/ack/controller.go @@ -46,6 +46,7 @@ var ( controllerIncludePaths = []string{ "boilerplate.go.tpl", "pkg/resource/references_read_referenced_resource.go.tpl", + "pkg/resource/sdk_delete_custom.go.tpl", "pkg/resource/sdk_find_custom.go.tpl", "pkg/resource/sdk_find_read_one.go.tpl", "pkg/resource/sdk_find_get_attributes.go.tpl", diff --git a/pkg/model/crd.go b/pkg/model/crd.go index 5cea57dba..532e4e623 100644 --- a/pkg/model/crd.go +++ b/pkg/model/crd.go @@ -724,6 +724,10 @@ func (r *CRD) CustomFindMethodName() string { return r.cfg.GetCustomFindMethodName(r.Names.Original) } +func (r *CRD) CustomDeleteMethodName() string { + return r.cfg.GetCustomDeleteMethodName(r.Names.Original) +} + // ListOpMatchFieldNames returns a slice of strings representing the field // names in the List operation's Output shape's element Shape that we should // check a corresponding value in the target Spec exists. diff --git a/templates/pkg/resource/sdk.go.tpl b/templates/pkg/resource/sdk.go.tpl index fcfa4b873..66b89a21e 100644 --- a/templates/pkg/resource/sdk.go.tpl +++ b/templates/pkg/resource/sdk.go.tpl @@ -145,7 +145,9 @@ func (rm *resourceManager) sdkDelete( exit(err) }() -{{- if .CRD.Ops.Delete }} +{{ if .CRD.CustomDeleteMethodName }} + {{- template "sdk_delete_custom" . }} +{{- else if .CRD.Ops.Delete }} {{- if $hookCode := Hook .CRD "sdk_delete_pre_build_request" }} {{ $hookCode }} {{- end }} diff --git a/templates/pkg/resource/sdk_delete_custom.go.tpl b/templates/pkg/resource/sdk_delete_custom.go.tpl new file mode 100644 index 000000000..5a2722c72 --- /dev/null +++ b/templates/pkg/resource/sdk_delete_custom.go.tpl @@ -0,0 +1,3 @@ +{{- define "sdk_delete_custom" -}} + return rm.{{ .CRD.CustomDeleteMethodName }}(ctx, r) +{{- end -}} \ No newline at end of file