@@ -23,20 +23,22 @@ import (
23
23
"sigs.k8s.io/controller-tools/pkg/markers"
24
24
)
25
25
26
- // ToplogyMarkers list topology markers (i.e. markers that specify if a
27
- // list is an associative-list or a set, or if a map is atomic or not).
26
+ // TopologyMarkers specify topology markers (i.e. markers that describe if a
27
+ // list behaves as an associative-list or a set, if a map is atomic or not).
28
28
var TopologyMarkers = []* definitionWithHelp {
29
29
must (markers .MakeDefinition ("listMapKey" , markers .DescribesField , ListMapKey ("" ))).
30
30
WithHelp (ListMapKey ("" ).Help ()),
31
31
must (markers .MakeDefinition ("listType" , markers .DescribesField , ListType ("" ))).
32
32
WithHelp (ListType ("" ).Help ()),
33
+ must (markers .MakeDefinition ("mapType" , markers .DescribesField , MapType ("" ))).
34
+ WithHelp (MapType ("" ).Help ()),
33
35
}
34
36
35
37
func init () {
36
38
AllDefinitions = append (AllDefinitions , TopologyMarkers ... )
37
39
}
38
40
39
- // +controllertools:marker:generateHelp:category="CRD topology "
41
+ // +controllertools:marker:generateHelp:category="CRD processing "
40
42
41
43
// ListType specifies the type of data-structure that the list
42
44
// represents (map, set, atomic).
@@ -54,7 +56,7 @@ func init() {
54
56
// are typically manipulated together by the same actor.
55
57
type ListType string
56
58
57
- // +controllertools:marker:generateHelp:category="CRD topology "
59
+ // +controllertools:marker:generateHelp:category="CRD processing "
58
60
59
61
// ListMapKey specifies the keys to map listTypes.
60
62
//
@@ -63,6 +65,22 @@ type ListType string
63
65
// should be scalar types.
64
66
type ListMapKey string
65
67
68
+ // +controllertools:marker:generateHelp:category="CRD processing"
69
+
70
+ // MapType specifies the level of atomicity of the map;
71
+ // i.e. whether each item in the map is independent of the others,
72
+ // or all fields are treated as a single unit.
73
+ //
74
+ // Possible values:
75
+ //
76
+ // - "granular": items in the map are independent of each other,
77
+ // and can be manipulated by different actors.
78
+ // This is the default behavior.
79
+ //
80
+ // - "atomic": all fields are treated as one unit.
81
+ // Any changes have to replace the entire map.
82
+ type MapType string
83
+
66
84
func (l ListType ) ApplyToSchema (schema * apiext.JSONSchemaProps ) error {
67
85
if schema .Type != "array" {
68
86
return fmt .Errorf ("must apply listType to an array" )
@@ -87,3 +105,18 @@ func (l ListMapKey) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
87
105
schema .XListMapKeys = append (schema .XListMapKeys , string (l ))
88
106
return nil
89
107
}
108
+
109
+ func (m MapType ) ApplyToSchema (schema * apiext.JSONSchemaProps ) error {
110
+ if schema .Type != "object" {
111
+ return fmt .Errorf ("must apply mapType to an object" )
112
+ }
113
+
114
+ if m != "atomic" && m != "granular" {
115
+ return fmt .Errorf (`MapType must be either "granular" or "atomic"` )
116
+ }
117
+
118
+ p := string (m )
119
+ schema .XMapType = & p
120
+
121
+ return nil
122
+ }
0 commit comments