Skip to content

Commit 8825c71

Browse files
committed
When generating sagemaker controller using make build-controller SERVICE=sagemaker we can observe the following error:
``` Building Kubernetes API objects for sagemaker Generating deepcopy code for sagemaker Generating custom resource definitions for sagemaker Building service controller for sagemaker Error: template: /home/amine/source/github.com/aws-controllers-k8s/code-generator/templates/pkg/resource/delta.go.tpl:21:3: executing "/home/amine/source/github.com/aws-controllers-k8s/code-generator/templates/pkg/resource/delta.go.tpl" at <GoCodeCompare .CRD "delta" "a.ko" "b.ko" 1>: error calling GoCodeCompare: strings: negative Repeat count make: *** [Makefile:31: build-controller] Error 1 exit status 2 ``` The reason behind this error was the `code.CompareResource` function that decreases `indentLevel` and added a closing bracket for a code that is not generated. The concerned block of code is `else if * != nil && * != nil {` statement generated when `nilCode` is not empty (see https://github.com/aws-controllers-k8s/code-generator/blob/99008660b665867ec69d7829be819411ee90b6cf/pkg/generate/code/compare.go#L109-L118) To solve this problem we need to add closing bracket and decrease `indentLevel` only when `nilCode` is not empty.
1 parent 7c0986e commit 8825c71

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pkg/generate/code/compare.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,13 @@ func CompareResource(
169169
indentLevel,
170170
)
171171
}
172-
// }
173-
out += fmt.Sprintf(
174-
"%s}\n", indent,
175-
)
176-
indentLevel--
172+
if nilCode != "" {
173+
// }
174+
out += fmt.Sprintf(
175+
"%s}\n", indent,
176+
)
177+
indentLevel--
178+
}
177179
}
178180
return out
179181
}
@@ -218,7 +220,6 @@ func compareNil(
218220
case "list", "blob":
219221
// for slice types, there is no nilability test. Instead, the normal
220222
// value test checks length of slices.
221-
return ""
222223
case "boolean", "string", "character", "byte", "short", "integer", "long",
223224
"float", "double", "timestamp", "structure", "map", "jsonvalue":
224225
// if ackcompare.HasNilDifference(a.ko.Spec.Name, b.ko.Spec.Name) {
@@ -431,6 +432,7 @@ func compareSlice(
431432
// TODO(jaypipes): Implement this by walking the slice of struct values
432433
// and comparing each struct individually, building up the fieldPath
433434
// appropriately...
435+
return ""
434436
default:
435437
panic("Unsupported shape type in generate.code.compareSlice: " + shape.Type)
436438
}
@@ -582,11 +584,13 @@ func compareStruct(
582584
indentLevel,
583585
)
584586
}
585-
// }
586-
out += fmt.Sprintf(
587-
"%s}\n", indent,
588-
)
589-
indentLevel--
587+
if nilCode != "" {
588+
// }
589+
out += fmt.Sprintf(
590+
"%s}\n", indent,
591+
)
592+
indentLevel--
593+
}
590594
}
591595
return out
592596
}

0 commit comments

Comments
 (0)