Beispiel #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
}
func CleanAllServiceUnderBlueGreenDeployment(kubeApiServerEndPoint string, kubeApiServerToken string, imageInformationName string) error {
	// Clean all service with this deployment name
	namespaceSlice, err := control.GetAllNamespaceName(kubeApiServerEndPoint, kubeApiServerToken)
	if err != nil {
		log.Error("Fail to get all namesapce with error %s", err)
		return err
	}
	for _, namespace := range namespaceSlice {
		service, _ := control.GetService(kubeApiServerEndPoint, kubeApiServerToken, namespace, GetBlueGreenServiceName(imageInformationName))
		if service != nil {
			err := control.DeleteService(kubeApiServerEndPoint, kubeApiServerToken, namespace, service.Name)
			if err != nil {
				log.Error("Fail to delete service %s in namesapce %s with error %s", imageInformationName, namespace, err)
				return err
			}
		}
	}
	return nil
}