Check request info when updating managed fields during scale

- Test all versions to make sure each resource version is in the
  mappings
- Fail when request info contains an unrecognized version. We have tests
  that guarantee that all known versions are in the mappings. If we
  get a version in request info that is not there we should fail fast to
  prevent inconsistent behaviour (e.g. for some reason the mappings is
  not up to date).

Ensure all known versions are in mappings

Kubernetes-commit: 09649e58b5a1368929e194991a763afc8011795e
This commit is contained in:
Andrea Nodari 2021-03-11 16:51:46 +01:00 committed by Kubernetes Publisher
parent ddd271ff4e
commit 8c0975e184
1 changed files with 9 additions and 9 deletions

View File

@ -39,17 +39,17 @@ type ResourcePathMappings map[string]fieldpath.Path
// ScaleHandler manages the conversion of managed fields between a main
// resource and the scale subresource
type ScaleHandler struct {
parentEntries []metav1.ManagedFieldsEntry
defaultGroupVersion schema.GroupVersion
mappings ResourcePathMappings
parentEntries []metav1.ManagedFieldsEntry
groupVersion schema.GroupVersion
mappings ResourcePathMappings
}
// NewScaleHandler creates a new ScaleHandler
func NewScaleHandler(parentEntries []metav1.ManagedFieldsEntry, defaultGroupVersion schema.GroupVersion, mappings ResourcePathMappings) *ScaleHandler {
func NewScaleHandler(parentEntries []metav1.ManagedFieldsEntry, groupVersion schema.GroupVersion, mappings ResourcePathMappings) *ScaleHandler {
return &ScaleHandler{
parentEntries: parentEntries,
defaultGroupVersion: defaultGroupVersion,
mappings: mappings,
parentEntries: parentEntries,
groupVersion: groupVersion,
mappings: mappings,
}
}
@ -136,8 +136,8 @@ func (h *ScaleHandler) ToParent(scaleEntries []metav1.ManagedFieldsEntry) ([]met
for manager, versionedSet := range scaleFields {
newVersionedSet := fieldpath.NewVersionedSet(
fieldpath.NewSet(h.mappings[h.defaultGroupVersion.String()]),
fieldpath.APIVersion(h.defaultGroupVersion.String()),
fieldpath.NewSet(h.mappings[h.groupVersion.String()]),
fieldpath.APIVersion(h.groupVersion.String()),
versionedSet.Applied(),
)
f[manager] = newVersionedSet