Merge pull request #45838 from deads2k/tpr-15-status

Automatic merge from submit-queue (batch tested with PRs 44520, 45253, 45838, 44685, 45901)

start serving customresourcedefinition based on status

This exposes the `customresourcedefinition/status` endpoint, wires a controller to drive `NameConflict` conditions, and serves discovery from status, not spec.

Next steps after this include wiring the conditions into handling and reswizzling the handling chain to be cleaner now that we have a custom mux.
This commit is contained in:
Kubernetes Submit Queue 2017-05-16 21:27:58 -07:00 committed by GitHub
commit ae045a70f6
23 changed files with 1163 additions and 83 deletions

View File

@ -434,6 +434,14 @@
"ImportPath": "github.com/grpc-ecosystem/grpc-gateway/utilities", "ImportPath": "github.com/grpc-ecosystem/grpc-gateway/utilities",
"Rev": "84398b94e188ee336f307779b57b3aa91af7063c" "Rev": "84398b94e188ee336f307779b57b3aa91af7063c"
}, },
{
"ImportPath": "github.com/hashicorp/golang-lru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{
"ImportPath": "github.com/hashicorp/golang-lru/simplelru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{ {
"ImportPath": "github.com/howeyc/gopass", "ImportPath": "github.com/howeyc/gopass",
"Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d" "Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d"

View File

@ -138,6 +138,14 @@
"ImportPath": "github.com/google/gofuzz", "ImportPath": "github.com/google/gofuzz",
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c" "Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
}, },
{
"ImportPath": "github.com/hashicorp/golang-lru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{
"ImportPath": "github.com/hashicorp/golang-lru/simplelru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{ {
"ImportPath": "github.com/howeyc/gopass", "ImportPath": "github.com/howeyc/gopass",
"Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d" "Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d"

View File

@ -53,6 +53,7 @@ go_library(
"index.go", "index.go",
"listers.go", "listers.go",
"listwatch.go", "listwatch.go",
"mutation_cache.go",
"mutation_detector.go", "mutation_detector.go",
"reflector.go", "reflector.go",
"shared_informer.go", "shared_informer.go",
@ -63,6 +64,7 @@ go_library(
tags = ["automanaged"], tags = ["automanaged"],
deps = [ deps = [
"//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/hashicorp/golang-lru:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",

View File

@ -28,6 +28,8 @@ type Indexer interface {
Store Store
// Retrieve list of objects that match on the named indexing function // Retrieve list of objects that match on the named indexing function
Index(indexName string, obj interface{}) ([]interface{}, error) Index(indexName string, obj interface{}) ([]interface{}, error)
// IndexKeys returns the set of keys that match on the named indexing function.
IndexKeys(indexName, indexKey string) ([]string, error)
// ListIndexFuncValues returns the list of generated values of an Index func // ListIndexFuncValues returns the list of generated values of an Index func
ListIndexFuncValues(indexName string) []string ListIndexFuncValues(indexName string) []string
// ByIndex lists object that match on the named indexing function with the exact key // ByIndex lists object that match on the named indexing function with the exact key

View File

@ -0,0 +1,220 @@
/*
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 cache
import (
"fmt"
"strconv"
"sync"
lru "github.com/hashicorp/golang-lru"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)
// MutationCache is able to take the result of update operations and stores them in an LRU
// that can be used to provide a more current view of a requested object. It requires interpretting
// resourceVersions for comparisons.
// Implementations must be thread-safe.
// TODO find a way to layer this into an informer/lister
type MutationCache interface {
GetByKey(key string) (interface{}, bool, error)
ByIndex(indexName, indexKey string) ([]interface{}, error)
Mutation(interface{})
}
type ResourceVersionComparator interface {
CompareResourceVersion(lhs, rhs runtime.Object) int
}
// NewIntegerResourceVersionMutationCache returns a MutationCache that understands how to
// deal with objects that have a resource version that:
//
// - is an integer
// - increases when updated
// - is comparable across the same resource in a namespace
//
// Most backends will have these semantics. Indexer may be nil.
func NewIntegerResourceVersionMutationCache(backingCache Store, indexer Indexer) MutationCache {
lru, err := lru.New(100)
if err != nil {
// errors only happen on invalid sizes, this would be programmer error
panic(err)
}
return &mutationCache{
backingCache: backingCache,
indexer: indexer,
mutationCache: lru,
comparator: etcdObjectVersioner{},
}
}
// mutationCache doesn't guarantee that it returns values added via Mutation since they can page out and
// since you can't distinguish between, "didn't observe create" and "was deleted after create",
// if the key is missing from the backing cache, we always return it as missing
type mutationCache struct {
lock sync.Mutex
backingCache Store
indexer Indexer
mutationCache *lru.Cache
comparator ResourceVersionComparator
}
// GetByKey is never guaranteed to return back the value set in Mutation. It could be paged out, it could
// be older than another copy, the backingCache may be more recent or, you might have written twice into the same key.
// You get a value that was valid at some snapshot of time and will always return the newer of backingCache and mutationCache.
func (c *mutationCache) GetByKey(key string) (interface{}, bool, error) {
c.lock.Lock()
defer c.lock.Unlock()
obj, exists, err := c.backingCache.GetByKey(key)
if err != nil {
return nil, false, err
}
if !exists {
// we can't distinguish between, "didn't observe create" and "was deleted after create", so
// if the key is missing, we always return it as missing
return nil, false, nil
}
objRuntime, ok := obj.(runtime.Object)
if !ok {
return obj, true, nil
}
return c.newerObject(key, objRuntime), true, nil
}
// ByIndex returns the newer objects that match the provided index and indexer key.
// Will return an error if no indexer was provided.
func (c *mutationCache) ByIndex(name string, indexKey string) ([]interface{}, error) {
c.lock.Lock()
defer c.lock.Unlock()
if c.indexer == nil {
return nil, fmt.Errorf("no indexer has been provided to the mutation cache")
}
keys, err := c.indexer.IndexKeys(name, indexKey)
if err != nil {
return nil, err
}
var items []interface{}
for _, key := range keys {
obj, exists, err := c.indexer.GetByKey(key)
if err != nil {
return nil, err
}
if !exists {
continue
}
if objRuntime, ok := obj.(runtime.Object); ok {
items = append(items, c.newerObject(key, objRuntime))
} else {
items = append(items, obj)
}
}
return items, nil
}
// newerObject checks the mutation cache for a newer object and returns one if found. If the
// mutated object is older than the backing object, it is removed from the Must be
// called while the lock is held.
func (c *mutationCache) newerObject(key string, backing runtime.Object) runtime.Object {
mutatedObj, exists := c.mutationCache.Get(key)
if !exists {
return backing
}
mutatedObjRuntime, ok := mutatedObj.(runtime.Object)
if !ok {
return backing
}
if c.comparator.CompareResourceVersion(backing, mutatedObjRuntime) >= 0 {
c.mutationCache.Remove(key)
return backing
}
return mutatedObjRuntime
}
// Mutation adds a change to the cache that can be returned in GetByKey if it is newer than the backingCache
// copy. If you call Mutation twice with the same object on different threads, one will win, but its not defined
// which one. This doesn't affect correctness, since the GetByKey guaranteed of "later of these two caches" is
// preserved, but you may not get the version of the object you want. The object you get is only guaranteed to
// "one that was valid at some point in time", not "the one that I want".
func (c *mutationCache) Mutation(obj interface{}) {
c.lock.Lock()
defer c.lock.Unlock()
key, err := DeletionHandlingMetaNamespaceKeyFunc(obj)
if err != nil {
// this is a "nice to have", so failures shouldn't do anything weird
utilruntime.HandleError(err)
return
}
if objRuntime, ok := obj.(runtime.Object); ok {
if mutatedObj, exists := c.mutationCache.Get(key); exists {
if mutatedObjRuntime, ok := mutatedObj.(runtime.Object); ok {
if c.comparator.CompareResourceVersion(objRuntime, mutatedObjRuntime) < 0 {
return
}
}
}
}
c.mutationCache.Add(key, obj)
}
// etcdObjectVersioner implements versioning and extracting etcd node information
// for objects that have an embedded ObjectMeta or ListMeta field.
type etcdObjectVersioner struct{}
// ObjectResourceVersion implements Versioner
func (a etcdObjectVersioner) ObjectResourceVersion(obj runtime.Object) (uint64, error) {
accessor, err := meta.Accessor(obj)
if err != nil {
return 0, err
}
version := accessor.GetResourceVersion()
if len(version) == 0 {
return 0, nil
}
return strconv.ParseUint(version, 10, 64)
}
// CompareResourceVersion compares etcd resource versions. Outside this API they are all strings,
// but etcd resource versions are special, they're actually ints, so we can easily compare them.
func (a etcdObjectVersioner) CompareResourceVersion(lhs, rhs runtime.Object) int {
lhsVersion, err := a.ObjectResourceVersion(lhs)
if err != nil {
// coder error
panic(err)
}
rhsVersion, err := a.ObjectResourceVersion(rhs)
if err != nil {
// coder error
panic(err)
}
if lhsVersion == rhsVersion {
return 0
}
if lhsVersion < rhsVersion {
return -1
}
return 1
}

View File

@ -172,6 +172,10 @@ func (c *cache) Index(indexName string, obj interface{}) ([]interface{}, error)
return c.cacheStorage.Index(indexName, obj) return c.cacheStorage.Index(indexName, obj)
} }
func (c *cache) IndexKeys(indexName, indexKey string) ([]string, error) {
return c.cacheStorage.IndexKeys(indexName, indexKey)
}
// ListIndexFuncValues returns the list of generated values of an Index func // ListIndexFuncValues returns the list of generated values of an Index func
func (c *cache) ListIndexFuncValues(indexName string) []string { func (c *cache) ListIndexFuncValues(indexName string) []string {
return c.cacheStorage.ListIndexFuncValues(indexName) return c.cacheStorage.ListIndexFuncValues(indexName)

View File

@ -43,6 +43,7 @@ type ThreadSafeStore interface {
ListKeys() []string ListKeys() []string
Replace(map[string]interface{}, string) Replace(map[string]interface{}, string)
Index(indexName string, obj interface{}) ([]interface{}, error) Index(indexName string, obj interface{}) ([]interface{}, error)
IndexKeys(indexName, indexKey string) ([]string, error)
ListIndexFuncValues(name string) []string ListIndexFuncValues(name string) []string
ByIndex(indexName, indexKey string) ([]interface{}, error) ByIndex(indexName, indexKey string) ([]interface{}, error)
GetIndexers() Indexers GetIndexers() Indexers
@ -184,6 +185,23 @@ func (c *threadSafeMap) ByIndex(indexName, indexKey string) ([]interface{}, erro
return list, nil return list, nil
} }
// IndexKeys returns a list of keys that match on the index function.
// IndexKeys is thread-safe so long as you treat all items as immutable.
func (c *threadSafeMap) IndexKeys(indexName, indexKey string) ([]string, error) {
c.lock.RLock()
defer c.lock.RUnlock()
indexFunc := c.indexers[indexName]
if indexFunc == nil {
return nil, fmt.Errorf("Index with name %s does not exist", indexName)
}
index := c.indices[indexName]
set := index[indexKey]
return set.List(), nil
}
func (c *threadSafeMap) ListIndexFuncValues(indexName string) []string { func (c *threadSafeMap) ListIndexFuncValues(indexName string) []string {
c.lock.RLock() c.lock.RLock()
defer c.lock.RUnlock() defer c.lock.RUnlock()

View File

@ -190,6 +190,14 @@
"ImportPath": "github.com/grpc-ecosystem/grpc-gateway/utilities", "ImportPath": "github.com/grpc-ecosystem/grpc-gateway/utilities",
"Rev": "84398b94e188ee336f307779b57b3aa91af7063c" "Rev": "84398b94e188ee336f307779b57b3aa91af7063c"
}, },
{
"ImportPath": "github.com/hashicorp/golang-lru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{
"ImportPath": "github.com/hashicorp/golang-lru/simplelru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{ {
"ImportPath": "github.com/howeyc/gopass", "ImportPath": "github.com/howeyc/gopass",
"Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d" "Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d"

View File

@ -182,6 +182,14 @@
"ImportPath": "github.com/grpc-ecosystem/grpc-gateway/utilities", "ImportPath": "github.com/grpc-ecosystem/grpc-gateway/utilities",
"Rev": "84398b94e188ee336f307779b57b3aa91af7063c" "Rev": "84398b94e188ee336f307779b57b3aa91af7063c"
}, },
{
"ImportPath": "github.com/hashicorp/golang-lru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{
"ImportPath": "github.com/hashicorp/golang-lru/simplelru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{ {
"ImportPath": "github.com/howeyc/gopass", "ImportPath": "github.com/howeyc/gopass",
"Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d" "Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d"

View File

@ -1,5 +1,5 @@
apiVersion: apiextensions.k8s.io/v1alpha1 apiVersion: apiextensions.k8s.io/v1alpha1
kind: CustomResource kind: CustomResourceDefinition
metadata: metadata:
name: noxus.mygroup.example.com name: noxus.mygroup.example.com
spec: spec:

View File

@ -11,6 +11,7 @@ go_library(
name = "go_default_library", name = "go_default_library",
srcs = [ srcs = [
"doc.go", "doc.go",
"helpers.go",
"register.go", "register.go",
"types.go", "types.go",
"zz_generated.deepcopy.go", "zz_generated.deepcopy.go",

View File

@ -0,0 +1,78 @@
/*
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 apiextensions
// SetCRDCondition sets the status condition. It either overwrites the existing one or
// creates a new one
func SetCRDCondition(customResourceDefinition *CustomResourceDefinition, newCondition CustomResourceDefinitionCondition) {
existingCondition := FindCRDCondition(customResourceDefinition, newCondition.Type)
if existingCondition == nil {
customResourceDefinition.Status.Conditions = append(customResourceDefinition.Status.Conditions, newCondition)
return
}
if existingCondition.Status != newCondition.Status {
existingCondition.Status = newCondition.Status
existingCondition.LastTransitionTime = newCondition.LastTransitionTime
}
existingCondition.Reason = newCondition.Reason
existingCondition.Message = newCondition.Message
}
// FindCRDCondition returns the condition you're looking for or nil
func FindCRDCondition(customResourceDefinition *CustomResourceDefinition, conditionType CustomResourceDefinitionConditionType) *CustomResourceDefinitionCondition {
for i := range customResourceDefinition.Status.Conditions {
if customResourceDefinition.Status.Conditions[i].Type == conditionType {
return &customResourceDefinition.Status.Conditions[i]
}
}
return nil
}
// IsCRDConditionTrue indicates if the condition is present and strictly true
func IsCRDConditionTrue(customResourceDefinition *CustomResourceDefinition, conditionType CustomResourceDefinitionConditionType) bool {
return IsCRDConditionPresentAndEqual(customResourceDefinition, conditionType, ConditionTrue)
}
// IsCRDConditionFalse indicates if the condition is present and false true
func IsCRDConditionFalse(customResourceDefinition *CustomResourceDefinition, conditionType CustomResourceDefinitionConditionType) bool {
return IsCRDConditionPresentAndEqual(customResourceDefinition, conditionType, ConditionFalse)
}
// IsCRDConditionPresentAndEqual indicates if the condition is present and equal to the arg
func IsCRDConditionPresentAndEqual(customResourceDefinition *CustomResourceDefinition, conditionType CustomResourceDefinitionConditionType, status ConditionStatus) bool {
for _, condition := range customResourceDefinition.Status.Conditions {
if condition.Type == conditionType {
return condition.Status == status
}
}
return false
}
// IsCRDConditionEquivalent returns true if the lhs and rhs are equivalent except for times
func IsCRDConditionEquivalent(lhs, rhs *CustomResourceDefinitionCondition) bool {
if lhs == nil && rhs == nil {
return true
}
if lhs == nil || rhs == nil {
return false
}
return lhs.Message == rhs.Message && lhs.Reason == rhs.Reason && lhs.Status == rhs.Status && lhs.Type == rhs.Type
}

View File

@ -54,6 +54,7 @@ go_library(
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion:go_default_library", "//vendor/k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion/apiextensions/internalversion:go_default_library", "//vendor/k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion/apiextensions/internalversion:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/listers/apiextensions/internalversion:go_default_library", "//vendor/k8s.io/kube-apiextensions-server/pkg/client/listers/apiextensions/internalversion:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/controller/status:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/registry/customresource:go_default_library", "//vendor/k8s.io/kube-apiextensions-server/pkg/registry/customresource:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/registry/customresourcedefinition:go_default_library", "//vendor/k8s.io/kube-apiextensions-server/pkg/registry/customresourcedefinition:go_default_library",
], ],

View File

@ -37,6 +37,7 @@ import (
"k8s.io/kube-apiextensions-server/pkg/apis/apiextensions/v1alpha1" "k8s.io/kube-apiextensions-server/pkg/apis/apiextensions/v1alpha1"
"k8s.io/kube-apiextensions-server/pkg/client/clientset/internalclientset" "k8s.io/kube-apiextensions-server/pkg/client/clientset/internalclientset"
internalinformers "k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion" internalinformers "k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion"
"k8s.io/kube-apiextensions-server/pkg/controller/status"
"k8s.io/kube-apiextensions-server/pkg/registry/customresourcedefinition" "k8s.io/kube-apiextensions-server/pkg/registry/customresourcedefinition"
// make sure the generated client works // make sure the generated client works
@ -113,8 +114,10 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(apiextensions.GroupName, registry, Scheme, metav1.ParameterCodec, Codecs) apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(apiextensions.GroupName, registry, Scheme, metav1.ParameterCodec, Codecs)
apiGroupInfo.GroupMeta.GroupVersion = v1alpha1.SchemeGroupVersion apiGroupInfo.GroupMeta.GroupVersion = v1alpha1.SchemeGroupVersion
customResourceDefintionStorage := customresourcedefinition.NewREST(Scheme, c.GenericConfig.RESTOptionsGetter)
v1alpha1storage := map[string]rest.Storage{} v1alpha1storage := map[string]rest.Storage{}
v1alpha1storage["customresourcedefinitions"] = customresourcedefinition.NewREST(Scheme, c.GenericConfig.RESTOptionsGetter) v1alpha1storage["customresourcedefinitions"] = customResourceDefintionStorage
v1alpha1storage["customresourcedefinitions/status"] = customresourcedefinition.NewStatusREST(Scheme, customResourceDefintionStorage)
apiGroupInfo.VersionedResourcesStorageMap["v1alpha1"] = v1alpha1storage apiGroupInfo.VersionedResourcesStorageMap["v1alpha1"] = v1alpha1storage
if err := s.GenericAPIServer.InstallAPIGroup(&apiGroupInfo); err != nil { if err := s.GenericAPIServer.InstallAPIGroup(&apiGroupInfo); err != nil {
@ -153,6 +156,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
s.GenericAPIServer.Handler.PostGoRestfulMux.HandlePrefix("/apis/", customResourceDefinitionHandler) s.GenericAPIServer.Handler.PostGoRestfulMux.HandlePrefix("/apis/", customResourceDefinitionHandler)
customResourceDefinitionController := NewDiscoveryController(customResourceDefinitionInformers.Apiextensions().InternalVersion().CustomResourceDefinitions(), versionDiscoveryHandler, groupDiscoveryHandler) customResourceDefinitionController := NewDiscoveryController(customResourceDefinitionInformers.Apiextensions().InternalVersion().CustomResourceDefinitions(), versionDiscoveryHandler, groupDiscoveryHandler)
namingController := status.NewNamingConditionController(customResourceDefinitionInformers.Apiextensions().InternalVersion().CustomResourceDefinitions(), customResourceDefinitionClient)
s.GenericAPIServer.AddPostStartHook("start-apiextensions-informers", func(context genericapiserver.PostStartHookContext) error { s.GenericAPIServer.AddPostStartHook("start-apiextensions-informers", func(context genericapiserver.PostStartHookContext) error {
customResourceDefinitionInformers.Start(context.StopCh) customResourceDefinitionInformers.Start(context.StopCh)
@ -160,6 +164,7 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
}) })
s.GenericAPIServer.AddPostStartHook("start-apiextensions-controllers", func(context genericapiserver.PostStartHookContext) error { s.GenericAPIServer.AddPostStartHook("start-apiextensions-controllers", func(context genericapiserver.PostStartHookContext) error {
go customResourceDefinitionController.Run(context.StopCh) go customResourceDefinitionController.Run(context.StopCh)
go namingController.Run(context.StopCh)
return nil return nil
}) })

View File

@ -40,8 +40,8 @@ type DiscoveryController struct {
versionHandler *versionDiscoveryHandler versionHandler *versionDiscoveryHandler
groupHandler *groupDiscoveryHandler groupHandler *groupDiscoveryHandler
customResourceDefinitionLister listers.CustomResourceDefinitionLister crdLister listers.CustomResourceDefinitionLister
customResourceDefinitionsSynced cache.InformerSynced crdsSynced cache.InformerSynced
// To allow injection for testing. // To allow injection for testing.
syncFn func(version schema.GroupVersion) error syncFn func(version schema.GroupVersion) error
@ -49,17 +49,17 @@ type DiscoveryController struct {
queue workqueue.RateLimitingInterface queue workqueue.RateLimitingInterface
} }
func NewDiscoveryController(customResourceDefinitionInformer informers.CustomResourceDefinitionInformer, versionHandler *versionDiscoveryHandler, groupHandler *groupDiscoveryHandler) *DiscoveryController { func NewDiscoveryController(crdInformer informers.CustomResourceDefinitionInformer, versionHandler *versionDiscoveryHandler, groupHandler *groupDiscoveryHandler) *DiscoveryController {
c := &DiscoveryController{ c := &DiscoveryController{
versionHandler: versionHandler, versionHandler: versionHandler,
groupHandler: groupHandler, groupHandler: groupHandler,
customResourceDefinitionLister: customResourceDefinitionInformer.Lister(), crdLister: crdInformer.Lister(),
customResourceDefinitionsSynced: customResourceDefinitionInformer.Informer().HasSynced, crdsSynced: crdInformer.Informer().HasSynced,
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "DiscoveryController"), queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "DiscoveryController"),
} }
customResourceDefinitionInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ crdInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.addCustomResourceDefinition, AddFunc: c.addCustomResourceDefinition,
UpdateFunc: c.updateCustomResourceDefinition, UpdateFunc: c.updateCustomResourceDefinition,
DeleteFunc: c.deleteCustomResourceDefinition, DeleteFunc: c.deleteCustomResourceDefinition,
@ -75,36 +75,39 @@ func (c *DiscoveryController) sync(version schema.GroupVersion) error {
apiVersionsForDiscovery := []metav1.GroupVersionForDiscovery{} apiVersionsForDiscovery := []metav1.GroupVersionForDiscovery{}
apiResourcesForDiscovery := []metav1.APIResource{} apiResourcesForDiscovery := []metav1.APIResource{}
customResourceDefinitions, err := c.customResourceDefinitionLister.List(labels.Everything()) crds, err := c.crdLister.List(labels.Everything())
if err != nil { if err != nil {
return err return err
} }
foundVersion := false foundVersion := false
foundGroup := false foundGroup := false
for _, customResourceDefinition := range customResourceDefinitions { for _, crd := range crds {
// TODO add status checking // if we can't definitively determine that our names are good, don't serve it
if !apiextensions.IsCRDConditionFalse(crd, apiextensions.NameConflict) {
continue
}
if customResourceDefinition.Spec.Group != version.Group { if crd.Spec.Group != version.Group {
continue continue
} }
foundGroup = true foundGroup = true
apiVersionsForDiscovery = append(apiVersionsForDiscovery, metav1.GroupVersionForDiscovery{ apiVersionsForDiscovery = append(apiVersionsForDiscovery, metav1.GroupVersionForDiscovery{
GroupVersion: customResourceDefinition.Spec.Group + "/" + customResourceDefinition.Spec.Version, GroupVersion: crd.Spec.Group + "/" + crd.Spec.Version,
Version: customResourceDefinition.Spec.Version, Version: crd.Spec.Version,
}) })
if customResourceDefinition.Spec.Version != version.Version { if crd.Spec.Version != version.Version {
continue continue
} }
foundVersion = true foundVersion = true
apiResourcesForDiscovery = append(apiResourcesForDiscovery, metav1.APIResource{ apiResourcesForDiscovery = append(apiResourcesForDiscovery, metav1.APIResource{
Name: customResourceDefinition.Spec.Names.Plural, Name: crd.Status.AcceptedNames.Plural,
SingularName: customResourceDefinition.Spec.Names.Singular, SingularName: crd.Status.AcceptedNames.Singular,
Namespaced: customResourceDefinition.Spec.Scope == apiextensions.NamespaceScoped, Namespaced: crd.Spec.Scope == apiextensions.NamespaceScoped,
Kind: customResourceDefinition.Spec.Names.Kind, Kind: crd.Status.AcceptedNames.Kind,
Verbs: metav1.Verbs([]string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"}), Verbs: metav1.Verbs([]string{"delete", "deletecollection", "get", "list", "patch", "create", "update", "watch"}),
ShortNames: customResourceDefinition.Spec.Names.ShortNames, ShortNames: crd.Status.AcceptedNames.ShortNames,
}) })
} }
@ -140,7 +143,7 @@ func (c *DiscoveryController) Run(stopCh <-chan struct{}) {
glog.Infof("Starting DiscoveryController") glog.Infof("Starting DiscoveryController")
if !cache.WaitForCacheSync(stopCh, c.customResourceDefinitionsSynced) { if !cache.WaitForCacheSync(stopCh, c.crdsSynced) {
utilruntime.HandleError(fmt.Errorf("timed out waiting for caches to sync")) utilruntime.HandleError(fmt.Errorf("timed out waiting for caches to sync"))
return return
} }

View File

@ -48,58 +48,58 @@ import (
"k8s.io/kube-apiextensions-server/pkg/registry/customresource" "k8s.io/kube-apiextensions-server/pkg/registry/customresource"
) )
// customResourceDefinitionHandler serves the `/apis` endpoint. // crdHandler serves the `/apis` endpoint.
// This is registered as a filter so that it never collides with any explictly registered endpoints // This is registered as a filter so that it never collides with any explictly registered endpoints
type customResourceDefinitionHandler struct { type crdHandler struct {
versionDiscoveryHandler *versionDiscoveryHandler versionDiscoveryHandler *versionDiscoveryHandler
groupDiscoveryHandler *groupDiscoveryHandler groupDiscoveryHandler *groupDiscoveryHandler
customStorageLock sync.Mutex customStorageLock sync.Mutex
// customStorage contains a customResourceDefinitionStorageMap // customStorage contains a crdStorageMap
customStorage atomic.Value customStorage atomic.Value
requestContextMapper apirequest.RequestContextMapper requestContextMapper apirequest.RequestContextMapper
customResourceDefinitionLister listers.CustomResourceDefinitionLister crdLister listers.CustomResourceDefinitionLister
delegate http.Handler delegate http.Handler
restOptionsGetter generic.RESTOptionsGetter restOptionsGetter generic.RESTOptionsGetter
admission admission.Interface admission admission.Interface
} }
// customResourceDefinitionInfo stores enough information to serve the storage for the custom resource // crdInfo stores enough information to serve the storage for the custom resource
type customResourceDefinitionInfo struct { type crdInfo struct {
storage *customresource.REST storage *customresource.REST
requestScope handlers.RequestScope requestScope handlers.RequestScope
} }
// customResourceDefinitionStorageMap goes from customresourcedefinition to its storage // crdStorageMap goes from customresourcedefinition to its storage
type customResourceDefinitionStorageMap map[types.UID]*customResourceDefinitionInfo type crdStorageMap map[types.UID]*crdInfo
func NewCustomResourceDefinitionHandler( func NewCustomResourceDefinitionHandler(
versionDiscoveryHandler *versionDiscoveryHandler, versionDiscoveryHandler *versionDiscoveryHandler,
groupDiscoveryHandler *groupDiscoveryHandler, groupDiscoveryHandler *groupDiscoveryHandler,
requestContextMapper apirequest.RequestContextMapper, requestContextMapper apirequest.RequestContextMapper,
customResourceDefinitionLister listers.CustomResourceDefinitionLister, crdLister listers.CustomResourceDefinitionLister,
delegate http.Handler, delegate http.Handler,
restOptionsGetter generic.RESTOptionsGetter, restOptionsGetter generic.RESTOptionsGetter,
admission admission.Interface) *customResourceDefinitionHandler { admission admission.Interface) *crdHandler {
ret := &customResourceDefinitionHandler{ ret := &crdHandler{
versionDiscoveryHandler: versionDiscoveryHandler, versionDiscoveryHandler: versionDiscoveryHandler,
groupDiscoveryHandler: groupDiscoveryHandler, groupDiscoveryHandler: groupDiscoveryHandler,
customStorage: atomic.Value{}, customStorage: atomic.Value{},
requestContextMapper: requestContextMapper, requestContextMapper: requestContextMapper,
customResourceDefinitionLister: customResourceDefinitionLister, crdLister: crdLister,
delegate: delegate, delegate: delegate,
restOptionsGetter: restOptionsGetter, restOptionsGetter: restOptionsGetter,
admission: admission, admission: admission,
} }
ret.customStorage.Store(customResourceDefinitionStorageMap{}) ret.customStorage.Store(crdStorageMap{})
return ret return ret
} }
func (r *customResourceDefinitionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
ctx, ok := r.requestContextMapper.Get(req) ctx, ok := r.requestContextMapper.Get(req)
if !ok { if !ok {
// programmer error // programmer error
@ -134,8 +134,8 @@ func (r *customResourceDefinitionHandler) ServeHTTP(w http.ResponseWriter, req *
return return
} }
customResourceDefinitionName := requestInfo.Resource + "." + requestInfo.APIGroup crdName := requestInfo.Resource + "." + requestInfo.APIGroup
customResourceDefinition, err := r.customResourceDefinitionLister.Get(customResourceDefinitionName) crd, err := r.crdLister.Get(crdName)
if apierrors.IsNotFound(err) { if apierrors.IsNotFound(err) {
r.delegate.ServeHTTP(w, req) r.delegate.ServeHTTP(w, req)
return return
@ -144,15 +144,18 @@ func (r *customResourceDefinitionHandler) ServeHTTP(w http.ResponseWriter, req *
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
if customResourceDefinition.Spec.Version != requestInfo.APIVersion { if crd.Spec.Version != requestInfo.APIVersion {
r.delegate.ServeHTTP(w, req) r.delegate.ServeHTTP(w, req)
return return
} }
// TODO this is the point to do the condition checks // if we can't definitively determine that our names are good, delegate
if !apiextensions.IsCRDConditionFalse(crd, apiextensions.NameConflict) {
r.delegate.ServeHTTP(w, req)
}
customResourceDefinitionInfo := r.getServingInfoFor(customResourceDefinition) crdInfo := r.getServingInfoFor(crd)
storage := customResourceDefinitionInfo.storage storage := crdInfo.storage
requestScope := customResourceDefinitionInfo.requestScope requestScope := crdInfo.requestScope
minRequestTimeout := 1 * time.Minute minRequestTimeout := 1 * time.Minute
switch requestInfo.Verb { switch requestInfo.Verb {
@ -195,12 +198,12 @@ func (r *customResourceDefinitionHandler) ServeHTTP(w http.ResponseWriter, req *
} }
// removeDeadStorage removes REST storage that isn't being used // removeDeadStorage removes REST storage that isn't being used
func (r *customResourceDefinitionHandler) removeDeadStorage() { func (r *crdHandler) removeDeadStorage() {
// these don't have to be live. A snapshot is fine // these don't have to be live. A snapshot is fine
// if we wrongly delete, that's ok. The rest storage will be recreated on the next request // if we wrongly delete, that's ok. The rest storage will be recreated on the next request
// if we wrongly miss one, that's ok. We'll get it next time // if we wrongly miss one, that's ok. We'll get it next time
storageMap := r.customStorage.Load().(customResourceDefinitionStorageMap) storageMap := r.customStorage.Load().(crdStorageMap)
allCustomResourceDefinitions, err := r.customResourceDefinitionLister.List(labels.Everything()) allCustomResourceDefinitions, err := r.crdLister.List(labels.Everything())
if err != nil { if err != nil {
utilruntime.HandleError(err) utilruntime.HandleError(err)
return return
@ -208,8 +211,8 @@ func (r *customResourceDefinitionHandler) removeDeadStorage() {
for uid := range storageMap { for uid := range storageMap {
found := false found := false
for _, customResourceDefinition := range allCustomResourceDefinitions { for _, crd := range allCustomResourceDefinitions {
if customResourceDefinition.UID == uid { if crd.UID == uid {
found = true found = true
break break
} }
@ -225,9 +228,9 @@ func (r *customResourceDefinitionHandler) removeDeadStorage() {
r.customStorage.Store(storageMap) r.customStorage.Store(storageMap)
} }
func (r *customResourceDefinitionHandler) getServingInfoFor(customResourceDefinition *apiextensions.CustomResourceDefinition) *customResourceDefinitionInfo { func (r *crdHandler) getServingInfoFor(crd *apiextensions.CustomResourceDefinition) *crdInfo {
storageMap := r.customStorage.Load().(customResourceDefinitionStorageMap) storageMap := r.customStorage.Load().(crdStorageMap)
ret, ok := storageMap[customResourceDefinition.UID] ret, ok := storageMap[crd.UID]
if ok { if ok {
return ret return ret
} }
@ -235,21 +238,21 @@ func (r *customResourceDefinitionHandler) getServingInfoFor(customResourceDefini
r.customStorageLock.Lock() r.customStorageLock.Lock()
defer r.customStorageLock.Unlock() defer r.customStorageLock.Unlock()
ret, ok = storageMap[customResourceDefinition.UID] ret, ok = storageMap[crd.UID]
if ok { if ok {
return ret return ret
} }
storage := customresource.NewREST( storage := customresource.NewREST(
schema.GroupResource{Group: customResourceDefinition.Spec.Group, Resource: customResourceDefinition.Spec.Names.Plural}, schema.GroupResource{Group: crd.Spec.Group, Resource: crd.Spec.Names.Plural},
schema.GroupVersionKind{Group: customResourceDefinition.Spec.Group, Version: customResourceDefinition.Spec.Version, Kind: customResourceDefinition.Spec.Names.ListKind}, schema.GroupVersionKind{Group: crd.Spec.Group, Version: crd.Spec.Version, Kind: crd.Spec.Names.ListKind},
UnstructuredCopier{}, UnstructuredCopier{},
customresource.NewStrategy(discovery.NewUnstructuredObjectTyper(nil), customResourceDefinition.Spec.Scope == apiextensions.NamespaceScoped), customresource.NewStrategy(discovery.NewUnstructuredObjectTyper(nil), crd.Spec.Scope == apiextensions.NamespaceScoped),
r.restOptionsGetter, r.restOptionsGetter,
) )
parameterScheme := runtime.NewScheme() parameterScheme := runtime.NewScheme()
parameterScheme.AddUnversionedTypes(schema.GroupVersion{Group: customResourceDefinition.Spec.Group, Version: customResourceDefinition.Spec.Version}, parameterScheme.AddUnversionedTypes(schema.GroupVersion{Group: crd.Spec.Group, Version: crd.Spec.Version},
&metav1.ListOptions{}, &metav1.ListOptions{},
&metav1.ExportOptions{}, &metav1.ExportOptions{},
&metav1.GetOptions{}, &metav1.GetOptions{},
@ -259,11 +262,11 @@ func (r *customResourceDefinitionHandler) getServingInfoFor(customResourceDefini
parameterCodec := runtime.NewParameterCodec(parameterScheme) parameterCodec := runtime.NewParameterCodec(parameterScheme)
selfLinkPrefix := "" selfLinkPrefix := ""
switch customResourceDefinition.Spec.Scope { switch crd.Spec.Scope {
case apiextensions.ClusterScoped: case apiextensions.ClusterScoped:
selfLinkPrefix = "/" + path.Join("apis", customResourceDefinition.Spec.Group, customResourceDefinition.Spec.Version) + "/" selfLinkPrefix = "/" + path.Join("apis", crd.Spec.Group, crd.Spec.Version) + "/"
case apiextensions.NamespaceScoped: case apiextensions.NamespaceScoped:
selfLinkPrefix = "/" + path.Join("apis", customResourceDefinition.Spec.Group, customResourceDefinition.Spec.Version, "namespaces") + "/" selfLinkPrefix = "/" + path.Join("apis", crd.Spec.Group, crd.Spec.Version, "namespaces") + "/"
} }
requestScope := handlers.RequestScope{ requestScope := handlers.RequestScope{
@ -273,7 +276,7 @@ func (r *customResourceDefinitionHandler) getServingInfoFor(customResourceDefini
return ret return ret
}, },
SelfLinker: meta.NewAccessor(), SelfLinker: meta.NewAccessor(),
ClusterScoped: customResourceDefinition.Spec.Scope == apiextensions.ClusterScoped, ClusterScoped: crd.Spec.Scope == apiextensions.ClusterScoped,
SelfLinkPathPrefix: selfLinkPrefix, SelfLinkPathPrefix: selfLinkPrefix,
}, },
ContextFunc: func(req *http.Request) apirequest.Context { ContextFunc: func(req *http.Request) apirequest.Context {
@ -291,18 +294,18 @@ func (r *customResourceDefinitionHandler) getServingInfoFor(customResourceDefini
Typer: discovery.NewUnstructuredObjectTyper(nil), Typer: discovery.NewUnstructuredObjectTyper(nil),
UnsafeConvertor: unstructured.UnstructuredObjectConverter{}, UnsafeConvertor: unstructured.UnstructuredObjectConverter{},
Resource: schema.GroupVersionResource{Group: customResourceDefinition.Spec.Group, Version: customResourceDefinition.Spec.Version, Resource: customResourceDefinition.Spec.Names.Plural}, Resource: schema.GroupVersionResource{Group: crd.Spec.Group, Version: crd.Spec.Version, Resource: crd.Spec.Names.Plural},
Kind: schema.GroupVersionKind{Group: customResourceDefinition.Spec.Group, Version: customResourceDefinition.Spec.Version, Kind: customResourceDefinition.Spec.Names.Kind}, Kind: schema.GroupVersionKind{Group: crd.Spec.Group, Version: crd.Spec.Version, Kind: crd.Spec.Names.Kind},
Subresource: "", Subresource: "",
MetaGroupVersion: metav1.SchemeGroupVersion, MetaGroupVersion: metav1.SchemeGroupVersion,
} }
ret = &customResourceDefinitionInfo{ ret = &crdInfo{
storage: storage, storage: storage,
requestScope: requestScope, requestScope: requestScope,
} }
storageMap[customResourceDefinition.UID] = ret storageMap[crd.UID] = ret
r.customStorage.Store(storageMap) r.customStorage.Store(storageMap)
return ret return ret
} }

View File

@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_test(
name = "go_default_test",
srcs = ["naming_controller_test.go"],
library = ":go_default_library",
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/apis/apiextensions:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/listers/apiextensions/internalversion:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["naming_controller.go"],
tags = ["automanaged"],
deps = [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
"//vendor/k8s.io/client-go/util/workqueue:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/apis/apiextensions:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/clientset/internalclientset/typed/apiextensions/internalversion:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion/apiextensions/internalversion:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/listers/apiextensions/internalversion:go_default_library",
],
)

View File

@ -0,0 +1,337 @@
/*
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 status
import (
"fmt"
"reflect"
"time"
"github.com/golang/glog"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/labels"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
"k8s.io/kube-apiextensions-server/pkg/apis/apiextensions"
client "k8s.io/kube-apiextensions-server/pkg/client/clientset/internalclientset/typed/apiextensions/internalversion"
informers "k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion/apiextensions/internalversion"
listers "k8s.io/kube-apiextensions-server/pkg/client/listers/apiextensions/internalversion"
)
var cloner = conversion.NewCloner()
// This controller is reserving names. To avoid conflicts, be sure to run only one instance of the worker at a time.
// This could eventually be lifted, but starting simple.
type NamingConditionController struct {
crdClient client.CustomResourceDefinitionsGetter
crdLister listers.CustomResourceDefinitionLister
crdSynced cache.InformerSynced
// crdMutationCache backs our lister and keeps track of committed updates to avoid racy
// write/lookup cycles. It's got 100 slots by default, so it unlikely to overrun
// TODO to revisit this if naming conflicts are found to occur in the wild
crdMutationCache cache.MutationCache
// To allow injection for testing.
syncFn func(key string) error
queue workqueue.RateLimitingInterface
}
func NewNamingConditionController(
crdInformer informers.CustomResourceDefinitionInformer,
crdClient client.CustomResourceDefinitionsGetter,
) *NamingConditionController {
c := &NamingConditionController{
crdClient: crdClient,
crdLister: crdInformer.Lister(),
crdSynced: crdInformer.Informer().HasSynced,
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "CustomResourceDefinition-NamingConditionController"),
}
informerIndexer := crdInformer.Informer().GetIndexer()
c.crdMutationCache = cache.NewIntegerResourceVersionMutationCache(informerIndexer, informerIndexer)
crdInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.addCustomResourceDefinition,
UpdateFunc: c.updateCustomResourceDefinition,
DeleteFunc: c.deleteCustomResourceDefinition,
})
c.syncFn = c.sync
return c
}
func (c *NamingConditionController) getAcceptedNamesForGroup(group string) (allResources sets.String, allKinds sets.String) {
allResources = sets.String{}
allKinds = sets.String{}
list, err := c.crdLister.List(labels.Everything())
if err != nil {
panic(err)
}
for _, curr := range list {
if curr.Spec.Group != group {
continue
}
// for each item here, see if we have a mutation cache entry that is more recent
// this makes sure that if we tight loop on update and run, our mutation cache will show
// us the version of the objects we just updated to.
item := curr
obj, exists, err := c.crdMutationCache.GetByKey(curr.Name)
if exists && err == nil {
item = obj.(*apiextensions.CustomResourceDefinition)
}
allResources.Insert(item.Status.AcceptedNames.Plural)
allResources.Insert(item.Status.AcceptedNames.Singular)
allResources.Insert(item.Status.AcceptedNames.ShortNames...)
allKinds.Insert(item.Status.AcceptedNames.Kind)
allKinds.Insert(item.Status.AcceptedNames.ListKind)
}
return allResources, allKinds
}
func (c *NamingConditionController) calculateNames(in *apiextensions.CustomResourceDefinition) (apiextensions.CustomResourceDefinitionNames, apiextensions.CustomResourceDefinitionCondition) {
// Get the names that have already been claimed
allResources, allKinds := c.getAcceptedNamesForGroup(in.Spec.Group)
condition := apiextensions.CustomResourceDefinitionCondition{
Type: apiextensions.NameConflict,
Status: apiextensions.ConditionUnknown,
}
requestedNames := in.Spec.Names
acceptedNames := in.Status.AcceptedNames
newNames := in.Status.AcceptedNames
// Check each name for mismatches. If there's a mismatch between spec and status, then try to deconflict.
// Continue on errors so that the status is the best match possible
if err := equalToAcceptedOrFresh(requestedNames.Plural, acceptedNames.Plural, allResources); err != nil {
condition.Status = apiextensions.ConditionTrue
condition.Reason = "Plural"
condition.Message = err.Error()
} else {
newNames.Plural = requestedNames.Plural
}
if err := equalToAcceptedOrFresh(requestedNames.Singular, acceptedNames.Singular, allResources); err != nil {
condition.Status = apiextensions.ConditionTrue
condition.Reason = "Singular"
condition.Message = err.Error()
} else {
newNames.Singular = requestedNames.Singular
}
if !reflect.DeepEqual(requestedNames.ShortNames, acceptedNames.ShortNames) {
errs := []error{}
existingShortNames := sets.NewString(acceptedNames.ShortNames...)
for _, shortName := range requestedNames.ShortNames {
// if the shortname is already ours, then we're fine
if existingShortNames.Has(shortName) {
continue
}
if err := equalToAcceptedOrFresh(shortName, "", allResources); err != nil {
errs = append(errs, err)
}
}
if err := utilerrors.NewAggregate(errs); err != nil {
condition.Status = apiextensions.ConditionTrue
condition.Reason = "ShortNames"
condition.Message = err.Error()
} else {
newNames.ShortNames = requestedNames.ShortNames
}
}
if err := equalToAcceptedOrFresh(requestedNames.Kind, acceptedNames.Kind, allKinds); err != nil {
condition.Status = apiextensions.ConditionTrue
condition.Reason = "Kind"
condition.Message = err.Error()
} else {
newNames.Kind = requestedNames.Kind
}
if err := equalToAcceptedOrFresh(requestedNames.ListKind, acceptedNames.ListKind, allKinds); err != nil {
condition.Status = apiextensions.ConditionTrue
condition.Reason = "ListKind"
condition.Message = err.Error()
} else {
newNames.ListKind = requestedNames.ListKind
}
// if we haven't changed the condition, then our names must be good.
if condition.Status == apiextensions.ConditionUnknown {
condition.Status = apiextensions.ConditionFalse
condition.Reason = "NoConflicts"
condition.Message = "no conflicts found"
}
return newNames, condition
}
func equalToAcceptedOrFresh(requestedName, acceptedName string, usedNames sets.String) error {
if requestedName == acceptedName {
return nil
}
if !usedNames.Has(requestedName) {
return nil
}
return fmt.Errorf("%q is already in use", requestedName)
}
func (c *NamingConditionController) sync(key string) error {
inCustomResourceDefinition, err := c.crdLister.Get(key)
if apierrors.IsNotFound(err) {
return nil
}
if err != nil {
return err
}
acceptedNames, namingCondition := c.calculateNames(inCustomResourceDefinition)
// nothing to do if accepted names and NameConflict condition didn't change
if reflect.DeepEqual(inCustomResourceDefinition.Status.AcceptedNames, acceptedNames) &&
apiextensions.IsCRDConditionEquivalent(
&namingCondition,
apiextensions.FindCRDCondition(inCustomResourceDefinition, apiextensions.NameConflict)) {
return nil
}
crd := &apiextensions.CustomResourceDefinition{}
if err := apiextensions.DeepCopy_apiextensions_CustomResourceDefinition(inCustomResourceDefinition, crd, cloner); err != nil {
return err
}
crd.Status.AcceptedNames = acceptedNames
apiextensions.SetCRDCondition(crd, namingCondition)
updatedObj, err := c.crdClient.CustomResourceDefinitions().UpdateStatus(crd)
if err != nil {
return err
}
// if the update was successful, go ahead and add the entry to the mutation cache
c.crdMutationCache.Mutation(updatedObj)
// we updated our status, so we may be releasing a name. When this happens, we need to rekick everything in our group
// if we fail to rekick, just return as normal. We'll get everything on a resync
list, err := c.crdLister.List(labels.Everything())
if err != nil {
return nil
}
for _, curr := range list {
if curr.Spec.Group == crd.Spec.Group {
c.queue.Add(curr.Name)
}
}
return nil
}
func (c *NamingConditionController) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
defer c.queue.ShutDown()
glog.Infof("Starting NamingConditionController")
defer glog.Infof("Shutting down NamingConditionController")
if !cache.WaitForCacheSync(stopCh, c.crdSynced) {
return
}
// only start one worker thread since its a slow moving API and the naming conflict resolution bits aren't thread-safe
go wait.Until(c.runWorker, time.Second, stopCh)
<-stopCh
}
func (c *NamingConditionController) runWorker() {
for c.processNextWorkItem() {
}
}
// processNextWorkItem deals with one key off the queue. It returns false when it's time to quit.
func (c *NamingConditionController) processNextWorkItem() bool {
key, quit := c.queue.Get()
if quit {
return false
}
defer c.queue.Done(key)
err := c.syncFn(key.(string))
if err == nil {
c.queue.Forget(key)
return true
}
utilruntime.HandleError(fmt.Errorf("%v failed with: %v", key, err))
c.queue.AddRateLimited(key)
return true
}
func (c *NamingConditionController) enqueue(obj *apiextensions.CustomResourceDefinition) {
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Couldn't get key for object %#v: %v", obj, err))
return
}
c.queue.Add(key)
}
func (c *NamingConditionController) addCustomResourceDefinition(obj interface{}) {
castObj := obj.(*apiextensions.CustomResourceDefinition)
glog.V(4).Infof("Adding %s", castObj.Name)
c.enqueue(castObj)
}
func (c *NamingConditionController) updateCustomResourceDefinition(obj, _ interface{}) {
castObj := obj.(*apiextensions.CustomResourceDefinition)
glog.V(4).Infof("Updating %s", castObj.Name)
c.enqueue(castObj)
}
func (c *NamingConditionController) deleteCustomResourceDefinition(obj interface{}) {
castObj, ok := obj.(*apiextensions.CustomResourceDefinition)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
glog.Errorf("Couldn't get object from tombstone %#v", obj)
return
}
castObj, ok = tombstone.Obj.(*apiextensions.CustomResourceDefinition)
if !ok {
glog.Errorf("Tombstone contained object that is not expected %#v", obj)
return
}
}
glog.V(4).Infof("Deleting %q", castObj.Name)
c.enqueue(castObj)
}

View File

@ -0,0 +1,256 @@
/*
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 status
import (
"reflect"
"strings"
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/kube-apiextensions-server/pkg/apis/apiextensions"
listers "k8s.io/kube-apiextensions-server/pkg/client/listers/apiextensions/internalversion"
)
type crdBuilder struct {
curr apiextensions.CustomResourceDefinition
}
func newCRD(name string) *crdBuilder {
tokens := strings.SplitN(name, ".", 2)
return &crdBuilder{
curr: apiextensions.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: apiextensions.CustomResourceDefinitionSpec{
Group: tokens[1],
Names: apiextensions.CustomResourceDefinitionNames{
Plural: tokens[0],
},
},
},
}
}
func (b *crdBuilder) SpecNames(plural, singular, kind, listKind string, shortNames ...string) *crdBuilder {
b.curr.Spec.Names.Plural = plural
b.curr.Spec.Names.Singular = singular
b.curr.Spec.Names.Kind = kind
b.curr.Spec.Names.ListKind = listKind
b.curr.Spec.Names.ShortNames = shortNames
return b
}
func (b *crdBuilder) StatusNames(plural, singular, kind, listKind string, shortNames ...string) *crdBuilder {
b.curr.Status.AcceptedNames.Plural = plural
b.curr.Status.AcceptedNames.Singular = singular
b.curr.Status.AcceptedNames.Kind = kind
b.curr.Status.AcceptedNames.ListKind = listKind
b.curr.Status.AcceptedNames.ShortNames = shortNames
return b
}
func names(plural, singular, kind, listKind string, shortNames ...string) apiextensions.CustomResourceDefinitionNames {
ret := apiextensions.CustomResourceDefinitionNames{
Plural: plural,
Singular: singular,
Kind: kind,
ListKind: listKind,
ShortNames: shortNames,
}
return ret
}
func (b *crdBuilder) NewOrDie() *apiextensions.CustomResourceDefinition {
return &b.curr
}
var goodCondition = apiextensions.CustomResourceDefinitionCondition{
Type: apiextensions.NameConflict,
Status: apiextensions.ConditionFalse,
Reason: "NoConflicts",
Message: "no conflicts found",
}
func badCondition(reason, message string) apiextensions.CustomResourceDefinitionCondition {
return apiextensions.CustomResourceDefinitionCondition{
Type: apiextensions.NameConflict,
Status: apiextensions.ConditionTrue,
Reason: reason,
Message: message,
}
}
func TestSync(t *testing.T) {
tests := []struct {
name string
in *apiextensions.CustomResourceDefinition
existing []*apiextensions.CustomResourceDefinition
expectedNames apiextensions.CustomResourceDefinitionNames
expectedCondition apiextensions.CustomResourceDefinitionCondition
}{
{
name: "first resource",
in: newCRD("alfa.bravo.com").NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{},
expectedNames: apiextensions.CustomResourceDefinitionNames{
Plural: "alfa",
},
expectedCondition: goodCondition,
},
{
name: "different groups",
in: newCRD("alfa.bravo.com").SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("alfa.charlie.com").StatusNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").NewOrDie(),
},
expectedNames: names("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2"),
expectedCondition: goodCondition,
},
{
name: "conflict plural to singular",
in: newCRD("alfa.bravo.com").SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("india.bravo.com").StatusNames("india", "alfa", "", "").NewOrDie(),
},
expectedNames: names("", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2"),
expectedCondition: badCondition("Plural", `"alfa" is already in use`),
},
{
name: "conflict singular to shortName",
in: newCRD("alfa.bravo.com").SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("india.bravo.com").StatusNames("india", "indias", "", "", "delta-singular").NewOrDie(),
},
expectedNames: names("alfa", "", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2"),
expectedCondition: badCondition("Singular", `"delta-singular" is already in use`),
},
{
name: "conflict on shortName to shortName",
in: newCRD("alfa.bravo.com").SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("india.bravo.com").StatusNames("india", "indias", "", "", "hotel-shortname-2").NewOrDie(),
},
expectedNames: names("alfa", "delta-singular", "echo-kind", "foxtrot-listkind"),
expectedCondition: badCondition("ShortNames", `"hotel-shortname-2" is already in use`),
},
{
name: "conflict on kind to listkind",
in: newCRD("alfa.bravo.com").SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("india.bravo.com").StatusNames("india", "indias", "", "echo-kind").NewOrDie(),
},
expectedNames: names("alfa", "delta-singular", "", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2"),
expectedCondition: badCondition("Kind", `"echo-kind" is already in use`),
},
{
name: "conflict on listkind to kind",
in: newCRD("alfa.bravo.com").SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("india.bravo.com").StatusNames("india", "indias", "foxtrot-listkind", "").NewOrDie(),
},
expectedNames: names("alfa", "delta-singular", "echo-kind", "", "golf-shortname-1", "hotel-shortname-2"),
expectedCondition: badCondition("ListKind", `"foxtrot-listkind" is already in use`),
},
{
name: "no conflict on resource and kind",
in: newCRD("alfa.bravo.com").SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("india.bravo.com").StatusNames("india", "echo-kind", "", "").NewOrDie(),
},
expectedNames: names("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2"),
expectedCondition: goodCondition,
},
{
name: "merge on conflicts",
in: newCRD("alfa.bravo.com").
SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
StatusNames("zulu", "yankee-singular", "xray-kind", "whiskey-listkind", "victor-shortname-1", "uniform-shortname-2").
NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("india.bravo.com").StatusNames("india", "indias", "foxtrot-listkind", "", "delta-singular").NewOrDie(),
},
expectedNames: names("alfa", "yankee-singular", "echo-kind", "whiskey-listkind", "golf-shortname-1", "hotel-shortname-2"),
expectedCondition: badCondition("ListKind", `"foxtrot-listkind" is already in use`),
},
{
name: "merge on conflicts shortNames as one",
in: newCRD("alfa.bravo.com").
SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
StatusNames("zulu", "yankee-singular", "xray-kind", "whiskey-listkind", "victor-shortname-1", "uniform-shortname-2").
NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("india.bravo.com").StatusNames("india", "indias", "foxtrot-listkind", "", "delta-singular", "golf-shortname-1").NewOrDie(),
},
expectedNames: names("alfa", "yankee-singular", "echo-kind", "whiskey-listkind", "victor-shortname-1", "uniform-shortname-2"),
expectedCondition: badCondition("ListKind", `"foxtrot-listkind" is already in use`),
},
{
name: "no conflicts on self",
in: newCRD("alfa.bravo.com").
SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
StatusNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("alfa.bravo.com").
SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
StatusNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
NewOrDie(),
},
expectedNames: names("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2"),
expectedCondition: goodCondition,
},
{
name: "no conflicts on self, remove shortname",
in: newCRD("alfa.bravo.com").
SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1").
StatusNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
NewOrDie(),
existing: []*apiextensions.CustomResourceDefinition{
newCRD("alfa.bravo.com").
SpecNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
StatusNames("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1", "hotel-shortname-2").
NewOrDie(),
},
expectedNames: names("alfa", "delta-singular", "echo-kind", "foxtrot-listkind", "golf-shortname-1"),
expectedCondition: goodCondition,
},
}
for _, tc := range tests {
crdIndexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
for _, obj := range tc.existing {
crdIndexer.Add(obj)
}
c := NamingConditionController{
crdLister: listers.NewCustomResourceDefinitionLister(crdIndexer),
crdMutationCache: cache.NewIntegerResourceVersionMutationCache(crdIndexer, crdIndexer),
}
actualNames, actualCondition := c.calculateNames(tc.in)
if e, a := tc.expectedNames, actualNames; !reflect.DeepEqual(e, a) {
t.Errorf("%v expected %v, got %#v", tc.name, e, a)
}
if e, a := tc.expectedCondition, actualCondition; !apiextensions.IsCRDConditionEquivalent(&e, &a) {
t.Errorf("%v expected %v, got %v", tc.name, e, a)
}
}
}

View File

@ -22,6 +22,7 @@ go_library(
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library", "//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library", "//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library", "//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library", "//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library", "//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/apis/apiextensions:go_default_library", "//vendor/k8s.io/kube-apiextensions-server/pkg/apis/apiextensions:go_default_library",

View File

@ -18,8 +18,10 @@ package customresourcedefinition
import ( import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/generic"
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kube-apiextensions-server/pkg/apis/apiextensions" "k8s.io/kube-apiextensions-server/pkg/apis/apiextensions"
) )
@ -52,3 +54,28 @@ func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) *REST
} }
return &REST{store} return &REST{store}
} }
// NewStatusREST makes a RESTStorage for status that has more limited options.
// It is based on the original REST so that we can share the same underlying store
func NewStatusREST(scheme *runtime.Scheme, rest *REST) *StatusREST {
statusStore := *rest.Store
statusStore.CreateStrategy = nil
statusStore.DeleteStrategy = nil
statusStore.UpdateStrategy = NewStatusStrategy(scheme)
return &StatusREST{store: &statusStore}
}
type StatusREST struct {
store *genericregistry.Store
}
var _ = rest.Updater(&StatusREST{})
func (r *StatusREST) New() runtime.Object {
return &apiextensions.CustomResourceDefinition{}
}
// Update alters the status subset of an object.
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo)
}

View File

@ -32,44 +32,82 @@ import (
"k8s.io/kube-apiextensions-server/pkg/apis/apiextensions/validation" "k8s.io/kube-apiextensions-server/pkg/apis/apiextensions/validation"
) )
type apiServerStrategy struct { type strategy struct {
runtime.ObjectTyper runtime.ObjectTyper
names.NameGenerator names.NameGenerator
} }
func NewStrategy(typer runtime.ObjectTyper) apiServerStrategy { func NewStrategy(typer runtime.ObjectTyper) strategy {
return apiServerStrategy{typer, names.SimpleNameGenerator} return strategy{typer, names.SimpleNameGenerator}
} }
func (apiServerStrategy) NamespaceScoped() bool { func (strategy) NamespaceScoped() bool {
return false return false
} }
func (apiServerStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) { func (strategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
} }
func (apiServerStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) { func (strategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
} }
func (apiServerStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList { func (strategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
return validation.ValidateCustomResourceDefinition(obj.(*apiextensions.CustomResourceDefinition)) return validation.ValidateCustomResourceDefinition(obj.(*apiextensions.CustomResourceDefinition))
} }
func (apiServerStrategy) AllowCreateOnUpdate() bool { func (strategy) AllowCreateOnUpdate() bool {
return false return false
} }
func (apiServerStrategy) AllowUnconditionalUpdate() bool { func (strategy) AllowUnconditionalUpdate() bool {
return false return false
} }
func (apiServerStrategy) Canonicalize(obj runtime.Object) { func (strategy) Canonicalize(obj runtime.Object) {
} }
func (apiServerStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList { func (strategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
return validation.ValidateCustomResourceDefinitionUpdate(obj.(*apiextensions.CustomResourceDefinition), old.(*apiextensions.CustomResourceDefinition)) return validation.ValidateCustomResourceDefinitionUpdate(obj.(*apiextensions.CustomResourceDefinition), old.(*apiextensions.CustomResourceDefinition))
} }
type statusStrategy struct {
runtime.ObjectTyper
names.NameGenerator
}
func NewStatusStrategy(typer runtime.ObjectTyper) statusStrategy {
return statusStrategy{typer, names.SimpleNameGenerator}
}
func (statusStrategy) NamespaceScoped() bool {
return false
}
func (statusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
newObj := obj.(*apiextensions.CustomResourceDefinition)
oldObj := old.(*apiextensions.CustomResourceDefinition)
newObj.Spec = oldObj.Spec
newObj.Labels = oldObj.Labels
newObj.Annotations = oldObj.Annotations
newObj.Finalizers = oldObj.Finalizers
newObj.OwnerReferences = oldObj.OwnerReferences
}
func (statusStrategy) AllowCreateOnUpdate() bool {
return false
}
func (statusStrategy) AllowUnconditionalUpdate() bool {
return false
}
func (statusStrategy) Canonicalize(obj runtime.Object) {
}
func (statusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
return validation.ValidateUpdateCustomResourceDefinitionStatus(obj.(*apiextensions.CustomResourceDefinition), old.(*apiextensions.CustomResourceDefinition))
}
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
apiserver, ok := obj.(*apiextensions.CustomResourceDefinition) apiserver, ok := obj.(*apiextensions.CustomResourceDefinition)
if !ok { if !ok {

View File

@ -182,6 +182,14 @@
"ImportPath": "github.com/grpc-ecosystem/grpc-gateway/utilities", "ImportPath": "github.com/grpc-ecosystem/grpc-gateway/utilities",
"Rev": "84398b94e188ee336f307779b57b3aa91af7063c" "Rev": "84398b94e188ee336f307779b57b3aa91af7063c"
}, },
{
"ImportPath": "github.com/hashicorp/golang-lru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{
"ImportPath": "github.com/hashicorp/golang-lru/simplelru",
"Rev": "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4"
},
{ {
"ImportPath": "github.com/howeyc/gopass", "ImportPath": "github.com/howeyc/gopass",
"Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d" "Rev": "3ca23474a7c7203e0a0a070fd33508f6efdb9b3d"