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


Golang api.ServiceType函数代码示例

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


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

示例1: ServiceSpec

func ServiceSpec(srvcSpecs []interface{}) api.ServiceSpec {
	if len(srvcSpecs) == 0 {
		return api.ServiceSpec{}
	}

	userServiceSpec := srvcSpecs[0].(map[string]interface{})

	srvcSpec := api.ServiceSpec{
		Ports: ServicePorts(userServiceSpec["ports"].([]interface{})),
	}

	if _, ok := userServiceSpec["selector"]; ok {
		srvcSpec.Selector = convertMapTypeToStringMap(userServiceSpec["selector"].(map[string]interface{}))
	}

	if _, ok := userServiceSpec["cluster_ip"]; ok {
		srvcSpec.ClusterIP = userServiceSpec["cluster_ip"].(string)
	}

	if _, ok := userServiceSpec["type"]; ok {
		srvcSpec.Type = api.ServiceType(userServiceSpec["type"].(string))
	}

	if _, ok := userServiceSpec["session_affinity"]; ok {
		srvcSpec.SessionAffinity = api.ServiceAffinity(userServiceSpec["session_affinity"].(string))
	}

	return srvcSpec
}
开发者ID:brendangibat,项目名称:terraform-provider-kubernetes,代码行数:29,代码来源:service.go

示例2: ServiceUsageFunc

// ServiceUsageFunc knows how to measure usage associated with services
func ServiceUsageFunc(object runtime.Object) api.ResourceList {
	result := api.ResourceList{}
	var serviceType api.ServiceType
	var ports int

	switch t := object.(type) {
	case *v1.Service:
		serviceType = api.ServiceType(t.Spec.Type)
		ports = len(t.Spec.Ports)
	case *api.Service:
		serviceType = t.Spec.Type
		ports = len(t.Spec.Ports)
	default:
		panic(fmt.Sprintf("expect *api.Service or *v1.Service, got %v", t))
	}

	// default service usage
	result[api.ResourceServices] = resource.MustParse("1")
	result[api.ResourceServicesLoadBalancers] = resource.MustParse("0")
	result[api.ResourceServicesNodePorts] = resource.MustParse("0")
	switch serviceType {
	case api.ServiceTypeNodePort:
		// node port services need to count node ports
		value := resource.NewQuantity(int64(ports), resource.DecimalSI)
		result[api.ResourceServicesNodePorts] = *value
	case api.ServiceTypeLoadBalancer:
		// load balancer services need to count load balancers
		result[api.ResourceServicesLoadBalancers] = resource.MustParse("1")
	}
	return result
}
开发者ID:alex-mohr,项目名称:kubernetes,代码行数:32,代码来源:services.go

示例3: GetQuotaServiceType

//GetQuotaServiceType returns ServiceType if the service type is eligible to track against a quota, nor return ""
func GetQuotaServiceType(service *api.Service) api.ServiceType {
	switch service.Spec.Type {
	case api.ServiceTypeNodePort:
		return api.ServiceTypeNodePort
	case api.ServiceTypeLoadBalancer:
		return api.ServiceTypeLoadBalancer
	}
	return api.ServiceType("")
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:10,代码来源:services.go

示例4: StructuredGenerate

func (s ServiceCommonGeneratorV1) StructuredGenerate() (runtime.Object, error) {
	err := s.validate()
	if err != nil {
		return nil, err
	}
	ports := []api.ServicePort{}
	for _, tcpString := range s.TCP {
		port, targetPort, err := parsePorts(tcpString)
		if err != nil {
			return nil, err
		}

		portName := strings.Replace(tcpString, ":", "-", -1)
		ports = append(ports, api.ServicePort{
			Name:       portName,
			Port:       port,
			TargetPort: targetPort,
			Protocol:   api.Protocol("TCP"),
			NodePort:   int32(s.NodePort),
		})
	}

	// setup default label and selector
	labels := map[string]string{}
	labels["app"] = s.Name
	selector := map[string]string{}
	selector["app"] = s.Name

	service := api.Service{
		ObjectMeta: api.ObjectMeta{
			Name:   s.Name,
			Labels: labels,
		},
		Spec: api.ServiceSpec{
			Type:         api.ServiceType(s.Type),
			Selector:     selector,
			Ports:        ports,
			ExternalName: s.ExternalName,
		},
	}
	if len(s.ClusterIP) > 0 {
		service.Spec.ClusterIP = s.ClusterIP
	}
	return &service, nil
}
开发者ID:alex-mohr,项目名称:kubernetes,代码行数:45,代码来源:service_basic.go

示例5: Generate

func (testServiceGenerator) Generate(genericParams map[string]interface{}) (runtime.Object, error) {
	params := map[string]string{}
	for key, value := range genericParams {
		strVal, isString := value.(string)
		if !isString {
			return nil, fmt.Errorf("expected string, saw %v for '%s'", value, key)
		}
		params[key] = strVal
	}
	labelsString, found := params["labels"]
	var labels map[string]string
	var err error
	if found && len(labelsString) > 0 {
		labels, err = kubectl.ParseLabels(labelsString)
		if err != nil {
			return nil, err
		}
	}

	name, found := params["name"]
	if !found || len(name) == 0 {
		name, found = params["default-name"]
		if !found || len(name) == 0 {
			return nil, fmt.Errorf("'name' is a required parameter.")
		}
	}
	portString, found := params["port"]
	if !found {
		return nil, fmt.Errorf("'port' is a required parameter.")
	}
	port, err := strconv.Atoi(portString)
	if err != nil {
		return nil, err
	}
	servicePortName, found := params["port-name"]
	if !found {
		// Leave the port unnamed.
		servicePortName = ""
	}
	service := api.Service{
		ObjectMeta: api.ObjectMeta{
			Name:   name,
			Labels: labels,
		},
		Spec: api.ServiceSpec{
			Ports: []api.ServicePort{
				{
					Name:     servicePortName,
					Port:     port,
					Protocol: api.Protocol(params["protocol"]),
				},
			},
		},
	}
	targetPort, found := params["target-port"]
	if !found {
		targetPort, found = params["container-port"]
	}
	if found && len(targetPort) > 0 {
		if portNum, err := strconv.Atoi(targetPort); err != nil {
			service.Spec.Ports[0].TargetPort = intstr.FromString(targetPort)
		} else {
			service.Spec.Ports[0].TargetPort = intstr.FromInt(portNum)
		}
	} else {
		service.Spec.Ports[0].TargetPort = intstr.FromInt(port)
	}
	if params["create-external-load-balancer"] == "true" {
		service.Spec.Type = api.ServiceTypeLoadBalancer
	}
	if len(params["external-ip"]) > 0 {
		service.Spec.ExternalIPs = []string{params["external-ip"]}
	}
	if len(params["type"]) != 0 {
		service.Spec.Type = api.ServiceType(params["type"])
	}
	if len(params["session-affinity"]) != 0 {
		switch api.ServiceAffinity(params["session-affinity"]) {
		case api.ServiceAffinityNone:
			service.Spec.SessionAffinity = api.ServiceAffinityNone
		case api.ServiceAffinityClientIP:
			service.Spec.SessionAffinity = api.ServiceAffinityClientIP
		default:
			return nil, fmt.Errorf("unknown session affinity: %s", params["session-affinity"])
		}
	}
	return &service, nil
}
开发者ID:kimsh92,项目名称:kubernetes,代码行数:88,代码来源:cmd_test.go

示例6: generate


//.........这里部分代码省略.........
	var portString string
	if portString, found = params["ports"]; !found {
		portString, found = params["port"]
		if !found {
			return nil, fmt.Errorf("'port' is a required parameter.")
		}
	}

	portStringSlice := strings.Split(portString, ",")
	for i, stillPortString := range portStringSlice {
		port, err := strconv.Atoi(stillPortString)
		if err != nil {
			return nil, err
		}
		name := servicePortName
		// If we are going to assign multiple ports to a service, we need to
		// generate a different name for each one.
		if len(portStringSlice) > 1 {
			name = fmt.Sprintf("port-%d", i+1)
		}
		protocol := params["protocol"]

		switch {
		case len(protocol) == 0 && len(portProtocolMap) == 0:
			// Default to TCP, what the flag was doing previously.
			protocol = "TCP"
		case len(protocol) > 0 && len(portProtocolMap) > 0:
			// User has specified the --protocol while exposing a multiprotocol resource
			// We should stomp multiple protocols with the one specified ie. do nothing
		case len(protocol) == 0 && len(portProtocolMap) > 0:
			// no --protocol and we expose a multiprotocol resource
			protocol = "TCP" // have the default so we can stay sane
			if exposeProtocol, found := portProtocolMap[stillPortString]; found {
				protocol = exposeProtocol
			}
		}
		ports = append(ports, api.ServicePort{
			Name:     name,
			Port:     int32(port),
			Protocol: api.Protocol(protocol),
		})
	}

	service := api.Service{
		ObjectMeta: api.ObjectMeta{
			Name:   name,
			Labels: labels,
		},
		Spec: api.ServiceSpec{
			Selector: selector,
			Ports:    ports,
		},
	}
	targetPortString, found := params["target-port"]
	if !found {
		targetPortString, found = params["container-port"]
	}
	if found && len(targetPortString) > 0 {
		var targetPort intstr.IntOrString
		if portNum, err := strconv.Atoi(targetPortString); err != nil {
			targetPort = intstr.FromString(targetPortString)
		} else {
			targetPort = intstr.FromInt(portNum)
		}
		// Use the same target-port for every port
		for i := range service.Spec.Ports {
			service.Spec.Ports[i].TargetPort = targetPort
		}
	} else {
		// If --target-port or --container-port haven't been specified, this
		// should be the same as Port
		for i := range service.Spec.Ports {
			port := service.Spec.Ports[i].Port
			service.Spec.Ports[i].TargetPort = intstr.FromInt(int(port))
		}
	}
	if params["create-external-load-balancer"] == "true" {
		service.Spec.Type = api.ServiceTypeLoadBalancer
	}
	if len(params["external-ip"]) > 0 {
		service.Spec.ExternalIPs = []string{params["external-ip"]}
	}
	if len(params["type"]) != 0 {
		service.Spec.Type = api.ServiceType(params["type"])
	}
	if service.Spec.Type == api.ServiceTypeLoadBalancer {
		service.Spec.LoadBalancerIP = params["load-balancer-ip"]
	}
	if len(params["session-affinity"]) != 0 {
		switch api.ServiceAffinity(params["session-affinity"]) {
		case api.ServiceAffinityNone:
			service.Spec.SessionAffinity = api.ServiceAffinityNone
		case api.ServiceAffinityClientIP:
			service.Spec.SessionAffinity = api.ServiceAffinityClientIP
		default:
			return nil, fmt.Errorf("unknown session affinity: %s", params["session-affinity"])
		}
	}
	return &service, nil
}
开发者ID:40a,项目名称:bootkube,代码行数:101,代码来源:service.go

示例7: generate

func generate(params map[string]string) (runtime.Object, error) {
	selectorString, found := params["selector"]
	if !found || len(selectorString) == 0 {
		return nil, fmt.Errorf("'selector' is a required parameter.")
	}
	selector, err := ParseLabels(selectorString)
	if err != nil {
		return nil, err
	}

	labelsString, found := params["labels"]
	var labels map[string]string
	if found && len(labelsString) > 0 {
		labels, err = ParseLabels(labelsString)
		if err != nil {
			return nil, err
		}
	}

	name, found := params["name"]
	if !found || len(name) == 0 {
		name, found = params["default-name"]
		if !found || len(name) == 0 {
			return nil, fmt.Errorf("'name' is a required parameter.")
		}
	}
	portString, found := params["port"]
	if !found {
		return nil, fmt.Errorf("'port' is a required parameter.")
	}
	port, err := strconv.Atoi(portString)
	if err != nil {
		return nil, err
	}
	servicePortName, found := params["port-name"]
	if !found {
		// Leave the port unnamed.
		servicePortName = ""
	}
	service := api.Service{
		ObjectMeta: api.ObjectMeta{
			Name:   name,
			Labels: labels,
		},
		Spec: api.ServiceSpec{
			Selector: selector,
			Ports: []api.ServicePort{
				{
					Name:     servicePortName,
					Port:     port,
					Protocol: api.Protocol(params["protocol"]),
				},
			},
		},
	}
	targetPort, found := params["target-port"]
	if !found {
		targetPort, found = params["container-port"]
	}
	if found && len(targetPort) > 0 {
		if portNum, err := strconv.Atoi(targetPort); err != nil {
			service.Spec.Ports[0].TargetPort = util.NewIntOrStringFromString(targetPort)
		} else {
			service.Spec.Ports[0].TargetPort = util.NewIntOrStringFromInt(portNum)
		}
	} else {
		service.Spec.Ports[0].TargetPort = util.NewIntOrStringFromInt(port)
	}
	if params["create-external-load-balancer"] == "true" {
		service.Spec.Type = api.ServiceTypeLoadBalancer
	}
	if len(params["public-ip"]) != 0 {
		service.Spec.DeprecatedPublicIPs = []string{params["public-ip"]}
	}
	if len(params["type"]) != 0 {
		service.Spec.Type = api.ServiceType(params["type"])
	}
	return &service, nil
}
开发者ID:Tlacenka,项目名称:origin,代码行数:79,代码来源:service.go


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