@@ -35,22 +35,22 @@ var _ meta.RESTMapper = &ControllerRESTMapper{}
35
35
36
36
// KindFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
37
37
func (m * ControllerRESTMapper ) KindFor (resource schema.GroupVersionResource ) (schema.GroupVersionKind , error ) {
38
- return schema.GroupVersionKind {}, fmt .Errorf ("ControllerRESTMaper does not support KindFor operation" )
38
+ return schema.GroupVersionKind {}, fmt .Errorf ("ControllerRESTMapper does not support KindFor operation" )
39
39
}
40
40
41
41
// KindsFor takes a partial resource and returns the list of potential kinds in priority order
42
42
func (m * ControllerRESTMapper ) KindsFor (resource schema.GroupVersionResource ) ([]schema.GroupVersionKind , error ) {
43
- return nil , fmt .Errorf ("ControllerRESTMaper does not support KindsFor operation" )
43
+ return nil , fmt .Errorf ("ControllerRESTMapper does not support KindsFor operation" )
44
44
}
45
45
46
46
// ResourceFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
47
47
func (m * ControllerRESTMapper ) ResourceFor (input schema.GroupVersionResource ) (schema.GroupVersionResource , error ) {
48
- return schema.GroupVersionResource {}, fmt .Errorf ("ControllerRESTMaper does not support ResourceFor operation" )
48
+ return schema.GroupVersionResource {}, fmt .Errorf ("ControllerRESTMapper does not support ResourceFor operation" )
49
49
}
50
50
51
51
// ResourcesFor takes a partial resource and returns the list of potential resource in priority order
52
52
func (m * ControllerRESTMapper ) ResourcesFor (input schema.GroupVersionResource ) ([]schema.GroupVersionResource , error ) {
53
- return nil , fmt .Errorf ("ControllerRESTMaper does not support ResourcesFor operation" )
53
+ return nil , fmt .Errorf ("ControllerRESTMapper does not support ResourcesFor operation" )
54
54
}
55
55
56
56
// RESTMapping identifies a preferred resource mapping for the provided group kind.
@@ -75,9 +75,53 @@ func (m *ControllerRESTMapper) RESTMapping(gk schema.GroupKind, versions ...stri
75
75
// version search is provided. Otherwise identifies a preferred resource mapping for
76
76
// the provided version(s).
77
77
func (m * ControllerRESTMapper ) RESTMappings (gk schema.GroupKind , versions ... string ) ([]* meta.RESTMapping , error ) {
78
- return nil , fmt .Errorf ("ControllerRESTMaper does not support RESTMappings operation" )
78
+ ctx := context .TODO ()
79
+
80
+ if len (versions ) != 0 {
81
+ return nil , fmt .Errorf ("ControllerRESTMapper does not support RESTMappings operation with specified versions" )
82
+ }
83
+
84
+ group , found , err := m .cache .findGroupInfo (ctx , m .uncached , gk .Group )
85
+ if err != nil {
86
+ return nil , err
87
+ }
88
+ if ! found {
89
+ return nil , & meta.NoResourceMatchError {PartialResource : schema.GroupVersionResource {Group : gk .Group , Resource : gk .Kind }}
90
+ }
91
+
92
+ var mappings []* meta.RESTMapping
93
+
94
+ if group .PreferredVersion .Version != "" {
95
+ gv := schema.GroupVersion {Group : gk .Group , Version : group .PreferredVersion .Version }
96
+ mapping , err := m .cache .findRESTMapping (ctx , m .uncached , gv , gk .Kind )
97
+ if err != nil {
98
+ return nil , err
99
+ }
100
+ if mapping != nil {
101
+ mappings = append (mappings , mapping )
102
+ }
103
+ }
104
+
105
+ for i := range group .Versions {
106
+ gv := schema.GroupVersion {Group : gk .Group , Version : group .Versions [i ].Version }
107
+ if gv .Version == group .PreferredVersion .Version {
108
+ continue
109
+ }
110
+ mapping , err := m .cache .findRESTMapping (ctx , m .uncached , gv , gk .Kind )
111
+ if err != nil {
112
+ return nil , err
113
+ }
114
+ if mapping != nil {
115
+ mappings = append (mappings , mapping )
116
+ }
117
+ }
118
+
119
+ if len (mappings ) == 0 {
120
+ return nil , & meta.NoResourceMatchError {PartialResource : schema.GroupVersionResource {Group : gk .Group , Resource : gk .Kind }}
121
+ }
122
+ return mappings , nil
79
123
}
80
124
81
125
func (m * ControllerRESTMapper ) ResourceSingularizer (resource string ) (singular string , err error ) {
82
- return "" , fmt .Errorf ("ControllerRESTMaper does not support ResourceSingularizer operation" )
126
+ return "" , fmt .Errorf ("ControllerRESTMapper does not support ResourceSingularizer operation" )
83
127
}
0 commit comments