From dabbe4c25eae2c46f861ab4fc23b837534a94603 Mon Sep 17 00:00:00 2001 From: cheliequan <liequanche@126.com> Date: 星期三, 31 五月 2023 19:32:14 +0800 Subject: [PATCH] k8s部署时通过环境变量传递数据库连接字符串 --- src/cluster/cluster.go | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/cluster/cluster.go b/src/cluster/cluster.go index bf26f6a..39e167d 100644 --- a/src/cluster/cluster.go +++ b/src/cluster/cluster.go @@ -9,6 +9,7 @@ "strings" "basic.com/aps/aps_deploy.git/src/util" + "basic.com/aps/aps_deploy.git/src/rancher" ) type Cluster struct { @@ -110,7 +111,7 @@ req, err := http.NewRequest("GET", url, nil) if err != nil { - return "", fmt.Errorf("failed to create cluster list request: %v", err) + return "", fmt.Errorf("failed to get cluster list request: %v", err) } req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", bearerToken)) @@ -154,10 +155,6 @@ SSHPort int `json:"sshPort"` } -type RancherConfig struct { - RancherURL string `json:"rancherURL"` - BearerToken string `json:"bearerToken"` -} type ClusterCreateRequest struct { Name string `json:"name"` @@ -250,16 +247,17 @@ return true, nil } -func CreateCluster(rancherConfig RancherConfig, clusterName string) error { +func CreateCluster(rancherClusterConfig rancher.RancherClusterConfig, clusterName string) error { requestBody := createClusterData(clusterName) + fmt.Println(rancherClusterConfig.RancherURL) - url := fmt.Sprintf("%s/v3/clusters", rancherConfig.RancherURL) + url := fmt.Sprintf("%s/v3/clusters", rancherClusterConfig.RancherURL) req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody)) if err != nil { return fmt.Errorf("Failed to create HTTP request: %v", err) } - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", rancherConfig.BearerToken)) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", rancherClusterConfig.BearerToken)) req.Header.Set("Content-Type", "application/json") client := util.CreateHTTPClient() -- Gitblit v1.8.0