当前位置: 首页>>代码示例>>Golang>>正文


Golang unversioned.IngressInterface类代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned.IngressInterface的典型用法代码示例。如果您正苦于以下问题:Golang IngressInterface类的具体用法?Golang IngressInterface怎么用?Golang IngressInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IngressInterface类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	var ingClient client.IngressInterface
	if kubeClient, err := client.NewInCluster(); err != nil {
		log.Fatalf("Failed to create client: %v.", err)
	} else {
		ingClient = kubeClient.Extensions().Ingress(api.NamespaceAll)
	}
	tmpl, _ := template.New("nginx").Parse(nginxConf)
	rateLimiter := util.NewTokenBucketRateLimiter(0.1, 1)
	known := &extensions.IngressList{}

	// Controller loop
	shellOut("nginx")
	for {
		rateLimiter.Accept()
		ingresses, err := ingClient.List(labels.Everything(), fields.Everything())
		if err != nil || reflect.DeepEqual(ingresses.Items, known.Items) {
			continue
		}
		known = ingresses
		if w, err := os.Create("/etc/nginx/nginx.conf"); err != nil {
			log.Fatalf("Failed to open %v: %v", nginxConf, err)
		} else if err := tmpl.Execute(w, ingresses); err != nil {
			log.Fatalf("Failed to write template %v", err)
		}
		shellOut("nginx -s reload")
	}
}
开发者ID:pupapaik,项目名称:contrib,代码行数:28,代码来源:controller.go

示例2: updateLbIp

// updateLbIp updates the loadbalancer status ip if required.
func updateLbIp(
	ingClient client.IngressInterface, ing extensions.Ingress, ip string) error {
	lbIPs := ing.Status.LoadBalancer.Ingress
	if len(lbIPs) > 0 && lbIPs[0].IP == ip {
		glog.Infof("Ingress %v/%v: %v doesn't require status update",
			ing.Namespace, ing.Name, lbIPs)
		return nil
	}
	glog.Infof("Updating Ingress %v/%v with ip %v",
		ing.Namespace, ing.Name, ip)

	currIng, err := ingClient.Get(ing.Name)
	if err != nil {
		return err
	}
	currIng.Status = extensions.IngressStatus{
		LoadBalancer: api.LoadBalancerStatus{
			Ingress: []api.LoadBalancerIngress{
				{IP: ip},
			},
		},
	}
	// TODO: If this update fails it's probably resource version related,
	// which means it's advantageous to retry right away vs requeuing,
	// which will lead to a full sync.
	if _, err := ingClient.UpdateStatus(currIng); err != nil {
		return err
	}
	return nil
}
开发者ID:rwehner,项目名称:contrib,代码行数:31,代码来源:utils.go

示例3: main

func main() {
	var ingClient client.IngressInterface
	if kubeClient, err := client.NewInCluster(); err != nil {
		log.Fatalf("Failed to create client: %v.", err)
	} else {
		ingClient = kubeClient.Extensions().Ingress("devops-test")
	}
	tmpl, _ := template.New("nginx").Parse(nginxConf)
	rateLimiter := util.NewTokenBucketRateLimiter(0.1, 1)
	known := &extensions.IngressList{}

	// Controller loop
	shellOut("nginx")
	for {
		rateLimiter.Accept()
		ingresses, err := ingClient.List(api.ListOptions{})
		if err != nil {
			log.Printf("Error retrieving ingresses: %v", err)
			continue
		}
		if reflect.DeepEqual(ingresses.Items, known.Items) {
			continue
		}
		known = ingresses
		if w, err := os.Create("/etc/nginx/nginx.conf"); err != nil {
			log.Fatalf("Failed to open %v: %v", nginxConf, err)
		} else if err := tmpl.Execute(w, ingresses); err != nil {
			log.Fatalf("Failed to write template %v", err)
		}

		restartNginx("nginx -t")

	}
}
开发者ID:Vungle,项目名称:contrib,代码行数:34,代码来源:controller.go

示例4: main

func main() {
	var ingClient client.IngressInterface
	var secretsClient client.SecretsInterface
	/* Anon http client
	config := client.Config{
		Host:     "http://localhost:8080",
		Username: "admin",
		Password: "admin",
	}
	kubeClient, err := client.New(&config)
	*/
	kubeClient, err := client.NewInCluster()
	if err != nil {
		log.Fatalf("Failed to create client: %v.", err)
	} else {
		ingClient = kubeClient.Extensions().Ingress(api.NamespaceAll)
		secretsClient = kubeClient.Secrets(api.NamespaceAll)
	}
	tmpl := template.New("nginx.tmpl").Funcs(template.FuncMap{"hasprefix": hasPrefix, "hassuffix": hasSuffix})
	if _, err := tmpl.ParseFiles("./nginx.tmpl"); err != nil {
		log.Fatalf("Failed to parse template %v", err)
	}

	rateLimiter := util.NewTokenBucketRateLimiter(0.1, 1)
	known := &extensions.IngressList{}
	known_secrets := &api.SecretList{}

	// Controller loop
	shellOut("nginx")
	for {
		rateLimiter.Accept()
		ingresses, err := ingClient.List(api.ListOptions{})
		if err != nil {
			log.Printf("Error retrieving ingresses: %v", err)
			continue
		}
		secrets, err := secretsClient.List(api.ListOptions{})
		if err != nil {
			log.Printf("Error retrieving secrets: %v", err)
			continue
		}
		if reflect.DeepEqual(ingresses.Items, known.Items) && reflect.DeepEqual(secrets.Items, known_secrets.Items) {
			continue
		}
		// Process SSL context
		// old values
		known = ingresses
		known_secrets = secrets
		// context variable
		context := &Context{Ingress: ingresses, Secrets: secrets}
		if w, err := os.Create("/etc/nginx/nginx.conf"); err != nil {
			log.Fatalf("Failed to open %v: %v", err)
		} else if err := tmpl.Execute(w, context); err != nil {
			log.Fatalf("Failed to write template %v", err)
		}
		shellOut("nginx -s reload")
	}
}
开发者ID:macropin,项目名称:nginx-ingress,代码行数:58,代码来源:controller.go

示例5: main

func main() {
	var ingClient client.IngressInterface
	if kubeClient, err := client.NewInCluster(); err != nil {
		log.Fatalf("Failed to create client: %v.", err)
	} else {
		ingClient = kubeClient.Extensions().Ingress(api.NamespaceAll)
	}
	tmpl, _ := template.New("nginx").Parse(nginxConf)
	tmplSSL, _ := template.New("nginx").Parse(nginxSSLConf)
	rateLimiter := util.NewTokenBucketRateLimiter(0.1, 1)
	known := &extensions.IngressList{}

	// Controller loop
	//shellOut("nginx")
	for {
		rateLimiter.Accept()
		ingresses, err := ingClient.List(api.ListOptions{})

		fmt.Printf("Port %+v\n", ingresses.Items[0].Spec.Rules[0].HTTP.Paths[0].Backend.ServicePort.IntValue())
		fmt.Printf("Path %+v\n", ingresses.Items[0].Spec.Rules[0].HTTP.Paths[0].Path)

		var httpIngressList extensions.IngressList
		var httpsIngressList extensions.IngressList

		for _, v := range ingresses.Items {
			fmt.Printf("%#v\n", v)
			if v.Spec.Rules[0].HTTP.Paths[0].Backend.ServicePort.IntVal == 80 {
				httpIngressList.Items = append(httpIngressList.Items, v)
			} else if v.Spec.Rules[0].HTTP.Paths[0].Backend.ServicePort.IntVal == 443 {
				httpsIngressList.Items = append(httpsIngressList.Items, v)
			}
		}

		if err != nil {
			log.Printf("Error retrieving ingresses: %v", err)
			continue
		}
		if reflect.DeepEqual(ingresses.Items, known.Items) {
			continue
		}
		known = ingresses
		if w, err := os.Create("/etc/nginx/conf.d/appcloud.conf"); err != nil {
			log.Fatalf("Failed to open %v: %v", nginxConf, err)
		} else if err := tmpl.Execute(w, httpIngressList); err != nil {
			log.Fatalf("Failed to write template %v", err)
		}

		if w, err := os.Create("/etc/nginx/conf.d/appcloud-ssl.conf"); err != nil {
			log.Fatalf("Failed to open %v: %v", nginxSSLConf, err)
		} else if err := tmplSSL.Execute(w, httpsIngressList); err != nil {
			log.Fatalf("Failed to write template %v", err)
		}

		//	shellOut("nginx -s reload")
	}
}
开发者ID:gnudeep,项目名称:contrib,代码行数:56,代码来源:controller.go


注:本文中的k8s/io/kubernetes/pkg/client/unversioned.IngressInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。