本文整理匯總了Golang中k8s/io/kubernetes/pkg/storage.Interface類的典型用法代碼示例。如果您正苦於以下問題:Golang Interface類的具體用法?Golang Interface怎麽用?Golang Interface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Interface類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createThirdPartyObject
func createThirdPartyObject(s storage.Interface, path, name string, obj interface{}) error {
data, err := encodeToThirdParty(name, obj)
if err != nil {
return err
}
return s.Create(context.TODO(), etcdtest.AddPrefix(path), data, nil, 0)
}
示例2: CreateObj
// CreateObj will create a single object using the storage interface
func CreateObj(t *testing.T, helper storage.Interface, name string, obj, out runtime.Object, ttl uint64) error {
err := helper.Set(context.TODO(), name, obj, out, ttl)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
return err
}
示例3: NewREST
// NewREST returns a RESTStorage object that will work against access tokens
func NewREST(s storage.Interface, backends ...storage.Interface) *REST {
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.OAuthAccessToken{} },
NewListFunc: func() runtime.Object { return &api.OAuthAccessTokenList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return EtcdPrefix
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return util.NoNamespaceKeyFunc(ctx, EtcdPrefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.OAuthAccessToken).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return oauthaccesstoken.Matcher(label, field)
},
TTLFunc: func(obj runtime.Object, existing uint64, update bool) (uint64, error) {
token := obj.(*api.OAuthAccessToken)
expires := uint64(token.ExpiresIn)
return expires, nil
},
EndpointName: "oauthaccesstokens",
Storage: s,
}
store.CreateStrategy = oauthaccesstoken.Strategy
if len(backends) > 0 {
// Build identical stores that talk to a single etcd, so we can verify the token is distributed after creation
watchers := []rest.Watcher{}
for i := range backends {
watcher := *store
watcher.Storage = backends[i]
watchers = append(watchers, &watcher)
}
// Observe the cluster for the particular resource version, requiring at least one backend to succeed
observer := observe.NewClusterObserver(s.Versioner(), watchers, 1)
// After creation, wait for the new token to propagate
store.AfterCreate = func(obj runtime.Object) error {
return observer.ObserveResourceVersion(obj.(*api.OAuthAccessToken).ResourceVersion, 5*time.Second)
}
}
return &REST{store}
}
示例4: updatePod
func updatePod(t *testing.T, s storage.Interface, obj, old *api.Pod) *api.Pod {
key := etcdtest.AddPrefix("pods/ns/" + obj.Name)
result := &api.Pod{}
if old == nil {
if err := s.Create(context.TODO(), key, obj, result, 0); err != nil {
t.Errorf("unexpected error: %v", err)
}
} else {
// To force "update" behavior of Set() we need to set ResourceVersion of
// previous version of object.
obj.ResourceVersion = old.ResourceVersion
if err := s.Set(context.TODO(), key, obj, result, 0); err != nil {
t.Errorf("unexpected error: %v", err)
}
obj.ResourceVersion = ""
}
return result
}
示例5: updatePod
func updatePod(t *testing.T, s storage.Interface, obj, old *api.Pod) *api.Pod {
updateFn := func(input runtime.Object, res storage.ResponseMeta) (runtime.Object, *uint64, error) {
newObj, err := api.Scheme.DeepCopy(obj)
if err != nil {
t.Errorf("unexpected error: %v", err)
return nil, nil, err
}
return newObj.(*api.Pod), nil, nil
}
key := etcdtest.AddPrefix("pods/ns/" + obj.Name)
if err := s.GuaranteedUpdate(context.TODO(), key, &api.Pod{}, old == nil, nil, updateFn); err != nil {
t.Errorf("unexpected error: %v", err)
}
obj.ResourceVersion = ""
result := &api.Pod{}
if err := s.Get(context.TODO(), key, result, false); err != nil {
t.Errorf("unexpected error: %v", err)
}
return result
}
示例6: CreateObj
// CreateObj will create a single object using the storage interface
func CreateObj(helper storage.Interface, name string, obj, out runtime.Object, ttl uint64) error {
return helper.Set(context.TODO(), name, obj, out, ttl)
}