當前位置: 首頁>>代碼示例>>Golang>>正文


Golang deletionhelper.NewDeletionHelper函數代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/federation/pkg/federation-controller/util/deletionhelper.NewDeletionHelper函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewDeletionHelper函數的具體用法?Golang NewDeletionHelper怎麽用?Golang NewDeletionHelper使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewDeletionHelper函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewNamespaceController

// NewNamespaceController returns a new namespace controller
func NewNamespaceController(client federationclientset.Interface) *NamespaceController {
    broadcaster := record.NewBroadcaster()
    broadcaster.StartRecordingToSink(eventsink.NewFederatedEventSink(client))
    recorder := broadcaster.NewRecorder(api.EventSource{Component: "federated-namespace-controller"})

    nc := &NamespaceController{
        federatedApiClient:    client,
        namespaceReviewDelay:  time.Second * 10,
        clusterAvailableDelay: time.Second * 20,
        smallDelay:            time.Second * 3,
        updateTimeout:         time.Second * 30,
        namespaceBackoff:      flowcontrol.NewBackOff(5*time.Second, time.Minute),
        eventRecorder:         recorder,
    }

    // Build delivereres for triggering reconciliations.
    nc.namespaceDeliverer = util.NewDelayingDeliverer()
    nc.clusterDeliverer = util.NewDelayingDeliverer()

    // Start informer in federated API servers on namespaces that should be federated.
    nc.namespaceInformerStore, nc.namespaceInformerController = cache.NewInformer(
        &cache.ListWatch{
            ListFunc: func(options api.ListOptions) (runtime.Object, error) {
                versionedOptions := util.VersionizeV1ListOptions(options)
                return client.Core().Namespaces().List(versionedOptions)
            },
            WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
                versionedOptions := util.VersionizeV1ListOptions(options)
                return client.Core().Namespaces().Watch(versionedOptions)
            },
        },
        &api_v1.Namespace{},
        controller.NoResyncPeriodFunc(),
        util.NewTriggerOnAllChanges(func(obj runtime.Object) { nc.deliverNamespaceObj(obj, 0, false) }))

    // Federated informer on namespaces in members of federation.
    nc.namespaceFederatedInformer = util.NewFederatedInformer(
        client,
        func(cluster *federation_api.Cluster, targetClient kubeclientset.Interface) (cache.Store, cache.ControllerInterface) {
            return cache.NewInformer(
                &cache.ListWatch{
                    ListFunc: func(options api.ListOptions) (runtime.Object, error) {
                        versionedOptions := util.VersionizeV1ListOptions(options)
                        return targetClient.Core().Namespaces().List(versionedOptions)
                    },
                    WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
                        versionedOptions := util.VersionizeV1ListOptions(options)
                        return targetClient.Core().Namespaces().Watch(versionedOptions)
                    },
                },
                &api_v1.Namespace{},
                controller.NoResyncPeriodFunc(),
                // Trigger reconciliation whenever something in federated cluster is changed. In most cases it
                // would be just confirmation that some namespace opration succeeded.
                util.NewTriggerOnMetaAndSpecChanges(
                    func(obj runtime.Object) { nc.deliverNamespaceObj(obj, nc.namespaceReviewDelay, false) },
                ))
        },
        &util.ClusterLifecycleHandlerFuncs{
            ClusterAvailable: func(cluster *federation_api.Cluster) {
                // When new cluster becomes available process all the namespaces again.
                nc.clusterDeliverer.DeliverAfter(allClustersKey, nil, nc.clusterAvailableDelay)
            },
        },
    )

    // Federated updeater along with Create/Update/Delete operations.
    nc.federatedUpdater = util.NewFederatedUpdater(nc.namespaceFederatedInformer,
        func(client kubeclientset.Interface, obj runtime.Object) error {
            namespace := obj.(*api_v1.Namespace)
            _, err := client.Core().Namespaces().Create(namespace)
            return err
        },
        func(client kubeclientset.Interface, obj runtime.Object) error {
            namespace := obj.(*api_v1.Namespace)
            _, err := client.Core().Namespaces().Update(namespace)
            return err
        },
        func(client kubeclientset.Interface, obj runtime.Object) error {
            namespace := obj.(*api_v1.Namespace)
            err := client.Core().Namespaces().Delete(namespace.Name, &api_v1.DeleteOptions{})
            // IsNotFound error is fine since that means the object is deleted already.
            if errors.IsNotFound(err) {
                return nil
            }
            return err
        })

    nc.deletionHelper = deletionhelper.NewDeletionHelper(
        nc.hasFinalizerFunc,
        nc.removeFinalizerFunc,
        nc.addFinalizerFunc,
        // objNameFunc
        func(obj runtime.Object) string {
            namespace := obj.(*api_v1.Namespace)
            return namespace.Name
        },
        nc.updateTimeout,
        nc.eventRecorder,
//.........這裏部分代碼省略.........
開發者ID:upmc-enterprises,項目名稱:kubernetes,代碼行數:101,代碼來源:namespace_controller.go

示例2: NewIngressController


//.........這裏部分代碼省略.........
                        if targetClient == nil {
                            glog.Errorf("Internal error: targetClient is nil")
                        }
                        return targetClient.Core().ConfigMaps(uidConfigMapNamespace).Watch(options) // as above
                    },
                },
                &v1.ConfigMap{},
                controller.NoResyncPeriodFunc(),
                // Trigger reconcilation whenever the ingress controller's configmap in a federated cluster is changed. In most cases it
                // would be just confirmation that the configmap for the ingress controller is correct.
                util.NewTriggerOnAllChanges(
                    func(obj pkgruntime.Object) {
                        ic.deliverConfigMapObj(cluster.Name, obj, ic.configMapReviewDelay, false)
                    },
                ))
        },

        &util.ClusterLifecycleHandlerFuncs{
            ClusterAvailable: func(cluster *federationapi.Cluster) {
                ic.clusterDeliverer.DeliverAfter(cluster.Name, cluster, ic.clusterAvailableDelay)
            },
        },
    )

    // Federated ingress updater along with Create/Update/Delete operations.
    ic.federatedIngressUpdater = util.NewFederatedUpdater(ic.ingressFederatedInformer,
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            ingress := obj.(*extensionsv1beta1.Ingress)
            glog.V(4).Infof("Attempting to create Ingress: %v", ingress)
            _, err := client.Extensions().Ingresses(ingress.Namespace).Create(ingress)
            if err != nil {
                glog.Errorf("Error creating ingress %q: %v", types.NamespacedName{Name: ingress.Name, Namespace: ingress.Namespace}, err)
            } else {
                glog.V(4).Infof("Successfully created ingress %q", types.NamespacedName{Name: ingress.Name, Namespace: ingress.Namespace})
            }
            return err
        },
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            ingress := obj.(*extensionsv1beta1.Ingress)
            glog.V(4).Infof("Attempting to update Ingress: %v", ingress)
            _, err := client.Extensions().Ingresses(ingress.Namespace).Update(ingress)
            if err != nil {
                glog.V(4).Infof("Failed to update Ingress: %v", err)
            } else {
                glog.V(4).Infof("Successfully updated Ingress: %q", types.NamespacedName{Name: ingress.Name, Namespace: ingress.Namespace})
            }
            return err
        },
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            ingress := obj.(*extensionsv1beta1.Ingress)
            glog.V(4).Infof("Attempting to delete Ingress: %v", ingress)
            err := client.Extensions().Ingresses(ingress.Namespace).Delete(ingress.Name, &v1.DeleteOptions{})
            return err
        })

    // Federated configmap updater along with Create/Update/Delete operations.  Only Update should ever be called.
    ic.federatedConfigMapUpdater = util.NewFederatedUpdater(ic.configMapFederatedInformer,
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            configMap := obj.(*v1.ConfigMap)
            configMapName := types.NamespacedName{Name: configMap.Name, Namespace: configMap.Namespace}
            glog.Errorf("Internal error: Incorrectly attempting to create ConfigMap: %q", configMapName)
            _, err := client.Core().ConfigMaps(configMap.Namespace).Create(configMap)
            return err
        },
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            configMap := obj.(*v1.ConfigMap)
            configMapName := types.NamespacedName{Name: configMap.Name, Namespace: configMap.Namespace}
            glog.V(4).Infof("Attempting to update ConfigMap: %v", configMap)
            _, err := client.Core().ConfigMaps(configMap.Namespace).Update(configMap)
            if err == nil {
                glog.V(4).Infof("Successfully updated ConfigMap %q", configMapName)
            } else {
                glog.V(4).Infof("Failed to update ConfigMap %q: %v", configMapName, err)
            }
            return err
        },
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            configMap := obj.(*v1.ConfigMap)
            configMapName := types.NamespacedName{Name: configMap.Name, Namespace: configMap.Namespace}
            glog.Errorf("Internal error: Incorrectly attempting to delete ConfigMap: %q", configMapName)
            err := client.Core().ConfigMaps(configMap.Namespace).Delete(configMap.Name, &v1.DeleteOptions{})
            return err
        })

    ic.deletionHelper = deletionhelper.NewDeletionHelper(
        ic.hasFinalizerFunc,
        ic.removeFinalizerFunc,
        ic.addFinalizerFunc,
        // objNameFunc
        func(obj pkgruntime.Object) string {
            ingress := obj.(*extensionsv1beta1.Ingress)
            return ingress.Name
        },
        ic.updateTimeout,
        ic.eventRecorder,
        ic.ingressFederatedInformer,
        ic.federatedIngressUpdater,
    )
    return ic
}
開發者ID:hpcloud,項目名稱:kubernetes,代碼行數:101,代碼來源:ingress_controller.go

示例3: NewReplicaSetController


//.........這裏部分代碼省略.........
                    return clientset.Extensions().ReplicaSets(apiv1.NamespaceAll).List(versionedOptions)
                },
                WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
                    versionedOptions := fedutil.VersionizeV1ListOptions(options)
                    return clientset.Extensions().ReplicaSets(apiv1.NamespaceAll).Watch(versionedOptions)
                },
            },
            &extensionsv1.ReplicaSet{},
            controller.NoResyncPeriodFunc(),
            fedutil.NewTriggerOnAllChanges(
                func(obj runtime.Object) { frsc.deliverLocalReplicaSet(obj, replicaSetReviewDelay) },
            ),
        )
    }
    clusterLifecycle := fedutil.ClusterLifecycleHandlerFuncs{
        ClusterAvailable: func(cluster *fedv1.Cluster) {
            frsc.clusterDeliverer.DeliverAfter(allClustersKey, nil, clusterAvailableDelay)
        },
        ClusterUnavailable: func(cluster *fedv1.Cluster, _ []interface{}) {
            frsc.clusterDeliverer.DeliverAfter(allClustersKey, nil, clusterUnavailableDelay)
        },
    }
    frsc.fedReplicaSetInformer = fedutil.NewFederatedInformer(federationClient, replicaSetFedInformerFactory, &clusterLifecycle)

    podFedInformerFactory := func(cluster *fedv1.Cluster, clientset kubeclientset.Interface) (cache.Store, cache.ControllerInterface) {
        return cache.NewInformer(
            &cache.ListWatch{
                ListFunc: func(options api.ListOptions) (runtime.Object, error) {
                    versionedOptions := fedutil.VersionizeV1ListOptions(options)
                    return clientset.Core().Pods(apiv1.NamespaceAll).List(versionedOptions)
                },
                WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
                    versionedOptions := fedutil.VersionizeV1ListOptions(options)
                    return clientset.Core().Pods(apiv1.NamespaceAll).Watch(versionedOptions)
                },
            },
            &apiv1.Pod{},
            controller.NoResyncPeriodFunc(),
            fedutil.NewTriggerOnAllChanges(
                func(obj runtime.Object) {
                    frsc.clusterDeliverer.DeliverAfter(allClustersKey, nil, allReplicaSetReviewDelay)
                },
            ),
        )
    }
    frsc.fedPodInformer = fedutil.NewFederatedInformer(federationClient, podFedInformerFactory, &fedutil.ClusterLifecycleHandlerFuncs{})

    frsc.replicaSetStore.Indexer, frsc.replicaSetController = cache.NewIndexerInformer(
        &cache.ListWatch{
            ListFunc: func(options api.ListOptions) (runtime.Object, error) {
                versionedOptions := fedutil.VersionizeV1ListOptions(options)
                return frsc.fedClient.Extensions().ReplicaSets(apiv1.NamespaceAll).List(versionedOptions)
            },
            WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
                versionedOptions := fedutil.VersionizeV1ListOptions(options)
                return frsc.fedClient.Extensions().ReplicaSets(apiv1.NamespaceAll).Watch(versionedOptions)
            },
        },
        &extensionsv1.ReplicaSet{},
        controller.NoResyncPeriodFunc(),
        fedutil.NewTriggerOnMetaAndSpecChanges(
            func(obj runtime.Object) { frsc.deliverFedReplicaSetObj(obj, replicaSetReviewDelay) },
        ),
        cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
    )

    frsc.fedUpdater = fedutil.NewFederatedUpdater(frsc.fedReplicaSetInformer,
        func(client kubeclientset.Interface, obj runtime.Object) error {
            rs := obj.(*extensionsv1.ReplicaSet)
            _, err := client.Extensions().ReplicaSets(rs.Namespace).Create(rs)
            return err
        },
        func(client kubeclientset.Interface, obj runtime.Object) error {
            rs := obj.(*extensionsv1.ReplicaSet)
            _, err := client.Extensions().ReplicaSets(rs.Namespace).Update(rs)
            return err
        },
        func(client kubeclientset.Interface, obj runtime.Object) error {
            rs := obj.(*extensionsv1.ReplicaSet)
            err := client.Extensions().ReplicaSets(rs.Namespace).Delete(rs.Name, &apiv1.DeleteOptions{})
            return err
        })

    frsc.deletionHelper = deletionhelper.NewDeletionHelper(
        frsc.hasFinalizerFunc,
        frsc.removeFinalizerFunc,
        frsc.addFinalizerFunc,
        // objNameFunc
        func(obj runtime.Object) string {
            replicaset := obj.(*extensionsv1.ReplicaSet)
            return replicaset.Name
        },
        updateTimeout,
        frsc.eventRecorder,
        frsc.fedReplicaSetInformer,
        frsc.fedUpdater,
    )

    return frsc
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:101,代碼來源:replicasetcontroller.go

示例4: NewSecretController

// NewSecretController returns a new secret controller
func NewSecretController(client federationclientset.Interface) *SecretController {
    broadcaster := record.NewBroadcaster()
    broadcaster.StartRecordingToSink(eventsink.NewFederatedEventSink(client))
    recorder := broadcaster.NewRecorder(apiv1.EventSource{Component: "federated-secrets-controller"})

    secretcontroller := &SecretController{
        federatedApiClient:    client,
        secretReviewDelay:     time.Second * 10,
        clusterAvailableDelay: time.Second * 20,
        smallDelay:            time.Second * 3,
        updateTimeout:         time.Second * 30,
        secretBackoff:         flowcontrol.NewBackOff(5*time.Second, time.Minute),
        eventRecorder:         recorder,
    }

    // Build delivereres for triggering reconciliations.
    secretcontroller.secretDeliverer = util.NewDelayingDeliverer()
    secretcontroller.clusterDeliverer = util.NewDelayingDeliverer()

    // Start informer in federated API servers on secrets that should be federated.
    secretcontroller.secretInformerStore, secretcontroller.secretInformerController = cache.NewInformer(
        &cache.ListWatch{
            ListFunc: func(options apiv1.ListOptions) (pkgruntime.Object, error) {
                return client.Core().Secrets(apiv1.NamespaceAll).List(options)
            },
            WatchFunc: func(options apiv1.ListOptions) (watch.Interface, error) {
                return client.Core().Secrets(apiv1.NamespaceAll).Watch(options)
            },
        },
        &apiv1.Secret{},
        controller.NoResyncPeriodFunc(),
        util.NewTriggerOnAllChanges(func(obj pkgruntime.Object) { secretcontroller.deliverSecretObj(obj, 0, false) }))

    // Federated informer on secrets in members of federation.
    secretcontroller.secretFederatedInformer = util.NewFederatedInformer(
        client,
        func(cluster *federationapi.Cluster, targetClient kubeclientset.Interface) (cache.Store, cache.ControllerInterface) {
            return cache.NewInformer(
                &cache.ListWatch{
                    ListFunc: func(options apiv1.ListOptions) (pkgruntime.Object, error) {
                        return targetClient.Core().Secrets(apiv1.NamespaceAll).List(options)
                    },
                    WatchFunc: func(options apiv1.ListOptions) (watch.Interface, error) {
                        return targetClient.Core().Secrets(apiv1.NamespaceAll).Watch(options)
                    },
                },
                &apiv1.Secret{},
                controller.NoResyncPeriodFunc(),
                // Trigger reconciliation whenever something in federated cluster is changed. In most cases it
                // would be just confirmation that some secret opration succeeded.
                util.NewTriggerOnAllChanges(
                    func(obj pkgruntime.Object) {
                        secretcontroller.deliverSecretObj(obj, secretcontroller.secretReviewDelay, false)
                    },
                ))
        },

        &util.ClusterLifecycleHandlerFuncs{
            ClusterAvailable: func(cluster *federationapi.Cluster) {
                // When new cluster becomes available process all the secrets again.
                secretcontroller.clusterDeliverer.DeliverAt(allClustersKey, nil, time.Now().Add(secretcontroller.clusterAvailableDelay))
            },
        },
    )

    // Federated updeater along with Create/Update/Delete operations.
    secretcontroller.federatedUpdater = util.NewFederatedUpdater(secretcontroller.secretFederatedInformer,
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            secret := obj.(*apiv1.Secret)
            _, err := client.Core().Secrets(secret.Namespace).Create(secret)
            return err
        },
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            secret := obj.(*apiv1.Secret)
            _, err := client.Core().Secrets(secret.Namespace).Update(secret)
            return err
        },
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            secret := obj.(*apiv1.Secret)
            err := client.Core().Secrets(secret.Namespace).Delete(secret.Name, &apiv1.DeleteOptions{})
            return err
        })

    secretcontroller.deletionHelper = deletionhelper.NewDeletionHelper(
        secretcontroller.hasFinalizerFunc,
        secretcontroller.removeFinalizerFunc,
        secretcontroller.addFinalizerFunc,
        // objNameFunc
        func(obj pkgruntime.Object) string {
            secret := obj.(*apiv1.Secret)
            return secret.Name
        },
        secretcontroller.updateTimeout,
        secretcontroller.eventRecorder,
        secretcontroller.secretFederatedInformer,
        secretcontroller.federatedUpdater,
    )

    return secretcontroller
//.........這裏部分代碼省略.........
開發者ID:nak3,項目名稱:kubernetes,代碼行數:101,代碼來源:secret_controller.go

示例5: NewDaemonSetController


//.........這裏部分代碼省略.........

    // Start informer in federated API servers on daemonsets that should be federated.
    daemonsetcontroller.daemonsetInformerStore, daemonsetcontroller.daemonsetInformerController = cache.NewInformer(
        &cache.ListWatch{
            ListFunc: func(options api_v1.ListOptions) (pkg_runtime.Object, error) {
                return client.Extensions().DaemonSets(api_v1.NamespaceAll).List(options)
            },
            WatchFunc: func(options api_v1.ListOptions) (watch.Interface, error) {
                return client.Extensions().DaemonSets(api_v1.NamespaceAll).Watch(options)
            },
        },
        &extensionsv1.DaemonSet{},
        controller.NoResyncPeriodFunc(),
        util.NewTriggerOnAllChanges(func(obj pkg_runtime.Object) { daemonsetcontroller.deliverDaemonSetObj(obj, 0, false) }))

    // Federated informer on daemonsets in members of federation.
    daemonsetcontroller.daemonsetFederatedInformer = util.NewFederatedInformer(
        client,
        func(cluster *federation_api.Cluster, targetClient kubeclientset.Interface) (cache.Store, cache.ControllerInterface) {
            return cache.NewInformer(
                &cache.ListWatch{
                    ListFunc: func(options api_v1.ListOptions) (pkg_runtime.Object, error) {
                        return targetClient.Extensions().DaemonSets(api_v1.NamespaceAll).List(options)
                    },
                    WatchFunc: func(options api_v1.ListOptions) (watch.Interface, error) {
                        return targetClient.Extensions().DaemonSets(api_v1.NamespaceAll).Watch(options)
                    },
                },
                &extensionsv1.DaemonSet{},
                controller.NoResyncPeriodFunc(),
                // Trigger reconciliation whenever something in federated cluster is changed. In most cases it
                // would be just confirmation that some daemonset opration succeeded.
                util.NewTriggerOnAllChanges(
                    func(obj pkg_runtime.Object) {
                        daemonsetcontroller.deliverDaemonSetObj(obj, daemonsetcontroller.daemonsetReviewDelay, false)
                    },
                ))
        },

        &util.ClusterLifecycleHandlerFuncs{
            ClusterAvailable: func(cluster *federation_api.Cluster) {
                // When new cluster becomes available process all the daemonsets again.
                daemonsetcontroller.clusterDeliverer.DeliverAt(allClustersKey, nil, time.Now().Add(daemonsetcontroller.clusterAvailableDelay))
            },
        },
    )

    // Federated updater along with Create/Update/Delete operations.
    daemonsetcontroller.federatedUpdater = util.NewFederatedUpdater(daemonsetcontroller.daemonsetFederatedInformer,
        func(client kubeclientset.Interface, obj pkg_runtime.Object) error {
            daemonset := obj.(*extensionsv1.DaemonSet)
            glog.V(4).Infof("Attempting to create daemonset: %s/%s", daemonset.Namespace, daemonset.Name)
            _, err := client.Extensions().DaemonSets(daemonset.Namespace).Create(daemonset)
            if err != nil {
                glog.Errorf("Error creating daemonset %s/%s/: %v", daemonset.Namespace, daemonset.Name, err)
            } else {
                glog.V(4).Infof("Successfully created deamonset %s/%s", daemonset.Namespace, daemonset.Name)
            }
            return err
        },
        func(client kubeclientset.Interface, obj pkg_runtime.Object) error {
            daemonset := obj.(*extensionsv1.DaemonSet)
            glog.V(4).Infof("Attempting to update daemonset: %s/%s", daemonset.Namespace, daemonset.Name)
            _, err := client.Extensions().DaemonSets(daemonset.Namespace).Update(daemonset)
            if err != nil {
                glog.Errorf("Error updating daemonset %s/%s/: %v", daemonset.Namespace, daemonset.Name, err)
            } else {
                glog.V(4).Infof("Successfully updating deamonset %s/%s", daemonset.Namespace, daemonset.Name)
            }
            return err
        },
        func(client kubeclientset.Interface, obj pkg_runtime.Object) error {
            daemonset := obj.(*extensionsv1.DaemonSet)
            glog.V(4).Infof("Attempting to delete daemonset: %s/%s", daemonset.Namespace, daemonset.Name)
            err := client.Extensions().DaemonSets(daemonset.Namespace).Delete(daemonset.Name, &api_v1.DeleteOptions{})
            if err != nil {
                glog.Errorf("Error deleting daemonset %s/%s/: %v", daemonset.Namespace, daemonset.Name, err)
            } else {
                glog.V(4).Infof("Successfully deleting deamonset %s/%s", daemonset.Namespace, daemonset.Name)
            }
            return err
        })

    daemonsetcontroller.deletionHelper = deletionhelper.NewDeletionHelper(
        daemonsetcontroller.hasFinalizerFunc,
        daemonsetcontroller.removeFinalizerFunc,
        daemonsetcontroller.addFinalizerFunc,
        // objNameFunc
        func(obj pkg_runtime.Object) string {
            daemonset := obj.(*extensionsv1.DaemonSet)
            return daemonset.Name
        },
        daemonsetcontroller.updateTimeout,
        daemonsetcontroller.eventRecorder,
        daemonsetcontroller.daemonsetFederatedInformer,
        daemonsetcontroller.federatedUpdater,
    )

    return daemonsetcontroller
}
開發者ID:paralin,項目名稱:kubernetes,代碼行數:101,代碼來源:daemonset_controller.go

示例6: New


//.........這裏部分代碼省略.........
            WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
                return s.federationClient.Federation().Clusters().Watch(options)
            },
        },
        &v1beta1.Cluster{},
        clusterSyncPeriod,
        cache.ResourceEventHandlerFuncs{
            DeleteFunc: s.clusterCache.delFromClusterSet,
            AddFunc:    s.clusterCache.addToClientMap,
            UpdateFunc: func(old, cur interface{}) {
                oldCluster, ok := old.(*v1beta1.Cluster)
                if !ok {
                    return
                }
                curCluster, ok := cur.(*v1beta1.Cluster)
                if !ok {
                    return
                }
                if !reflect.DeepEqual(oldCluster.Spec, curCluster.Spec) {
                    // update when spec is changed
                    s.clusterCache.addToClientMap(cur)
                }

                pred := getClusterConditionPredicate()
                // only update when condition changed to ready from not-ready
                if !pred(*oldCluster) && pred(*curCluster) {
                    s.clusterCache.addToClientMap(cur)
                }
                // did not handle ready -> not-ready
                // how could we stop a controller?
            },
        },
    )

    clusterLifecycle := fedutil.ClusterLifecycleHandlerFuncs{
        ClusterAvailable: func(cluster *v1beta1.Cluster) {
            s.clusterDeliverer.DeliverAfter(allClustersKey, nil, clusterAvailableDelay)
        },
    }
    fedInformerFactory := func(cluster *v1beta1.Cluster, targetClient kubeclientset.Interface) (cache.Store, cache.Controller) {
        return cache.NewInformer(
            &cache.ListWatch{
                ListFunc: func(options v1.ListOptions) (pkgruntime.Object, error) {
                    return targetClient.Core().Services(v1.NamespaceAll).List(options)
                },
                WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
                    return targetClient.Core().Services(v1.NamespaceAll).Watch(options)
                },
            },
            &v1.Service{},
            controller.NoResyncPeriodFunc(),
            // Trigger reconciliation whenever something in federated cluster is changed. In most cases it
            // would be just confirmation that some service operation succeeded.
            util.NewTriggerOnAllChanges(
                func(obj pkgruntime.Object) {
                    // TODO: Use this to enque services.
                },
            ))
    }

    s.federatedInformer = fedutil.NewFederatedInformer(federationClient, fedInformerFactory, &clusterLifecycle)

    federatedUpdater := fedutil.NewFederatedUpdater(s.federatedInformer,
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            svc := obj.(*v1.Service)
            _, err := client.Core().Services(svc.Namespace).Create(svc)
            return err
        },
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            svc := obj.(*v1.Service)
            _, err := client.Core().Services(svc.Namespace).Update(svc)
            return err
        },
        func(client kubeclientset.Interface, obj pkgruntime.Object) error {
            svc := obj.(*v1.Service)
            err := client.Core().Services(svc.Namespace).Delete(svc.Name, &v1.DeleteOptions{})
            return err
        })

    s.deletionHelper = deletionhelper.NewDeletionHelper(
        s.hasFinalizerFunc,
        s.removeFinalizerFunc,
        s.addFinalizerFunc,
        // objNameFunc
        func(obj pkgruntime.Object) string {
            service := obj.(*v1.Service)
            return service.Name
        },
        updateTimeout,
        s.eventRecorder,
        s.federatedInformer,
        federatedUpdater,
    )

    s.endpointWorkerMap = make(map[string]bool)
    s.serviceWorkerMap = make(map[string]bool)
    s.endpointWorkerDoneChan = make(chan string, maxNoOfClusters)
    s.serviceWorkerDoneChan = make(chan string, maxNoOfClusters)
    return s
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:101,代碼來源:servicecontroller.go


注:本文中的k8s/io/kubernetes/federation/pkg/federation-controller/util/deletionhelper.NewDeletionHelper函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。