예제 #1
0
func getReplicationController(request *restful.Request, response *restful.Response) {
	namespace := request.PathParameter("namespace")
	replicationControllerName := request.PathParameter("replicationcontroller")

	kubeApiServerEndPoint, kubeApiServerToken, err := configuration.GetAvailablekubeApiServerEndPoint()
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get kube apiserver endpoint and token failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["namespace"] = namespace
		jsonMap["replicationControllerName"] = replicationControllerName
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	replicationController, err := control.GetReplicationController(kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get replication controller failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["kubeApiServerEndPoint"] = kubeApiServerEndPoint
		jsonMap["namespace"] = namespace
		jsonMap["replicationController"] = replicationControllerName
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}

	response.WriteJson(replicationController, "[]ReplicationController")
}
예제 #2
0
func UpdateDeployBlueGreen(kubeApiServerEndPoint string, kubeApiServerToken string, deployBlueGreen *DeployBlueGreen) error {
	deployInformation, err := GetStorage().LoadDeployInformation(
		deployBlueGreen.Namespace, deployBlueGreen.ImageInformation)
	if err != nil {
		log.Error("Fail to load deploy information %s in namespace %s with error %s",
			deployBlueGreen.ImageInformation, deployBlueGreen.Namespace, err)
		return err
	}

	replicationController, err := control.GetReplicationController(
		kubeApiServerEndPoint, kubeApiServerToken, deployBlueGreen.Namespace,
		getBlueGreenReplicationControllerName(deployInformation.ImageInformationName, deployInformation.CurrentVersion))
	if err != nil {
		log.Error("Fail to load target replication controller information %s in namespace %s with error %s",
			deployInformation.ImageInformationName+deployInformation.CurrentVersion, deployBlueGreen.Namespace, err)
		return err
	}

	// TODO support multiple ports
	portName := replicationController.ContainerSlice[0].PortSlice[0].Name
	containerPort := replicationController.ContainerSlice[0].PortSlice[0].ContainerPort

	// Clean all the previous blue green deployment
	CleanAllServiceUnderBlueGreenDeployment(kubeApiServerEndPoint, kubeApiServerToken, deployBlueGreen.ImageInformation)

	selector := make(map[string]interface{})
	selector["name"] = deployBlueGreen.ImageInformation
	labelMap := make(map[string]interface{})
	labelMap["name"] = deployBlueGreen.ImageInformation

	portSlice := make([]control.ServicePort, 0)
	// TODO read protocol rather than TCP
	portSlice = append(portSlice, control.ServicePort{
		portName, "TCP", containerPort, strconv.Itoa(containerPort), deployBlueGreen.NodePort})

	service := control.Service{
		GetBlueGreenServiceName(deployBlueGreen.ImageInformation),
		deployBlueGreen.Namespace,
		portSlice,
		selector,
		"",
		labelMap,
		deployBlueGreen.SessionAffinity,
	}
	err = control.CreateService(kubeApiServerEndPoint, kubeApiServerToken, deployBlueGreen.Namespace, service)
	if err != nil {
		log.Error("Create target service failure service %s with error %s",
			service, err)
		return err
	}

	// Update DeployBlueGreen
	err = GetStorage().saveDeployBlueGreen(deployBlueGreen)
	if err != nil {
		log.Error("Save deploy blude grenn %s with error %s",
			deployBlueGreen, err)
		return err
	}

	return nil
}