Skip to content

Commit ece451c

Browse files
authored
Add newline to generated resource guards (aws-controllers-k8s#695)
- Update resourceIsGuarded to start output with a newline to avoid generated code ending up on same line as previous characters in template. Issue #, if available: Description of changes: When no `pre_build` hook was present the code generated by the `updatable` and `deletable` resource guard configs would end up on the same line as the function signature. This PR updates the generated resource guard code to include a new line to avoid collisions with the function signature when no hook code is present. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent ac02b64 commit ece451c

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

pkg/generate/code/resource_guard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func resourceIsGuarded(
126126
return "", fmt.Errorf("unknown config key %q", configKey)
127127
}
128128

129+
out += "\n"
129130
for _, condCfg := range conditions {
130131
if condCfg.Path == nil || *condCfg.Path == "" {
131132
return "", fmt.Errorf(

pkg/generate/code/resource_guard_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestResourceIsUpdateable_SingleCondition(t *testing.T) {
3131
crd := testutil.GetCRDByName(t, g, "Function")
3232
require.NotNil(crd)
3333

34-
expected := ` if latest.ko.Status.State != nil {
34+
expected := "\n" + ` if latest.ko.Status.State != nil {
3535
if !ackutil.InStrings(*latest.ko.Status.State, []string{"Active"}) {
3636
return nil, ackrequeue.NeededAfter(
3737
fmt.Errorf("resource is in %s state, cannot be updated",
@@ -55,7 +55,7 @@ func TestResourceIsDeletable_SingleCondition(t *testing.T) {
5555
crd := testutil.GetCRDByName(t, g, "Function")
5656
require.NotNil(crd)
5757

58-
expected := ` if r.ko.Status.State != nil {
58+
expected := "\n" + ` if r.ko.Status.State != nil {
5959
if !ackutil.InStrings(*r.ko.Status.State, []string{"Active", "Failed"}) {
6060
return nil, ackrequeue.NeededAfter(
6161
fmt.Errorf("resource is in %s state, cannot be deleted",
@@ -82,7 +82,7 @@ func TestResourceIsUpdateable_MultipleConditions_CustomRequeue(t *testing.T) {
8282
crd := testutil.GetCRDByName(t, g, "Function")
8383
require.NotNil(crd)
8484

85-
expected := ` if latest.ko.Status.State != nil {
85+
expected := "\n" + ` if latest.ko.Status.State != nil {
8686
if !ackutil.InStrings(*latest.ko.Status.State, []string{"Active"}) {
8787
return nil, ackrequeue.NeededAfter(
8888
fmt.Errorf("resource is in %s state, cannot be updated",
@@ -180,7 +180,7 @@ func TestResourceIsDeletable_MultipleConditions_CustomRequeue(t *testing.T) {
180180
crd := testutil.GetCRDByName(t, g, "Function")
181181
require.NotNil(crd)
182182

183-
expected := ` if r.ko.Status.State != nil {
183+
expected := "\n" + ` if r.ko.Status.State != nil {
184184
if !ackutil.InStrings(*r.ko.Status.State, []string{"Active"}) {
185185
return nil, ackrequeue.NeededAfter(
186186
fmt.Errorf("resource is in %s state, cannot be deleted",

0 commit comments

Comments
 (0)