Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions pkg/generate/ack/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions pkg/model/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion templates/pkg/resource/sdk.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
8 changes: 8 additions & 0 deletions templates/pkg/resource/sdk_delete_custom.go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- define "sdk_delete_custom" -}}
func (rm *resourceManager) sdkDelete(
ctx context.Context,
r *resource,
) (latest *resource, err error) {
return rm.{{ .CRD.CustomDeleteMethodName }}(ctx, r)
}
{{- end -}}