-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from openinfradev/release
20231107 release to main
- Loading branch information
Showing
7 changed files
with
164 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/openinfradev/tks-api/pkg/domain" | ||
"github.com/openinfradev/tks-api/pkg/log" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var token string | ||
|
||
func processClusterByoh() error { | ||
// get clusters | ||
clusters, err := clusterAccessor.GetBootstrappedByohClusters() | ||
if err != nil { | ||
return err | ||
} | ||
if len(clusters) == 0 { | ||
return nil | ||
} | ||
log.Info("byoh clusters : ", clusters) | ||
|
||
token = getTksApiToken() | ||
if token != "" { | ||
apiClient.SetToken(token) | ||
} | ||
for _, cluster := range clusters { | ||
clusterId := cluster.ID | ||
|
||
// check agent node | ||
url := fmt.Sprintf("clusters/%s/nodes", clusterId) | ||
body, err := apiClient.Get(url) | ||
if err != nil { | ||
log.Error(err) | ||
continue | ||
} | ||
|
||
var out domain.GetClusterNodesResponse | ||
transcode(body, &out) | ||
|
||
completed := true | ||
for _, node := range out.Nodes { | ||
if node.Status != "COMPLETED" { | ||
completed = false | ||
} | ||
} | ||
log.Info(out.Nodes) | ||
|
||
//completed = true // FOR TEST | ||
if completed { | ||
log.Info(fmt.Sprintf("all agents registered! starting stack creation. clusterId %s", clusterId)) | ||
// clusterId, newStatus, newMessage, workflowId | ||
if err = clusterAccessor.UpdateClusterStatus(clusterId, domain.ClusterStatus_INSTALLING, "", ""); err != nil { | ||
log.Error("Failed to update cluster status err : ", err) | ||
continue | ||
} | ||
|
||
if cluster.IsStack { | ||
if _, err = apiClient.Post(fmt.Sprintf("organizations/%s/stacks/%s/install", cluster.OrganizationId, clusterId), nil); err != nil { | ||
log.Error(err) | ||
continue | ||
} | ||
} else { | ||
if _, err = apiClient.Post("clusters/"+clusterId+"/install", nil); err != nil { | ||
log.Error(err) | ||
continue | ||
} | ||
} | ||
|
||
} | ||
} | ||
return nil | ||
} | ||
|
||
func transcode(in, out interface{}) { | ||
buf := new(bytes.Buffer) | ||
err := json.NewEncoder(buf).Encode(in) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
err = json.NewDecoder(buf).Decode(out) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} | ||
|
||
func getTksApiToken() string { | ||
_, err := apiClient.Post("auth/ping", domain.PingTokenRequest{ | ||
Token: token, | ||
OrganizationId: "master", | ||
}) | ||
if err != nil { | ||
body, err := apiClient.Post("auth/login", domain.LoginRequest{ | ||
AccountId: viper.GetString("tks-api-account"), | ||
Password: viper.GetString("tks-api-password"), | ||
OrganizationId: "master", | ||
}) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
var out domain.LoginResponse | ||
transcode(body, &out) | ||
|
||
log.Info(out.User.Token) | ||
token = out.User.Token | ||
} | ||
|
||
return token | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters