Content-Length: 574478 | pFad | http://github.com/kubernetes/kubernetes/commit/5b666a61a170f61c7e223085478b24a03612fa99

7B Add nil path to mapping when a CR has no "scale" subresource · kubernetes/kubernetes@5b666a6 · GitHub
Skip to content

Commit 5b666a6

Browse files
committed
Add nil path to mapping when a CR has no "scale" subresource
This is to prevent the ScaleHandler to drop the entry. In this way entries just get ignored.
1 parent c10dd88 commit 5b666a6

File tree

3 files changed

+76
-13
lines changed

3 files changed

+76
-13
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
709709
return nil, fmt.Errorf("the server could not properly serve the CR subresources")
710710
}
711711
if subresources == nil || subresources.Scale == nil {
712+
replicasPathInCustomResource[schema.GroupVersion{Group: crd.Spec.Group, Version: v.Name}.String()] = nil
712713
continue
713714
}
714715
path := fieldpath.Path{}

staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/scalehandler.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func (h *ScaleHandler) ToSubresource() ([]metav1.ManagedFieldsEntry, error) {
6969
t := map[string]*metav1.Time{}
7070
for manager, versionedSet := range managed.Fields() {
7171
path, ok := h.mappings[string(versionedSet.APIVersion())]
72-
// Drop the field if the APIVersion of the managed field is unknown
73-
if !ok {
72+
// Skip the entry if the APIVersion is unknown
73+
if !ok || path == nil {
7474
continue
7575
}
7676

@@ -110,13 +110,15 @@ func (h *ScaleHandler) ToParent(scaleEntries []metav1.ManagedFieldsEntry) ([]met
110110
for manager, versionedSet := range parentFields {
111111
// Get the main resource "replicas" path
112112
path, ok := h.mappings[string(versionedSet.APIVersion())]
113-
// Drop the field if the APIVersion of the managed field is unknown
113+
// Drop the entry if the APIVersion is unknown.
114114
if !ok {
115115
continue
116116
}
117117

118-
// If the parent entry does not have the replicas path, just keep it as it is
119-
if !versionedSet.Set().Has(path) {
118+
// If the parent entry does not have the replicas path or it is nil, just
119+
// keep it as it is. The path is nil for Custom Resources without scale
120+
// subresource.
121+
if path == nil || !versionedSet.Set().Has(path) {
120122
f[manager] = versionedSet
121123
t[manager] = decodedParentEntries.Times()[manager]
122124
continue

staging/src/k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/scalehandler_test.go

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ func TestTransformingManagedFieldsToParent(t *testing.T) {
578578
},
579579
},
580580
{
581-
desc: "drops other fields if the api version is unknown",
581+
desc: "drops the entry if the api version is unknown",
582582
parent: []metav1.ManagedFieldsEntry{
583583
{
584584
Manager: "test",
@@ -636,14 +636,16 @@ func TestTransformingManagedFieldsToParent(t *testing.T) {
636636

637637
func TestTransformingManagedFieldsToParentMultiVersion(t *testing.T) {
638638
tests := []struct {
639-
desc string
640-
mappings ResourcePathMappings
641-
parent []metav1.ManagedFieldsEntry
642-
subresource []metav1.ManagedFieldsEntry
643-
expected []metav1.ManagedFieldsEntry
639+
desc string
640+
groupVersion schema.GroupVersion
641+
mappings ResourcePathMappings
642+
parent []metav1.ManagedFieldsEntry
643+
subresource []metav1.ManagedFieldsEntry
644+
expected []metav1.ManagedFieldsEntry
644645
}{
645646
{
646-
desc: "multi-version",
647+
desc: "multi-version",
648+
groupVersion: schema.GroupVersion{Group: "apps", Version: "v1"},
647649
mappings: ResourcePathMappings{
648650
"apps/v1": fieldpath.MakePathOrDie("spec", "the-replicas"),
649651
"apps/v2": fieldpath.MakePathOrDie("spec", "not-the-replicas"),
@@ -699,13 +701,71 @@ func TestTransformingManagedFieldsToParentMultiVersion(t *testing.T) {
699701
},
700702
},
701703
},
704+
{
705+
desc: "Custom resource without scale subresource, scaling a version with `scale`",
706+
groupVersion: schema.GroupVersion{Group: "mygroup", Version: "v1"},
707+
mappings: ResourcePathMappings{
708+
"mygroup/v1": fieldpath.MakePathOrDie("spec", "the-replicas"),
709+
"mygroup/v2": nil,
710+
},
711+
parent: []metav1.ManagedFieldsEntry{
712+
{
713+
Manager: "test",
714+
Operation: metav1.ManagedFieldsOperationApply,
715+
APIVersion: "mygroup/v1",
716+
FieldsType: "FieldsV1",
717+
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:the-replicas":{},"f:selector":{}}}`)},
718+
},
719+
{
720+
Manager: "test-other",
721+
Operation: metav1.ManagedFieldsOperationApply,
722+
APIVersion: "mygroup/v2",
723+
FieldsType: "FieldsV1",
724+
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:test-other":{}}}`)},
725+
},
726+
},
727+
subresource: []metav1.ManagedFieldsEntry{
728+
{
729+
Manager: "scale",
730+
Operation: metav1.ManagedFieldsOperationUpdate,
731+
APIVersion: "autoscaling/v1",
732+
FieldsType: "FieldsV1",
733+
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:replicas":{}}}`)},
734+
Subresource: "scale",
735+
},
736+
},
737+
expected: []metav1.ManagedFieldsEntry{
738+
{
739+
Manager: "test",
740+
Operation: metav1.ManagedFieldsOperationApply,
741+
APIVersion: "mygroup/v1",
742+
FieldsType: "FieldsV1",
743+
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:selector":{}}}`)},
744+
},
745+
{
746+
Manager: "test-other",
747+
Operation: metav1.ManagedFieldsOperationApply,
748+
APIVersion: "mygroup/v2",
749+
FieldsType: "FieldsV1",
750+
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:test-other":{}}}`)},
751+
},
752+
{
753+
Manager: "scale",
754+
Operation: metav1.ManagedFieldsOperationUpdate,
755+
APIVersion: "mygroup/v1",
756+
FieldsType: "FieldsV1",
757+
FieldsV1: &metav1.FieldsV1{Raw: []byte(`{"f:spec":{"f:the-replicas":{}}}`)},
758+
Subresource: "scale",
759+
},
760+
},
761+
},
702762
}
703763

704764
for _, test := range tests {
705765
t.Run(test.desc, func(t *testing.T) {
706766
handler := NewScaleHandler(
707767
test.parent,
708-
schema.GroupVersion{Group: "apps", Version: "v1"},
768+
test.groupVersion,
709769
test.mappings,
710770
)
711771
parentEntries, err := handler.ToParent(test.subresource)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/kubernetes/kubernetes/commit/5b666a61a170f61c7e223085478b24a03612fa99

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy