Skip to content

Commit

Permalink
fix: print det faktiske clusternavnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrremann committed Jun 20, 2023
1 parent 11f232e commit b68734c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
6 changes: 5 additions & 1 deletion cmd/commands/clusterCmd/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ func subCommands() []*cli.Command {
includeOnprem := context.Bool("includeOnprem")
tenant := context.String("tenant")

_, err := gcp.GetClusters(context.Context, includeManagement, includeOnprem, tenant)
clusters, err := gcp.GetClusters(context.Context, includeManagement, includeOnprem, tenant)
if err != nil {
return err
}

for _, cluster := range clusters {
fmt.Println(cluster.Name)
}

return nil
},
},
Expand Down
30 changes: 10 additions & 20 deletions pkg/gcp/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package gcp
import (
"context"
"encoding/json"
"fmt"
"strings"

"google.golang.org/api/cloudresourcemanager/v3"
"google.golang.org/api/compute/v1"
"google.golang.org/api/container/v1"
Expand All @@ -23,6 +20,7 @@ type Cluster struct {
Endpoint string
Location string
CA string
Tenant string
User *User
}

Expand All @@ -39,7 +37,7 @@ func GetClusters(ctx context.Context, includeManagement, includeOnprem bool, ten
return nil, err
}

return getClusters(ctx, projects, tenant)
return getClusters(ctx, projects)
}

func getProjects(ctx context.Context, includeManagement, includeOnprem bool, filterTenant string) ([]Project, error) {
Expand Down Expand Up @@ -85,18 +83,17 @@ func getProjects(ctx context.Context, includeManagement, includeOnprem bool, fil
return projects, nil
}

func getClusters(ctx context.Context, projects []Project, tenant string) ([]Cluster, error) {
func getClusters(ctx context.Context, projects []Project) ([]Cluster, error) {
var clusters []Cluster
for _, project := range projects {
fmt.Println(project.ID)
var cluster []Cluster
var err error

switch project.Kind {
case "onprem":
cluster, err = getOnpremClusters(ctx, project, tenant)
cluster, err = getOnpremClusters(ctx, project)
default:
cluster, err = getGCPClusters(ctx, project, tenant)
cluster, err = getGCPClusters(ctx, project)
}

if err != nil {
Expand All @@ -108,7 +105,7 @@ func getClusters(ctx context.Context, projects []Project, tenant string) ([]Clus
return clusters, nil
}

func getGCPClusters(ctx context.Context, project Project, filterTenant string) ([]Cluster, error) {
func getGCPClusters(ctx context.Context, project Project) ([]Cluster, error) {
svc, err := container.NewService(ctx)
if err != nil {
return nil, err
Expand All @@ -122,21 +119,18 @@ func getGCPClusters(ctx context.Context, project Project, filterTenant string) (

var clusters []Cluster
for _, cluster := range response.Clusters {
name := cluster.Name
if filterTenant != "" {
name = project.Tenant + "-" + strings.TrimPrefix(name, "nais-")
}
clusters = append(clusters, Cluster{
Name: name,
Name: cluster.Name,
Endpoint: "https://" + cluster.Endpoint,
Location: cluster.Location,
CA: cluster.MasterAuth.ClusterCaCertificate,
Tenant: project.Tenant,
})
}
return clusters, nil
}

func getOnpremClusters(ctx context.Context, project Project, filterTenant string) ([]Cluster, error) {
func getOnpremClusters(ctx context.Context, project Project) ([]Cluster, error) {
if project.Kind != "onprem" {
return nil, nil
}
Expand Down Expand Up @@ -167,12 +161,8 @@ func getOnpremClusters(ctx context.Context, project Project, filterTenant string
return nil, err
}

environment := project.Environment
if filterTenant != "" {
environment = project.Tenant + "-" + strings.TrimPrefix(environment, "nais-")
}
clusters = append(clusters, Cluster{
Name: environment,
Name: project.Environment,
Endpoint: config.URL,
User: &User{
ServerID: config.ServerID,
Expand Down

0 comments on commit b68734c

Please sign in to comment.