From 1fc5dc35078c598c01b1c5efb4e88a53aa6d976a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Fern=C3=A1ndez?= <7312236+fernandezcuesta@users.noreply.github.com> Date: Wed, 10 Jun 2026 17:41:39 +0200 Subject: [PATCH 1/2] feat: add Description field to SSA InjectedKey MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com> --- pkg/config/resource.go | 1 + pkg/types/builder.go | 6 ++- pkg/types/builder_test.go | 91 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/pkg/config/resource.go b/pkg/config/resource.go index c60dd671..7044c3bc 100644 --- a/pkg/config/resource.go +++ b/pkg/config/resource.go @@ -384,6 +384,7 @@ func setExternalTagsWithPaved(externalTags map[string]string, paved *fieldpath.P type InjectedKey struct { Key string DefaultValue string + Description string } // ListMapKeys is the list map keys when the server-side apply merge strategy diff --git a/pkg/types/builder.go b/pkg/types/builder.go index 18c1076d..8de6c393 100644 --- a/pkg/types/builder.go +++ b/pkg/types/builder.go @@ -120,10 +120,14 @@ func injectServerSideApplyListMergeKeys(cfg *config.Resource) error { //nolint:g return errors.Errorf("element schema for the object list %q already contains the argument key %q", f, k) } } + desc := descriptionInjectedKey + if s.ListMergeStrategy.ListMapKeys.InjectedKey.Description != "" { + desc = s.ListMergeStrategy.ListMapKeys.InjectedKey.Description + } el.Schema[s.ListMergeStrategy.ListMapKeys.InjectedKey.Key] = &schema.Schema{ Type: schema.TypeString, Required: true, - Description: descriptionInjectedKey, + Description: desc, } if s.ListMergeStrategy.ListMapKeys.InjectedKey.DefaultValue != "" { el.Schema[s.ListMergeStrategy.ListMapKeys.InjectedKey.Key].Default = s.ListMergeStrategy.ListMapKeys.InjectedKey.DefaultValue diff --git a/pkg/types/builder_test.go b/pkg/types/builder_test.go index 68d5b5dd..b9b5bc2d 100644 --- a/pkg/types/builder_test.go +++ b/pkg/types/builder_test.go @@ -209,6 +209,97 @@ func TestBuilder_generateTypeName(t *testing.T) { } } +func TestInjectServerSideApplyListMergeKeys(t *testing.T) { + type want struct { + description string + err error + } + cases := map[string]struct { + cfg *config.Resource + want want + }{ + "DefaultDescription": { + cfg: &config.Resource{ + TerraformResource: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule": { + Type: schema.TypeList, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": {Type: schema.TypeString}, + }, + }, + }, + }, + }, + ServerSideApplyMergeStrategies: map[string]config.MergeStrategy{ + "rule": { + ListMergeStrategy: config.ListMergeStrategy{ + MergeStrategy: config.ListTypeMap, + ListMapKeys: config.ListMapKeys{ + InjectedKey: config.InjectedKey{ + Key: "index", + }, + }, + }, + }, + }, + }, + want: want{ + description: descriptionInjectedKey, + }, + }, + "CustomDescription": { + cfg: &config.Resource{ + TerraformResource: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule": { + Type: schema.TypeList, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": {Type: schema.TypeString}, + }, + }, + }, + }, + }, + ServerSideApplyMergeStrategies: map[string]config.MergeStrategy{ + "rule": { + ListMergeStrategy: config.ListMergeStrategy{ + MergeStrategy: config.ListTypeMap, + ListMapKeys: config.ListMapKeys{ + InjectedKey: config.InjectedKey{ + Key: "index", + Description: "Custom description for the injected key.", + }, + }, + }, + }, + }, + }, + want: want{ + description: "Custom description for the injected key.", + }, + }, + } + for n, tc := range cases { + t.Run(n, func(t *testing.T) { + err := injectServerSideApplyListMergeKeys(tc.cfg) + if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { + t.Fatalf("injectServerSideApplyListMergeKeys(...): -want error, +got error: %s", diff) + } + if err != nil { + return + } + el := tc.cfg.TerraformResource.Schema["rule"].Elem.(*schema.Resource) + got := el.Schema["index"].Description + if diff := cmp.Diff(tc.want.description, got); diff != "" { + t.Errorf("injectServerSideApplyListMergeKeys(...) description: -want, +got: %s", diff) + } + }) + } +} + func TestBuild(t *testing.T) { type args struct { crdScope CRDScope From 28ac43b85124fc2c1730ba6e867bdfdebb60677a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Fern=C3=A1ndez?= <7312236+fernandezcuesta@users.noreply.github.com> Date: Thu, 11 Jun 2026 09:09:28 +0200 Subject: [PATCH 2/2] chore: coderabbitai review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com> --- pkg/config/resource.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/config/resource.go b/pkg/config/resource.go index 7044c3bc..9ede7f1a 100644 --- a/pkg/config/resource.go +++ b/pkg/config/resource.go @@ -384,7 +384,9 @@ func setExternalTagsWithPaved(externalTags map[string]string, paved *fieldpath.P type InjectedKey struct { Key string DefaultValue string - Description string + // Description is the OpenAPI schema description for the injected list-map key field. + // If empty, defaults to a standard description about server-side apply merge behavior. + Description string } // ListMapKeys is the list map keys when the server-side apply merge strategy