forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[client-go] Add apps.Scale support to Scale client
apps/v1betaX inadventertently contains its own variant of Scale. In order to support scaling Deployments, ReplicaSets, etc, we need to support these versions of Scale as well.
- Loading branch information
1 parent
32b47a3
commit 2c9fc43
Showing
20 changed files
with
764 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"doc.go", | ||
"register.go", | ||
], | ||
importpath = "k8s.io/client-go/scale/scheme/appsint", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//vendor/k8s.io/api/apps/v1beta2:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", | ||
"//vendor/k8s.io/client-go/scale/scheme:go_default_library", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "package-srcs", | ||
srcs = glob(["**"]), | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
filegroup( | ||
name = "all-srcs", | ||
srcs = [":package-srcs"], | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package appsint contains the necessary scaffolding of the | ||
// internal version of extensions as required by conversion logic. | ||
// It doesn't have any of its own types -- it's just necessary to | ||
// get the expected behavoir out of runtime.Scheme.ConvertToVersion | ||
// and associated methods. | ||
package appsint |
53 changes: 53 additions & 0 deletions
53
staging/src/k8s.io/client-go/scale/scheme/appsint/register.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package appsint | ||
|
||
import ( | ||
appsv1beta2 "k8s.io/api/apps/v1beta2" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
scalescheme "k8s.io/client-go/scale/scheme" | ||
) | ||
|
||
// GroupName is the group name use in this package | ||
const GroupName = appsv1beta2.GroupName | ||
|
||
// SchemeGroupVersion is group version used to register these objects | ||
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} | ||
|
||
// Kind takes an unqualified kind and returns a Group qualified GroupKind | ||
func Kind(kind string) schema.GroupKind { | ||
return SchemeGroupVersion.WithKind(kind).GroupKind() | ||
} | ||
|
||
// Resource takes an unqualified resource and returns a Group qualified GroupResource | ||
func Resource(resource string) schema.GroupResource { | ||
return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
} | ||
|
||
var ( | ||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) | ||
|
||
// Adds the list of known types to api.Scheme. | ||
func addKnownTypes(scheme *runtime.Scheme) error { | ||
scheme.AddKnownTypes(SchemeGroupVersion, | ||
&scalescheme.Scale{}, | ||
) | ||
return nil | ||
} |
35 changes: 35 additions & 0 deletions
35
staging/src/k8s.io/client-go/scale/scheme/appsv1beta1/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"conversion.go", | ||
"doc.go", | ||
"register.go", | ||
"zz_generated.conversion.go", | ||
], | ||
importpath = "k8s.io/client-go/scale/scheme/appsv1beta1", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//vendor/k8s.io/api/apps/v1beta1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", | ||
"//vendor/k8s.io/client-go/scale/scheme:go_default_library", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "package-srcs", | ||
srcs = glob(["**"]), | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
filegroup( | ||
name = "all-srcs", | ||
srcs = [":package-srcs"], | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:public"], | ||
) |
87 changes: 87 additions & 0 deletions
87
staging/src/k8s.io/client-go/scale/scheme/appsv1beta1/conversion.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package appsv1beta1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1beta1 "k8s.io/api/apps/v1beta1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/conversion" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
scheme "k8s.io/client-go/scale/scheme" | ||
) | ||
|
||
// addConversions registers conversions between the internal version | ||
// of Scale and supported external versions of Scale. | ||
func addConversionFuncs(scheme *runtime.Scheme) error { | ||
err := scheme.AddConversionFuncs( | ||
Convert_scheme_ScaleStatus_To_v1beta1_ScaleStatus, | ||
Convert_v1beta1_ScaleStatus_To_scheme_ScaleStatus, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
func Convert_scheme_ScaleStatus_To_v1beta1_ScaleStatus(in *scheme.ScaleStatus, out *v1beta1.ScaleStatus, s conversion.Scope) error { | ||
out.Replicas = in.Replicas | ||
out.Selector = nil | ||
out.TargetSelector = "" | ||
if in.Selector != nil { | ||
if in.Selector.MatchExpressions == nil || len(in.Selector.MatchExpressions) == 0 { | ||
out.Selector = in.Selector.MatchLabels | ||
} | ||
|
||
selector, err := metav1.LabelSelectorAsSelector(in.Selector) | ||
if err != nil { | ||
return fmt.Errorf("invalid label selector: %v", err) | ||
} | ||
out.TargetSelector = selector.String() | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Convert_v1beta1_ScaleStatus_To_scheme_ScaleStatus(in *v1beta1.ScaleStatus, out *scheme.ScaleStatus, s conversion.Scope) error { | ||
out.Replicas = in.Replicas | ||
|
||
// Normally when 2 fields map to the same internal value we favor the old field, since | ||
// old clients can't be expected to know about new fields but clients that know about the | ||
// new field can be expected to know about the old field (though that's not quite true, due | ||
// to kubectl apply). However, these fields are readonly, so any non-nil value should work. | ||
if in.TargetSelector != "" { | ||
labelSelector, err := metav1.ParseToLabelSelector(in.TargetSelector) | ||
if err != nil { | ||
out.Selector = nil | ||
return fmt.Errorf("failed to parse target selector: %v", err) | ||
} | ||
out.Selector = labelSelector | ||
} else if in.Selector != nil { | ||
out.Selector = new(metav1.LabelSelector) | ||
selector := make(map[string]string) | ||
for key, val := range in.Selector { | ||
selector[key] = val | ||
} | ||
out.Selector.MatchLabels = selector | ||
} else { | ||
out.Selector = nil | ||
} | ||
|
||
return nil | ||
} |
20 changes: 20 additions & 0 deletions
20
staging/src/k8s.io/client-go/scale/scheme/appsv1beta1/doc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// +k8s:conversion-gen=k8s.io/kubernetes/vendor/k8s.io/client-go/scale/scheme | ||
// +k8s:conversion-gen-external-types=../../../../../k8s.io/api/apps/v1beta1 | ||
|
||
package appsv1beta1 // import "k8s.io/client-go/scale/scheme/appsv1beta1" |
Oops, something went wrong.