本文整理汇总了Golang中k8s/io/kubernetes/pkg/controller/framework.NewSharedIndexInformer函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSharedIndexInformer函数的具体用法?Golang NewSharedIndexInformer怎么用?Golang NewSharedIndexInformer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSharedIndexInformer函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Informer
func (f *podInformer) Informer() framework.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informerObj := &kapi.Pod{}
informerType := reflect.TypeOf(informerObj)
informer, exists := f.informers[informerType]
if exists {
return informer
}
lw := f.customListerWatchers.GetListerWatcher(kapi.Resource("pods"))
if lw == nil {
lw = &cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return f.kubeClient.Pods(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return f.kubeClient.Pods(kapi.NamespaceAll).Watch(options)
},
}
}
informer = framework.NewSharedIndexInformer(
lw,
informerObj,
f.defaultResync,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
f.informers[informerType] = informer
return informer
}
示例2: Informer
func (f *deploymentConfigInformer) Informer() framework.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informerObj := &deployapi.DeploymentConfig{}
informerType := reflect.TypeOf(informerObj)
informer, exists := f.informers[informerType]
if exists {
return informer
}
informer = framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return f.originClient.DeploymentConfigs(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return f.originClient.DeploymentConfigs(kapi.NamespaceAll).Watch(options)
},
},
informerObj,
f.defaultResync,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, oscache.ImageStreamReferenceIndex: oscache.ImageStreamReferenceIndexFunc},
)
f.informers[informerType] = informer
return informer
}
示例3: NewPersistentVolumeControllerFromClient
// NewPersistentVolumeControllerFromClient returns a new
// *PersistentVolumeController that runs its own informer.
func NewPersistentVolumeControllerFromClient(
kubeClient clientset.Interface,
syncPeriod time.Duration,
alphaProvisioner vol.ProvisionableVolumePlugin,
volumePlugins []vol.VolumePlugin,
cloud cloudprovider.Interface,
clusterName string,
volumeSource, claimSource, classSource cache.ListerWatcher,
eventRecorder record.EventRecorder,
enableDynamicProvisioning bool,
) *PersistentVolumeController {
pvInformer := informers.NewPVInformer(kubeClient, syncPeriod)
if volumeSource != nil {
pvInformer = framework.NewSharedIndexInformer(volumeSource, &api.PersistentVolume{}, syncPeriod, cache.Indexers{"accessmodes": accessModesIndexFunc})
}
ctrl := NewPersistentVolumeController(
kubeClient,
syncPeriod,
alphaProvisioner,
volumePlugins,
cloud,
clusterName,
pvInformer,
claimSource,
classSource,
eventRecorder,
enableDynamicProvisioning,
)
ctrl.isInformerInternal = true
return ctrl
}
示例4: Informer
func (s *securityContextConstraintsInformer) Informer() framework.SharedIndexInformer {
s.lock.Lock()
defer s.lock.Unlock()
informerObj := &kapi.SecurityContextConstraints{}
informerType := reflect.TypeOf(informerObj)
informer, exists := s.informers[informerType]
if exists {
return informer
}
informer = framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return s.kubeClient.Core().SecurityContextConstraints().List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return s.kubeClient.Core().SecurityContextConstraints().Watch(options)
},
},
informerObj,
s.defaultResync,
cache.Indexers{},
)
s.informers[informerType] = informer
return informer
}
示例5: Informer
func (f *clusterResourceQuotaInformer) Informer() framework.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informerObj := "aapi.ClusterResourceQuota{}
informerType := reflect.TypeOf(informerObj)
informer, exists := f.informers[informerType]
if exists {
return informer
}
lw := f.customListerWatchers.GetListerWatcher(kapi.Resource("clusterresourcequotas"))
if lw == nil {
lw = &cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return f.originClient.ClusterResourceQuotas().List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return f.originClient.ClusterResourceQuotas().Watch(options)
},
}
}
informer = framework.NewSharedIndexInformer(
lw,
informerObj,
f.defaultResync,
cache.Indexers{},
)
f.informers[informerType] = informer
return informer
}
示例6: Informer
func (s *serviceAccountInformer) Informer() framework.SharedIndexInformer {
s.lock.Lock()
defer s.lock.Unlock()
informerObj := &kapi.ServiceAccount{}
informerType := reflect.TypeOf(informerObj)
informer, exists := s.informers[informerType]
if exists {
return informer
}
informer = framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return s.kubeClient.Core().ServiceAccounts(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return s.kubeClient.Core().ServiceAccounts(kapi.NamespaceAll).Watch(options)
},
},
informerObj,
s.defaultResync,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
s.informers[informerType] = informer
return informer
}
示例7: Informer
// Informer checks whether namespaceInformer exists in sharedInformerFactory and if not, it creates new informer of type
// namespaceInformer and connects it to sharedInformerFactory
func (f *namespaceInformer) Informer() framework.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informerObj := &api.Namespace{}
informerType := reflect.TypeOf(informerObj)
informer, exists := f.informers[informerType]
if exists {
return informer
}
informer = framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
return f.client.Core().Namespaces().List(options)
},
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
return f.client.Core().Namespaces().Watch(options)
},
},
informerObj,
f.defaultResync,
cache.Indexers{},
)
f.informers[informerType] = informer
return informer
}
示例8: okDeploymentController
func okDeploymentController(fake kclient.Interface, deployment *kapi.ReplicationController, hookPodNames []string, related bool) *DeploymentController {
rcInformer := framework.NewSharedIndexInformer(&cache.ListWatch{}, &kapi.ReplicationController{}, 2*time.Minute, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
podInformer := framework.NewSharedIndexInformer(&cache.ListWatch{}, &kapi.Pod{}, 2*time.Minute, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
c := NewDeploymentController(rcInformer, podInformer, fake, "sa:test", "openshift/origin-deployer", env, codec)
// deployer pod
if deployment != nil {
pod := deployerPod(deployment, "", related)
c.podStore.Add(pod)
}
// hook pods
for _, name := range hookPodNames {
pod := deployerPod(deployment, name, related)
c.podStore.Add(pod)
}
return c
}
示例9: CreateSharedNamespaceIndexInformer
// CreateSharedNamespaceIndexInformer returns a SharedIndexInformer that lists and watches namespaces
func CreateSharedNamespaceIndexInformer(client clientset.Interface, resyncPeriod time.Duration) framework.SharedIndexInformer {
sharedIndexInformer := framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
return client.Core().Namespaces().List(options)
},
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
return client.Core().Namespaces().Watch(options)
},
},
&api.Namespace{},
resyncPeriod,
cache.Indexers{})
return sharedIndexInformer
}
示例10: NewPodInformer
// NewPodInformer returns a SharedIndexInformer that lists and watches all pods
func NewPodInformer(client clientset.Interface, resyncPeriod time.Duration) framework.SharedIndexInformer {
sharedIndexInformer := framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
return client.Core().Pods(api.NamespaceAll).List(options)
},
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
return client.Core().Pods(api.NamespaceAll).Watch(options)
},
},
&api.Pod{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
return sharedIndexInformer
}
示例11: init
"k8s.io/kubernetes/pkg/client/cache"
ktestclient "k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/runtime"
oscache "github.com/openshift/origin/pkg/client/cache"
"github.com/openshift/origin/pkg/client/testclient"
deployapi "github.com/openshift/origin/pkg/deploy/api"
testapi "github.com/openshift/origin/pkg/deploy/api/test"
imageapi "github.com/openshift/origin/pkg/image/api"
)
var (
dcInformer = framework.NewSharedIndexInformer(
&cache.ListWatch{},
&deployapi.DeploymentConfig{},
2*time.Minute,
cache.Indexers{oscache.ImageStreamReferenceIndex: oscache.ImageStreamReferenceIndexFunc},
)
streamInformer = framework.NewSharedIndexInformer(
&cache.ListWatch{},
&imageapi.ImageStream{},
2*time.Minute,
cache.Indexers{},
)
)
func init() {
flag.Set("v", "5")
}
func makeStream(name, tag, dir, image string) *imageapi.ImageStream {
示例12: TestHandleScenarios
//.........这里部分代码省略.........
},
after: []deployment{
{version: 1, replicas: 1, replicasA: newInt32(1), status: deployapi.DeploymentStatusComplete, cancelled: false},
{version: 2, replicas: 0, replicasA: newInt32(0), desiredA: newInt32(1), status: deployapi.DeploymentStatusFailed, cancelled: true},
},
errExpected: false,
},
}
for _, test := range tests {
t.Logf("evaluating test: %s", test.name)
deployments := map[string]kapi.ReplicationController{}
toStore := []kapi.ReplicationController{}
for _, template := range test.before {
deployment := mkdeployment(template)
deployments[deployment.Name] = deployment
toStore = append(toStore, deployment)
}
oc := &testclient.Fake{}
kc := &ktestclient.Fake{}
kc.AddReactor("create", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
rc := action.(ktestclient.CreateAction).GetObject().(*kapi.ReplicationController)
deployments[rc.Name] = *rc
return true, rc, nil
})
kc.AddReactor("update", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
rc := action.(ktestclient.UpdateAction).GetObject().(*kapi.ReplicationController)
deployments[rc.Name] = *rc
return true, rc, nil
})
codec := kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion)
dcInformer := framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return oc.DeploymentConfigs(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return oc.DeploymentConfigs(kapi.NamespaceAll).Watch(options)
},
},
&deployapi.DeploymentConfig{},
2*time.Minute,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
rcInformer := framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return kc.ReplicationControllers(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return kc.ReplicationControllers(kapi.NamespaceAll).Watch(options)
},
},
&kapi.ReplicationController{},
2*time.Minute,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
c := NewDeploymentConfigController(dcInformer, rcInformer, oc, kc, codec)
for i := range toStore {
c.rcStore.Add(&toStore[i])
}
config := deploytest.OkDeploymentConfig(test.newVersion)
if test.test {
config = deploytest.TestDeploymentConfig(config)
}
config.Spec.Replicas = test.replicas
if err := c.Handle(config); err != nil && !test.errExpected {
t.Errorf("unexpected error: %s", err)
continue
}
expectedDeployments := []kapi.ReplicationController{}
for _, template := range test.after {
expectedDeployments = append(expectedDeployments, mkdeployment(template))
}
actualDeployments := []kapi.ReplicationController{}
for _, deployment := range deployments {
actualDeployments = append(actualDeployments, deployment)
}
sort.Sort(deployutil.ByLatestVersionDesc(expectedDeployments))
sort.Sort(deployutil.ByLatestVersionDesc(actualDeployments))
if e, a := test.expectedReplicas, config.Spec.Replicas; e != a {
t.Errorf("expected config replicas to be %d, got %d", e, a)
continue
}
for i := 0; i < len(expectedDeployments); i++ {
expected, actual := expectedDeployments[i], actualDeployments[i]
if !kapi.Semantic.DeepEqual(expected, actual) {
t.Errorf("actual deployment don't match expected: %v", diff.ObjectDiff(expected, actual))
}
}
}
}
示例13:
_ "github.com/openshift/origin/pkg/deploy/api/install"
testapi "github.com/openshift/origin/pkg/deploy/api/test"
deployutil "github.com/openshift/origin/pkg/deploy/util"
imageapi "github.com/openshift/origin/pkg/image/api"
)
var (
codec = kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion)
mock = &testclient.Fake{}
dcInformer = framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return mock.DeploymentConfigs(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return mock.DeploymentConfigs(kapi.NamespaceAll).Watch(options)
},
},
&deployapi.DeploymentConfig{},
2*time.Minute,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
streamInformer = framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return mock.ImageStreams(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return mock.ImageStreams(kapi.NamespaceAll).Watch(options)
},
示例14:
deployapi "github.com/openshift/origin/pkg/deploy/api"
_ "github.com/openshift/origin/pkg/deploy/api/install"
testapi "github.com/openshift/origin/pkg/deploy/api/test"
deployv1 "github.com/openshift/origin/pkg/deploy/api/v1"
imageapi "github.com/openshift/origin/pkg/image/api"
)
var (
codec = kapi.Codecs.LegacyCodec(deployv1.SchemeGroupVersion)
dcInformer = framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return (&testclient.Fake{}).DeploymentConfigs(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return (&testclient.Fake{}).DeploymentConfigs(kapi.NamespaceAll).Watch(options)
},
},
&deployapi.DeploymentConfig{},
2*time.Minute,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
rcInformer = framework.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return (fake.NewSimpleClientset()).Core().ReplicationControllers(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return (fake.NewSimpleClientset()).Core().ReplicationControllers(kapi.NamespaceAll).Watch(options)
},
},