Skip to content

Commit

Permalink
Fix kubebuilder topological markers: use "=" instead of ":" between t…
Browse files Browse the repository at this point in the history
…okens

- Do not add topological markers for sensitive fields

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Dec 4, 2023
1 parent 8ef1aa2 commit 5150500
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions pkg/types/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/types/markers/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/types/markers/ssa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down

0 comments on commit 5150500

Please sign in to comment.