コード例 #1
0
ファイル: serviceService.go プロジェクト: w19900227/go-k8s
func (this *ServiceService) CreateServiceRouting(data []byte) Service {
	type service_format struct {
		Service_name string            `json:"service_name"`
		Routing_ip   string            `json:"routing_ip"`
		Port         string            `json:"port"`
		Label        map[string]string `json:"label"`
		NodePort     string            `json:"nodePort"`
	}

	var _service_format service_format
	json.Unmarshal(data, &_service_format)

	var _k8s_service k8s_format.Service
	_k8s_service.Kind = "Service"
	_k8s_service.Metadata.Name = _service_format.Service_name
	_k8s_service.Metadata.Labels = _service_format.Label
	_k8s_service.Metadata.Labels["name"] = _service_format.Service_name

	var _k8s_service_ports k8s_format.ServicePort
	_k8s_service_ports.Port, _ = strconv.Atoi(_service_format.Port)
	_k8s_service_ports.TargetPort, _ = strconv.Atoi(_service_format.Port)
	_k8s_service_ports.Protocol = "TCP"
	_k8s_service.Spec.Ports = append(_k8s_service.Spec.Ports, _k8s_service_ports)
	_k8s_service.Spec.Type = "NodePort"
	service_model := k8sModel.ServiceModel{}
	// rep := service_model.CreateService(_k8s_service)
	service_model.CreateService(_k8s_service)

	var _k8s_endpoint k8s_format.Endpoints
	_k8s_endpoint.Kind = "Endpoints"
	_k8s_endpoint.Metadata.Name = _service_format.Service_name
	_k8s_endpoint.Metadata.Labels = _service_format.Label
	_k8s_endpoint.Metadata.Labels["name"] = _service_format.Service_name

	var _k8s_endpoint_address k8s_format.EndpointAddress
	_k8s_endpoint_address.IP = _service_format.Routing_ip

	var _k8s_endpoint_port k8s_format.EndpointPort
	_k8s_endpoint_port.Port, _ = strconv.Atoi(_service_format.Port)
	_k8s_endpoint_port.Protocol = "TCP"

	var _k8s_endpoint_subset k8s_format.EndpointSubset
	_k8s_endpoint_subset.Addresses = append(_k8s_endpoint_subset.Addresses, _k8s_endpoint_address)
	_k8s_endpoint_subset.Ports = append(_k8s_endpoint_subset.Ports, _k8s_endpoint_port)

	_k8s_endpoint.Subsets = append(_k8s_endpoint.Subsets, _k8s_endpoint_subset)

	var endpoint_model k8sModel.EndpointModel
	endpoint_model.CreateEndpoint(_k8s_endpoint)

	var _service Service
	// if rep == nil {
	// 	_service.Status = "fail"
	// 	return _service
	// }

	_service.Status = "ok"
	return _service
}
コード例 #2
0
ファイル: serviceService.go プロジェクト: w19900227/go-k8s
func (this *ServiceService) CreateBoth(data []byte) Service {
	var data_format struct {
		Service_name    string            `json:"service_name"`
		Port            string            `json:"port"`
		Container_count string            `json:"container_count"`
		Cpu             string            `json:"cpu"`
		Image           string            `json:"image"`
		Label           map[string]string `json:"label"`
	}
	json.Unmarshal(data, &data_format)

	var _k8s_service k8s_format.Service
	_k8s_service.Kind = "Service"
	_k8s_service.Metadata.Name = data_format.Service_name
	_k8s_service.Metadata.Labels = data_format.Label
	_k8s_service.Metadata.Labels["name"] = data_format.Service_name
	_k8s_service.Spec.Type = "NodePort"
	_k8s_service.Spec.Selector = map[string]string{"name": data_format.Service_name}

	var _k8s_service_ports k8s_format.ServicePort
	_k8s_service_ports.Port, _ = strconv.Atoi(data_format.Port)
	_k8s_service_ports.TargetPort, _ = strconv.Atoi(data_format.Port)
	_k8s_service_ports.Protocol = "TCP"
	_k8s_service.Spec.Ports = append(_k8s_service.Spec.Ports, _k8s_service_ports)

	var k8s_rc k8s_format.ReplicationController
	k8s_rc.Kind = "ReplicationController"
	k8s_rc.Metadata.Name = data_format.Service_name
	k8s_rc.Metadata.Labels = data_format.Label
	k8s_rc.Metadata.Labels["name"] = data_format.Service_name
	k8s_rc.Spec.Replicas, _ = strconv.Atoi(data_format.Container_count)
	k8s_rc.Spec.Selector = map[string]string{"name": data_format.Service_name}
	k8s_rc.Spec.Template.Metadata.Labels = map[string]string{"name": data_format.Service_name}

	var k8s_rc_container_port k8s_format.ContainerPort
	k8s_rc_container_port.ContainerPort, _ = strconv.Atoi(data_format.Port)

	var k8s_rc_container k8s_format.Container
	k8s_rc_container.Name = data_format.Service_name
	k8s_rc_container.Image = data_format.Image
	k8s_rc_container.Ports = append(k8s_rc_container.Ports, k8s_rc_container_port)
	k8s_rc.Spec.Template.Spec.Containers = append(k8s_rc.Spec.Template.Spec.Containers, k8s_rc_container)

	var rc_model k8sModel.ReplicationControllerModel
	var service_model k8sModel.ServiceModel

	rc_model.CreateReplicationController(k8s_rc)
	service_model.CreateService(_k8s_service)
	// _rc_service := data_format

	var service Service
	service.Status = "ok"
	// service.Data = ""
	return service
}
コード例 #3
0
ファイル: serviceService.go プロジェクト: w19900227/go-k8s
func (this *ServiceService) CreateService(data []byte) Service {
	type service_format struct {
		Service_name string            `json:"service_name"`
		Port         string            `json:"port"`
		Label        map[string]string `json:"label"`
		NodePort     string            `json:"nodePort"`
	}

	var _service_format service_format
	json.Unmarshal(data, &_service_format)

	var _k8s_service k8s_format.Service
	var _k8s_service_ports k8s_format.ServicePort
	_k8s_service.Kind = "Service"
	// _k8s_service.APIVersion = "v1beta3"
	_k8s_service.Metadata.Name = _service_format.Service_name
	_k8s_service.Metadata.Labels = _service_format.Label
	_k8s_service.Metadata.Labels["name"] = _service_format.Service_name

	_k8s_service_ports.Port, _ = strconv.Atoi(_service_format.Port)
	_k8s_service_ports.TargetPort, _ = strconv.Atoi(_service_format.Port)
	_k8s_service_ports.Protocol = "TCP"
	_k8s_service.Spec.Ports = append(_k8s_service.Spec.Ports, _k8s_service_ports)

	_k8s_service.Spec.Selector = map[string]string{"name": _service_format.Service_name}
	_k8s_service.Spec.Type = "NodePort"

	service_model := k8sModel.ServiceModel{}
	// rep := service_model.CreateService(_k8s_service)
	service_model.CreateService(_k8s_service)
	var _service Service
	// if rep == nil {
	// 	_service.Status = "fail"
	// 	return _service
	// }

	_service.Status = "ok"
	return _service
}