本文整理汇总了Golang中k8s/io/kubernetes/pkg/api.IsServiceIPSet函数的典型用法代码示例。如果您正苦于以下问题:Golang IsServiceIPSet函数的具体用法?Golang IsServiceIPSet怎么用?Golang IsServiceIPSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsServiceIPSet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WatchServices
func (registry *Registry) WatchServices(receiver chan<- *osdnapi.ServiceEvent, ready chan<- bool, start <-chan string, stop <-chan bool) error {
eventQueue, startVersion := registry.createAndRunEventQueue("Service", ready, start)
checkCondition := true
for {
eventType, obj, err := getEvent(eventQueue, startVersion, &checkCondition)
if err != nil {
return err
}
kServ := obj.(*kapi.Service)
// Ignore headless services
if !kapi.IsServiceIPSet(kServ) {
continue
}
switch eventType {
case watch.Added:
oServ := newSDNService(kServ)
receiver <- &osdnapi.ServiceEvent{Type: osdnapi.Added, Service: oServ}
case watch.Deleted:
oServ := newSDNService(kServ)
receiver <- &osdnapi.ServiceEvent{Type: osdnapi.Deleted, Service: oServ}
case watch.Modified:
oServ := newSDNService(kServ)
receiver <- &osdnapi.ServiceEvent{Type: osdnapi.Modified, Service: oServ}
}
}
}
示例2: Delete
func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
service, err := rs.registry.GetService(ctx, id)
if err != nil {
return nil, err
}
err = rs.registry.DeleteService(ctx, id)
if err != nil {
return nil, err
}
if api.IsServiceIPSet(service) {
rs.serviceIPs.Release(net.ParseIP(service.Spec.ClusterIP))
}
for _, nodePort := range CollectServiceNodePorts(service) {
err := rs.serviceNodePorts.Release(nodePort)
if err != nil {
// these should be caught by an eventual reconciliation / restart
glog.Errorf("Error releasing service %s node port %d: %v", service.Name, nodePort, err)
}
}
return &api.Status{Status: api.StatusSuccess}, nil
}
示例3: WatchServices
func (oi *OsdnRegistryInterface) WatchServices(receiver chan<- *osdnapi.ServiceEvent, ready chan<- bool, start <-chan string, stop <-chan bool) error {
eventQueue, startVersion := oi.createAndRunEventQueue("Service", ready, start)
checkCondition := true
for {
eventType, obj, err := getEvent(eventQueue, startVersion, &checkCondition)
if err != nil {
return err
}
kServ := obj.(*kapi.Service)
// Ignore headless services
if !kapi.IsServiceIPSet(kServ) {
continue
}
switch eventType {
case watch.Added:
for _, port := range kServ.Spec.Ports {
oServ := newSDNService(kServ, port)
receiver <- &osdnapi.ServiceEvent{Type: osdnapi.Added, Service: oServ}
}
case watch.Deleted:
for _, port := range kServ.Spec.Ports {
oServ := newSDNService(kServ, port)
receiver <- &osdnapi.ServiceEvent{Type: osdnapi.Deleted, Service: oServ}
}
case watch.Modified:
// Ignore, we don't need to update SDN in case of service updates
}
}
}
示例4: FromServices
// FromServices builds environment variables that a container is started with,
// which tell the container where to find the services it may need, which are
// provided as an argument.
func FromServices(services *api.ServiceList) []api.EnvVar {
var result []api.EnvVar
for i := range services.Items {
service := &services.Items[i]
// ignore services where ClusterIP is "None" or empty
// the services passed to this method should be pre-filtered
// only services that have the cluster IP set should be included here
if !api.IsServiceIPSet(service) {
continue
}
// Host
name := makeEnvVariableName(service.Name) + "_SERVICE_HOST"
result = append(result, api.EnvVar{Name: name, Value: service.Spec.ClusterIP})
// First port - give it the backwards-compatible name
name = makeEnvVariableName(service.Name) + "_SERVICE_PORT"
result = append(result, api.EnvVar{Name: name, Value: strconv.Itoa(service.Spec.Ports[0].Port)})
// All named ports (only the first may be unnamed, checked in validation)
for i := range service.Spec.Ports {
sp := &service.Spec.Ports[i]
if sp.Name != "" {
pn := name + "_" + makeEnvVariableName(sp.Name)
result = append(result, api.EnvVar{Name: pn, Value: strconv.Itoa(sp.Port)})
}
}
// Docker-compatible vars.
result = append(result, makeLinkVariables(service)...)
}
return result
}
示例5: Delete
func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
service, err := rs.registry.GetService(ctx, id)
if err != nil {
return nil, err
}
err = rs.registry.DeleteService(ctx, id)
if err != nil {
return nil, err
}
// TODO: can leave dangling endpoints, and potentially return incorrect
// endpoints if a new service is created with the same name
err = rs.endpoints.DeleteEndpoints(ctx, id)
if err != nil && !errors.IsNotFound(err) {
return nil, err
}
if api.IsServiceIPSet(service) {
rs.serviceIPs.Release(net.ParseIP(service.Spec.ClusterIP))
}
for _, nodePort := range CollectServiceNodePorts(service) {
err := rs.serviceNodePorts.Release(nodePort)
if err != nil {
// these should be caught by an eventual reconciliation / restart
glog.Errorf("Error releasing service %s node port %d: %v", service.Name, nodePort, err)
}
}
return &unversioned.Status{Status: unversioned.StatusSuccess}, nil
}
示例6: addDNS
func (ks *kube2sky) addDNS(subdomain string, service *kapi.Service, isNewStyleFormat bool) error {
if len(service.Spec.Ports) == 0 {
glog.Fatalf("unexpected service with no ports: %v", service)
}
// if ClusterIP is not set, a DNS entry should not be created
if !kapi.IsServiceIPSet(service) {
return ks.newHeadlessService(subdomain, service, isNewStyleFormat)
}
return ks.generateRecordsForPortalService(subdomain, service, isNewStyleFormat)
}
示例7: registerable
func registerable(s *api.Service, sl ServiceSelector) bool {
for k, v := range sl.fixNamespace() {
if sv, ok := s.Labels[k]; !ok || sv != v {
if sv, ok := s.Annotations[k]; !ok || sv != v {
return false
}
}
}
return api.IsServiceIPSet(s)
}
示例8: addDNS
func (ks *kube2sky) addDNS(subdomain string, service *kapi.Service) error {
// if ClusterIP is not set, a DNS entry should not be created
if !kapi.IsServiceIPSet(service) {
return ks.newHeadlessService(subdomain, service)
}
if len(service.Spec.Ports) == 0 {
glog.Info("Unexpected service with no ports, this should not have happend: %v", service)
}
return ks.generateRecordsForPortalService(subdomain, service)
}
示例9: addDNS
func (ks *kube2dnsimple) addDNS(service *kapi.Service) error {
if len(service.Spec.Ports) == 0 {
glog.Fatalf("unexpected service with no ports: %v", service)
}
if !kapi.IsServiceIPSet(service) {
return nil
}
return ks.generateRecordsForPortalService(service)
}
示例10: addDNSUsingEndpoints
func (kd *KubeDNS) addDNSUsingEndpoints(e *kapi.Endpoints) error {
svc, err := kd.getServiceFromEndpoints(e)
if err != nil {
return err
}
if svc == nil || kapi.IsServiceIPSet(svc) {
// No headless service found corresponding to endpoints object.
return nil
}
return kd.generateRecordsForHeadlessService(e, svc)
}
示例11: newService
func (k2c *Kube2Consul) newService(obj interface{}) {
if svc, ok := assertIsService(obj); ok {
glog.Infof("Add/Updated for service %q", svc.Name)
if !kapi.IsServiceIPSet(svc) {
glog.Info("start to register service into Consul.")
k2c.newHeadlessService(svc)
} else {
glog.Errorf("service %q in namespace %q is none headless service, skip it.", svc.Name, svc.Namespace)
}
}
}
示例12: createDNS
func (ks *kube2consul) createDNS(record string, service *kapi.Service, node *nodeInformation) error {
if strings.Contains(record, ".") {
glog.Infof("Service names containing '.' are not supported: %s\n", service.Name)
return nil
}
// if ClusterIP is not set, do not create a DNS records
if !kapi.IsServiceIPSet(service) {
glog.Infof("Skipping dns record for headless service: %s\n", service.Name)
return nil
}
//Currently this is only for NodePorts.
if service.Spec.Type != kapi.ServiceTypeNodePort {
glog.V(3).Infof("Skipping non-NodePort service: %s\n", service.Name)
return nil
}
for i := range service.Spec.Ports {
newId := node.name + record + service.Spec.Ports[i].Name
var asrName string
//If the port has a name. Use that.
if len(service.Spec.Ports[i].Name) > 0 {
asrName = record + "-" + service.Spec.Ports[i].Name
} else if len(service.Spec.Ports) == 1 { //TODO: Pull out logic later
asrName = record
} else {
asrName = record + "-" + strconv.Itoa(service.Spec.Ports[i].Port)
}
asr := &consulapi.AgentServiceRegistration{
ID: newId,
Name: asrName,
Address: node.address,
Port: service.Spec.Ports[i].NodePort,
Tags: []string{"Kube"},
}
if Contains(node.ids[record], newId) == false {
glog.Infof("Setting DNS record: %v -> %v:%d\n", asr.Name, asr.Address, asr.Port)
if ks.consulClient != nil {
if err := ks.consulClient.Agent().ServiceRegister(asr); err != nil {
return err
}
}
node.ids[record] = append(node.ids[record], newId)
}
}
return nil
}
示例13: getServiceEnvVarMap
// getServiceEnvVarMap makes a map[string]string of env vars for services a
// pod in namespace ns should see.
func (kl *Kubelet) getServiceEnvVarMap(ns string) (map[string]string, error) {
var (
serviceMap = make(map[string]*api.Service)
m = make(map[string]string)
)
// Get all service resources from the master (via a cache),
// and populate them into service environment variables.
if kl.serviceLister == nil {
// Kubelets without masters (e.g. plain GCE ContainerVM) don't set env vars.
return m, nil
}
services, err := kl.serviceLister.List(labels.Everything())
if err != nil {
return m, fmt.Errorf("failed to list services when setting up env vars.")
}
// project the services in namespace ns onto the master services
for i := range services {
service := services[i]
// ignore services where ClusterIP is "None" or empty
if !api.IsServiceIPSet(service) {
continue
}
serviceName := service.Name
switch service.Namespace {
// for the case whether the master service namespace is the namespace the pod
// is in, the pod should receive all the services in the namespace.
//
// ordering of the case clauses below enforces this
case ns:
serviceMap[serviceName] = service
case kl.masterServiceNamespace:
if masterServices.Has(serviceName) {
if _, exists := serviceMap[serviceName]; !exists {
serviceMap[serviceName] = service
}
}
}
}
mappedServices := []*api.Service{}
for key := range serviceMap {
mappedServices = append(mappedServices, serviceMap[key])
}
for _, e := range envvars.FromServices(mappedServices) {
m[e.Name] = e.Value
}
return m, nil
}
示例14: AddService
func (rly *relay) AddService(obj interface{}) {
log.WithField("service", obj).Debug("Attempting to add service")
if s, ok := obj.(*kubeAPI.Service); ok {
serviceID := vulcandID(s)
if s.Spec.Type != kubeAPI.ServiceTypeClusterIP || kubeAPI.IsServiceIPSet(s) {
log.WithField("serviceID", serviceID).Info("Not adding service")
return
}
rly.handleAddService(s)
}
}
示例15: newService
func (kd *KubeDNS) newService(obj interface{}) {
if service, ok := assertIsService(obj); ok {
// if ClusterIP is not set, a DNS entry should not be created
if !kapi.IsServiceIPSet(service) {
kd.newHeadlessService(service)
return
}
if len(service.Spec.Ports) == 0 {
glog.Warning("Unexpected service with no ports, this should not have happend: %v", service)
}
kd.newPortalService(service)
}
}