You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a new SetFieldConfig struct to the code generator config that
allows teams to instruct the code generator to handle the SetResource
generator specially for a particular `pkg/model.OpType`.
This is useful for at least a couple use cases:
1. Different Go types in input and output shapes
When the Go type of a field in the Create Input shape differs from the
Go type of the same-named field in another operation's Output shape, the
code generator doesn't know how to handle this situation and ends up
outputting invalid Go code.
An example of this behaviour is in the RDS controller's DBInstance
resource. The DBSecurityGroups field in the Create Input shape is of
type `[]*string`, but the same field in the Create, ReadMany and Update
output shapes is of type `[]*DBSecurityGroupMembership`. The
`DBSecurityGroupMembership` struct has two fields, `DBSecurityGroupName`
and `Status`. The only part of that struct that is relevant to the
`Spec.DBSecurityGroups` field is the `DBSecurityGroupName` field, which
corresponds to the string identifier of the DB security group provided
by the user in the `CreateDBInstanceRequest.DBSecurityGroups` field.
The code generator ends up calling `pkg/generate/code.SetResource` for
the DBInstance resource, gets to the `Spec.DBSecurityGroups` field and
just doesn't know how to handle the different Go types and so ends up
outputting nothing, which breaks compilation and has caused us to
manually comment out or fix the generated code. operation.
See: https://github.com/aws-controllers-k8s/rds-controller/blob/dc3271fa7b455fc99c3531ce372ea221c9f5b8e7/pkg/resource/db_instance/sdk.go#L853-L864
In the RDS DBInstance DBSecurityGroups case, we'd add the following to
the RDS generator.yaml file to instruct the code generator how to
transform the response from the DescribeDBInstances Output shape for
setting the value of `Spec.DBSecurityGroups` from the set of
`DBSecurityGroupMembership.DBSecurityGroupName` values:
```yaml
resources:
DBInstance:
fields:
DBSecurityGroups:
set:
- on: READ_MANY
from: DBSecurityGroupName
```
2. Ignoring fields in output shapes containing stale data
For some service APIs, the returned value for a field in the Output
shape of an Update operation contains the *originally-set* value instead
of the value of the field that was set in the Update operation itself.
An example of this situation is the ElastiCache ModifyReplicationGroup
API call. If you pass some value for the LogDeliveryConfiguration field
in the Input shape (which comes from the Spec.LogDeliveryConfiguration
field of the ReplicationGroup resource), the value that is returned in
the Output shape's LogDeliveryConfiguration is actually the *old*
(stale) value for the field. The reason for this return of stale data is
because the log delivery configuration is asynchronously mutated.
For these cases, we want to be able to tell the code generator to ignore
these fields when outputting code for the
`pkg/generate/code.SetResource` function, but only for the Update
operation. In this case, we'd add the following to the ElastiCache
generator.yaml file:
```yaml
resources:
ReplicationGroup:
fields:
LogDeliveryConfiguration:
set:
- on: UPDATE
ignore: true
```
Signed-off-by: Jay Pipes <[email protected]>
0 commit comments