Skip to content

Commit 80b085f

Browse files
authored
Merge pull request #47 from openinfradev/release
241015 main from release ( v3.2.1 )
2 parents c49f5d2 + 0584c49 commit 80b085f

21 files changed

+936
-603
lines changed

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v2
15+
with:
16+
ref: ${{ github.event.pull_request.head.sha }}
1517

1618
- name: Set up Docker Buildx
1719
uses: docker/setup-buildx-action@v1

.github/workflows/golangcic-lint.yml

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
name: Lint
22
on:
33
push:
4+
tags:
5+
- v*
6+
branches:
7+
- main
8+
- develop
9+
- release
410
pull_request:
5-
11+
branches:
12+
- main
13+
- develop
14+
- release
615
jobs:
716
golangci:
817
name: lint
918
runs-on: ubuntu-latest
1019
steps:
11-
- uses: actions/checkout@v2
12-
- name: golangci-lint
13-
uses: golangci/golangci-lint-action@v2
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-go@v4
1422
with:
15-
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
16-
version: latest
17-
args: --timeout=5m
18-
19-
# Optional: working directory, useful for monorepos
20-
# working-directory: somedir
21-
22-
# Optional: golangci-lint command line arguments.
23-
# args: --issues-exit-code=0
24-
25-
# Optional: show only new issues if it's a pull request. The default value is `false`.
26-
# only-new-issues: true
27-
28-
# Optional: if set to true then the action will use pre-installed Go.
29-
# skip-go-installation: true
30-
31-
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
32-
# skip-pkg-cache: true
33-
34-
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
35-
# skip-build-cache: true
23+
go-version: "1.21"
24+
cache: false
25+
- name: Install golangci-lint
26+
# Install golangci-lint from source instead of using
27+
# golangci-lint-action to ensure the golangci-lint binary is built with
28+
# the same Go version we're targeting.
29+
# Avoids incompatibility issues such as:
30+
# - https://github.com/golangci/golangci-lint/issues/2922
31+
# - https://github.com/golangci/golangci-lint/issues/2673
32+
# - https://github.com/golangci/golangci-lint-action/issues/442
33+
run: go install github.com/golangci/golangci-lint/cmd/[email protected]
34+
- name: Run golangci-lint
35+
run: golangci-lint run --verbose --out-format=github-actions

.github/workflows/unittest.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ jobs:
99
steps:
1010
- name: Check out repository code
1111
uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.event.pull_request.head.sha }}
1214

1315
- name: Set up Go
1416
uses: actions/setup-go@v2
1517
with:
16-
go-version: 1.18
18+
go-version: 1.21
1719

1820
- name: Test
1921
run: go test -v -cover ./...

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
cmd/server/server
18+
cmd/server/start_dev.sh

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=linux/amd64 docker.io/library/golang:1.18-buster AS builder
1+
FROM --platform=linux/amd64 docker.io/library/golang:1.21 AS builder
22

33
RUN mkdir -p /app
44
WORKDIR /app

cmd/server/appgroup_status.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/openinfradev/tks-api/pkg/domain"
@@ -17,7 +18,7 @@ func processAppGroupStatus() error {
1718
if len(appGroups) == 0 {
1819
return nil
1920
}
20-
log.Info("appGroups : ", appGroups)
21+
log.Info(context.TODO(), "[processAppGroupStatus] appGroups : ", appGroups)
2122

2223
for i := range appGroups {
2324
appGroup := appGroups[i]
@@ -32,13 +33,13 @@ func processAppGroupStatus() error {
3233
var newMessage string
3334

3435
if workflowId != "" {
35-
workflow, err := argowfClient.GetWorkflow("argo", workflowId)
36+
workflow, err := argowfClient.GetWorkflow(context.TODO(), "argo", workflowId)
3637
if err != nil {
37-
log.Error("failed to get argo workflow. err : ", err)
38+
log.Error(context.TODO(), "failed to get argo workflow. err : ", err)
3839
continue
3940
}
4041
newMessage = fmt.Sprintf("(%s) %s", workflow.Status.Progress, workflow.Status.Message)
41-
log.Debug(fmt.Sprintf("status [%s], newMessage [%s], phase [%s]", status, newMessage, workflow.Status.Phase))
42+
log.Debug(context.TODO(), fmt.Sprintf("status [%s], newMessage [%s], phase [%s]", status, newMessage, workflow.Status.Phase))
4243
if status == domain.AppGroupStatus_INSTALLING {
4344
switch workflow.Status.Phase {
4445
case "Running":
@@ -70,10 +71,10 @@ func processAppGroupStatus() error {
7071
}
7172

7273
if status != newStatus || statusDesc != newMessage {
73-
log.Debug(fmt.Sprintf("update status!! appGroupId [%s], newStatus [%s], newMessage [%s]", appGroupId, newStatus, newMessage))
74+
log.Debug(context.TODO(), fmt.Sprintf("update status!! appGroupId [%s], newStatus [%s], newMessage [%s]", appGroupId, newStatus, newMessage))
7475
err := applicationAccessor.UpdateAppGroupStatus(appGroupId, newStatus, newMessage, workflowId)
7576
if err != nil {
76-
log.Error("Failed to update appgroup status err : ", err)
77+
log.Error(context.TODO(), "Failed to update appgroup status err : ", err)
7778
continue
7879
}
7980
}

cmd/server/cloud_account_status.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/openinfradev/tks-api/pkg/domain"
@@ -16,7 +17,7 @@ func processCloudAccountStatus() error {
1617
if len(cloudAccounts) == 0 {
1718
return nil
1819
}
19-
log.Info("cloudAccounts : ", cloudAccounts)
20+
log.Info(context.TODO(), "[processCloudAccountStatus] cloudAccounts : ", cloudAccounts)
2021

2122
for i := range cloudAccounts {
2223
cloudaccount := cloudAccounts[i]
@@ -31,14 +32,14 @@ func processCloudAccountStatus() error {
3132
var newMessage string
3233

3334
if workflowId != "" {
34-
workflow, err := argowfClient.GetWorkflow("argo", workflowId)
35+
workflow, err := argowfClient.GetWorkflow(context.TODO(), "argo", workflowId)
3536
if err != nil {
36-
log.Error("failed to get argo workflow. err : ", err)
37+
log.Error(context.TODO(), "failed to get argo workflow. err : ", err)
3738
continue
3839
}
3940

4041
newMessage = fmt.Sprintf("(%s) %s", workflow.Status.Progress, workflow.Status.Message)
41-
log.Debug(fmt.Sprintf("status [%s], newMessage [%s], phase [%s]", status, newMessage, workflow.Status.Phase))
42+
log.Debug(context.TODO(), fmt.Sprintf("status [%s], newMessage [%s], phase [%s]", status, newMessage, workflow.Status.Phase))
4243

4344
if status == domain.CloudAccountStatus_CREATING {
4445
switch workflow.Status.Phase {
@@ -71,17 +72,17 @@ func processCloudAccountStatus() error {
7172
}
7273

7374
if status != newStatus || statusDesc != newMessage {
74-
log.Debug(fmt.Sprintf("update status!! cloudAccountId [%s], newStatus [%s], newMessage [%s]", cloudAccountId, newStatus, newMessage))
75+
log.Debug(context.TODO(), fmt.Sprintf("update status!! cloudAccountId [%s], newStatus [%s], newMessage [%s]", cloudAccountId, newStatus, newMessage))
7576
err := cloudAccountAccessor.UpdateCloudAccountStatus(cloudAccountId, newStatus, newMessage, workflowId)
7677
if err != nil {
77-
log.Error("Failed to update cloudaccount status err : ", err)
78+
log.Error(context.TODO(), "Failed to update cloudaccount status err : ", err)
7879
continue
7980
}
8081

8182
if newStatus == domain.CloudAccountStatus_CREATED {
8283
err = cloudAccountAccessor.UpdateCreatedIAM(cloudAccountId, true)
8384
if err != nil {
84-
log.Error("Failed to update cloudaccount createdIAM err : ", err)
85+
log.Error(context.TODO(), "Failed to update cloudaccount createdIAM err : ", err)
8586
continue
8687
}
8788

cmd/server/cluster_byoh.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/json"
67
"fmt"
78

@@ -21,7 +22,7 @@ func processClusterByoh() error {
2122
if len(clusters) == 0 {
2223
return nil
2324
}
24-
log.Info("byoh clusters : ", clusters)
25+
log.Info(context.TODO(), "[processClusterByoh] byoh clusters : ", clusters)
2526

2627
token = getTksApiToken()
2728
if token != "" {
@@ -34,7 +35,7 @@ func processClusterByoh() error {
3435
url := fmt.Sprintf("clusters/%s/nodes", clusterId)
3536
body, err := apiClient.Get(url)
3637
if err != nil {
37-
log.Error(err)
38+
log.Error(context.TODO(), err)
3839
continue
3940
}
4041

@@ -47,25 +48,25 @@ func processClusterByoh() error {
4748
completed = false
4849
}
4950
}
50-
log.Info(out.Nodes)
51+
log.Info(context.TODO(), out.Nodes)
5152

5253
//completed = true // FOR TEST
5354
if completed {
54-
log.Info(fmt.Sprintf("all agents registered! starting stack creation. clusterId %s", clusterId))
55+
log.Info(context.TODO(), fmt.Sprintf("all agents registered! starting stack creation. clusterId %s", clusterId))
5556
// clusterId, newStatus, newMessage, workflowId
5657
if err = clusterAccessor.UpdateClusterStatus(clusterId, domain.ClusterStatus_INSTALLING, "", ""); err != nil {
57-
log.Error("Failed to update cluster status err : ", err)
58+
log.Error(context.TODO(), "Failed to update cluster status err : ", err)
5859
continue
5960
}
6061

6162
if cluster.IsStack {
6263
if _, err = apiClient.Post(fmt.Sprintf("organizations/%s/stacks/%s/install", cluster.OrganizationId, clusterId), nil); err != nil {
63-
log.Error(err)
64+
log.Error(context.TODO(), err)
6465
continue
6566
}
6667
} else {
6768
if _, err = apiClient.Post("clusters/"+clusterId+"/install", nil); err != nil {
68-
log.Error(err)
69+
log.Error(context.TODO(), err)
6970
continue
7071
}
7172
}
@@ -88,10 +89,7 @@ func transcode(in, out interface{}) {
8889
}
8990

9091
func getTksApiToken() string {
91-
_, err := apiClient.Post("auth/ping", domain.PingTokenRequest{
92-
Token: token,
93-
OrganizationId: "master",
94-
})
92+
_, err := apiClient.Get("auth/verify-token")
9593
if err != nil {
9694
body, err := apiClient.Post("auth/login", domain.LoginRequest{
9795
AccountId: viper.GetString("tks-api-account"),
@@ -105,7 +103,7 @@ func getTksApiToken() string {
105103
var out domain.LoginResponse
106104
transcode(body, &out)
107105

108-
log.Info(out.User.Token)
106+
log.Info(context.TODO(), out.User.Token)
109107
token = out.User.Token
110108
}
111109

cmd/server/cluster_status.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/openinfradev/tks-api/pkg/domain"
@@ -16,7 +17,7 @@ func processClusterStatus() error {
1617
if len(clusters) == 0 {
1718
return nil
1819
}
19-
log.Info("clusters : ", clusters)
20+
log.Info(context.TODO(), "[processClusterStatus] clusters : ", clusters)
2021

2122
for i := range clusters {
2223
cluster := clusters[i]
@@ -31,19 +32,26 @@ func processClusterStatus() error {
3132
var newMessage string
3233

3334
if workflowId != "" {
34-
workflow, err := argowfClient.GetWorkflow("argo", workflowId)
35+
workflow, err := argowfClient.GetWorkflow(context.TODO(), "argo", workflowId)
3536
if err != nil {
36-
log.Error("failed to get argo workflow. err : ", err)
37+
log.Error(context.TODO(), "failed to get argo workflow. err : ", err)
3738
continue
3839
}
3940

4041
newMessage = fmt.Sprintf("(%s) %s", workflow.Status.Progress, workflow.Status.Message)
41-
log.Debug(fmt.Sprintf("status [%s], newMessage [%s], phase [%s]", status, newMessage, workflow.Status.Phase))
42+
log.Debug(context.TODO(), fmt.Sprintf("status [%s], newMessage [%s], phase [%s]", status, newMessage, workflow.Status.Phase))
4243

4344
if status == domain.ClusterStatus_INSTALLING {
4445
switch workflow.Status.Phase {
4546
case "Running":
4647
newStatus = domain.ClusterStatus_INSTALLING
48+
49+
paused, err := argowfClient.IsPausedWorkflow(context.TODO(), "argo", workflowId)
50+
if err == nil && paused {
51+
newStatus = domain.ClusterStatus_STOPPED
52+
}
53+
case "Stopped":
54+
newStatus = domain.ClusterStatus_STOPPED
4755
case "Succeeded":
4856
newStatus = domain.ClusterStatus_RUNNING
4957
case "Failed":
@@ -82,10 +90,10 @@ func processClusterStatus() error {
8290
}
8391

8492
if status != newStatus || statusDesc != newMessage {
85-
log.Debug(fmt.Sprintf("update status!! clusterId [%s], newStatus [%s], newMessage [%s]", clusterId, newStatus, newMessage))
93+
log.Debug(context.TODO(), fmt.Sprintf("update status!! clusterId [%s], newStatus [%s], newMessage [%s]", clusterId, newStatus, newMessage))
8694
err := clusterAccessor.UpdateClusterStatus(clusterId, newStatus, newMessage, workflowId)
8795
if err != nil {
88-
log.Error("Failed to update cluster status err : ", err)
96+
log.Error(context.TODO(), "Failed to update cluster status err : ", err)
8997
continue
9098
}
9199
}

0 commit comments

Comments
 (0)