Пример #1
0
func addCommandFromAllBlueGreenDeployment(command *slb.Command, kubeApiServerEndPoint string, kubeApiServerToken string) error {
	deployBlueGreenSlice, err := deploy.GetStorage().LoadAllDeployBlueGreen()
	if err != nil {
		log.Error(err)
		return err
	}

	kubernetesServiceHTTPSlice := make([]slb.KubernetesServiceHTTP, 0)

	for _, deployBlueGreen := range deployBlueGreenSlice {
		deployInformation, err := deploy.GetStorage().LoadDeployInformation(deployBlueGreen.Namespace, deployBlueGreen.ImageInformation)
		if err != nil {
			log.Error(err)
			return err
		}

		serviceName := deploy.GetBlueGreenServiceName(deployBlueGreen.ImageInformation)
		service, err := control.GetService(kubeApiServerEndPoint, kubeApiServerToken, deployBlueGreen.Namespace, serviceName)
		if err != nil {
			log.Error(err)
			return err
		}

		for _, servicePort := range service.PortSlice {
			// Get protocol
			protocol := ""
			for _, containerPort := range deployInformation.ContainerPortSlice {
				if servicePort.TargetPort == strconv.Itoa(containerPort.ContainerPort) {
					protocol = containerPort.Protocol
				}
			}
			// HTTP
			if protocol == deploy.ProtocolTypeHTTP && servicePort.NodePort >= 0 {
				kubernetesServiceHTTP := slb.KubernetesServiceHTTP{
					deployBlueGreen.Namespace,
					BlueGreenDeploymentPrefix + deployBlueGreen.ImageInformation,
					servicePort.Port,
					servicePort.NodePort,
				}

				kubernetesServiceHTTPSlice = append(kubernetesServiceHTTPSlice, kubernetesServiceHTTP)
			}
		}
	}

	if command.KubernetesServiceHTTPSlice == nil {
		command.KubernetesServiceHTTPSlice = kubernetesServiceHTTPSlice
	} else {
		command.KubernetesServiceHTTPSlice = append(command.KubernetesServiceHTTPSlice, kubernetesServiceHTTPSlice...)
	}

	return nil
}
Пример #2
0
func (slbDaemon *SLBDaemon) SendCommand(command *slb.Command) error {
	command.NodeHostSlice = slbDaemon.NodeHostSlice

	buffer := bytes.Buffer{}
	for _, endPoint := range slbDaemon.EndPointSlice {
		url := endPoint + "/api/v1/slb"
		_, err := restclient.RequestPut(url, command, nil, false)
		if err != nil {
			log.Error(err)
			buffer.WriteString("Fail to configure " + endPoint + " with error " + err.Error() + "\n")
		}
	}

	if buffer.Len() > 0 {
		return errors.New(buffer.String())
	} else {
		return nil
	}
}