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


Golang tools.ParseWatchResourceVersion函數代碼示例

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


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

示例1: WatchControllers

// WatchControllers begins watching for new, changed, or deleted controllers.
func (r *Registry) WatchControllers(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	if !field.Empty() {
		return nil, fmt.Errorf("field selectors are not supported on replication controllers")
	}
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "replicationControllers")
	if err != nil {
		return nil, err
	}
	key := makeControllerListKey(ctx)
	return r.WatchList(key, version, func(obj runtime.Object) bool {
		controller, ok := obj.(*api.ReplicationController)
		if !ok {
			// Must be an error: return true to propagate to upper level.
			return true
		}
		match := label.Matches(labels.Set(controller.Labels))
		if match {
			pods, err := r.pods.ListPods(ctx, labels.Set(controller.Spec.Selector).AsSelector())
			if err != nil {
				glog.Warningf("Error listing pods: %v", err)
				// No object that's useable so drop it on the floor
				return false
			}
			if pods == nil {
				glog.Warningf("Pods list is nil.  This should never happen...")
				// No object that's useable so drop it on the floor
				return false
			}
			controller.Status.Replicas = len(pods.Items)
		}
		return match
	})
}
開發者ID:SivagnanamCiena,項目名稱:calico-kubernetes,代碼行數:34,代碼來源:etcd.go

示例2: WatchPredicate

// WatchPredicate starts a watch for the items that m matches.
func (e *Etcd) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersion string) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, e.EndpointName)
	if err != nil {
		return nil, err
	}

	filterFunc := func(obj runtime.Object) bool {
		matches, err := m.Matches(obj)
		if err != nil {
			glog.Errorf("unable to match watch: %v", err)
			return false
		}
		if matches && e.Decorator != nil {
			if err := e.Decorator(obj); err != nil {
				glog.Errorf("unable to decorate watch: %v", err)
				return false
			}
		}
		return matches
	}

	if name, ok := m.MatchesSingle(); ok {
		key, err := e.KeyFunc(ctx, name)
		if err != nil {
			return nil, err
		}
		return e.Helper.Watch(key, version, filterFunc)
	}

	return e.Helper.WatchList(e.KeyRootFunc(ctx), version, filterFunc)
}
開發者ID:brandon-adams,項目名稱:origin,代碼行數:32,代碼來源:etcd.go

示例3: WatchControllers

// WatchControllers begins watching for new, changed, or deleted controllers.
func (r *Registry) WatchControllers(ctx api.Context, resourceVersion string) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "replicationControllers")
	if err != nil {
		return nil, err
	}
	key := makeControllerListKey(ctx)
	return r.WatchList(key, version, tools.Everything)
}
開發者ID:TencentSA,項目名稱:kubernetes-0.5,代碼行數:9,代碼來源:etcd.go

示例4: Watch

// Watch starts a watch for the items that m matches.
// TODO: Detect if m references a single object instead of a list.
func (e *Etcd) Watch(ctx api.Context, m generic.Matcher, resourceVersion string) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, e.EndpointName)
	if err != nil {
		return nil, err
	}
	return e.Helper.WatchList(e.KeyRootFunc(ctx), version, func(obj runtime.Object) bool {
		matches, err := m.Matches(obj)
		return err == nil && matches
	})
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:12,代碼來源:etcd.go

示例5: WatchMinions

func (r *Registry) WatchMinions(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "node")
	if err != nil {
		return nil, err
	}
	key := makeNodeListKey()
	return r.WatchList(key, version, func(obj runtime.Object) bool {
		minionObj, ok := obj.(*api.Node)
		if !ok {
			// Must be an error: return true to propagate to upper level.
			return true
		}
		// TODO: Add support for filtering based on field, once NodeStatus is defined.
		return label.Matches(labels.Set(minionObj.Labels))
	})
}
開發者ID:vrosnet,項目名稱:kubernetes,代碼行數:16,代碼來源:etcd.go

示例6: WatchPods

// WatchPods begins watching for new, changed, or deleted pods.
func (r *Registry) WatchPods(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "pod")
	if err != nil {
		return nil, err
	}
	key := makePodListKey(ctx)
	return r.WatchList(key, version, func(obj runtime.Object) bool {
		podObj, ok := obj.(*api.Pod)
		if !ok {
			// Must be an error: return true to propagate to upper level.
			return true
		}
		fields := pod.PodToSelectableFields(podObj)
		return label.Matches(labels.Set(podObj.Labels)) && field.Matches(fields)
	})
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:17,代碼來源:etcd.go

示例7: WatchPods

// WatchPods begins watching for new, changed, or deleted pods.
func (r *Registry) WatchPods(ctx api.Context, resourceVersion string, filter func(*api.Pod) bool) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "pod")
	if err != nil {
		return nil, err
	}
	key := makePodListKey(ctx)
	return r.WatchList(key, version, func(obj runtime.Object) bool {
		switch t := obj.(type) {
		case *api.Pod:
			return filter(t)
		default:
			// Must be an error
			return true
		}
	})
}
開發者ID:TencentSA,項目名稱:kubernetes-0.5,代碼行數:17,代碼來源:etcd.go

示例8: WatchBuildConfigs

// WatchBuildConfigs begins watching for new, changed, or deleted BuildConfigs.
func (r *Etcd) WatchBuildConfigs(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "buildConfig")
	if err != nil {
		return nil, err
	}

	return r.WatchList(makeBuildConfigListKey(ctx), version, func(obj runtime.Object) bool {
		buildConfig, ok := obj.(*api.BuildConfig)
		if !ok {
			glog.Errorf("Unexpected object during %s/%s BuildConfig watch: %#v", buildConfig.Namespace, buildConfig.Name, obj)
			return false
		}
		fields := labels.Set{
			"metadata.name": buildConfig.Name,
		}
		return label.Matches(labels.Set(buildConfig.Labels)) && field.Matches(fields)
	})
}
開發者ID:pombredanne,項目名稱:atomic-enterprise,代碼行數:19,代碼來源:etcd.go

示例9: WatchEndpoints

// WatchEndpoints begins watching for new, changed, or deleted endpoint configurations.
func (r *Registry) WatchEndpoints(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "endpoints")
	if err != nil {
		return nil, err
	}
	if !label.Empty() {
		return nil, fmt.Errorf("label selectors are not supported on endpoints")
	}
	if value, found := field.RequiresExactMatch("name"); found {
		key, err := makeServiceEndpointsKey(ctx, value)
		if err != nil {
			return nil, err
		}
		return r.Watch(key, version), nil
	}
	if field.Empty() {
		return r.WatchList(makeServiceEndpointsListKey(ctx), version, tools.Everything)
	}
	return nil, fmt.Errorf("only the 'ID' and default (everything) field selectors are supported")
}
開發者ID:vrosnet,項目名稱:kubernetes,代碼行數:21,代碼來源:etcd.go

示例10: WatchBuilds

// WatchBuilds begins watching for new, changed, or deleted Builds.
func (r *Etcd) WatchBuilds(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "build")
	if err != nil {
		return nil, err
	}

	return r.WatchList(makeBuildListKey(ctx), version, func(obj runtime.Object) bool {
		build, ok := obj.(*api.Build)
		setDuration(build)
		if !ok {
			glog.Errorf("Unexpected object during build watch: %#v", obj)
			return false
		}
		fields := labels.Set{
			"metadata.name": build.Name,
			"status":        string(build.Status),
			"podName":       buildutil.GetBuildPodName(build),
		}
		return label.Matches(labels.Set(build.Labels)) && field.Matches(fields)
	})
}
開發者ID:pombredanne,項目名稱:atomic-enterprise,代碼行數:22,代碼來源:etcd.go

示例11: WatchControllers

// WatchControllers begins watching for new, changed, or deleted controllers.
func (r *Registry) WatchControllers(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
	if !field.Empty() {
		return nil, fmt.Errorf("field selectors are not supported on replication controllers")
	}
	version, err := tools.ParseWatchResourceVersion(resourceVersion, "replicationControllers")
	if err != nil {
		return nil, err
	}
	key := makeControllerListKey(ctx)
	return r.WatchList(key, version, func(obj runtime.Object) bool {
		controller, ok := obj.(*api.ReplicationController)
		if !ok {
			// Must be an error: return true to propagate to upper level.
			return true
		}
		match := label.Matches(labels.Set(controller.Labels))
		if match {
			pods, _ := r.ListPods(ctx, labels.Set(controller.Spec.Selector).AsSelector())
			controller.Status.Replicas = len(pods.Items)
		}
		return match
	})
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:24,代碼來源:etcd.go

示例12: WatchRoutes

// WatchRoutes begins watching for new, changed, or deleted route configurations.
func (registry *Etcd) WatchRoutes(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	if !label.Empty() {
		return nil, fmt.Errorf("label selectors are not supported on routes yet")
	}

	version, err := tools.ParseWatchResourceVersion(resourceVersion, "pod")
	if err != nil {
		return nil, err
	}

	if value, found := field.RequiresExactMatch("ID"); found {
		key, err := makeRouteKey(ctx, value)
		if err != nil {
			return nil, err
		}
		return registry.Watch(key, version, tools.Everything)
	}

	if field.Empty() {
		key := kubeetcd.MakeEtcdListKey(ctx, RoutePath)
		return registry.WatchList(key, version, tools.Everything)
	}
	return nil, fmt.Errorf("only the 'ID' and default (everything) field selectors are supported")
}
開發者ID:pombredanne,項目名稱:atomic-enterprise,代碼行數:25,代碼來源:etcd.go


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