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


Golang util.Forever函數代碼示例

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


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

示例1: Run

// Run begins watching and syncing.
func (c *RouterController) Run() {
	glog.V(4).Info("Running router controller")
	if c.Namespaces != nil {
		c.HandleNamespaces()
		go util.Forever(c.HandleNamespaces, c.NamespaceSyncInterval)
	}
	go util.Forever(c.HandleRoute, 0)
	go util.Forever(c.HandleEndpoints, 0)
}
開發者ID:johnmccawley,項目名稱:origin,代碼行數:10,代碼來源:controller.go

示例2: Run

// Run starts an asynchronous loop that monitors the status of cluster nodes.
func (nc *NodeController) Run(period time.Duration) {
	// Incorporate the results of node status pushed from kubelet to master.
	go util.Forever(func() {
		if err := nc.monitorNodeStatus(); err != nil {
			glog.Errorf("Error monitoring node status: %v", err)
		}
	}, nc.nodeMonitorPeriod)

	go util.Forever(func() {
		nc.podEvictor.TryEvict(func(nodeName string) { nc.deletePods(nodeName) })
	}, nodeEvictionPeriod)
}
開發者ID:shrids,項目名稱:kubernetes,代碼行數:13,代碼來源:nodecontroller.go

示例3: Run

func (s *Source) Run() error {
	// locate the oldest snapshot
	snapshotSize := uint64(1000)
	snapshotWindow := snapshotSize
	resp, err := s.client.Get("/", false, false)
	if err != nil {
		return err
	}
	recentIndex := uint64(1)
	if resp.EtcdIndex > snapshotSize {
		recentIndex = resp.EtcdIndex - snapshotWindow + 1
	}

	watches := make(chan chan *etcd.Response)

	go util.Forever(func() {
		ch := make(chan *etcd.Response)
		watches <- ch
		if _, err := s.client.Watch("/", recentIndex, true, ch, nil); err != nil {
			snapshotWindow = snapshotWindow * 9 / 10
			if etcdError, ok := err.(*etcd.EtcdError); ok {
				recentIndex = etcdError.Index - snapshotWindow
			}
			glog.Errorf("Unable to watch: %v", err)
			return
		}
		snapshotWindow = snapshotSize
	}, 1*time.Second)

	lowestIndex := uint64(0)
	go util.Forever(func() {
		glog.Infof("Ready to archive changes from etcd ...")

		for ch := range watches {
			glog.Infof("Watching ...")
			for resp := range ch {
				index, err := s.OnEvent(resp)
				if err != nil {
					glog.Errorf("error: %v", err)
					continue
				}
				if index == 0 {
					break
				}
				lowestIndex = index
			}
		}
	}, 10*time.Millisecond)
	return nil
}
開發者ID:smarterclayton,項目名稱:kube-archiver,代碼行數:50,代碼來源:etcd.go

示例4: Run

func (rc *RouteController) Run(syncPeriod time.Duration) {
	go util.Forever(func() {
		if err := rc.reconcileNodeRoutes(); err != nil {
			glog.Errorf("Couldn't reconcile node routes: %v", err)
		}
	}, syncPeriod)
}
開發者ID:ngbinh,項目名稱:kubernetes,代碼行數:7,代碼來源:routecontroller.go

示例5: Run

func (a *HorizontalPodAutoscalerController) Run(syncPeriod time.Duration) {
	go util.Forever(func() {
		if err := a.reconcileAutoscalers(); err != nil {
			glog.Errorf("Couldn't reconcile horizontal pod autoscalers: %v", err)
		}
	}, syncPeriod)
}
開發者ID:npreys,項目名稱:kubernetes,代碼行數:7,代碼來源:horizontalpodautoscaler_controller.go

示例6: startKubelet

func startKubelet(k KubeletBootstrap, podCfg *config.PodConfig, kc *KubeletConfig) {
	// start the kubelet
	go util.Forever(func() { k.Run(podCfg.Updates()) }, 0)

	// start the kubelet server
	if kc.EnableServer {
		go util.Forever(func() {
			k.ListenAndServe(kc.Address, kc.Port, kc.TLSOptions, kc.EnableDebuggingHandlers)
		}, 0)
	}
	if kc.ReadOnlyPort > 0 {
		go util.Forever(func() {
			k.ListenAndServeReadOnly(kc.Address, kc.ReadOnlyPort)
		}, 0)
	}
}
開發者ID:nvnvrts,項目名稱:kubernetes,代碼行數:16,代碼來源:server.go

示例7: serve

// serve starts serving the provided http.Handler using security settings derived from the MasterConfig
func (c *MasterConfig) serve(handler http.Handler, extra []string) {
	timeout := c.Options.ServingInfo.RequestTimeoutSeconds
	if timeout == -1 {
		timeout = 0
	}

	server := &http.Server{
		Addr:           c.Options.ServingInfo.BindAddress,
		Handler:        handler,
		ReadTimeout:    time.Duration(timeout) * time.Second,
		WriteTimeout:   time.Duration(timeout) * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	go util.Forever(func() {
		for _, s := range extra {
			glog.Infof(s, c.Options.ServingInfo.BindAddress)
		}
		if c.TLS {
			server.TLSConfig = &tls.Config{
				// Change default from SSLv3 to TLSv1.0 (because of POODLE vulnerability)
				MinVersion: tls.VersionTLS10,
				// Populate PeerCertificates in requests, but don't reject connections without certificates
				// This allows certificates to be validated by authenticators, while still allowing other auth types
				ClientAuth: tls.RequestClientCert,
				ClientCAs:  c.ClientCAs,
			}
			glog.Fatal(cmdutil.ListenAndServeTLS(server, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.ServerCert.CertFile, c.Options.ServingInfo.ServerCert.KeyFile))
		} else {
			glog.Fatal(server.ListenAndServe())
		}
	}, 0)
}
開發者ID:ncantor,項目名稱:origin,代碼行數:34,代碼來源:master.go

示例8: RunProxy

// RunProxy starts the proxy
func (c *NodeConfig) RunProxy() {
	// initialize kube proxy
	serviceConfig := pconfig.NewServiceConfig()
	endpointsConfig := pconfig.NewEndpointsConfig()
	loadBalancer := proxy.NewLoadBalancerRR()
	endpointsConfig.RegisterHandler(loadBalancer)

	host, _, err := net.SplitHostPort(c.BindAddress)
	if err != nil {
		glog.Fatalf("The provided value to bind to must be an ip:port %q", c.BindAddress)
	}
	ip := net.ParseIP(host)
	if ip == nil {
		glog.Fatalf("The provided value to bind to must be an ip:port: %q", c.BindAddress)
	}

	protocol := iptables.ProtocolIpv4
	if ip.To4() == nil {
		protocol = iptables.ProtocolIpv6
	}

	syncPeriod, err := time.ParseDuration(c.IPTablesSyncPeriod)
	if err != nil {
		glog.Fatalf("Cannot parse the provided ip-tables sync period (%s) : %v", c.IPTablesSyncPeriod, err)
	}

	go util.Forever(func() {
		proxier, err := proxy.NewProxier(loadBalancer, ip, iptables.New(kexec.New(), protocol), util.PortRange{}, syncPeriod)
		if err != nil {
			switch {
			// conflicting use of iptables, retry
			case proxy.IsProxyLocked(err):
				glog.Errorf("Unable to start proxy, will retry: %v", err)
				return
			// on a system without iptables
			case strings.Contains(err.Error(), "executable file not found in path"):
				glog.V(4).Infof("kube-proxy initialization error: %v", err)
				glog.Warningf("WARNING: Could not find the iptables command. The service proxy requires iptables and will be disabled.")
			case err == proxy.ErrProxyOnLocalhost:
				glog.Warningf("WARNING: The service proxy cannot bind to localhost and will be disabled.")
			case strings.Contains(err.Error(), "you must be root"):
				glog.Warningf("WARNING: Could not modify iptables. You must run this process as root to use the service proxy.")
			default:
				glog.Warningf("WARNING: Could not modify iptables. You must run this process as root to use the service proxy: %v", err)
			}
			select {}
		}

		pconfig.NewSourceAPI(
			c.Client,
			30*time.Second,
			serviceConfig.Channel("api"),
			endpointsConfig.Channel("api"))

		serviceConfig.RegisterHandler(proxier)
		glog.Infof("Started Kubernetes Proxy on %s", host)
		select {}
	}, 5*time.Second)
}
開發者ID:ncantor,項目名稱:origin,代碼行數:60,代碼來源:node.go

示例9: New

func New(ttl time.Duration) GCStore {
	store := &gcStore{
		data: make(map[interface{}]*dataItem),
		ttl:  ttl,
	}
	go util.Forever(store.garbageCollect, ttl/2)
	return store
}
開發者ID:MohamedFAhmed,項目名稱:heapster,代碼行數:8,代碼來源:gcstore.go

示例10: Run

// Run starts an http server for the static assets listening on the configured
// bind address
func (c *AssetConfig) Run() {
	publicURL, err := url.Parse(c.Options.PublicURL)
	if err != nil {
		glog.Fatal(err)
	}

	mux := http.NewServeMux()
	err = c.addHandlers(mux)
	if err != nil {
		glog.Fatal(err)
	}

	if publicURL.Path != "/" {
		mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
			http.Redirect(w, req, publicURL.Path, http.StatusFound)
		})
	}

	timeout := c.Options.ServingInfo.RequestTimeoutSeconds
	if timeout == -1 {
		timeout = 0
	}

	server := &http.Server{
		Addr:           c.Options.ServingInfo.BindAddress,
		Handler:        mux,
		ReadTimeout:    time.Duration(timeout) * time.Second,
		WriteTimeout:   time.Duration(timeout) * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	isTLS := configapi.UseTLS(c.Options.ServingInfo.ServingInfo)

	go util.Forever(func() {
		if isTLS {
			extraCerts, err := configapi.GetNamedCertificateMap(c.Options.ServingInfo.NamedCertificates)
			if err != nil {
				glog.Fatal(err)
			}
			server.TLSConfig = &tls.Config{
				// Change default from SSLv3 to TLSv1.0 (because of POODLE vulnerability)
				MinVersion: tls.VersionTLS10,
				// Set SNI certificate func
				GetCertificate: cmdutil.GetCertificateFunc(extraCerts),
			}
			glog.Infof("Web console listening at https://%s", c.Options.ServingInfo.BindAddress)
			glog.Fatal(cmdutil.ListenAndServeTLS(server, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.ServerCert.CertFile, c.Options.ServingInfo.ServerCert.KeyFile))
		} else {
			glog.Infof("Web console listening at http://%s", c.Options.ServingInfo.BindAddress)
			glog.Fatal(server.ListenAndServe())
		}
	}, 0)

	// Attempt to verify the server came up for 20 seconds (100 tries * 100ms, 100ms timeout per try)
	cmdutil.WaitForSuccessfulDial(isTLS, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.BindAddress, 100*time.Millisecond, 100*time.Millisecond, 100)

	glog.Infof("Web console available at %s", c.Options.PublicURL)
}
開發者ID:sztsian,項目名稱:origin,代碼行數:60,代碼來源:asset.go

示例11: NewSourceFile

func NewSourceFile(path string, nodeName string, period time.Duration, updates chan<- interface{}) {
	config := &sourceFile{
		path:     path,
		nodeName: nodeName,
		updates:  updates,
	}
	glog.V(1).Infof("Watching path %q", path)
	go util.Forever(config.run, period)
}
開發者ID:ngbinh,項目名稱:kubernetes,代碼行數:9,代碼來源:file.go

示例12: Run

// Run begins watching and scheduling. It starts a goroutine and returns immediately.
func (s *Scheduler) Run() {
	if s.config.BindPodsRateLimiter != nil {
		go util.Forever(func() {
			sat := s.config.BindPodsRateLimiter.Saturation()
			metrics.BindingRateLimiterSaturation.Set(sat)
		}, metrics.BindingSaturationReportInterval)
	}
	go util.Until(s.scheduleOne, 0, s.config.StopEverything)
}
開發者ID:erinboyd,項目名稱:origin,代碼行數:10,代碼來源:scheduler.go

示例13: experimental

// experimental returns the resources and codec for the experimental api
func (m *Master) experimental(c *Config) *apiserver.APIGroupVersion {
	controllerStorage := expcontrolleretcd.NewStorage(c.DatabaseStorage)
	autoscalerStorage := horizontalpodautoscaleretcd.NewREST(c.ExpDatabaseStorage)
	thirdPartyResourceStorage := thirdpartyresourceetcd.NewREST(c.ExpDatabaseStorage)
	daemonSetStorage, daemonSetStatusStorage := daemonetcd.NewREST(c.ExpDatabaseStorage)
	deploymentStorage := deploymentetcd.NewStorage(c.ExpDatabaseStorage)
	jobStorage, jobStatusStorage := jobetcd.NewREST(c.ExpDatabaseStorage)

	thirdPartyControl := ThirdPartyController{
		master: m,
		thirdPartyResourceRegistry: thirdPartyResourceStorage,
	}
	go func() {
		util.Forever(func() {
			if err := thirdPartyControl.SyncResources(); err != nil {
				glog.Warningf("third party resource sync failed: %v", err)
			}
		}, 10*time.Second)
	}()
	storage := map[string]rest.Storage{
		strings.ToLower("replicationControllers"):       controllerStorage.ReplicationController,
		strings.ToLower("replicationControllers/scale"): controllerStorage.Scale,
		strings.ToLower("horizontalpodautoscalers"):     autoscalerStorage,
		strings.ToLower("thirdpartyresources"):          thirdPartyResourceStorage,
		strings.ToLower("daemonsets"):                   daemonSetStorage,
		strings.ToLower("daemonsets/status"):            daemonSetStatusStorage,
		strings.ToLower("deployments"):                  deploymentStorage.Deployment,
		strings.ToLower("deployments/scale"):            deploymentStorage.Scale,
		strings.ToLower("jobs"):                         jobStorage,
		strings.ToLower("jobs/status"):                  jobStatusStorage,
	}

	expMeta := latest.GroupOrDie("experimental")

	return &apiserver.APIGroupVersion{
		Root: m.apiGroupPrefix,
		APIRequestInfoResolver: m.newAPIRequestInfoResolver(),

		Creater:   api.Scheme,
		Convertor: api.Scheme,
		Typer:     api.Scheme,

		Mapper:        expMeta.RESTMapper,
		Codec:         expMeta.Codec,
		Linker:        expMeta.SelfLinker,
		Storage:       storage,
		Version:       expMeta.GroupVersion,
		ServerVersion: latest.GroupOrDie("").GroupVersion,

		Admit:   m.admissionControl,
		Context: m.requestContextMapper,

		ProxyDialerFn:     m.dialer,
		MinRequestTimeout: m.minRequestTimeout,
	}
}
開發者ID:chiefy,項目名稱:kubernetes,代碼行數:57,代碼來源:master.go

示例14: NewSourceURL

func NewSourceURL(url string, header http.Header, nodeName string, period time.Duration, updates chan<- interface{}) {
	config := &sourceURL{
		url:      url,
		header:   header,
		nodeName: nodeName,
		updates:  updates,
		data:     nil,
	}
	glog.V(1).Infof("Watching URL %s", url)
	go util.Forever(config.run, period)
}
開發者ID:MarWestermann,項目名稱:gofabric8,代碼行數:11,代碼來源:http.go

示例15: Run

// Run starts an asynchronous loop that monitors the status of cluster nodes.
func (nc *NodeController) Run(period time.Duration) {
	// Incorporate the results of node status pushed from kubelet to master.
	go util.Forever(func() {
		if err := nc.monitorNodeStatus(); err != nil {
			glog.Errorf("Error monitoring node status: %v", err)
		}
	}, nc.nodeMonitorPeriod)

	go util.Forever(func() {
		nc.podEvictor.Try(func(value TimedValue) (bool, time.Duration) {
			remaining, err := nc.deletePods(value.Value)
			if err != nil {
				util.HandleError(fmt.Errorf("unable to evict node %q: %v", value.Value, err))
				return false, 0
			}
			if remaining {
				glog.V(2).Infof("Pods terminating on %q", value.Value)
				nc.terminationEvictor.Add(value.Value)
			}
			return true, 0
		})
	}, nodeEvictionPeriod)

	// TODO: replace with a controller that ensures pods that are terminating complete
	// in a particular time period
	go util.Forever(func() {
		nc.terminationEvictor.Try(func(value TimedValue) (bool, time.Duration) {
			remaining, err := nc.terminatePods(value.Value, value.Added)
			if err != nil {
				util.HandleError(fmt.Errorf("unable to terminate pods on node %q: %v", value.Value, err))
				return false, 0
			}
			if remaining != 0 {
				glog.V(2).Infof("Pods still terminating on %q, estimated completion %s", value.Value, remaining)
				return false, remaining
			}
			return true, 0
		})
	}, nodeEvictionPeriod)
}
開發者ID:Vitamen,項目名稱:kubernetes,代碼行數:41,代碼來源:nodecontroller.go


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