Skip to content

Commit 62c73f2

Browse files
authored
always ensure operation overrides work (#375)
There were two bugs in the code generator's construction of the OperationMap during API inference. The first bug was a non-deterministic behaviour that showed itself when an API had multiple Operations of a single operation type (say, READ_ONE). The code that was responsible for determining which Operation mapped to which operation type for a particular resource was looping over the `aws-sdk-go` `private/model/api:API`'s `Operations` field, which is a map. Depending on the parsing of the underlying api-2.json files, same-typed Operations with different IDs -- e.g. `DescribeStreamSummary` and `DescribeStream` -- were being mapped to a single operation type -- OpTypeGet. Depending on which Operation ID came last, that is the operation that was being mapped, regardless of which one appeared in the OperationConfig configuration option that handles overrides. The second bug was that the `OpTypeFromString` method was too strict in its comparison logic. The strings "get", "READ_ONE", "read_one" and "Get" should all lead to OpTypeGet, but only "Get" was being matched. Fixes Issue aws-controllers-k8s/community#1555 Signed-off-by: Jay Pipes <[email protected]> By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f6dd767 commit 62c73f2

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

pkg/model/op.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,32 @@ func GetOpTypeAndResourceNameFromOpID(
150150
}
151151

152152
func OpTypeFromString(s string) OpType {
153-
switch s {
154-
case "Create":
153+
switch strings.ToLower(s) {
154+
case "create":
155155
return OpTypeCreate
156-
case "CreateBatch":
156+
case "createbatch":
157157
return OpTypeCreateBatch
158-
case "Delete":
158+
case "delete":
159159
return OpTypeDelete
160-
case "Replace":
160+
case "replace":
161161
return OpTypeReplace
162-
case "Update":
162+
case "update":
163163
return OpTypeUpdate
164-
case "AddChild":
164+
case "addchild":
165165
return OpTypeAddChild
166-
case "AddChildren":
166+
case "addchildren":
167167
return OpTypeAddChildren
168-
case "RemoveChild":
168+
case "removechild":
169169
return OpTypeRemoveChild
170-
case "RemoveChildren":
170+
case "removechildren":
171171
return OpTypeRemoveChildren
172-
case "Get":
172+
case "get", "readone", "read_one":
173173
return OpTypeGet
174-
case "List":
174+
case "list", "readmany", "read_many":
175175
return OpTypeList
176-
case "GetAttributes":
176+
case "getattributes":
177177
return OpTypeGetAttributes
178-
case "SetAttributes":
178+
case "setattributes":
179179
return OpTypeSetAttributes
180180
}
181181

pkg/model/sdk_api.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ func (a *SDKAPI) GetOperationMap(cfg *ackgenconfig.Config) *OperationMap {
8686
opMap[opType][resName] = op
8787
}
8888
}
89+
90+
// We need to do a second pass over the operation overrides because some
91+
// APIs have multiple operations of a particular OpType and we need to
92+
// always be sure that the overridden operation is the one that we use
93+
// during inference.
94+
//
95+
// An example of this is the Kinesis API which has two OpTypeGet
96+
// Operations: DescribeStream and DescribeStreamSummary. We want the latter
97+
// only and list that in our `operations:` configuration value.
98+
//
99+
// see: https://github.com/aws-controllers-k8s/community/issues/1555
100+
for opID, opCfg := range cfg.Operations {
101+
if opCfg.ResourceName == "" {
102+
continue
103+
}
104+
op, found := a.API.Operations[opID]
105+
if !found {
106+
panic("operation " + opID + " in generator.yaml 'operations:' object does not exist.")
107+
}
108+
for _, ot := range opCfg.OperationType {
109+
opType := OpTypeFromString(ot)
110+
opMap[opType][opCfg.ResourceName] = op
111+
}
112+
}
89113
a.opMap = &opMap
90114
return &opMap
91115
}

0 commit comments

Comments
 (0)