mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Merge pull request #109957 from adammw/adammw/disruption-implements-scale
disruptioncontroller: check for scale subresource correctly
This commit is contained in:
commit
375fd32b9f
@ -297,14 +297,13 @@ func (dc *DisruptionController) getScaleController(ctx context.Context, controll
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
gr := mapping.Resource.GroupResource()
|
gr := mapping.Resource.GroupResource()
|
||||||
|
|
||||||
scale, err := dc.scaleNamespacer.Scales(namespace).Get(ctx, gr, controllerRef.Name, metav1.GetOptions{})
|
scale, err := dc.scaleNamespacer.Scales(namespace).Get(ctx, gr, controllerRef.Name, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsNotFound(err) {
|
if errors.IsNotFound(err) {
|
||||||
// The IsNotFound error can mean either that the resource does not exist,
|
// The IsNotFound error can mean either that the resource does not exist,
|
||||||
// or it exist but doesn't implement the scale subresource. We check which
|
// or it exist but doesn't implement the scale subresource. We check which
|
||||||
// situation we are facing so we can give an appropriate error message.
|
// situation we are facing so we can give an appropriate error message.
|
||||||
isScale, err := dc.implementsScale(gv, controllerRef.Kind)
|
isScale, err := dc.implementsScale(mapping.Resource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -321,19 +320,26 @@ func (dc *DisruptionController) getScaleController(ctx context.Context, controll
|
|||||||
return &controllerAndScale{scale.UID, scale.Spec.Replicas}, nil
|
return &controllerAndScale{scale.UID, scale.Spec.Replicas}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DisruptionController) implementsScale(gv schema.GroupVersion, kind string) (bool, error) {
|
func (dc *DisruptionController) implementsScale(gvr schema.GroupVersionResource) (bool, error) {
|
||||||
resourceList, err := dc.discoveryClient.ServerResourcesForGroupVersion(gv.String())
|
resourceList, err := dc.discoveryClient.ServerResourcesForGroupVersion(gvr.GroupVersion().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scaleSubresourceName := fmt.Sprintf("%s/scale", gvr.Resource)
|
||||||
for _, resource := range resourceList.APIResources {
|
for _, resource := range resourceList.APIResources {
|
||||||
if resource.Kind != kind {
|
if resource.Name != scaleSubresourceName {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(resource.Name, "/scale") {
|
|
||||||
|
for _, scaleGv := range scaleclient.NewScaleConverter().ScaleVersions() {
|
||||||
|
if resource.Group == scaleGv.Group &&
|
||||||
|
resource.Version == scaleGv.Version &&
|
||||||
|
resource.Kind == "Scale" {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,6 +663,25 @@ func TestScaleFinderNoResource(t *testing.T) {
|
|||||||
expectError bool
|
expectError bool
|
||||||
}{
|
}{
|
||||||
"resource implements scale": {
|
"resource implements scale": {
|
||||||
|
apiResources: []metav1.APIResource{
|
||||||
|
{
|
||||||
|
Kind: customGVK.Kind,
|
||||||
|
Name: resourceName + "/status",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: "Scale",
|
||||||
|
Group: autoscalingapi.GroupName,
|
||||||
|
Version: "v1",
|
||||||
|
Name: resourceName + "/scale",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Kind: customGVK.Kind,
|
||||||
|
Name: resourceName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectError: false,
|
||||||
|
},
|
||||||
|
"resource implements unsupported data format for scale subresource": {
|
||||||
apiResources: []metav1.APIResource{
|
apiResources: []metav1.APIResource{
|
||||||
{
|
{
|
||||||
Kind: customGVK.Kind,
|
Kind: customGVK.Kind,
|
||||||
@ -673,7 +692,7 @@ func TestScaleFinderNoResource(t *testing.T) {
|
|||||||
Name: resourceName + "/scale",
|
Name: resourceName + "/scale",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectError: false,
|
expectError: true,
|
||||||
},
|
},
|
||||||
"resource does not implement scale": {
|
"resource does not implement scale": {
|
||||||
apiResources: []metav1.APIResource{
|
apiResources: []metav1.APIResource{
|
||||||
|
Loading…
Reference in New Issue
Block a user