本文整理汇总了Golang中k8s/io/kubernetes/pkg/controller/framework.DeletionHandlingMetaNamespaceKeyFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang DeletionHandlingMetaNamespaceKeyFunc函数的具体用法?Golang DeletionHandlingMetaNamespaceKeyFunc怎么用?Golang DeletionHandlingMetaNamespaceKeyFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DeletionHandlingMetaNamespaceKeyFunc函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExampleInformer
func ExampleInformer() {
// source simulates an apiserver object endpoint.
source := framework.NewFakeControllerSource()
// Let's do threadsafe output to get predictable test results.
deletionCounter := make(chan string, 1000)
// Make a controller that immediately deletes anything added to it, and
// logs anything deleted.
_, controller := framework.NewInformer(
source,
&api.Pod{},
time.Millisecond*100,
framework.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
source.Delete(obj.(runtime.Object))
},
DeleteFunc: func(obj interface{}) {
key, err := framework.DeletionHandlingMetaNamespaceKeyFunc(obj)
if err != nil {
key = "oops something went wrong with the key"
}
// Report this deletion.
deletionCounter <- key
},
},
)
// Run the controller and run it until we close stop.
stop := make(chan struct{})
defer close(stop)
go controller.Run(stop)
// Let's add a few objects to the source.
testIDs := []string{"a-hello", "b-controller", "c-framework"}
for _, name := range testIDs {
// Note that these pods are not valid-- the fake source doesn't
// call validation or anything.
source.Add(&api.Pod{ObjectMeta: api.ObjectMeta{Name: name}})
}
// Let's wait for the controller to process the things we just added.
outputSet := util.StringSet{}
for i := 0; i < len(testIDs); i++ {
outputSet.Insert(<-deletionCounter)
}
for _, key := range outputSet.List() {
fmt.Println(key)
}
// Output:
// a-hello
// b-controller
// c-framework
}
示例2: Get
func (i *InformerToClusterPolicyLister) Get(name string) (*authorizationapi.ClusterPolicy, error) {
keyObj := &authorizationapi.ClusterPolicy{ObjectMeta: kapi.ObjectMeta{Name: name}}
key, _ := framework.DeletionHandlingMetaNamespaceKeyFunc(keyObj)
item, exists, getErr := i.GetIndexer().GetByKey(key)
if getErr != nil {
return nil, getErr
}
if !exists {
existsErr := kapierrors.NewNotFound(authorizationapi.Resource("clusterpolicy"), name)
return nil, existsErr
}
return item.(*authorizationapi.ClusterPolicy), nil
}
示例3: Get
func (i *indexerToPolicyBindingLister) Get(name string) (*authorizationapi.PolicyBinding, error) {
keyObj := &authorizationapi.PolicyBinding{ObjectMeta: kapi.ObjectMeta{Namespace: i.namespace, Name: name}}
key, _ := framework.DeletionHandlingMetaNamespaceKeyFunc(keyObj)
item, exists, getErr := i.Indexer.GetByKey(key)
if getErr != nil {
return nil, getErr
}
if !exists {
existsErr := kapierrors.NewNotFound(authorizationapi.Resource("policyBinding"), name)
return nil, existsErr
}
return item.(*authorizationapi.PolicyBinding), nil
}
示例4: Get
func (s *IndexerToSecurityContextConstraintsLister) Get(name string) (*kapi.SecurityContextConstraints, error) {
keyObj := &kapi.SecurityContextConstraints{ObjectMeta: kapi.ObjectMeta{Name: name}}
key, _ := framework.DeletionHandlingMetaNamespaceKeyFunc(keyObj)
item, exists, getErr := s.GetByKey(key)
if getErr != nil {
return nil, getErr
}
if !exists {
existsErr := kerrors.NewNotFound(kapi.Resource("securitycontexconstraints"), name)
return nil, existsErr
}
return item.(*kapi.SecurityContextConstraints), nil
}
示例5: Get
func (i *IndexerToClusterResourceQuotaLister) Get(name string) (*quotaapi.ClusterResourceQuota, error) {
keyObj := "aapi.ClusterResourceQuota{ObjectMeta: kapi.ObjectMeta{Name: name}}
key, _ := framework.DeletionHandlingMetaNamespaceKeyFunc(keyObj)
item, exists, getErr := i.GetByKey(key)
if getErr != nil {
return nil, getErr
}
if !exists {
existsErr := kapierrors.NewNotFound(quotaapi.Resource("clusterresourcequota"), name)
return nil, existsErr
}
return item.(*quotaapi.ClusterResourceQuota), nil
}
示例6: TestHammerController
func TestHammerController(t *testing.T) {
// This test executes a bunch of requests through the fake source and
// controller framework to make sure there's no locking/threading
// errors. If an error happens, it should hang forever or trigger the
// race detector.
// source simulates an apiserver object endpoint.
source := framework.NewFakeControllerSource()
// Let's do threadsafe output to get predictable test results.
outputSetLock := sync.Mutex{}
// map of key to operations done on the key
outputSet := map[string][]string{}
recordFunc := func(eventType string, obj interface{}) {
key, err := framework.DeletionHandlingMetaNamespaceKeyFunc(obj)
if err != nil {
t.Errorf("something wrong with key: %v", err)
key = "oops something went wrong with the key"
}
// Record some output when items are deleted.
outputSetLock.Lock()
defer outputSetLock.Unlock()
outputSet[key] = append(outputSet[key], eventType)
}
// Make a controller which just logs all the changes it gets.
_, controller := framework.NewInformer(
source,
&api.Pod{},
time.Millisecond*100,
framework.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { recordFunc("add", obj) },
UpdateFunc: func(oldObj, newObj interface{}) { recordFunc("update", newObj) },
DeleteFunc: func(obj interface{}) { recordFunc("delete", obj) },
},
)
if controller.HasSynced() {
t.Errorf("Expected HasSynced() to return false before we started the controller")
}
// Run the controller and run it until we close stop.
stop := make(chan struct{})
go controller.Run(stop)
// Let's wait for the controller to do its initial sync
time.Sleep(100 * time.Millisecond)
if !controller.HasSynced() {
t.Errorf("Expected HasSynced() to return true after the initial sync")
}
wg := sync.WaitGroup{}
const threads = 3
wg.Add(threads)
for i := 0; i < threads; i++ {
go func() {
defer wg.Done()
// Let's add a few objects to the source.
currentNames := util.StringSet{}
rs := rand.NewSource(rand.Int63())
f := fuzz.New().NilChance(.5).NumElements(0, 2).RandSource(rs)
r := rand.New(rs) // Mustn't use r and f concurrently!
for i := 0; i < 100; i++ {
var name string
var isNew bool
if currentNames.Len() == 0 || r.Intn(3) == 1 {
f.Fuzz(&name)
isNew = true
} else {
l := currentNames.List()
name = l[r.Intn(len(l))]
}
pod := &api.Pod{}
f.Fuzz(pod)
pod.ObjectMeta.Name = name
pod.ObjectMeta.Namespace = "default"
// Add, update, or delete randomly.
// Note that these pods are not valid-- the fake source doesn't
// call validation or perform any other checking.
if isNew {
currentNames.Insert(name)
source.Add(pod)
continue
}
switch r.Intn(2) {
case 0:
currentNames.Insert(name)
source.Modify(pod)
case 1:
currentNames.Delete(name)
source.Delete(pod)
}
}
}()
}
wg.Wait()
//.........这里部分代码省略.........
示例7: GetKeyFor
// GetKey for returns the key under which the item would be put in the store.
func (fs *federatedStoreImpl) GetKeyFor(item interface{}) string {
// TODO: support other keying functions.
key, _ := framework.DeletionHandlingMetaNamespaceKeyFunc(item)
return key
}