Skip to content

Commit 63cb4ec

Browse files
committed
Add custom delete_operation support
1 parent 3753ca3 commit 63cb4ec

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

pkg/config/resource.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ type ResourceConfig struct {
7575
// operation `notImplemented`. Custom read function allows the
7676
// reconciler's progression.
7777
ReadOperation *ReadOperationsConfig `json:"find_operation,omitempty"`
78+
//DeleteOperation contains instructions for the code generator to generate
79+
// Go code for the delete operation for the resource.
80+
DeleteOperation *DeleteOperationsConfig `json:"delete_operation,omitempty"`
7881
// Reconcile describes options for controlling the reconciliation
7982
// logic for a particular resource.
8083
Reconcile *ReconcileConfig `json:"reconcile,omitempty"`
@@ -347,6 +350,15 @@ type ReadOperationsConfig struct {
347350
CustomMethodName string `json:"custom_method_name"`
348351
}
349352

353+
// DeleteOperationsConfig contains instructions for the code generator to handle
354+
// custom delete operations for service APIs that have resources that have
355+
// difficult-to-standardize delete operations.
356+
type DeleteOperationsConfig struct {
357+
// CustomMethodName is a string for the method name to replace the
358+
// sdkDelete() method implementation for this resource
359+
CustomMethodName string `json:"custom_method_name"`
360+
}
361+
350362
// AdditionalColumnConfig can be used to specify additional printer columns to be included
351363
// in a Resource's output from kubectl.
352364
type AdditionalColumnConfig struct {
@@ -685,6 +697,19 @@ func (c *Config) GetCustomFindMethodName(resourceName string) string {
685697
return ""
686698
}
687699

700+
func (c *Config) GetCustomDeleteMethodName(resourceName string) string {
701+
if c == nil {
702+
return ""
703+
}
704+
rConfig, found := c.Resources[resourceName]
705+
if found {
706+
if rConfig.DeleteOperation != nil {
707+
return rConfig.DeleteOperation.CustomMethodName
708+
}
709+
}
710+
return ""
711+
}
712+
688713
// GetAllRenames returns all of the CRD's field renames observed in the generator config
689714
// for a given map of operations.
690715
func (c *Config) GetAllRenames(

pkg/generate/ack/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var (
4646
controllerIncludePaths = []string{
4747
"boilerplate.go.tpl",
4848
"pkg/resource/references_read_referenced_resource.go.tpl",
49+
"pkg/resource/sdk_delete_custom.go.tpl",
4950
"pkg/resource/sdk_find_custom.go.tpl",
5051
"pkg/resource/sdk_find_read_one.go.tpl",
5152
"pkg/resource/sdk_find_get_attributes.go.tpl",

pkg/model/crd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,10 @@ func (r *CRD) CustomFindMethodName() string {
724724
return r.cfg.GetCustomFindMethodName(r.Names.Original)
725725
}
726726

727+
func (r *CRD) CustomDeleteMethodName() string {
728+
return r.cfg.GetCustomDeleteMethodName(r.Names.Original)
729+
}
730+
727731
// ListOpMatchFieldNames returns a slice of strings representing the field
728732
// names in the List operation's Output shape's element Shape that we should
729733
// check a corresponding value in the target Spec exists.

templates/pkg/resource/sdk.go.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ func (rm *resourceManager) sdkDelete(
145145
exit(err)
146146
}()
147147

148-
{{- if .CRD.Ops.Delete }}
148+
{{ if .CRD.CustomDeleteMethodName }}
149+
{{- template "sdk_delete_custom" . }}
150+
{{- else if .CRD.Ops.Delete }}
149151
{{- if $hookCode := Hook .CRD "sdk_delete_pre_build_request" }}
150152
{{ $hookCode }}
151153
{{- end }}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{- define "sdk_delete_custom" -}}
2+
func (rm *resourceManager) sdkDelete(
3+
ctx context.Context,
4+
r *resource,
5+
) (latest *resource, err error) {
6+
return rm.{{ .CRD.CustomDeleteMethodName }}(ctx, r)
7+
}
8+
{{- end -}}

0 commit comments

Comments
 (0)