Bumping k8s dependencies to 1.13
This commit is contained in:
13
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresource/etcd.go
generated
vendored
13
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresource/etcd.go
generated
vendored
@@ -40,8 +40,8 @@ type CustomResourceStorage struct {
|
||||
Scale *ScaleREST
|
||||
}
|
||||
|
||||
func NewStorage(resource schema.GroupResource, listKind schema.GroupVersionKind, strategy customResourceStrategy, optsGetter generic.RESTOptionsGetter, categories []string, tableConvertor rest.TableConvertor) CustomResourceStorage {
|
||||
customResourceREST, customResourceStatusREST := newREST(resource, listKind, strategy, optsGetter, categories, tableConvertor)
|
||||
func NewStorage(resource schema.GroupResource, kind, listKind schema.GroupVersionKind, strategy customResourceStrategy, optsGetter generic.RESTOptionsGetter, categories []string, tableConvertor rest.TableConvertor) CustomResourceStorage {
|
||||
customResourceREST, customResourceStatusREST := newREST(resource, kind, listKind, strategy, optsGetter, categories, tableConvertor)
|
||||
|
||||
s := CustomResourceStorage{
|
||||
CustomResource: customResourceREST,
|
||||
@@ -75,9 +75,14 @@ type REST struct {
|
||||
}
|
||||
|
||||
// newREST returns a RESTStorage object that will work against API services.
|
||||
func newREST(resource schema.GroupResource, listKind schema.GroupVersionKind, strategy customResourceStrategy, optsGetter generic.RESTOptionsGetter, categories []string, tableConvertor rest.TableConvertor) (*REST, *StatusREST) {
|
||||
func newREST(resource schema.GroupResource, kind, listKind schema.GroupVersionKind, strategy customResourceStrategy, optsGetter generic.RESTOptionsGetter, categories []string, tableConvertor rest.TableConvertor) (*REST, *StatusREST) {
|
||||
store := &genericregistry.Store{
|
||||
NewFunc: func() runtime.Object { return &unstructured.Unstructured{} },
|
||||
NewFunc: func() runtime.Object {
|
||||
// set the expected group/version/kind in the new object as a signal to the versioning decoder
|
||||
ret := &unstructured.Unstructured{}
|
||||
ret.SetGroupVersionKind(kind)
|
||||
return ret
|
||||
},
|
||||
NewListFunc: func() runtime.Object {
|
||||
// lists are never stored, only manufactured, so stomp in the right kind
|
||||
ret := &unstructured.UnstructuredList{}
|
||||
|
1
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresource/etcd_test.go
generated
vendored
1
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresource/etcd_test.go
generated
vendored
@@ -91,6 +91,7 @@ func newStorage(t *testing.T) (customresource.CustomResourceStorage, *etcdtestin
|
||||
|
||||
storage := customresource.NewStorage(
|
||||
schema.GroupResource{Group: "mygroup.example.com", Resource: "noxus"},
|
||||
kind,
|
||||
schema.GroupVersionKind{Group: "mygroup.example.com", Version: "v1beta1", Kind: "NoxuItemList"},
|
||||
customresource.NewStrategy(
|
||||
typer,
|
||||
|
51
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy.go
generated
vendored
51
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy.go
generated
vendored
@@ -87,45 +87,46 @@ func (a customResourceStrategy) PrepareForCreate(ctx context.Context, obj runtim
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (a customResourceStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) || a.status == nil {
|
||||
return
|
||||
}
|
||||
|
||||
newCustomResourceObject := obj.(*unstructured.Unstructured)
|
||||
oldCustomResourceObject := old.(*unstructured.Unstructured)
|
||||
|
||||
newCustomResource := newCustomResourceObject.UnstructuredContent()
|
||||
oldCustomResource := oldCustomResourceObject.UnstructuredContent()
|
||||
|
||||
// update is not allowed to set status
|
||||
_, ok1 := newCustomResource["status"]
|
||||
_, ok2 := oldCustomResource["status"]
|
||||
switch {
|
||||
case ok2:
|
||||
newCustomResource["status"] = oldCustomResource["status"]
|
||||
case ok1:
|
||||
delete(newCustomResource, "status")
|
||||
// If the /status subresource endpoint is installed, update is not allowed to set status.
|
||||
if utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) && a.status != nil {
|
||||
_, ok1 := newCustomResource["status"]
|
||||
_, ok2 := oldCustomResource["status"]
|
||||
switch {
|
||||
case ok2:
|
||||
newCustomResource["status"] = oldCustomResource["status"]
|
||||
case ok1:
|
||||
delete(newCustomResource, "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 CustomResource has *seen*.
|
||||
newSpec, ok1 := newCustomResource["spec"]
|
||||
oldSpec, ok2 := oldCustomResource["spec"]
|
||||
|
||||
// spec is changed, created or deleted
|
||||
if (ok1 && ok2 && !apiequality.Semantic.DeepEqual(oldSpec, newSpec)) || (ok1 && !ok2) || (!ok1 && ok2) {
|
||||
// except for the changes to `metadata`, any other changes
|
||||
// cause the generation to increment.
|
||||
newCopyContent := copyNonMetadata(newCustomResource)
|
||||
oldCopyContent := copyNonMetadata(oldCustomResource)
|
||||
if !apiequality.Semantic.DeepEqual(newCopyContent, oldCopyContent) {
|
||||
oldAccessor, _ := meta.Accessor(oldCustomResourceObject)
|
||||
newAccessor, _ := meta.Accessor(newCustomResourceObject)
|
||||
newAccessor.SetGeneration(oldAccessor.GetGeneration() + 1)
|
||||
}
|
||||
}
|
||||
|
||||
func copyNonMetadata(original map[string]interface{}) map[string]interface{} {
|
||||
ret := make(map[string]interface{})
|
||||
for key, val := range original {
|
||||
if key == "metadata" {
|
||||
continue
|
||||
}
|
||||
ret[key] = val
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Validate validates a new CustomResource.
|
||||
func (a customResourceStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
|
||||
return a.validator.Validate(ctx, obj, a.scale)
|
||||
|
257
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy_test.go
generated
vendored
Normal file
257
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy_test.go
generated
vendored
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
Copyright 2018 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 customresource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func generation1() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"generation": int64(1),
|
||||
}
|
||||
}
|
||||
|
||||
func generation2() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"generation": int64(2),
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrategyPrepareForUpdate(t *testing.T) {
|
||||
strategy := customResourceStrategy{}
|
||||
tcs := []struct {
|
||||
name string
|
||||
old *unstructured.Unstructured
|
||||
obj *unstructured.Unstructured
|
||||
statusEnabled bool
|
||||
expected *unstructured.Unstructured
|
||||
}{
|
||||
{
|
||||
name: "/status is enabled, spec changes increment generation",
|
||||
statusEnabled: true,
|
||||
old: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
obj: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "new",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
expected: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation2(),
|
||||
"spec": "new",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "/status is enabled, status changes do not increment generation, status changes removed",
|
||||
statusEnabled: true,
|
||||
old: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
obj: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"status": "new",
|
||||
},
|
||||
},
|
||||
expected: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "/status is enabled, metadata changes do not increment generation",
|
||||
statusEnabled: true,
|
||||
old: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"generation": int64(1),
|
||||
"other": "old",
|
||||
},
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
obj: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"generation": int64(1),
|
||||
"other": "new",
|
||||
},
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
expected: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"generation": int64(1),
|
||||
"other": "new",
|
||||
},
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "/status is disabled, spec changes increment generation",
|
||||
statusEnabled: false,
|
||||
old: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
obj: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "new",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
expected: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation2(),
|
||||
"spec": "new",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "/status is disabled, status changes increment generation",
|
||||
statusEnabled: false,
|
||||
old: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
obj: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"status": "new",
|
||||
},
|
||||
},
|
||||
expected: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation2(),
|
||||
"spec": "old",
|
||||
"status": "new",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "/status is disabled, other top-level field changes increment generation",
|
||||
statusEnabled: false,
|
||||
old: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"image": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
obj: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation1(),
|
||||
"spec": "old",
|
||||
"image": "new",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
expected: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": generation2(),
|
||||
"spec": "old",
|
||||
"image": "new",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "/status is disabled, metadata changes do not increment generation",
|
||||
statusEnabled: false,
|
||||
old: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"generation": int64(1),
|
||||
"other": "old",
|
||||
},
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
obj: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"generation": int64(1),
|
||||
"other": "new",
|
||||
},
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
expected: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"generation": int64(1),
|
||||
"other": "new",
|
||||
},
|
||||
"spec": "old",
|
||||
"status": "old",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
if tc.statusEnabled {
|
||||
strategy.status = &apiextensions.CustomResourceSubresourceStatus{}
|
||||
} else {
|
||||
strategy.status = nil
|
||||
}
|
||||
strategy.PrepareForUpdate(context.TODO(), tc.obj, tc.old)
|
||||
if !reflect.DeepEqual(tc.obj, tc.expected) {
|
||||
t.Errorf("test %q failed: expected: %v, got %v", tc.name, tc.expected, tc.obj)
|
||||
}
|
||||
}
|
||||
}
|
15
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresourcedefinition/strategy.go
generated
vendored
15
vendor/k8s.io/apiextensions-apiserver/pkg/registry/customresourcedefinition/strategy.go
generated
vendored
@@ -20,6 +20,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation"
|
||||
apiextensionsfeatures "k8s.io/apiextensions-apiserver/pkg/features"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
@@ -29,10 +32,6 @@ import (
|
||||
"k8s.io/apiserver/pkg/storage"
|
||||
"k8s.io/apiserver/pkg/storage/names"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
|
||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
|
||||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/validation"
|
||||
apiextensionsfeatures "k8s.io/apiextensions-apiserver/pkg/features"
|
||||
)
|
||||
|
||||
// strategy implements behavior for CustomResources.
|
||||
@@ -62,6 +61,9 @@ func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceSubresources) {
|
||||
crd.Spec.Subresources = nil
|
||||
}
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceWebhookConversion) && crd.Spec.Conversion != nil {
|
||||
crd.Spec.Conversion.WebhookClientConfig = nil
|
||||
}
|
||||
|
||||
for _, v := range crd.Spec.Versions {
|
||||
if v.Storage {
|
||||
@@ -99,6 +101,11 @@ func (strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
||||
newCRD.Spec.Subresources = nil
|
||||
oldCRD.Spec.Subresources = nil
|
||||
}
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(apiextensionsfeatures.CustomResourceWebhookConversion) && newCRD.Spec.Conversion != nil {
|
||||
if oldCRD.Spec.Conversion == nil || newCRD.Spec.Conversion.WebhookClientConfig == nil {
|
||||
newCRD.Spec.Conversion.WebhookClientConfig = nil
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range newCRD.Spec.Versions {
|
||||
if v.Storage {
|
||||
|
Reference in New Issue
Block a user