Ejemplo n.º 1
0
func getAllKubernetesNamespaceName(request *restful.Request, response *restful.Response) {
	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()
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

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

	response.WriteJson(nameSlice, "[]string")
}
Ejemplo n.º 2
0
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
}