本文整理汇总了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)
}
示例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
}
示例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
}