Skip to content

Commit 53dcde4

Browse files
a-hilalyjljaco
andcommitted
Normalize field names specific to comparison in generator config
While generating code for iam-controller OIDC resource, we found a tiny bug causing the code-generator to generate comparison code for a field that was marked as `compare.is_ignored`. This was found to be the result of the code-generator not properly normalizing field names. This patch fixes this bug by normalizing the field name using camel case. This not a good long term fix. Ideally normalization should happen earlier. Co-authored-by: John Jacobs <[email protected]>
1 parent 5ee0ac0 commit 53dcde4

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

pkg/generate/code/compare.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ func CompareResource(
112112
secondResAdaptedVarName += "." + specField.Names.Camel
113113

114114
var compareConfig *ackgenconfig.CompareFieldConfig
115-
fieldConfig := fieldConfigs[fieldName]
115+
116+
// TODO(amine,john): This is fragile. We actually need to have a way of
117+
// normalizing names in a lossless fashion...
118+
//
119+
// We chose to normalize names as camel case.
120+
fieldNameCamel := names.New(fieldName).Camel
121+
fieldConfig := fieldConfigs[fieldNameCamel]
116122
if fieldConfig != nil {
117123
compareConfig = fieldConfig.Compare
118124
}

pkg/generate/code/compare_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,35 @@ func TestCompareResource_APIGatewayv2_Route(t *testing.T) {
476476
)
477477
}
478478

479+
func TestCompareResource_IAM_OIDC_URL(t *testing.T) {
480+
assert := assert.New(t)
481+
require := require.New(t)
482+
483+
g := testutil.NewModelForServiceWithOptions(t, "iam", &testutil.TestingModelOptions{
484+
GeneratorConfigFile: "generator-oidc-url.yaml",
485+
})
486+
487+
crd := testutil.GetCRDByName(t, g, "OpenIDConnectProvider")
488+
require.NotNil(crd)
489+
expected := `
490+
if !ackcompare.SliceStringPEqual(a.ko.Spec.ClientIDList, b.ko.Spec.ClientIDList) {
491+
delta.Add("Spec.ClientIDList", a.ko.Spec.ClientIDList, b.ko.Spec.ClientIDList)
492+
}
493+
if !reflect.DeepEqual(a.ko.Spec.Tags, b.ko.Spec.Tags) {
494+
delta.Add("Spec.Tags", a.ko.Spec.Tags, b.ko.Spec.Tags)
495+
}
496+
if !ackcompare.SliceStringPEqual(a.ko.Spec.ThumbprintList, b.ko.Spec.ThumbprintList) {
497+
delta.Add("Spec.ThumbprintList", a.ko.Spec.ThumbprintList, b.ko.Spec.ThumbprintList)
498+
}
499+
`
500+
assert.Equal(
501+
expected,
502+
code.CompareResource(
503+
crd.Config(), crd, "delta", "a.ko", "b.ko", 1,
504+
),
505+
)
506+
}
507+
479508
func TestCompareResource_MemoryDB_User(t *testing.T) {
480509
assert := assert.New(t)
481510
require := require.New(t)
@@ -520,4 +549,4 @@ func TestCompareResource_MemoryDB_User(t *testing.T) {
520549
crd.Config(), crd, "delta", "a.ko", "b.ko", 1,
521550
),
522551
)
523-
}
552+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ignore:
2+
resource_names:
3+
- AccessKey
4+
- AccountAlias
5+
- Group
6+
- InstanceProfile
7+
- LoginProfile
8+
# OpenIDConnectProvider
9+
- Policy
10+
- PolicyVersion
11+
- Role
12+
- SAMLProvider
13+
- ServiceLinkedRole
14+
- ServiceSpecificCredential
15+
- User
16+
- VirtualMFADevice
17+
resources:
18+
OpenIDConnectProvider:
19+
fields:
20+
URL:
21+
compare:
22+
is_ignored: true

0 commit comments

Comments
 (0)