Skip to content

Commit

Permalink
feature. reuse tks-api client
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Oct 23, 2023
1 parent 7ebef02 commit 2fb7b1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
24 changes: 4 additions & 20 deletions cmd/server/cluster_byoh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"

_apiClient "github.com/openinfradev/tks-api/pkg/api-client"
"github.com/openinfradev/tks-api/pkg/domain"
"github.com/openinfradev/tks-api/pkg/log"
"github.com/spf13/viper"
Expand All @@ -25,16 +24,13 @@ func processClusterByoh() error {
log.Info("byoh clusters : ", clusters)

token = getTksApiToken()
if token != "" {
apiClient.SetToken(token)

Check failure on line 28 in cmd/server/cluster_byoh.go

View workflow job for this annotation

GitHub Actions / unittest

apiClient.SetToken undefined (type apiClient.ApiClient has no field or method SetToken)

Check failure on line 28 in cmd/server/cluster_byoh.go

View workflow job for this annotation

GitHub Actions / unittest

apiClient.SetToken undefined (type apiClient.ApiClient has no field or method SetToken)
}
for _, cluster := range clusters {
clusterId := cluster.ID

// check agent node
apiClient, err := _apiClient.New(fmt.Sprintf("%s:%d", viper.GetString("tks-api-address"), viper.GetInt("tks-api-port")), token)
if err != nil {
log.Error(err)
continue
}

url := fmt.Sprintf("clusters/%s/nodes", clusterId)
body, err := apiClient.Get(url)
if err != nil {
Expand Down Expand Up @@ -62,12 +58,6 @@ func processClusterByoh() error {
continue
}

apiClient, err := _apiClient.New(fmt.Sprintf("%s:%d", viper.GetString("tks-api-address"), viper.GetInt("tks-api-port")), token)
if err != nil {
log.Error(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)
Expand Down Expand Up @@ -98,13 +88,7 @@ func transcode(in, out interface{}) {
}

func getTksApiToken() string {
apiClient, err := _apiClient.New(fmt.Sprintf("%s:%d", viper.GetString("tks-api-address"), viper.GetInt("tks-api-port")), "")
if err != nil {
log.Error(err)
return ""
}

_, err = apiClient.Post("auth/ping", domain.PingTokenRequest{
_, err := apiClient.Post("auth/ping", domain.PingTokenRequest{
Token: token,
OrganizationId: "master",
})
Expand Down
6 changes: 6 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

_apiClient "github.com/openinfradev/tks-api/pkg/api-client"
argo "github.com/openinfradev/tks-api/pkg/argo-client"
"github.com/openinfradev/tks-api/pkg/log"
"github.com/spf13/pflag"
Expand All @@ -25,6 +26,7 @@ var (
applicationAccessor *application.ApplicationAccessor
cloudAccountAccessor *cloudAccount.CloudAccountAccessor
organizationAccessor *organization.OrganizationAccessor
apiClient _apiClient.ApiClient
)

func init() {
Expand Down Expand Up @@ -72,6 +74,10 @@ func main() {
if err != nil {
log.Fatal("failed to create argowf client : ", err)
}
apiClient, err = _apiClient.New(fmt.Sprintf("%s:%d", viper.GetString("tks-api-address"), viper.GetInt("tks-api-port")))

Check failure on line 77 in cmd/server/main.go

View workflow job for this annotation

GitHub Actions / unittest

not enough arguments in call to _apiClient.New

Check failure on line 77 in cmd/server/main.go

View workflow job for this annotation

GitHub Actions / unittest

not enough arguments in call to _apiClient.New
if err != nil {
log.Fatal("failed to create tks-api client : ", err)
}

for {
err = processClusterStatus()
Expand Down

0 comments on commit 2fb7b1f

Please sign in to comment.