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


Golang Service.Status方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/api.Service.Status方法的典型用法代碼示例。如果您正苦於以下問題:Golang Service.Status方法的具體用法?Golang Service.Status怎麽用?Golang Service.Status使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/pkg/api.Service的用法示例。


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

示例1: allocate

// allocate assigns an unallocated ip to a service and updates the
// service's persisted state.
func (ic *IngressIPController) allocate(service *kapi.Service, key string) error {
	// Make a copy to avoid mutating cache state
	t, err := kapi.Scheme.DeepCopy(service)
	if err != nil {
		return err
	}
	service = t.(*kapi.Service)

	ip, err := ic.allocateIP(service.Spec.LoadBalancerIP)
	if err != nil {
		return err
	}
	ipString := ip.String()

	glog.V(5).Infof("Allocating ip %v to service %v", ipString, key)
	service.Status = kapi.ServiceStatus{
		LoadBalancer: kapi.LoadBalancerStatus{
			Ingress: []kapi.LoadBalancerIngress{
				{
					IP: ipString,
				},
			},
		},
	}
	if err = ic.persistServiceStatus(service); err != nil {
		if releaseErr := ic.ipAllocator.Release(ip); releaseErr != nil {
			// Release from contiguous allocator should never return an error, but just in case...
			utilruntime.HandleError(fmt.Errorf("Error releasing ip %v for service %v: %v", ipString, key, releaseErr))
		}
		return err
	}
	ic.allocationMap[ipString] = key

	return ic.ensureExternalIP(service, key, ipString)
}
開發者ID:xgwang-zte,項目名稱:origin,代碼行數:37,代碼來源:controller.go

示例2: UpdateServiceRouting

func (su *ServiceUpdater) UpdateServiceRouting(service *api.Service) error {
	err := su.UpdateRouteIfNeeded(service)
	if err != nil {
		log.Println("Unable to update service route", err)

		return err
	}

	if ServiceHasLoadBalancerAddress(service) {
		log.Println("The route was found and the service has an address, not updating the status")

		return nil
	}

	log.Println("Found route for the service", service.ObjectMeta.Name, "updating the service load-balancer status")
	service.Status = api.ServiceStatus{
		LoadBalancer: api.LoadBalancerStatus{
			Ingress: []api.LoadBalancerIngress{
				api.LoadBalancerIngress{
					Hostname: su.GetDomainNamesFromService(service)[0],
				},
			},
		},
	}

	_, err = su.ServiceRepository.Update(service)
	if err != nil {
		log.Println("Error while updating the service:", err)

		return err
	}

	log.Println("Successfully updated the service status")

	return nil
}
開發者ID:sroze,項目名稱:kubernetes-vamp-router,代碼行數:36,代碼來源:serviceupdater.go

示例3: ReviewService

func ReviewService(client *client.Client, service *api.Service, rootDns string) error {
	if service.Spec.Type != api.ServiceTypeLoadBalancer {
		log.Println("Skipping service", service.ObjectMeta.Name, "as it is not a LoadBalancer")

		return nil
	}

	// If there's an IP and/or DNS address in the load balancer status, skip it
	if ServiceHasLoadBalancerAddress(service) {
		log.Println("Skipping service", service.ObjectMeta.Name, "as it already have a LoadBalancer address")

		return nil
	}

	log.Println("Service", service.ObjectMeta.Name, "needs to be reviewed")

	// Get existing proxy configuration
	var proxyConfiguration reverseproxy.Configuration
	if jsonConfiguration, found := service.ObjectMeta.Annotations["kubernetesReverseproxy"]; found {
		proxyConfiguration = reverseproxy.Configuration{}

		if err := json.Unmarshal([]byte(jsonConfiguration), &proxyConfiguration); err != nil {
			log.Println("Unable to unmarshal the configuration, keep the empty one")
		}

	} else {
		log.Println("No `kubernetesReverseproxy` annotation found")
		proxyConfiguration = reverseproxy.Configuration{}
	}

	// If configuration found, skip it
	if len(proxyConfiguration.Hosts) == 0 {
		// Create the expected hostname of the service
		host := strings.Join([]string{
			service.ObjectMeta.Name,
			service.ObjectMeta.Namespace,
			rootDns,
		}, ".")

		// Append the new host to the configuration
		proxyConfiguration.Hosts = append(proxyConfiguration.Hosts, reverseproxy.Host{
			Host: host,
			Port: 80,
		})

		jsonConfiguration, err := json.Marshal(proxyConfiguration)
		if err != nil {
			log.Println("Unable to JSON-encode the proxy configuration: ", err)

			return err
		}

		if service.ObjectMeta.Annotations == nil {
			service.ObjectMeta.Annotations = map[string]string{}
		}

		service.ObjectMeta.Annotations["kubernetesReverseproxy"] = string(jsonConfiguration)

		// Update the service
		log.Println("Adding the `kubernetesReverseproxy` annotation to service")
		updated, err := client.Services(service.ObjectMeta.Namespace).Update(service)
		if err != nil {
			log.Println("Error while updated the service:", err)

			return err
		}

		log.Println("Successfully added the reverse proxy configuration", updated)
	} else {
		// Updating service load-balancer status
		log.Println("Updating the service load-balancer status")
		service.Status = api.ServiceStatus{
			LoadBalancer: api.LoadBalancerStatus{
				Ingress: []api.LoadBalancerIngress{
					api.LoadBalancerIngress{
						Hostname: proxyConfiguration.Hosts[0].Host,
					},
				},
			},
		}

		updated, err := client.Services(service.ObjectMeta.Namespace).Update(service)
		if err != nil {
			log.Println("Error while updated the service:", err)

			return err
		}

		log.Println("Successfully updated the service status", updated)
	}

	return nil
}
開發者ID:sroze,項目名稱:kubernetes-load-balancer-proxifier,代碼行數:93,代碼來源:main.go


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