Commit 767082e8 authored by Janet Kuo's avatar Janet Kuo

Add new API version apps/v1beta2

Add a new API version apps/v1beta2 and enable it by default. apps/v1beta2 has a copy of apps/v1beta1 types, except for ControllerRevision.
parent 088141ca
...@@ -174,6 +174,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{ ...@@ -174,6 +174,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{
{Group: "extensions", Version: "v1beta1"}: {group: 17900, version: 1}, {Group: "extensions", Version: "v1beta1"}: {group: 17900, version: 1},
// to my knowledge, nothing below here collides // to my knowledge, nothing below here collides
{Group: "apps", Version: "v1beta1"}: {group: 17800, version: 1}, {Group: "apps", Version: "v1beta1"}: {group: 17800, version: 1},
{Group: "apps", Version: "v1beta2"}: {group: 17800, version: 1},
{Group: "authentication.k8s.io", Version: "v1"}: {group: 17700, version: 15}, {Group: "authentication.k8s.io", Version: "v1"}: {group: 17700, version: 15},
{Group: "authentication.k8s.io", Version: "v1beta1"}: {group: 17700, version: 9}, {Group: "authentication.k8s.io", Version: "v1beta1"}: {group: 17700, version: 9},
{Group: "authorization.k8s.io", Version: "v1"}: {group: 17600, version: 15}, {Group: "authorization.k8s.io", Version: "v1"}: {group: 17600, version: 15},
......
...@@ -55,6 +55,7 @@ v1 \ ...@@ -55,6 +55,7 @@ v1 \
admissionregistration.k8s.io/v1alpha1 \ admissionregistration.k8s.io/v1alpha1 \
admission.k8s.io/v1alpha1 \ admission.k8s.io/v1alpha1 \
apps/v1beta1 \ apps/v1beta1 \
apps/v1beta2 \
authentication.k8s.io/v1 \ authentication.k8s.io/v1 \
authentication.k8s.io/v1beta1 \ authentication.k8s.io/v1beta1 \
authorization.k8s.io/v1 \ authorization.k8s.io/v1 \
......
...@@ -82,6 +82,8 @@ func TestDefaulting(t *testing.T) { ...@@ -82,6 +82,8 @@ func TestDefaulting(t *testing.T) {
{Group: "", Version: "v1", Kind: "ServiceList"}: {}, {Group: "", Version: "v1", Kind: "ServiceList"}: {},
{Group: "apps", Version: "v1beta1", Kind: "StatefulSet"}: {}, {Group: "apps", Version: "v1beta1", Kind: "StatefulSet"}: {},
{Group: "apps", Version: "v1beta1", Kind: "StatefulSetList"}: {}, {Group: "apps", Version: "v1beta1", Kind: "StatefulSetList"}: {},
{Group: "apps", Version: "v1beta2", Kind: "StatefulSet"}: {},
{Group: "apps", Version: "v1beta2", Kind: "StatefulSetList"}: {},
{Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscaler"}: {}, {Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscaler"}: {},
{Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscalerList"}: {}, {Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscalerList"}: {},
{Group: "autoscaling", Version: "v2alpha1", Kind: "HorizontalPodAutoscaler"}: {}, {Group: "autoscaling", Version: "v2alpha1", Kind: "HorizontalPodAutoscaler"}: {},
...@@ -110,6 +112,8 @@ func TestDefaulting(t *testing.T) { ...@@ -110,6 +112,8 @@ func TestDefaulting(t *testing.T) {
{Group: "extensions", Version: "v1beta1", Kind: "DeploymentList"}: {}, {Group: "extensions", Version: "v1beta1", Kind: "DeploymentList"}: {},
{Group: "apps", Version: "v1beta1", Kind: "Deployment"}: {}, {Group: "apps", Version: "v1beta1", Kind: "Deployment"}: {},
{Group: "apps", Version: "v1beta1", Kind: "DeploymentList"}: {}, {Group: "apps", Version: "v1beta1", Kind: "DeploymentList"}: {},
{Group: "apps", Version: "v1beta2", Kind: "Deployment"}: {},
{Group: "apps", Version: "v1beta2", Kind: "DeploymentList"}: {},
{Group: "extensions", Version: "v1beta1", Kind: "ReplicaSet"}: {}, {Group: "extensions", Version: "v1beta1", Kind: "ReplicaSet"}: {},
{Group: "extensions", Version: "v1beta1", Kind: "ReplicaSetList"}: {}, {Group: "extensions", Version: "v1beta1", Kind: "ReplicaSetList"}: {},
{Group: "rbac.authorization.k8s.io", Version: "v1alpha1", Kind: "ClusterRoleBinding"}: {}, {Group: "rbac.authorization.k8s.io", Version: "v1alpha1", Kind: "ClusterRoleBinding"}: {},
......
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/apps" "k8s.io/kubernetes/pkg/apis/apps"
"k8s.io/kubernetes/pkg/apis/apps/v1beta1" "k8s.io/kubernetes/pkg/apis/apps/v1beta1"
"k8s.io/kubernetes/pkg/apis/apps/v1beta2"
) )
func init() { func init() {
...@@ -36,12 +37,13 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r ...@@ -36,12 +37,13 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
if err := announced.NewGroupMetaFactory( if err := announced.NewGroupMetaFactory(
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: apps.GroupName, GroupName: apps.GroupName,
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version, v1beta2.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/apps", ImportPrefix: "k8s.io/api/apps",
AddInternalObjectsToScheme: apps.AddToScheme, AddInternalObjectsToScheme: apps.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{
v1beta1.SchemeGroupVersion.Version: v1beta1.AddToScheme, v1beta1.SchemeGroupVersion.Version: v1beta1.AddToScheme,
v1beta2.SchemeGroupVersion.Version: v1beta2.AddToScheme,
}, },
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil { ).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
panic(err) panic(err)
......
...@@ -20,7 +20,6 @@ import ( ...@@ -20,7 +20,6 @@ import (
"fmt" "fmt"
appsv1beta1 "k8s.io/api/apps/v1beta1" appsv1beta1 "k8s.io/api/apps/v1beta1"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/conversion"
......
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"conversion.go",
"defaults.go",
"doc.go",
"register.go",
"zz_generated.conversion.go",
"zz_generated.defaults.go",
],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/v1:go_default_library",
"//pkg/apis/apps:go_default_library",
"//pkg/apis/extensions:go_default_library",
"//vendor/k8s.io/api/apps/v1beta1:go_default_library",
"//vendor/k8s.io/api/core/v1: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/apimachinery/pkg/util/intstr:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
go_test(
name = "go_default_xtest",
srcs = ["defaults_test.go"],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/install:go_default_library",
"//pkg/apis/apps/install:go_default_library",
"//pkg/apis/apps/v1beta1:go_default_library",
"//vendor/k8s.io/api/apps/v1beta1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
],
)
/*
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 v1beta2
import (
appsv1beta2 "k8s.io/api/apps/v1beta2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}
func SetDefaults_StatefulSet(obj *appsv1beta2.StatefulSet) {
if len(obj.Spec.PodManagementPolicy) == 0 {
obj.Spec.PodManagementPolicy = appsv1beta2.OrderedReadyPodManagement
}
if obj.Spec.UpdateStrategy.Type == "" {
obj.Spec.UpdateStrategy.Type = appsv1beta2.OnDeleteStatefulSetStrategyType
}
labels := obj.Spec.Template.Labels
if labels != nil {
if obj.Spec.Selector == nil {
obj.Spec.Selector = &metav1.LabelSelector{
MatchLabels: labels,
}
}
if len(obj.Labels) == 0 {
obj.Labels = labels
}
}
if obj.Spec.Replicas == nil {
obj.Spec.Replicas = new(int32)
*obj.Spec.Replicas = 1
}
if obj.Spec.RevisionHistoryLimit == nil {
obj.Spec.RevisionHistoryLimit = new(int32)
*obj.Spec.RevisionHistoryLimit = 10
}
if obj.Spec.UpdateStrategy.Type == appsv1beta2.RollingUpdateStatefulSetStrategyType &&
obj.Spec.UpdateStrategy.RollingUpdate != nil &&
obj.Spec.UpdateStrategy.RollingUpdate.Partition == nil {
obj.Spec.UpdateStrategy.RollingUpdate.Partition = new(int32)
*obj.Spec.UpdateStrategy.RollingUpdate.Partition = 0
}
}
// SetDefaults_Deployment sets additional defaults compared to its counterpart
// in extensions. These addons are:
// - MaxUnavailable during rolling update set to 25% (1 in extensions)
// - MaxSurge value during rolling update set to 25% (1 in extensions)
// - RevisionHistoryLimit set to 2 (not set in extensions)
// - ProgressDeadlineSeconds set to 600s (not set in extensions)
func SetDefaults_Deployment(obj *appsv1beta2.Deployment) {
// Default labels and selector to labels from pod template spec.
labels := obj.Spec.Template.Labels
if labels != nil {
if obj.Spec.Selector == nil {
obj.Spec.Selector = &metav1.LabelSelector{MatchLabels: labels}
}
if len(obj.Labels) == 0 {
obj.Labels = labels
}
}
// Set appsv1beta2.DeploymentSpec.Replicas to 1 if it is not set.
if obj.Spec.Replicas == nil {
obj.Spec.Replicas = new(int32)
*obj.Spec.Replicas = 1
}
strategy := &obj.Spec.Strategy
// Set default appsv1beta2.DeploymentStrategyType as RollingUpdate.
if strategy.Type == "" {
strategy.Type = appsv1beta2.RollingUpdateDeploymentStrategyType
}
if strategy.Type == appsv1beta2.RollingUpdateDeploymentStrategyType {
if strategy.RollingUpdate == nil {
rollingUpdate := appsv1beta2.RollingUpdateDeployment{}
strategy.RollingUpdate = &rollingUpdate
}
if strategy.RollingUpdate.MaxUnavailable == nil {
// Set default MaxUnavailable as 25% by default.
maxUnavailable := intstr.FromString("25%")
strategy.RollingUpdate.MaxUnavailable = &maxUnavailable
}
if strategy.RollingUpdate.MaxSurge == nil {
// Set default MaxSurge as 25% by default.
maxSurge := intstr.FromString("25%")
strategy.RollingUpdate.MaxSurge = &maxSurge
}
}
if obj.Spec.RevisionHistoryLimit == nil {
obj.Spec.RevisionHistoryLimit = new(int32)
*obj.Spec.RevisionHistoryLimit = 2
}
if obj.Spec.ProgressDeadlineSeconds == nil {
obj.Spec.ProgressDeadlineSeconds = new(int32)
*obj.Spec.ProgressDeadlineSeconds = 600
}
}
/*
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 v1beta2_test
import (
"reflect"
"testing"
appsv1beta2 "k8s.io/api/apps/v1beta2"
"k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/kubernetes/pkg/api"
_ "k8s.io/kubernetes/pkg/api/install"
_ "k8s.io/kubernetes/pkg/apis/apps/install"
. "k8s.io/kubernetes/pkg/apis/apps/v1beta2"
)
func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := intstr.FromString("25%")
differentIntOrString := intstr.FromInt(5)
period := int64(v1.DefaultTerminationGracePeriodSeconds)
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
RestartPolicy: v1.RestartPolicyAlways,
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
SchedulerName: api.DefaultSchedulerName,
},
}
tests := []struct {
original *appsv1beta2.Deployment
expected *appsv1beta2.Deployment
}{
{
original: &appsv1beta2.Deployment{},
expected: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(1),
Strategy: appsv1beta2.DeploymentStrategy{
Type: appsv1beta2.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1beta2.RollingUpdateDeployment{
MaxSurge: &defaultIntOrString,
MaxUnavailable: &defaultIntOrString,
},
},
RevisionHistoryLimit: newInt32(2),
ProgressDeadlineSeconds: newInt32(600),
Template: defaultTemplate,
},
},
},
{
original: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(5),
Strategy: appsv1beta2.DeploymentStrategy{
RollingUpdate: &appsv1beta2.RollingUpdateDeployment{
MaxSurge: &differentIntOrString,
},
},
},
},
expected: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(5),
Strategy: appsv1beta2.DeploymentStrategy{
Type: appsv1beta2.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1beta2.RollingUpdateDeployment{
MaxSurge: &differentIntOrString,
MaxUnavailable: &defaultIntOrString,
},
},
RevisionHistoryLimit: newInt32(2),
ProgressDeadlineSeconds: newInt32(600),
Template: defaultTemplate,
},
},
},
{
original: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(3),
Strategy: appsv1beta2.DeploymentStrategy{
Type: appsv1beta2.RollingUpdateDeploymentStrategyType,
RollingUpdate: nil,
},
},
},
expected: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(3),
Strategy: appsv1beta2.DeploymentStrategy{
Type: appsv1beta2.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1beta2.RollingUpdateDeployment{
MaxSurge: &defaultIntOrString,
MaxUnavailable: &defaultIntOrString,
},
},
RevisionHistoryLimit: newInt32(2),
ProgressDeadlineSeconds: newInt32(600),
Template: defaultTemplate,
},
},
},
{
original: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(5),
Strategy: appsv1beta2.DeploymentStrategy{
Type: appsv1beta2.RecreateDeploymentStrategyType,
},
RevisionHistoryLimit: newInt32(0),
},
},
expected: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(5),
Strategy: appsv1beta2.DeploymentStrategy{
Type: appsv1beta2.RecreateDeploymentStrategyType,
},
RevisionHistoryLimit: newInt32(0),
ProgressDeadlineSeconds: newInt32(600),
Template: defaultTemplate,
},
},
},
{
original: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(5),
Strategy: appsv1beta2.DeploymentStrategy{
Type: appsv1beta2.RecreateDeploymentStrategyType,
},
ProgressDeadlineSeconds: newInt32(30),
RevisionHistoryLimit: newInt32(2),
},
},
expected: &appsv1beta2.Deployment{
Spec: appsv1beta2.DeploymentSpec{
Replicas: newInt32(5),
Strategy: appsv1beta2.DeploymentStrategy{
Type: appsv1beta2.RecreateDeploymentStrategyType,
},
ProgressDeadlineSeconds: newInt32(30),
RevisionHistoryLimit: newInt32(2),
Template: defaultTemplate,
},
},
},
}
for _, test := range tests {
original := test.original
expected := test.expected
obj2 := roundTrip(t, runtime.Object(original))
got, ok := obj2.(*appsv1beta2.Deployment)
if !ok {
t.Errorf("unexpected object: %v", got)
t.FailNow()
}
if !apiequality.Semantic.DeepEqual(got.Spec, expected.Spec) {
t.Errorf("object mismatch!\nexpected:\n\t%+v\ngot:\n\t%+v", got.Spec, expected.Spec)
}
}
}
func TestDefaultDeploymentAvailability(t *testing.T) {
d := roundTrip(t, runtime.Object(&appsv1beta2.Deployment{})).(*appsv1beta2.Deployment)
maxUnavailable, err := intstr.GetValueFromIntOrPercent(d.Spec.Strategy.RollingUpdate.MaxUnavailable, int(*(d.Spec.Replicas)), false)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if *(d.Spec.Replicas)-int32(maxUnavailable) <= 0 {
t.Fatalf("the default value of maxUnavailable can lead to no active replicas during rolling update")
}
}
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
data, err := runtime.Encode(api.Codecs.LegacyCodec(SchemeGroupVersion), obj)
if err != nil {
t.Errorf("%v\n %#v", err, obj)
return nil
}
obj2, err := runtime.Decode(api.Codecs.UniversalDecoder(), data)
if err != nil {
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
return nil
}
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
err = api.Scheme.Convert(obj2, obj3, nil)
if err != nil {
t.Errorf("%v\nSource: %#v", err, obj2)
return nil
}
return obj3
}
func newInt32(val int32) *int32 {
p := new(int32)
*p = val
return p
}
/*
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.
*/
// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/apps
// +k8s:conversion-gen-external-types=../../../../vendor/k8s.io/api/apps/v1beta2
// +k8s:defaulter-gen=TypeMeta
// +k8s:defaulter-gen-input=../../../../vendor/k8s.io/api/apps/v1beta2
package v1beta2 // import "k8s.io/kubernetes/pkg/apis/apps/v1beta2"
/*
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 v1beta2
import (
appsv1beta2 "k8s.io/api/apps/v1beta2"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// GroupName is the group name use in this package
const GroupName = "apps"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta2"}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
localSchemeBuilder = &appsv1beta2.SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)
func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addDefaultingFuncs, addConversionFuncs)
}
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
"time" "time"
appsv1beta1 "k8s.io/api/apps/v1beta1" appsv1beta1 "k8s.io/api/apps/v1beta1"
appsv1beta2 "k8s.io/api/apps/v1beta2"
authenticationv1 "k8s.io/api/authentication/v1" authenticationv1 "k8s.io/api/authentication/v1"
authenticationv1beta1 "k8s.io/api/authentication/v1beta1" authenticationv1beta1 "k8s.io/api/authentication/v1beta1"
authorizationapiv1 "k8s.io/api/authorization/v1" authorizationapiv1 "k8s.io/api/authorization/v1"
...@@ -389,6 +390,7 @@ func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig { ...@@ -389,6 +390,7 @@ func DefaultAPIResourceConfigSource() *serverstorage.ResourceConfig {
authenticationv1beta1.SchemeGroupVersion, authenticationv1beta1.SchemeGroupVersion,
autoscalingapiv1.SchemeGroupVersion, autoscalingapiv1.SchemeGroupVersion,
appsv1beta1.SchemeGroupVersion, appsv1beta1.SchemeGroupVersion,
appsv1beta2.SchemeGroupVersion,
policyapiv1beta1.SchemeGroupVersion, policyapiv1beta1.SchemeGroupVersion,
rbacv1beta1.SchemeGroupVersion, rbacv1beta1.SchemeGroupVersion,
// Don't copy this pattern. We enable rbac/v1alpha1 and settings/v1laph1 // Don't copy this pattern. We enable rbac/v1alpha1 and settings/v1laph1
......
...@@ -18,6 +18,7 @@ package rest ...@@ -18,6 +18,7 @@ package rest
import ( import (
appsapiv1beta1 "k8s.io/api/apps/v1beta1" appsapiv1beta1 "k8s.io/api/apps/v1beta1"
appsapiv1beta2 "k8s.io/api/apps/v1beta2"
"k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest" "k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server" genericapiserver "k8s.io/apiserver/pkg/server"
...@@ -40,6 +41,10 @@ func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorag ...@@ -40,6 +41,10 @@ func (p RESTStorageProvider) NewRESTStorage(apiResourceConfigSource serverstorag
apiGroupInfo.VersionedResourcesStorageMap[appsapiv1beta1.SchemeGroupVersion.Version] = p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter) apiGroupInfo.VersionedResourcesStorageMap[appsapiv1beta1.SchemeGroupVersion.Version] = p.v1beta1Storage(apiResourceConfigSource, restOptionsGetter)
apiGroupInfo.GroupMeta.GroupVersion = appsapiv1beta1.SchemeGroupVersion apiGroupInfo.GroupMeta.GroupVersion = appsapiv1beta1.SchemeGroupVersion
} }
if apiResourceConfigSource.AnyResourcesForVersionEnabled(appsapiv1beta2.SchemeGroupVersion) {
apiGroupInfo.VersionedResourcesStorageMap[appsapiv1beta2.SchemeGroupVersion.Version] = p.v1beta2Storage(apiResourceConfigSource, restOptionsGetter)
apiGroupInfo.GroupMeta.GroupVersion = appsapiv1beta2.SchemeGroupVersion
}
return apiGroupInfo, true return apiGroupInfo, true
} }
...@@ -67,6 +72,25 @@ func (p RESTStorageProvider) v1beta1Storage(apiResourceConfigSource serverstorag ...@@ -67,6 +72,25 @@ func (p RESTStorageProvider) v1beta1Storage(apiResourceConfigSource serverstorag
return storage return storage
} }
func (p RESTStorageProvider) v1beta2Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
version := appsapiv1beta2.SchemeGroupVersion
storage := map[string]rest.Storage{}
if apiResourceConfigSource.ResourceEnabled(version.WithResource("deployments")) {
deploymentStorage := deploymentstore.NewStorage(restOptionsGetter)
storage["deployments"] = deploymentStorage.Deployment
storage["deployments/status"] = deploymentStorage.Status
storage["deployments/rollback"] = deploymentStorage.Rollback
storage["deployments/scale"] = deploymentStorage.Scale
}
if apiResourceConfigSource.ResourceEnabled(version.WithResource("statefulsets")) {
statefulsetStorage, statefulsetStatusStorage := statefulsetstore.NewREST(restOptionsGetter)
storage["statefulsets"] = statefulsetStorage
storage["statefulsets/status"] = statefulsetStatusStorage
}
return storage
}
func (p RESTStorageProvider) GroupName() string { func (p RESTStorageProvider) GroupName() string {
return apps.GroupName return apps.GroupName
} }
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"generated.pb.go",
"register.go",
"types.generated.go",
"types.go",
"types_swagger_doc_generated.go",
"zz_generated.deepcopy.go",
],
tags = ["automanaged"],
deps = [
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/gogo/protobuf/sortkeys:go_default_library",
"//vendor/github.com/ugorji/go/codec:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/resource: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/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
],
)
/*
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.
*/
// +k8s:deepcopy-gen=package,register
// +k8s:openapi-gen=true
package v1beta2 // import "k8s.io/api/apps/v1beta2"
/*
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 v1beta2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// GroupName is the group name use in this package
const GroupName = "apps"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta2"}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
// TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api.
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
localSchemeBuilder = &SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)
// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Deployment{},
&DeploymentList{},
&DeploymentRollback{},
&Scale{},
&StatefulSet{},
&StatefulSetList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
...@@ -81,6 +81,7 @@ func New() *Generator { ...@@ -81,6 +81,7 @@ func New() *Generator {
`k8s.io/api/batch/v1`, `k8s.io/api/batch/v1`,
`k8s.io/api/batch/v2alpha1`, `k8s.io/api/batch/v2alpha1`,
`k8s.io/api/apps/v1beta1`, `k8s.io/api/apps/v1beta1`,
`k8s.io/api/apps/v1beta2`,
`k8s.io/api/authentication/v1`, `k8s.io/api/authentication/v1`,
`k8s.io/api/authentication/v1beta1`, `k8s.io/api/authentication/v1beta1`,
`k8s.io/api/rbac/v1alpha1`, `k8s.io/api/rbac/v1alpha1`,
......
...@@ -147,6 +147,19 @@ var etcdStorageData = map[schema.GroupVersionResource]struct { ...@@ -147,6 +147,19 @@ var etcdStorageData = map[schema.GroupVersionResource]struct {
}, },
// -- // --
// k8s.io/kubernetes/pkg/apis/apps/v1beta2
gvr("apps", "v1beta2", "statefulsets"): {
stub: `{"metadata": {"name": "ss2"}, "spec": {"template": {"metadata": {"labels": {"a": "b"}}}}}`,
expectedEtcdPath: "/registry/statefulsets/etcdstoragepathtestnamespace/ss2",
expectedGVK: gvkP("apps", "v1beta1", "StatefulSet"),
},
gvr("apps", "v1beta2", "deployments"): {
stub: `{"metadata": {"name": "deployment3"}, "spec": {"selector": {"matchLabels": {"f": "z"}}, "template": {"metadata": {"labels": {"f": "z"}}, "spec": {"containers": [{"image": "fedora:latest", "name": "container6"}]}}}}`,
expectedEtcdPath: "/registry/deployments/etcdstoragepathtestnamespace/deployment3",
expectedGVK: gvkP("extensions", "v1beta1", "Deployment"),
},
// --
// k8s.io/kubernetes/pkg/apis/autoscaling/v1 // k8s.io/kubernetes/pkg/apis/autoscaling/v1
gvr("autoscaling", "v1", "horizontalpodautoscalers"): { gvr("autoscaling", "v1", "horizontalpodautoscalers"): {
stub: `{"metadata": {"name": "hpa2"}, "spec": {"maxReplicas": 3, "scaleTargetRef": {"kind": "something", "name": "cross"}}}`, stub: `{"metadata": {"name": "hpa2"}, "spec": {"maxReplicas": 3, "scaleTargetRef": {"kind": "something", "name": "cross"}}}`,
...@@ -361,6 +374,11 @@ var ephemeralWhiteList = createEphemeralWhiteList( ...@@ -361,6 +374,11 @@ var ephemeralWhiteList = createEphemeralWhiteList(
gvr("apps", "v1beta1", "deploymentrollbacks"), // used to rollback deployment, not stored in etcd gvr("apps", "v1beta1", "deploymentrollbacks"), // used to rollback deployment, not stored in etcd
// -- // --
// k8s.io/kubernetes/pkg/apis/apps/v1beta2
gvr("apps", "v1beta2", "scales"), // not stored in etcd, part of kapiv1.ReplicationController
gvr("apps", "v1beta2", "deploymentrollbacks"), // used to rollback deployment, not stored in etcd
// --
// k8s.io/kubernetes/pkg/apis/batch/v2alpha1 // k8s.io/kubernetes/pkg/apis/batch/v2alpha1
gvr("batch", "v2alpha1", "jobtemplates"), // not stored in etcd gvr("batch", "v2alpha1", "jobtemplates"), // not stored in etcd
// -- // --
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment