diff --git a/internal/db/mongo.go b/internal/db/mongo.go index 98c8be82..63f5c5ca 100644 --- a/internal/db/mongo.go +++ b/internal/db/mongo.go @@ -110,7 +110,12 @@ func (mdbcl *MongoDBClient) ImportClusterIfEmpty(silent bool) (pkgtypes.Cluster, // find the secret in mgmt cluster's kubefirst namespace and read import payload and clustername var kcfg *k8s.KubernetesClient - if env.IsClusterZero == "" { + var isClusterZero bool = true + if env.IsClusterZero == "false" { + isClusterZero = false + } + + if isClusterZero { log.Info("IS_CLUSTER_ZERO is set to true, skipping import cluster logic.") return pkgtypes.Cluster{}, nil } @@ -121,7 +126,12 @@ func (mdbcl *MongoDBClient) ImportClusterIfEmpty(silent bool) (pkgtypes.Cluster, } clusterDir := fmt.Sprintf("%s/.k1/%s", homeDir, "") - kcfg = k8s.CreateKubeConfig(env.InCluster, fmt.Sprintf("%s/kubeconfig", clusterDir)) + var inCluster bool = false + if env.InCluster == "true" { + inCluster = true + } + + kcfg = k8s.CreateKubeConfig(inCluster, fmt.Sprintf("%s/kubeconfig", clusterDir)) log.Infof("reading secret mongo-state to determine if import is needed") secData, err := k8s.ReadSecretV2(kcfg.Clientset, "kubefirst", "mongodb-state") diff --git a/internal/env/env.go b/internal/env/env.go index 16db8d5d..8fa20b8c 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -7,7 +7,7 @@ import ( ) type Env struct { - ServerPort int `env:"SERVER_PORT" envDefault:"8081"` + ServerPort string `env:"SERVER_PORT" envDefault:"8081"` K1AccessToken string `env:"K1_ACCESS_TOKEN"` MongoDBHost string `env:"MONGODB_HOST,notEmpty"` MongoDBHostType string `env:"MONGODB_HOST_TYPE,notEmpty"` @@ -24,8 +24,8 @@ type Env struct { KubefirstTeamInfo string `env:"KUBEFIRST_TEAM_INFO"` AWSRegion string `env:"AWS_REGION"` AWSProfile string `env:"AWS_PROFILE"` - IsClusterZero string `env:"IS_CLUSTER_ZERO"` - InCluster bool `env:"IN_CLUSTER" envDefault:"false"` + IsClusterZero string `env:"IS_CLUSTER_ZERO" envDefault:"false"` + InCluster string `env:"IN_CLUSTER" envDefault:"false"` EnterpriseApiUrl string `env:"ENTERPRISE_API_URL"` } diff --git a/internal/env/env_test.go b/internal/env/env_test.go index c569de9b..9117f2ad 100644 --- a/internal/env/env_test.go +++ b/internal/env/env_test.go @@ -3,6 +3,8 @@ package env import ( "os" "testing" + + "github.com/kubefirst/kubefirst-api/internal/constants" ) func TestEnv(t *testing.T) { @@ -51,13 +53,13 @@ func TestEnv(t *testing.T) { }() env := Env{} - env, err := GetEnv(true) + env, err := GetEnv(constants.SilenceGetEnv) if err != nil { t.Errorf("unexpected error: %v", err) } - if env.ServerPort != 8081 { - t.Errorf("expected ServerPort to be 8081, but got %d", env.ServerPort) + if env.ServerPort != "8081" { + t.Errorf("expected ServerPort to be 8081, but got %v", env.ServerPort) } if env.K1AccessToken != "k1_access_token" { @@ -125,11 +127,11 @@ func TestEnv(t *testing.T) { } if env.IsClusterZero != "true" { - t.Errorf("expected IsClusterZero to be true, but got false") + t.Errorf("expected IsClusterZero to be true, but got %v", env.IsClusterZero) } - if env.InCluster != false { - t.Errorf("expected InCluster to be false, but got true") + if env.InCluster != "false" { + t.Errorf("expected InCluster to be false, but got %v", env.InCluster) } if env.EnterpriseApiUrl != "enterprise_api_url" { diff --git a/internal/router/api/v1/cluster.go b/internal/router/api/v1/cluster.go index ad537b2f..7fb613ea 100644 --- a/internal/router/api/v1/cluster.go +++ b/internal/router/api/v1/cluster.go @@ -289,8 +289,13 @@ func PostCreateCluster(c *gin.Context) { env, _ := env.GetEnv(constants.SilenceGetEnv) - if env.InCluster { - kcfg := k8s.CreateKubeConfig(env.InCluster, "") + var inCluster bool = false + if env.InCluster == "true" { + inCluster = true + } + + if inCluster { + kcfg := k8s.CreateKubeConfig(inCluster, "") k1AuthSecret, err := k8s.ReadSecretV2(kcfg.Clientset, constants.KubefirstNamespace, constants.KubefirstAuthSecretName) if err != nil { log.Warnf("authentication secret does not exist, continuing: %s", err) diff --git a/internal/services/services.go b/internal/services/services.go index 629fafb8..ef2d0c3f 100644 --- a/internal/services/services.go +++ b/internal/services/services.go @@ -97,7 +97,12 @@ func CreateService(cl *pkgtypes.Cluster, serviceName string, appDef *types.Gitop env, _ := env.GetEnv(constants.SilenceGetEnv) - kcfg = k8s.CreateKubeConfig(env.InCluster, fmt.Sprintf("%s/kubeconfig", tmpGitopsDir)) + var inCluster bool = false + if env.InCluster == "true" { + inCluster = true + } + + kcfg = k8s.CreateKubeConfig(inCluster, fmt.Sprintf("%s/kubeconfig", tmpGitopsDir)) var fullDomainName string if cl.SubdomainName != "" {