From 5150500b82b67cf882591ef7ed751a07fb52db4a Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Fri, 1 Dec 2023 03:01:30 +0300 Subject: [PATCH] Fix kubebuilder topological markers: use "=" instead of ":" between tokens - Do not add topological markers for sensitive fields Signed-off-by: Alper Rifat Ulucinar --- pkg/types/field.go | 6 ++++-- pkg/types/markers/ssa.go | 10 +++++----- pkg/types/markers/ssa_test.go | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg/types/field.go b/pkg/types/field.go index d2ed2325..97d6e9c9 100644 --- a/pkg/types/field.go +++ b/pkg/types/field.go @@ -152,7 +152,9 @@ func NewField(g *Builder, cfg *config.Resource, r *resource, sch *schema.Schema, f.FieldType = fieldType f.InitType = initType - AddServerSideApplyMarkers(f) + if !sch.Sensitive { + AddServerSideApplyMarkers(f) + } return f, nil } @@ -173,7 +175,7 @@ func AddServerSideApplyMarkers(f *Field) { case schema.TypeSet: if es, ok := f.Schema.Elem.(*schema.Schema); ok { switch es.Type { //nolint:exhaustive - // We assume scalar types can be granular maps. + // We assume scalar types can be granular sets. case schema.TypeString, schema.TypeBool, schema.TypeInt, schema.TypeFloat: f.Comment.ServerSideApplyOptions.ListType = ptr.To[markers.ListType](markers.ListTypeSet) } diff --git a/pkg/types/markers/ssa.go b/pkg/types/markers/ssa.go index c6891fc4..6a26c875 100644 --- a/pkg/types/markers/ssa.go +++ b/pkg/types/markers/ssa.go @@ -20,7 +20,7 @@ const ( // elements. ListTypeSet ListType = "set" - // ListTypeSet can be granularly merged, and different managers can own + // ListTypeMap can be granularly merged, and different managers can own // different elements in the list. The list can include only nested types // (i.e. objects). ListTypeMap ListType = "map" @@ -68,19 +68,19 @@ func (o ServerSideApplyOptions) String() string { m := "" if o.ListType != nil { - m += fmt.Sprintf("+listType:%s\n", *o.ListType) + m += fmt.Sprintf("+listType=%s\n", *o.ListType) } for _, k := range o.ListMapKey { - m += fmt.Sprintf("+listMapKey:%s\n", k) + m += fmt.Sprintf("+listMapKey=%s\n", k) } if o.MapType != nil { - m += fmt.Sprintf("+mapType:%s\n", *o.MapType) + m += fmt.Sprintf("+mapType=%s\n", *o.MapType) } if o.StructType != nil { - m += fmt.Sprintf("+structType:%s\n", *o.StructType) + m += fmt.Sprintf("+structType=%s\n", *o.StructType) } return m diff --git a/pkg/types/markers/ssa_test.go b/pkg/types/markers/ssa_test.go index 062d808c..dbfa5513 100644 --- a/pkg/types/markers/ssa_test.go +++ b/pkg/types/markers/ssa_test.go @@ -20,20 +20,20 @@ func TestServerSideApplyOptions(t *testing.T) { o: ServerSideApplyOptions{ MapType: ptr.To[MapType](MapTypeAtomic), }, - want: "+mapType:atomic\n", + want: "+mapType=atomic\n", }, "StructType": { o: ServerSideApplyOptions{ StructType: ptr.To[StructType](StructTypeAtomic), }, - want: "+structType:atomic\n", + want: "+structType=atomic\n", }, "ListType": { o: ServerSideApplyOptions{ ListType: ptr.To[ListType](ListTypeMap), ListMapKey: []string{"name", "coolness"}, }, - want: "+listType:map\n+listMapKey:name\n+listMapKey:coolness\n", + want: "+listType=map\n+listMapKey=name\n+listMapKey=coolness\n", }, }