Skip to content

Commit 062afeb

Browse files
authored
Add new type to OperationConfig so user can implement CustomCheckRequiredFieldsMissingMethod (#112)
Issue #, if available: [#850](aws-controllers-k8s/community#850) Description of changes: Adds new `pkg/generate/config.OperationConfig.CustomCheckRequiredFieldsMissingMethod `field of type *string so that user can implement a `CustomCheckRequiredFieldsMissingMethod` method as code-generator cannot handle certain cases. ex. For the `SageMaker` resource `ModelPackage`. There are versioned `modelPackage` and unversioned `modelPackage`, they both have a different required field being `ModelPackageGroupName` and `ModelPackageName`. `requiredFieldsMissingFromReadOneInput` will by default auto-generate to check for `ModelPackageName` and will infinitely recreate since it will never find the required field when a user attempts to make a versioned `modelPackage` which is `modelPackageGroupName` as it does not contain a `ModelPackageName`. ModelPackage has one or the other for its required field but not both. This new field allows the user to create their own custom implementation for `requiredFieldsMissingFromReadOneInput`, `requiredFieldsMissingFromSetAttributesInput`, and `requiredFieldsMissingFromGetAttributesInput`so that in cases where the auto-generated default required fields do not handle cases where it may be complicated ex: Have an exclusive-or of required fields. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 1f3c922 commit 062afeb

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

pkg/generate/config/operation.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import (
2222
// OperationConfig represents instructions to the ACK code generator to
2323
// specify the overriding values for API operation parameters and its custom implementation.
2424
type OperationConfig struct {
25-
CustomImplementation string `json:"custom_implementation,omitempty"`
26-
OverrideValues map[string]string `json:"override_values"`
25+
CustomImplementation string `json:"custom_implementation,omitempty"`
26+
CustomCheckRequiredFieldsMissingMethod string `json:"custom_check_required_fields_missing_method,omitempty"`
27+
OverrideValues map[string]string `json:"override_values"`
2728
// SetOutputCustomMethodName provides the name of the custom method on the
2829
// `resourceManager` struct that will set fields on a `resource` struct
2930
// depending on the output of the operation.

pkg/model/crd.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,24 @@ func (r *CRD) UpdateConditionsCustomMethodName() string {
507507
return resGenConfig.UpdateConditionsCustomMethodName
508508
}
509509

510+
// GetCustomCheckRequiredFieldsMissingMethod returns custom check required fields missing method
511+
// as string for custom resource, if specified in generator config
512+
func (r *CRD) GetCustomCheckRequiredFieldsMissingMethod(
513+
// The type of operation
514+
op *awssdkmodel.Operation,
515+
) string {
516+
if op == nil || r.cfg == nil {
517+
return ""
518+
}
519+
520+
operationConfig, found := r.cfg.Operations[op.Name]
521+
if !found {
522+
return ""
523+
}
524+
525+
return operationConfig.CustomCheckRequiredFieldsMissingMethod
526+
}
527+
510528
// SpecIdentifierField returns the name of the "Name" or string identifier field
511529
// in the Spec.
512530
// This method does not guarantee that the identifier field returned is the
@@ -560,7 +578,7 @@ func (r *CRD) PrintAgeColumn() bool {
560578
}
561579

562580
// ReconcileRequeuOnSuccessSeconds returns the duration after which to requeue
563-
// the custom resource as int, if specified in generator config.
581+
// the custom resource as int, if specified in generator config.
564582
func (r *CRD) ReconcileRequeuOnSuccessSeconds() int {
565583
if r.cfg == nil {
566584
return 0

templates/pkg/resource/sdk_find_get_attributes.go.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ func (rm *resourceManager) sdkFind(
5757
func (rm *resourceManager) requiredFieldsMissingFromGetAttributesInput(
5858
r *resource,
5959
) bool {
60+
{{- if $customCheckMethod := .CRD.GetCustomCheckRequiredFieldsMissingMethod .CRD.Ops.GetAttributes }}
61+
return rm.{{ $customCheckMethod }}(r)
62+
{{- else }}
6063
{{ GoCodeRequiredFieldsMissingFromGetAttributesInput .CRD "r.ko" 1 }}
64+
{{- end }}
6165
}
6266

6367
// newGetAttributesRequestPayload returns SDK-specific struct for the HTTP

templates/pkg/resource/sdk_find_read_one.go.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ func (rm *resourceManager) sdkFind(
6565
func (rm *resourceManager) requiredFieldsMissingFromReadOneInput(
6666
r *resource,
6767
) bool {
68+
{{- if $customCheckMethod := .CRD.GetCustomCheckRequiredFieldsMissingMethod .CRD.Ops.ReadOne }}
69+
return rm.{{ $customCheckMethod }}(r)
70+
{{- else }}
6871
{{ GoCodeRequiredFieldsMissingFromReadOneInput .CRD "r.ko" 1 }}
72+
{{- end }}
6973
}
7074

7175
// newDescribeRequestPayload returns SDK-specific struct for the HTTP request

templates/pkg/resource/sdk_update_set_attributes.go.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ func (rm *resourceManager) sdkUpdate(
4545
func (rm *resourceManager) requiredFieldsMissingFromSetAttributesInput(
4646
r *resource,
4747
) bool {
48+
{{- if $customCheckMethod := .CRD.GetCustomCheckRequiredFieldsMissingMethod .CRD.Ops.SetAttributes }}
49+
return rm.{{ $customCheckMethod }}(r)
50+
{{- else }}
4851
{{ GoCodeRequiredFieldsMissingFromSetAttributesInput .CRD "r.ko" 1 }}
52+
{{- end }}
4953
}
5054

5155
// newSetAttributesRequestPayload returns SDK-specific struct for the HTTP

0 commit comments

Comments
 (0)