You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
return schema.GroupVersionKind{}, fmt.Errorf("cannot create group-version-kind for unversioned type %T", obj)
141
142
}
142
143
143
-
iflen(gvks) <1 {
144
-
return schema.GroupVersionKind{}, fmt.Errorf("no group-version-kinds associated with type %T", obj)
145
-
}
146
-
iflen(gvks) >1 {
147
-
// this should only trigger for things like metav1.XYZ --
148
-
// normal versioned types should be fine
144
+
switch {
145
+
caselen(gvks) <1:
146
+
// If the object has no GVK, the object might not have been registered with the scheme.
147
+
// or it's not a valid object.
148
+
return schema.GroupVersionKind{}, fmt.Errorf("no GroupVersionKind associated with Go type %T, was the type registered with the Scheme?", obj)
149
+
caselen(gvks) >1:
150
+
err:=fmt.Errorf("multiple GroupVersionKinds associated with Go type %T within the Scheme, this can happen when a type is registered for multiple GVKs at the same time", obj)
// If the base object has a GVK, check if it's in the list of GVKs before using it.
156
+
for_, gvk:=rangegvks {
157
+
ifgvk==currentGVK {
158
+
returngvk, nil
159
+
}
160
+
}
161
+
162
+
return schema.GroupVersionKind{}, fmt.Errorf(
163
+
"%w: the object's supplied GroupVersionKind %q was not found in the Scheme's list; refusing to guess at one: %q", err, currentGVK, gvks)
164
+
}
165
+
166
+
// This should only trigger for things like metav1.XYZ --
167
+
// normal versioned types should be fine.
168
+
//
169
+
// See https://github.com/kubernetes-sigs/controller-runtime/issues/362
170
+
// for more information.
149
171
return schema.GroupVersionKind{}, fmt.Errorf(
150
-
"multiple group-version-kinds associated with type %T, refusing to guess at one", obj)
172
+
"%w: callers can either fix their type registration to only register it once, or specify the GroupVersionKind to use for object passed in; refusing to guess at one: %q", err, gvks)
173
+
default:
174
+
// In any other case, we've found a single GVK for the object.
175
+
returngvks[0], nil
151
176
}
152
-
returngvks[0], nil
153
177
}
154
178
155
179
// RESTClientForGVK constructs a new rest.Interface capable of accessing the resource associated
0 commit comments