| | |
| | | ALHost string // 算法Host |
| | | Host string // 服务Host |
| | | NodeID string // Nsq节点ID |
| | | HttpNodePort int32 // HTTP nodePort端口 |
| | | RpcNodePort int32 // RPC nodePort端口 |
| | | } |
| | | |
| | | func create_test() { |
| | |
| | | return err |
| | | } |
| | | |
| | | config.HttpPort, config.RpcPort, err = getTwoNodePort(config.Client) |
| | | config.HttpNodePort, config.RpcNodePort, err = getTwoNodePort(config.Client) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | }, |
| | | { |
| | | Name: "GRPC_NODE_PORT", |
| | | Value: strconv.Itoa(int(config.RpcPort)), |
| | | Value: strconv.Itoa(int(config.RpcNodePort)), |
| | | }, |
| | | { |
| | | Name: "NODE_ID", |
| | |
| | | { |
| | | Name: "http", |
| | | Protocol: apiv1.ProtocolTCP, |
| | | Port: port, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(port)), // 容器对外端口 |
| | | NodePort: config.HttpPort, // 外部访问端口 |
| | | Port: config.HttpPort, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(config.HttpPort)), // 容器对外端口 |
| | | NodePort: config.HttpNodePort, // 外部访问端口 |
| | | }, |
| | | { |
| | | Name: "tcp", |
| | | Protocol: apiv1.ProtocolTCP, |
| | | Port: rpcPort, |
| | | TargetPort: intstr.FromInt(int(rpcPort)), |
| | | NodePort: config.RpcPort, |
| | | Port: config.RpcPort, |
| | | TargetPort: intstr.FromInt(int(config.RpcPort)), |
| | | NodePort: config.RpcNodePort, |
| | | }, |
| | | }, |
| | | SessionAffinity: apiv1.ServiceAffinityClientIP, |
| | |
| | | return err |
| | | } |
| | | |
| | | config.HttpPort, err = getRandomNodePort(config.Client) |
| | | config.HttpNodePort, err = getRandomNodePort(config.Client) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | |
| | | // createService 创建指定的 Service |
| | | func (c *CrmCreate) CreateService(config Config) error { |
| | | fmt.Println("\033[1;37;40mCreating Service:", config.ServiceName, "\033[0m") |
| | | httpServiceName := config.ServiceName + "-http" |
| | | fmt.Println("\033[1;37;40mCreating Service:", httpServiceName, "\033[0m") |
| | | |
| | | service := &apiv1.Service{ |
| | | ObjectMeta: metav1.ObjectMeta{ |
| | | Name: config.ServiceName, |
| | | Name: httpServiceName, |
| | | }, |
| | | Spec: apiv1.ServiceSpec{ |
| | | Selector: map[string]string{ |
| | |
| | | { |
| | | Name: "http", |
| | | Protocol: apiv1.ProtocolTCP, |
| | | Port: port, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(port)), // 容器对外端口 |
| | | NodePort: config.HttpPort, // 外部访问端口 |
| | | Port: config.HttpPort, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(config.HttpPort)), // 容器对外端口 |
| | | NodePort: config.HttpNodePort, // 外部访问端口 |
| | | }, |
| | | }, |
| | | SessionAffinity: apiv1.ServiceAffinityClientIP, |
| | |
| | | if !errors.IsAlreadyExists(err) { |
| | | return fmt.Errorf("failed to create Service: %v", err) |
| | | } |
| | | log.Printf("Service %s already exists in Namespace %s\n", httpServiceName, config.NameSpace) |
| | | } else { |
| | | log.Printf("Service %s created in Namespace %s\n", httpServiceName, config.NameSpace) |
| | | } |
| | | |
| | | clusterIPService := &apiv1.Service{ |
| | | ObjectMeta: metav1.ObjectMeta{ |
| | | Name: config.ServiceName, |
| | | }, |
| | | Spec: apiv1.ServiceSpec{ |
| | | Selector: map[string]string{ |
| | | "cid": c.GetCid(config), |
| | | }, |
| | | Type: apiv1.ServiceTypeClusterIP, |
| | | Ports: []apiv1.ServicePort{ |
| | | { |
| | | Name: "grpc", |
| | | Protocol: apiv1.ProtocolTCP, |
| | | Port: config.RpcPort, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(config.RpcPort)), // 容器对外端口 |
| | | }, |
| | | }, |
| | | SessionAffinity: apiv1.ServiceAffinityClientIP, |
| | | }, |
| | | } |
| | | |
| | | _, err = config.Client.CoreV1().Services(config.NameSpace).Create(context.TODO(), clusterIPService, metav1.CreateOptions{}) |
| | | |
| | | if err != nil { |
| | | if !errors.IsAlreadyExists(err) { |
| | | return fmt.Errorf("failed to create clusterIP Service: %v", err) |
| | | } |
| | | log.Printf("Service %s already exists in Namespace %s\n", config.ServiceName, config.NameSpace) |
| | | } else { |
| | | log.Printf("Service %s created in Namespace %s\n", config.ServiceName, config.NameSpace) |
| | |
| | | return err |
| | | } |
| | | |
| | | config.HttpPort, err = getRandomNodePort(config.Client) |
| | | config.HttpNodePort, err = getRandomNodePort(config.Client) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | |
| | | // createService 创建指定的 Service |
| | | func (c *SrmCreate) CreateService(config Config) error { |
| | | fmt.Println("\033[1;37;40mCreating Service:", config.ServiceName, "\033[0m") |
| | | httpServiceName := config.ServiceName + "-http" |
| | | fmt.Println("\033[1;37;40mCreating Service:", httpServiceName, "\033[0m") |
| | | |
| | | service := &apiv1.Service{ |
| | | ObjectMeta: metav1.ObjectMeta{ |
| | | Name: config.ServiceName, |
| | | Name: httpServiceName, |
| | | }, |
| | | Spec: apiv1.ServiceSpec{ |
| | | Selector: map[string]string{ |
| | |
| | | { |
| | | Name: "http", |
| | | Protocol: apiv1.ProtocolTCP, |
| | | Port: port, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(port)), // 容器对外端口 |
| | | NodePort: config.HttpPort, // 外部访问端口 |
| | | Port: config.HttpPort, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(config.HttpPort)), // 容器对外端口 |
| | | NodePort: config.HttpNodePort, // 外部访问端口 |
| | | }, |
| | | }, |
| | | SessionAffinity: apiv1.ServiceAffinityClientIP, |
| | |
| | | if !errors.IsAlreadyExists(err) { |
| | | return fmt.Errorf("failed to create Service: %v", err) |
| | | } |
| | | log.Printf("Service %s already exists in Namespace %s\n", httpServiceName, config.NameSpace) |
| | | } else { |
| | | log.Printf("Service %s created in Namespace %s\n", httpServiceName, config.NameSpace) |
| | | } |
| | | |
| | | clusterIPService := &apiv1.Service{ |
| | | ObjectMeta: metav1.ObjectMeta{ |
| | | Name: config.ServiceName, |
| | | }, |
| | | Spec: apiv1.ServiceSpec{ |
| | | Selector: map[string]string{ |
| | | "cid": c.GetCid(config), |
| | | }, |
| | | Type: apiv1.ServiceTypeClusterIP, |
| | | Ports: []apiv1.ServicePort{ |
| | | { |
| | | Name: "grpc", |
| | | Protocol: apiv1.ProtocolTCP, |
| | | Port: config.RpcPort, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(config.RpcPort)), // 容器对外端口 |
| | | }, |
| | | }, |
| | | SessionAffinity: apiv1.ServiceAffinityClientIP, |
| | | }, |
| | | } |
| | | |
| | | _, err = config.Client.CoreV1().Services(config.NameSpace).Create(context.TODO(), clusterIPService, metav1.CreateOptions{}) |
| | | |
| | | if err != nil { |
| | | if !errors.IsAlreadyExists(err) { |
| | | return fmt.Errorf("failed to create clusterIP Service: %v", err) |
| | | } |
| | | log.Printf("Service %s already exists in Namespace %s\n", config.ServiceName, config.NameSpace) |
| | | } else { |
| | | log.Printf("Service %s created in Namespace %s\n", config.ServiceName, config.NameSpace) |
| | |
| | | return err |
| | | } |
| | | |
| | | config.HttpPort, err = getRandomNodePort(config.Client) |
| | | config.HttpNodePort, err = getRandomNodePort(config.Client) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | |
| | | // createService 创建指定的 Service |
| | | func (c *WmsCreate) CreateService(config Config) error { |
| | | fmt.Println("\033[1;37;40mCreating Service:", config.ServiceName, "\033[0m") |
| | | httpServiceName := config.ServiceName + "-http" |
| | | fmt.Println("\033[1;37;40mCreating Service:", httpServiceName, "\033[0m") |
| | | |
| | | service := &apiv1.Service{ |
| | | ObjectMeta: metav1.ObjectMeta{ |
| | | Name: config.ServiceName, |
| | | Name: httpServiceName, |
| | | }, |
| | | Spec: apiv1.ServiceSpec{ |
| | | Selector: map[string]string{ |
| | |
| | | { |
| | | Name: "http", |
| | | Protocol: apiv1.ProtocolTCP, |
| | | Port: port, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(port)), // 容器对外端口 |
| | | NodePort: config.HttpPort, // 外部访问端口 |
| | | Port: config.HttpPort, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(config.HttpPort)), // 容器对外端口 |
| | | NodePort: config.HttpNodePort, // 外部访问端口 |
| | | }, |
| | | }, |
| | | SessionAffinity: apiv1.ServiceAffinityClientIP, |
| | |
| | | if !errors.IsAlreadyExists(err) { |
| | | return fmt.Errorf("failed to create Service: %v", err) |
| | | } |
| | | log.Printf("Service %s already exists in Namespace %s\n", httpServiceName, config.NameSpace) |
| | | } else { |
| | | log.Printf("Service %s created in Namespace %s\n", httpServiceName, config.NameSpace) |
| | | } |
| | | |
| | | clusterIPService := &apiv1.Service{ |
| | | ObjectMeta: metav1.ObjectMeta{ |
| | | Name: config.ServiceName, |
| | | }, |
| | | Spec: apiv1.ServiceSpec{ |
| | | Selector: map[string]string{ |
| | | "cid": c.GetCid(config), |
| | | }, |
| | | Type: apiv1.ServiceTypeClusterIP, |
| | | Ports: []apiv1.ServicePort{ |
| | | { |
| | | Name: "grpc", |
| | | Protocol: apiv1.ProtocolTCP, |
| | | Port: config.RpcPort, // 集群内部访问端口 |
| | | TargetPort: intstr.FromInt(int(config.RpcPort)), // 容器对外端口 |
| | | }, |
| | | }, |
| | | SessionAffinity: apiv1.ServiceAffinityClientIP, |
| | | }, |
| | | } |
| | | |
| | | _, err = config.Client.CoreV1().Services(config.NameSpace).Create(context.TODO(), clusterIPService, metav1.CreateOptions{}) |
| | | |
| | | if err != nil { |
| | | if !errors.IsAlreadyExists(err) { |
| | | return fmt.Errorf("failed to create clusterIP Service: %v", err) |
| | | } |
| | | log.Printf("Service %s already exists in Namespace %s\n", config.ServiceName, config.NameSpace) |
| | | } else { |
| | | log.Printf("Service %s created in Namespace %s\n", config.ServiceName, config.NameSpace) |