Add glide.yaml and vendor deps
This commit is contained in:
parent
db918f12ad
commit
5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions
46
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/BUILD
generated
vendored
Normal file
46
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
"go_test",
|
||||
"cgo_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"registry.go",
|
||||
"strategy.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/apis/extensions/validation:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/storage:go_default_library",
|
||||
"//pkg/util/validation/field:go_default_library",
|
||||
"//pkg/watch:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["strategy_test.go"],
|
||||
library = "go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
19
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
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 replicaset provides Registry interface and it's RESTStorage
|
||||
// implementation for storing ReplicaSet api objects.
|
||||
package replicaset // import "k8s.io/kubernetes/pkg/registry/extensions/replicaset"
|
||||
51
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/etcd/BUILD
generated
vendored
Normal file
51
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/etcd/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
"go_test",
|
||||
"cgo_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["etcd.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/apis/extensions/validation:go_default_library",
|
||||
"//pkg/registry/cachesize:go_default_library",
|
||||
"//pkg/registry/extensions/replicaset:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/storage:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["etcd_test.go"],
|
||||
library = "go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/errors:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/registrytest:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
"//pkg/storage/etcd/testing:go_default_library",
|
||||
"//pkg/util/diff:go_default_library",
|
||||
],
|
||||
)
|
||||
218
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/etcd/etcd.go
generated
vendored
Normal file
218
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/etcd/etcd.go
generated
vendored
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// If you make changes to this file, you should also make the corresponding change in ReplicationController.
|
||||
|
||||
package etcd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
extvalidation "k8s.io/kubernetes/pkg/apis/extensions/validation"
|
||||
"k8s.io/kubernetes/pkg/registry/cachesize"
|
||||
"k8s.io/kubernetes/pkg/registry/extensions/replicaset"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/storage"
|
||||
)
|
||||
|
||||
// ReplicaSetStorage includes dummy storage for ReplicaSets and for Scale subresource.
|
||||
type ReplicaSetStorage struct {
|
||||
ReplicaSet *REST
|
||||
Status *StatusREST
|
||||
Scale *ScaleREST
|
||||
}
|
||||
|
||||
func NewStorage(opts generic.RESTOptions) ReplicaSetStorage {
|
||||
replicaSetRest, replicaSetStatusRest := NewREST(opts)
|
||||
replicaSetRegistry := replicaset.NewRegistry(replicaSetRest)
|
||||
|
||||
return ReplicaSetStorage{
|
||||
ReplicaSet: replicaSetRest,
|
||||
Status: replicaSetStatusRest,
|
||||
Scale: &ScaleREST{registry: replicaSetRegistry},
|
||||
}
|
||||
}
|
||||
|
||||
type REST struct {
|
||||
*genericregistry.Store
|
||||
}
|
||||
|
||||
// NewREST returns a RESTStorage object that will work against ReplicaSet.
|
||||
func NewREST(opts generic.RESTOptions) (*REST, *StatusREST) {
|
||||
prefix := "/" + opts.ResourcePrefix
|
||||
|
||||
newListFunc := func() runtime.Object { return &extensions.ReplicaSetList{} }
|
||||
storageInterface, dFunc := opts.Decorator(
|
||||
opts.StorageConfig,
|
||||
cachesize.GetWatchCacheSizeByResource(cachesize.Replicasets),
|
||||
&extensions.ReplicaSet{},
|
||||
prefix,
|
||||
replicaset.Strategy,
|
||||
newListFunc,
|
||||
replicaset.GetAttrs,
|
||||
storage.NoTriggerPublisher,
|
||||
)
|
||||
|
||||
store := &genericregistry.Store{
|
||||
NewFunc: func() runtime.Object { return &extensions.ReplicaSet{} },
|
||||
|
||||
// NewListFunc returns an object capable of storing results of an etcd list.
|
||||
NewListFunc: newListFunc,
|
||||
// Produces a path that etcd understands, to the root of the resource
|
||||
// by combining the namespace in the context with the given prefix
|
||||
KeyRootFunc: func(ctx api.Context) string {
|
||||
return genericregistry.NamespaceKeyRootFunc(ctx, prefix)
|
||||
},
|
||||
// Produces a path that etcd understands, to the resource by combining
|
||||
// the namespace in the context with the given prefix
|
||||
KeyFunc: func(ctx api.Context, name string) (string, error) {
|
||||
return genericregistry.NamespaceKeyFunc(ctx, prefix, name)
|
||||
},
|
||||
// Retrieve the name field of a ReplicaSet
|
||||
ObjectNameFunc: func(obj runtime.Object) (string, error) {
|
||||
return obj.(*extensions.ReplicaSet).Name, nil
|
||||
},
|
||||
// Used to match objects based on labels/fields for list and watch
|
||||
PredicateFunc: replicaset.MatchReplicaSet,
|
||||
QualifiedResource: api.Resource("replicasets"),
|
||||
EnableGarbageCollection: opts.EnableGarbageCollection,
|
||||
DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
|
||||
|
||||
// Used to validate ReplicaSet creation
|
||||
CreateStrategy: replicaset.Strategy,
|
||||
|
||||
// Used to validate ReplicaSet updates
|
||||
UpdateStrategy: replicaset.Strategy,
|
||||
DeleteStrategy: replicaset.Strategy,
|
||||
|
||||
Storage: storageInterface,
|
||||
DestroyFunc: dFunc,
|
||||
}
|
||||
statusStore := *store
|
||||
statusStore.UpdateStrategy = replicaset.StatusStrategy
|
||||
|
||||
return &REST{store}, &StatusREST{store: &statusStore}
|
||||
}
|
||||
|
||||
// StatusREST implements the REST endpoint for changing the status of a ReplicaSet
|
||||
type StatusREST struct {
|
||||
store *genericregistry.Store
|
||||
}
|
||||
|
||||
func (r *StatusREST) New() runtime.Object {
|
||||
return &extensions.ReplicaSet{}
|
||||
}
|
||||
|
||||
// Get retrieves the object from the storage. It is required to support Patch.
|
||||
func (r *StatusREST) Get(ctx api.Context, name string) (runtime.Object, error) {
|
||||
return r.store.Get(ctx, name)
|
||||
}
|
||||
|
||||
// Update alters the status subset of an object.
|
||||
func (r *StatusREST) Update(ctx api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
return r.store.Update(ctx, name, objInfo)
|
||||
}
|
||||
|
||||
type ScaleREST struct {
|
||||
registry replicaset.Registry
|
||||
}
|
||||
|
||||
// ScaleREST implements Patcher
|
||||
var _ = rest.Patcher(&ScaleREST{})
|
||||
|
||||
// New creates a new Scale object
|
||||
func (r *ScaleREST) New() runtime.Object {
|
||||
return &extensions.Scale{}
|
||||
}
|
||||
|
||||
func (r *ScaleREST) Get(ctx api.Context, name string) (runtime.Object, error) {
|
||||
rs, err := r.registry.GetReplicaSet(ctx, name)
|
||||
if err != nil {
|
||||
return nil, errors.NewNotFound(extensions.Resource("replicasets/scale"), name)
|
||||
}
|
||||
scale, err := scaleFromReplicaSet(rs)
|
||||
if err != nil {
|
||||
return nil, errors.NewBadRequest(fmt.Sprintf("%v", err))
|
||||
}
|
||||
return scale, err
|
||||
}
|
||||
|
||||
func (r *ScaleREST) Update(ctx api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
rs, err := r.registry.GetReplicaSet(ctx, name)
|
||||
if err != nil {
|
||||
return nil, false, errors.NewNotFound(extensions.Resource("replicasets/scale"), name)
|
||||
}
|
||||
|
||||
oldScale, err := scaleFromReplicaSet(rs)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
obj, err := objInfo.UpdatedObject(ctx, oldScale)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if obj == nil {
|
||||
return nil, false, errors.NewBadRequest(fmt.Sprintf("nil update passed to Scale"))
|
||||
}
|
||||
scale, ok := obj.(*extensions.Scale)
|
||||
if !ok {
|
||||
return nil, false, errors.NewBadRequest(fmt.Sprintf("wrong object passed to Scale update: %v", obj))
|
||||
}
|
||||
|
||||
if errs := extvalidation.ValidateScale(scale); len(errs) > 0 {
|
||||
return nil, false, errors.NewInvalid(extensions.Kind("Scale"), scale.Name, errs)
|
||||
}
|
||||
|
||||
rs.Spec.Replicas = scale.Spec.Replicas
|
||||
rs.ResourceVersion = scale.ResourceVersion
|
||||
rs, err = r.registry.UpdateReplicaSet(ctx, rs)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
newScale, err := scaleFromReplicaSet(rs)
|
||||
if err != nil {
|
||||
return nil, false, errors.NewBadRequest(fmt.Sprintf("%v", err))
|
||||
}
|
||||
return newScale, false, err
|
||||
}
|
||||
|
||||
// scaleFromReplicaSet returns a scale subresource for a replica set.
|
||||
func scaleFromReplicaSet(rs *extensions.ReplicaSet) (*extensions.Scale, error) {
|
||||
return &extensions.Scale{
|
||||
// TODO: Create a variant of ObjectMeta type that only contains the fields below.
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: rs.Name,
|
||||
Namespace: rs.Namespace,
|
||||
UID: rs.UID,
|
||||
ResourceVersion: rs.ResourceVersion,
|
||||
CreationTimestamp: rs.CreationTimestamp,
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Replicas: rs.Spec.Replicas,
|
||||
},
|
||||
Status: extensions.ScaleStatus{
|
||||
Replicas: rs.Status.Replicas,
|
||||
Selector: rs.Spec.Selector,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
367
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/etcd/etcd_test.go
generated
vendored
Normal file
367
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/etcd/etcd_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
/*
|
||||
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 etcd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
etcdtesting "k8s.io/kubernetes/pkg/storage/etcd/testing"
|
||||
"k8s.io/kubernetes/pkg/util/diff"
|
||||
)
|
||||
|
||||
const defaultReplicas = 100
|
||||
|
||||
func newStorage(t *testing.T) (*ReplicaSetStorage, *etcdtesting.EtcdTestServer) {
|
||||
etcdStorage, server := registrytest.NewEtcdStorage(t, "extensions")
|
||||
restOptions := generic.RESTOptions{StorageConfig: etcdStorage, Decorator: generic.UndecoratedStorage, DeleteCollectionWorkers: 1, ResourcePrefix: "replicasets"}
|
||||
replicaSetStorage := NewStorage(restOptions)
|
||||
return &replicaSetStorage, server
|
||||
}
|
||||
|
||||
// createReplicaSet is a helper function that returns a ReplicaSet with the updated resource version.
|
||||
func createReplicaSet(storage *REST, rs extensions.ReplicaSet, t *testing.T) (extensions.ReplicaSet, error) {
|
||||
ctx := api.WithNamespace(api.NewContext(), rs.Namespace)
|
||||
obj, err := storage.Create(ctx, &rs)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create ReplicaSet, %v", err)
|
||||
}
|
||||
newRS := obj.(*extensions.ReplicaSet)
|
||||
return *newRS, nil
|
||||
}
|
||||
|
||||
func validNewReplicaSet() *extensions.ReplicaSet {
|
||||
return &extensions.ReplicaSet{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.ReplicaSetSpec{
|
||||
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"a": "b"}},
|
||||
Template: api.PodTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: map[string]string{"a": "b"},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: "test",
|
||||
Image: "test_image",
|
||||
ImagePullPolicy: api.PullIfNotPresent,
|
||||
},
|
||||
},
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
Replicas: 7,
|
||||
},
|
||||
Status: extensions.ReplicaSetStatus{
|
||||
Replicas: 5,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var validReplicaSet = *validNewReplicaSet()
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.ReplicaSet.Store)
|
||||
rs := validNewReplicaSet()
|
||||
rs.ObjectMeta = api.ObjectMeta{}
|
||||
test.TestCreate(
|
||||
// valid
|
||||
rs,
|
||||
// invalid (invalid selector)
|
||||
&extensions.ReplicaSet{
|
||||
Spec: extensions.ReplicaSetSpec{
|
||||
Replicas: 2,
|
||||
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{}},
|
||||
Template: validReplicaSet.Spec.Template,
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.ReplicaSet.Store)
|
||||
test.TestUpdate(
|
||||
// valid
|
||||
validNewReplicaSet(),
|
||||
// valid updateFunc
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*extensions.ReplicaSet)
|
||||
object.Spec.Replicas = object.Spec.Replicas + 1
|
||||
return object
|
||||
},
|
||||
// invalid updateFunc
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*extensions.ReplicaSet)
|
||||
object.Name = ""
|
||||
return object
|
||||
},
|
||||
func(obj runtime.Object) runtime.Object {
|
||||
object := obj.(*extensions.ReplicaSet)
|
||||
object.Spec.Selector = &metav1.LabelSelector{MatchLabels: map[string]string{}}
|
||||
return object
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.ReplicaSet.Store)
|
||||
test.TestDelete(validNewReplicaSet())
|
||||
}
|
||||
|
||||
func TestGenerationNumber(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
modifiedSno := *validNewReplicaSet()
|
||||
modifiedSno.Generation = 100
|
||||
modifiedSno.Status.ObservedGeneration = 10
|
||||
ctx := api.NewDefaultContext()
|
||||
rs, err := createReplicaSet(storage.ReplicaSet, modifiedSno, t)
|
||||
etcdRS, err := storage.ReplicaSet.Get(ctx, rs.Name)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
storedRS, _ := etcdRS.(*extensions.ReplicaSet)
|
||||
|
||||
// Generation initialization
|
||||
if storedRS.Generation != 1 && storedRS.Status.ObservedGeneration != 0 {
|
||||
t.Fatalf("Unexpected generation number %v, status generation %v", storedRS.Generation, storedRS.Status.ObservedGeneration)
|
||||
}
|
||||
|
||||
// Updates to spec should increment the generation number
|
||||
storedRS.Spec.Replicas += 1
|
||||
storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS, api.Scheme))
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
etcdRS, err = storage.ReplicaSet.Get(ctx, rs.Name)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
storedRS, _ = etcdRS.(*extensions.ReplicaSet)
|
||||
if storedRS.Generation != 2 || storedRS.Status.ObservedGeneration != 0 {
|
||||
t.Fatalf("Unexpected generation, spec: %v, status: %v", storedRS.Generation, storedRS.Status.ObservedGeneration)
|
||||
}
|
||||
|
||||
// Updates to status should not increment either spec or status generation numbers
|
||||
storedRS.Status.Replicas += 1
|
||||
storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS, api.Scheme))
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
etcdRS, err = storage.ReplicaSet.Get(ctx, rs.Name)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
storedRS, _ = etcdRS.(*extensions.ReplicaSet)
|
||||
if storedRS.Generation != 2 || storedRS.Status.ObservedGeneration != 0 {
|
||||
t.Fatalf("Unexpected generation number, spec: %v, status: %v", storedRS.Generation, storedRS.Status.ObservedGeneration)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.ReplicaSet.Store)
|
||||
test.TestGet(validNewReplicaSet())
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.ReplicaSet.Store)
|
||||
test.TestList(validNewReplicaSet())
|
||||
}
|
||||
|
||||
func TestWatch(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
test := registrytest.New(t, storage.ReplicaSet.Store)
|
||||
test.TestWatch(
|
||||
validNewReplicaSet(),
|
||||
// matching labels
|
||||
[]labels.Set{
|
||||
{"a": "b"},
|
||||
},
|
||||
// not matching labels
|
||||
[]labels.Set{
|
||||
{"a": "c"},
|
||||
{"foo": "bar"},
|
||||
},
|
||||
// matching fields
|
||||
[]fields.Set{
|
||||
{"status.replicas": "5"},
|
||||
{"metadata.name": "foo"},
|
||||
{"status.replicas": "5", "metadata.name": "foo"},
|
||||
},
|
||||
// not matchin fields
|
||||
[]fields.Set{
|
||||
{"status.replicas": "10"},
|
||||
{"metadata.name": "bar"},
|
||||
{"name": "foo"},
|
||||
{"status.replicas": "10", "metadata.name": "foo"},
|
||||
{"status.replicas": "0", "metadata.name": "bar"},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestScaleGet(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
|
||||
name := "foo"
|
||||
|
||||
var rs extensions.ReplicaSet
|
||||
ctx := api.WithNamespace(api.NewContext(), api.NamespaceDefault)
|
||||
key := "/replicasets/" + api.NamespaceDefault + "/" + name
|
||||
if err := storage.ReplicaSet.Storage.Create(ctx, key, &validReplicaSet, &rs, 0); err != nil {
|
||||
t.Fatalf("error setting new replica set (key: %s) %v: %v", key, validReplicaSet, err)
|
||||
}
|
||||
|
||||
want := &extensions.Scale{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: api.NamespaceDefault,
|
||||
UID: rs.UID,
|
||||
ResourceVersion: rs.ResourceVersion,
|
||||
CreationTimestamp: rs.CreationTimestamp,
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Replicas: validReplicaSet.Spec.Replicas,
|
||||
},
|
||||
Status: extensions.ScaleStatus{
|
||||
Replicas: validReplicaSet.Status.Replicas,
|
||||
Selector: validReplicaSet.Spec.Selector,
|
||||
},
|
||||
}
|
||||
obj, err := storage.Scale.Get(ctx, name)
|
||||
got := obj.(*extensions.Scale)
|
||||
if err != nil {
|
||||
t.Fatalf("error fetching scale for %s: %v", name, err)
|
||||
}
|
||||
if !api.Semantic.DeepEqual(got, want) {
|
||||
t.Errorf("unexpected scale: %s", diff.ObjectDiff(got, want))
|
||||
}
|
||||
}
|
||||
|
||||
func TestScaleUpdate(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
|
||||
name := "foo"
|
||||
|
||||
var rs extensions.ReplicaSet
|
||||
ctx := api.WithNamespace(api.NewContext(), api.NamespaceDefault)
|
||||
key := "/replicasets/" + api.NamespaceDefault + "/" + name
|
||||
if err := storage.ReplicaSet.Storage.Create(ctx, key, &validReplicaSet, &rs, 0); err != nil {
|
||||
t.Fatalf("error setting new replica set (key: %s) %v: %v", key, validReplicaSet, err)
|
||||
}
|
||||
replicas := 12
|
||||
update := extensions.Scale{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: extensions.ScaleSpec{
|
||||
Replicas: int32(replicas),
|
||||
},
|
||||
}
|
||||
|
||||
if _, _, err := storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update, api.Scheme)); err != nil {
|
||||
t.Fatalf("error updating scale %v: %v", update, err)
|
||||
}
|
||||
|
||||
obj, err := storage.Scale.Get(ctx, name)
|
||||
if err != nil {
|
||||
t.Fatalf("error fetching scale for %s: %v", name, err)
|
||||
}
|
||||
scale := obj.(*extensions.Scale)
|
||||
if scale.Spec.Replicas != int32(replicas) {
|
||||
t.Errorf("wrong replicas count expected: %d got: %d", replicas, scale.Spec.Replicas)
|
||||
}
|
||||
|
||||
update.ResourceVersion = rs.ResourceVersion
|
||||
update.Spec.Replicas = 15
|
||||
|
||||
if _, _, err = storage.Scale.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update, api.Scheme)); err != nil && !errors.IsConflict(err) {
|
||||
t.Fatalf("unexpected error, expecting an update conflict but got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusUpdate(t *testing.T) {
|
||||
storage, server := newStorage(t)
|
||||
defer server.Terminate(t)
|
||||
defer storage.ReplicaSet.Store.DestroyFunc()
|
||||
|
||||
ctx := api.WithNamespace(api.NewContext(), api.NamespaceDefault)
|
||||
key := "/replicasets/" + api.NamespaceDefault + "/foo"
|
||||
if err := storage.ReplicaSet.Storage.Create(ctx, key, &validReplicaSet, nil, 0); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
update := extensions.ReplicaSet{
|
||||
ObjectMeta: validReplicaSet.ObjectMeta,
|
||||
Spec: extensions.ReplicaSetSpec{
|
||||
Replicas: defaultReplicas,
|
||||
},
|
||||
Status: extensions.ReplicaSetStatus{
|
||||
Replicas: defaultReplicas,
|
||||
},
|
||||
}
|
||||
|
||||
if _, _, err := storage.Status.Update(ctx, update.Name, rest.DefaultUpdatedObjectInfo(&update, api.Scheme)); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
obj, err := storage.ReplicaSet.Get(ctx, "foo")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
rs := obj.(*extensions.ReplicaSet)
|
||||
if rs.Spec.Replicas != 7 {
|
||||
t.Errorf("we expected .spec.replicas to not be updated but it was updated to %v", rs.Spec.Replicas)
|
||||
}
|
||||
if rs.Status.Replicas != defaultReplicas {
|
||||
t.Errorf("we expected .status.replicas to be updated to %d but it was %v", defaultReplicas, rs.Status.Replicas)
|
||||
}
|
||||
}
|
||||
93
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/registry.go
generated
vendored
Normal file
93
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/registry.go
generated
vendored
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// If you make changes to this file, you should also make the corresponding change in ReplicationController.
|
||||
|
||||
package replicaset
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
// Registry is an interface for things that know how to store ReplicaSets.
|
||||
type Registry interface {
|
||||
ListReplicaSets(ctx api.Context, options *api.ListOptions) (*extensions.ReplicaSetList, error)
|
||||
WatchReplicaSets(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
GetReplicaSet(ctx api.Context, replicaSetID string) (*extensions.ReplicaSet, error)
|
||||
CreateReplicaSet(ctx api.Context, replicaSet *extensions.ReplicaSet) (*extensions.ReplicaSet, error)
|
||||
UpdateReplicaSet(ctx api.Context, replicaSet *extensions.ReplicaSet) (*extensions.ReplicaSet, error)
|
||||
DeleteReplicaSet(ctx api.Context, replicaSetID string) error
|
||||
}
|
||||
|
||||
// storage puts strong typing around storage calls
|
||||
type storage struct {
|
||||
rest.StandardStorage
|
||||
}
|
||||
|
||||
// NewRegistry returns a new Registry interface for the given Storage. Any mismatched
|
||||
// types will panic.
|
||||
func NewRegistry(s rest.StandardStorage) Registry {
|
||||
return &storage{s}
|
||||
}
|
||||
|
||||
func (s *storage) ListReplicaSets(ctx api.Context, options *api.ListOptions) (*extensions.ReplicaSetList, error) {
|
||||
if options != nil && options.FieldSelector != nil && !options.FieldSelector.Empty() {
|
||||
return nil, fmt.Errorf("field selector not supported yet")
|
||||
}
|
||||
obj, err := s.List(ctx, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.ReplicaSetList), err
|
||||
}
|
||||
|
||||
func (s *storage) WatchReplicaSets(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
return s.Watch(ctx, options)
|
||||
}
|
||||
|
||||
func (s *storage) GetReplicaSet(ctx api.Context, replicaSetID string) (*extensions.ReplicaSet, error) {
|
||||
obj, err := s.Get(ctx, replicaSetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.ReplicaSet), nil
|
||||
}
|
||||
|
||||
func (s *storage) CreateReplicaSet(ctx api.Context, replicaSet *extensions.ReplicaSet) (*extensions.ReplicaSet, error) {
|
||||
obj, err := s.Create(ctx, replicaSet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.ReplicaSet), nil
|
||||
}
|
||||
|
||||
func (s *storage) UpdateReplicaSet(ctx api.Context, replicaSet *extensions.ReplicaSet) (*extensions.ReplicaSet, error) {
|
||||
obj, _, err := s.Update(ctx, replicaSet.Name, rest.DefaultUpdatedObjectInfo(replicaSet, api.Scheme))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.ReplicaSet), nil
|
||||
}
|
||||
|
||||
func (s *storage) DeleteReplicaSet(ctx api.Context, replicaSetID string) error {
|
||||
_, err := s.Delete(ctx, replicaSetID, nil)
|
||||
return err
|
||||
}
|
||||
157
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/strategy.go
generated
vendored
Normal file
157
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/strategy.go
generated
vendored
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// If you make changes to this file, you should also make the corresponding change in ReplicationController.
|
||||
|
||||
package replicaset
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions/validation"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
apistorage "k8s.io/kubernetes/pkg/storage"
|
||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||
)
|
||||
|
||||
// rsStrategy implements verification logic for ReplicaSets.
|
||||
type rsStrategy struct {
|
||||
runtime.ObjectTyper
|
||||
api.NameGenerator
|
||||
}
|
||||
|
||||
// Strategy is the default logic that applies when creating and updating ReplicaSet objects.
|
||||
var Strategy = rsStrategy{api.Scheme, api.SimpleNameGenerator}
|
||||
|
||||
// DefaultGarbageCollectionPolicy returns Orphan because that's the default
|
||||
// behavior before the server-side garbage collection is implemented.
|
||||
func (rsStrategy) DefaultGarbageCollectionPolicy() rest.GarbageCollectionPolicy {
|
||||
return rest.OrphanDependents
|
||||
}
|
||||
|
||||
// NamespaceScoped returns true because all ReplicaSets need to be within a namespace.
|
||||
func (rsStrategy) NamespaceScoped() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// PrepareForCreate clears the status of a ReplicaSet before creation.
|
||||
func (rsStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
rs := obj.(*extensions.ReplicaSet)
|
||||
rs.Status = extensions.ReplicaSetStatus{}
|
||||
|
||||
rs.Generation = 1
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (rsStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
newRS := obj.(*extensions.ReplicaSet)
|
||||
oldRS := old.(*extensions.ReplicaSet)
|
||||
// update is not allowed to set status
|
||||
newRS.Status = oldRS.Status
|
||||
|
||||
// Any changes to the spec increment the generation number, any changes to the
|
||||
// status should reflect the generation number of the corresponding object. We push
|
||||
// the burden of managing the status onto the clients because we can't (in general)
|
||||
// know here what version of spec the writer of the status has seen. It may seem like
|
||||
// we can at first -- since obj contains spec -- but in the future we will probably make
|
||||
// status its own object, and even if we don't, writes may be the result of a
|
||||
// read-update-write loop, so the contents of spec may not actually be the spec that
|
||||
// the ReplicaSet has *seen*.
|
||||
if !reflect.DeepEqual(oldRS.Spec, newRS.Spec) {
|
||||
newRS.Generation = oldRS.Generation + 1
|
||||
}
|
||||
}
|
||||
|
||||
// Validate validates a new ReplicaSet.
|
||||
func (rsStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
rs := obj.(*extensions.ReplicaSet)
|
||||
return validation.ValidateReplicaSet(rs)
|
||||
}
|
||||
|
||||
// Canonicalize normalizes the object after validation.
|
||||
func (rsStrategy) Canonicalize(obj runtime.Object) {
|
||||
}
|
||||
|
||||
// AllowCreateOnUpdate is false for ReplicaSets; this means a POST is
|
||||
// needed to create one.
|
||||
func (rsStrategy) AllowCreateOnUpdate() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (rsStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
validationErrorList := validation.ValidateReplicaSet(obj.(*extensions.ReplicaSet))
|
||||
updateErrorList := validation.ValidateReplicaSetUpdate(obj.(*extensions.ReplicaSet), old.(*extensions.ReplicaSet))
|
||||
return append(validationErrorList, updateErrorList...)
|
||||
}
|
||||
|
||||
func (rsStrategy) AllowUnconditionalUpdate() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// ReplicaSetToSelectableFields returns a field set that represents the object.
|
||||
func ReplicaSetToSelectableFields(rs *extensions.ReplicaSet) fields.Set {
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&rs.ObjectMeta, true)
|
||||
rsSpecificFieldsSet := fields.Set{
|
||||
"status.replicas": strconv.Itoa(int(rs.Status.Replicas)),
|
||||
}
|
||||
return generic.MergeFieldsSets(objectMetaFieldsSet, rsSpecificFieldsSet)
|
||||
}
|
||||
|
||||
// GetAttrs returns labels and fields of a given object for filtering purposes.
|
||||
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
|
||||
rs, ok := obj.(*extensions.ReplicaSet)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("Given object is not a ReplicaSet.")
|
||||
}
|
||||
return labels.Set(rs.ObjectMeta.Labels), ReplicaSetToSelectableFields(rs), nil
|
||||
}
|
||||
|
||||
// MatchReplicaSet is the filter used by the generic etcd backend to route
|
||||
// watch events from etcd to clients of the apiserver only interested in specific
|
||||
// labels/fields.
|
||||
func MatchReplicaSet(label labels.Selector, field fields.Selector) apistorage.SelectionPredicate {
|
||||
return apistorage.SelectionPredicate{
|
||||
Label: label,
|
||||
Field: field,
|
||||
GetAttrs: GetAttrs,
|
||||
}
|
||||
}
|
||||
|
||||
type rsStatusStrategy struct {
|
||||
rsStrategy
|
||||
}
|
||||
|
||||
var StatusStrategy = rsStatusStrategy{Strategy}
|
||||
|
||||
func (rsStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
newRS := obj.(*extensions.ReplicaSet)
|
||||
oldRS := old.(*extensions.ReplicaSet)
|
||||
// update is not allowed to set spec
|
||||
newRS.Spec = oldRS.Spec
|
||||
}
|
||||
|
||||
func (rsStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateReplicaSetStatusUpdate(obj.(*extensions.ReplicaSet), old.(*extensions.ReplicaSet))
|
||||
}
|
||||
142
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/strategy_test.go
generated
vendored
Normal file
142
vendor/k8s.io/kubernetes/pkg/registry/extensions/replicaset/strategy_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
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 replicaset
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func TestReplicaSetStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
if !Strategy.NamespaceScoped() {
|
||||
t.Errorf("ReplicaSet must be namespace scoped")
|
||||
}
|
||||
if Strategy.AllowCreateOnUpdate() {
|
||||
t.Errorf("ReplicaSet should not allow create on update")
|
||||
}
|
||||
|
||||
validSelector := map[string]string{"a": "b"}
|
||||
validPodTemplate := api.PodTemplate{
|
||||
Template: api.PodTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: validSelector,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
Containers: []api.Container{{Name: "abc", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
rs := &extensions.ReplicaSet{
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
|
||||
Spec: extensions.ReplicaSetSpec{
|
||||
Selector: &metav1.LabelSelector{MatchLabels: validSelector},
|
||||
Template: validPodTemplate.Template,
|
||||
},
|
||||
Status: extensions.ReplicaSetStatus{
|
||||
Replicas: 1,
|
||||
ObservedGeneration: int64(10),
|
||||
},
|
||||
}
|
||||
|
||||
Strategy.PrepareForCreate(ctx, rs)
|
||||
if rs.Status.Replicas != 0 {
|
||||
t.Error("ReplicaSet should not allow setting status.replicas on create")
|
||||
}
|
||||
if rs.Status.ObservedGeneration != int64(0) {
|
||||
t.Error("ReplicaSet should not allow setting status.observedGeneration on create")
|
||||
}
|
||||
errs := Strategy.Validate(ctx, rs)
|
||||
if len(errs) != 0 {
|
||||
t.Errorf("Unexpected error validating %v", errs)
|
||||
}
|
||||
|
||||
invalidRc := &extensions.ReplicaSet{
|
||||
ObjectMeta: api.ObjectMeta{Name: "bar", ResourceVersion: "4"},
|
||||
}
|
||||
Strategy.PrepareForUpdate(ctx, invalidRc, rs)
|
||||
errs = Strategy.ValidateUpdate(ctx, invalidRc, rs)
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("Expected a validation error")
|
||||
}
|
||||
if invalidRc.ResourceVersion != "4" {
|
||||
t.Errorf("Incoming resource version on update should not be mutated")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplicaSetStatusStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
if !StatusStrategy.NamespaceScoped() {
|
||||
t.Errorf("ReplicaSet must be namespace scoped")
|
||||
}
|
||||
if StatusStrategy.AllowCreateOnUpdate() {
|
||||
t.Errorf("ReplicaSet should not allow create on update")
|
||||
}
|
||||
validSelector := map[string]string{"a": "b"}
|
||||
validPodTemplate := api.PodTemplate{
|
||||
Template: api.PodTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Labels: validSelector,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
Containers: []api.Container{{Name: "abc", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
oldRS := &extensions.ReplicaSet{
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault, ResourceVersion: "10"},
|
||||
Spec: extensions.ReplicaSetSpec{
|
||||
Replicas: 3,
|
||||
Selector: &metav1.LabelSelector{MatchLabels: validSelector},
|
||||
Template: validPodTemplate.Template,
|
||||
},
|
||||
Status: extensions.ReplicaSetStatus{
|
||||
Replicas: 1,
|
||||
ObservedGeneration: int64(10),
|
||||
},
|
||||
}
|
||||
newRS := &extensions.ReplicaSet{
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault, ResourceVersion: "9"},
|
||||
Spec: extensions.ReplicaSetSpec{
|
||||
Replicas: 1,
|
||||
Selector: &metav1.LabelSelector{MatchLabels: validSelector},
|
||||
Template: validPodTemplate.Template,
|
||||
},
|
||||
Status: extensions.ReplicaSetStatus{
|
||||
Replicas: 3,
|
||||
ObservedGeneration: int64(11),
|
||||
},
|
||||
}
|
||||
StatusStrategy.PrepareForUpdate(ctx, newRS, oldRS)
|
||||
if newRS.Status.Replicas != 3 {
|
||||
t.Errorf("ReplicaSet status updates should allow change of replicas: %v", newRS.Status.Replicas)
|
||||
}
|
||||
if newRS.Spec.Replicas != 3 {
|
||||
t.Errorf("PrepareForUpdate should have preferred spec")
|
||||
}
|
||||
errs := StatusStrategy.ValidateUpdate(ctx, newRS, oldRS)
|
||||
if len(errs) != 0 {
|
||||
t.Errorf("Unexpected error %v", errs)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue