@@ -578,7 +578,7 @@ func TestTransformingManagedFieldsToParent(t *testing.T) {
578
578
},
579
579
},
580
580
{
581
- desc : "drops other fields if the api version is unknown" ,
581
+ desc : "drops the entry if the api version is unknown" ,
582
582
parent : []metav1.ManagedFieldsEntry {
583
583
{
584
584
Manager : "test" ,
@@ -636,14 +636,16 @@ func TestTransformingManagedFieldsToParent(t *testing.T) {
636
636
637
637
func TestTransformingManagedFieldsToParentMultiVersion (t * testing.T ) {
638
638
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
644
645
}{
645
646
{
646
- desc : "multi-version" ,
647
+ desc : "multi-version" ,
648
+ groupVersion : schema.GroupVersion {Group : "apps" , Version : "v1" },
647
649
mappings : ResourcePathMappings {
648
650
"apps/v1" : fieldpath .MakePathOrDie ("spec" , "the-replicas" ),
649
651
"apps/v2" : fieldpath .MakePathOrDie ("spec" , "not-the-replicas" ),
@@ -699,13 +701,71 @@ func TestTransformingManagedFieldsToParentMultiVersion(t *testing.T) {
699
701
},
700
702
},
701
703
},
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
+ },
702
762
}
703
763
704
764
for _ , test := range tests {
705
765
t .Run (test .desc , func (t * testing.T ) {
706
766
handler := NewScaleHandler (
707
767
test .parent ,
708
- schema. GroupVersion { Group : "apps" , Version : "v1" } ,
768
+ test . groupVersion ,
709
769
test .mappings ,
710
770
)
711
771
parentEntries , err := handler .ToParent (test .subresource )
0 commit comments