Skip to content

Commit

Permalink
feat: env er egentlig navn
Browse files Browse the repository at this point in the history
Siden dette er et navn bør vi ikke bruke en enum for å holde styr på dette.
  • Loading branch information
Kyrremann committed Jun 26, 2023
1 parent b89361e commit 0620f68
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 88 deletions.
6 changes: 3 additions & 3 deletions pkg/gcp/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Cluster struct {
Tenant string
User *OnpremUser
Kind Kind
Environment Environment
Environment string
}

type OnpremUser struct {
Expand Down Expand Up @@ -98,7 +98,7 @@ func getGCPClusters(ctx context.Context, project Project) ([]Cluster, error) {
CA: cluster.MasterAuth.ClusterCaCertificate,
Tenant: project.Tenant,
Kind: project.Kind,
Environment: project.Environment,
Environment: project.Name,
})
}
return clusters, nil
Expand Down Expand Up @@ -136,7 +136,7 @@ func getOnpremClusters(ctx context.Context, project Project) ([]Cluster, error)
}

clusters = append(clusters, Cluster{
Name: project.Environment.String(),
Name: project.Name,
Endpoint: config.URL,
Tenant: "nav",
Kind: KindOnprem,
Expand Down
78 changes: 4 additions & 74 deletions pkg/gcp/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,83 +30,13 @@ func ParseKind(in string) Kind {
}
}

type Environment int64

const (
EnvironmentCi Environment = iota
EnvironmentCiFSS
EnvironmentCiGCP
EnvironmentDev
EnvironmentDevFSS
EnvironmentDevGCP
EnvironmentProd
EnvironmentProdFSS
EnvironmentProdGCP
EnvironmentStaging
EnvironmentUnknown
)

func (env Environment) String() string {
switch env {
case EnvironmentCi:
return "ci"
case EnvironmentCiFSS:
return "ci-fss"
case EnvironmentCiGCP:
return "ci-gcp"
case EnvironmentDev:
return "dev"
case EnvironmentDevFSS:
return "dev-fss"
case EnvironmentDevGCP:
return "dev-gcp"
case EnvironmentProd:
return "prod"
case EnvironmentProdFSS:
return "prod-fss"
case EnvironmentProdGCP:
return "prod-gcp"
case EnvironmentStaging:
return "prod-fss"
default:
return "Unknown"
}
}

func ParseEnvironment(in string) Environment {
switch strings.ToLower(in) {
case "ci":
return EnvironmentCi
case "ci-fss":
return EnvironmentCiFSS
case "ci-gcp":
return EnvironmentCiGCP
case "dev":
return EnvironmentDev
case "dev-fss":
return EnvironmentDevFSS
case "dev-gcp":
return EnvironmentDevGCP
case "prod":
return EnvironmentProd
case "prod-fss":
return EnvironmentProdFSS
func GetClusterServerForLegacyGCP(name string) string {
switch name {
case "prod-gcp":
return EnvironmentProdGCP
case "staging":
return EnvironmentStaging
default:
return EnvironmentUnknown
}
}

func GetClusterServerForLegacyGCP(env Environment) string {
switch env {
case EnvironmentProdGCP:
return "https://10.255.240.6"
case EnvironmentDevGCP:
case "dev-gcp":
return "https://10.255.240.5"
case EnvironmentCiGCP:
case "ci-gcp":
return "https://10.255.240.7"
default:
return "unknown-cluster"
Expand Down
16 changes: 8 additions & 8 deletions pkg/gcp/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
)

type Project struct {
ID string
Tenant string
Environment Environment
Kind Kind
ID string
Tenant string
Name string
Kind Kind
}

func getProjects(ctx context.Context, includeManagement, includeOnprem, includeKnada bool, filterTenant string) ([]Project, error) {
Expand Down Expand Up @@ -55,10 +55,10 @@ func getProjects(ctx context.Context, includeManagement, includeOnprem, includeK

for _, project := range response.Projects {
projects = append(projects, Project{
ID: project.ProjectId,
Tenant: project.Labels["tenant"],
Environment: ParseEnvironment(project.Labels["environment"]),
Kind: ParseKind(project.Labels["kind"]),
ID: project.ProjectId,
Tenant: project.Labels["tenant"],
Name: project.Labels["environment"],
Kind: ParseKind(project.Labels["kind"]),
})
}
if response.NextPageToken == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubeconfig/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func addCluster(config *clientcmdapi.Config, cluster gcp.Cluster, overwrite, ver
if cluster.Kind == gcp.KindLegacy {
kubeconfigCluster.CertificateAuthorityData = nil
kubeconfigCluster.InsecureSkipTLSVerify = true
kubeconfigCluster.Server = gcp.GetClusterServerForLegacyGCP(cluster.Environment)
kubeconfigCluster.Server = gcp.GetClusterServerForLegacyGCP(cluster.Name)
}

config.Clusters[cluster.Name] = kubeconfigCluster
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubeconfig/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/nais/narcos/pkg/gcp"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"strings"
)

func addContext(config *clientcmdapi.Config, cluster gcp.Cluster, overwrite, seperateAdmin, verbose bool, email string) {
Expand Down Expand Up @@ -43,12 +44,12 @@ func contextShouldNotBeInKubeconfig(email string, cluster gcp.Cluster) bool {
return (isEmailNais(email) && cluster.Kind == gcp.KindKNADA) ||
(isEmailNav(email) && cluster.Tenant != "nav") ||
(isEmailNav(email) && cluster.Kind == gcp.KindManagment) ||
(isEmailNav(email) && cluster.Environment == gcp.EnvironmentCiGCP)
(isEmailNav(email) && cluster.Name == "ci-gcp")
}

func contextShouldHaveSeperateAdminContext(email string, cluster gcp.Cluster, seperateAdmin bool) bool {
return seperateAdmin &&
isEmailNais(email) &&
cluster.Tenant == "nav" &&
(cluster.Environment == gcp.EnvironmentDevGCP || cluster.Environment == gcp.EnvironmentProdGCP)
strings.HasSuffix(cluster.Environment, "-gcp")
}

0 comments on commit 0620f68

Please sign in to comment.