Skip to content

Commit

Permalink
k8s: Recognize Red Hat CodeReady Containers as a local cluster (#3242)
Browse files Browse the repository at this point in the history
  • Loading branch information
noseka1 committed Apr 28, 2020
1 parent 305898a commit 7e94878
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/k8s/env.go
Expand Up @@ -23,6 +23,7 @@ const (
EnvMinikube Env = "minikube"
EnvDockerDesktop Env = "docker-for-desktop"
EnvMicroK8s Env = "microk8s"
EnvCRC Env = "crc"

// Kind v0.6 substantially changed the protocol for detecting and pulling,
// so we represent them as two separate envs.
Expand All @@ -37,7 +38,7 @@ func (e Env) UsesLocalDockerRegistry() bool {
}

func (e Env) IsLocalCluster() bool {
return e == EnvMinikube || e == EnvDockerDesktop || e == EnvMicroK8s || e == EnvKIND5 || e == EnvKIND6 || e == EnvK3D
return e == EnvMinikube || e == EnvDockerDesktop || e == EnvMicroK8s || e == EnvCRC || e == EnvKIND5 || e == EnvKIND6 || e == EnvK3D
}

func ProvideKubeContext(config *api.Config) (KubeContext, error) {
Expand Down Expand Up @@ -91,6 +92,8 @@ func ProvideEnv(ctx context.Context, config *api.Config) Env {
return EnvKIND6
} else if strings.HasPrefix(cn, "microk8s-cluster") {
return EnvMicroK8s
} else if strings.HasPrefix(cn, "api-crc-testing") {
return EnvCRC
}

loc := c.LocationOfOrigin
Expand Down
12 changes: 12 additions & 0 deletions internal/k8s/env_test.go
Expand Up @@ -66,6 +66,16 @@ func TestProvideEnv(t *testing.T) {
Cluster: "microk8s-cluster-dev-cluster-1",
},
}
crcContexts := map[string]*api.Context{
"api-crc-testing": &api.Context{
Cluster: "api-crc-testing",
},
}
crcPrefixContexts := map[string]*api.Context{
"api-crc-testing:6443": &api.Context{
Cluster: "api-crc-testing:6443",
},
}

homedir, err := homedir.Dir()
assert.NoError(t, err)
Expand Down Expand Up @@ -99,6 +109,8 @@ func TestProvideEnv(t *testing.T) {
{EnvKIND5, &api.Config{CurrentContext: "kubernetes-admin@kind-1", Contexts: kind5Contexts}},
{EnvMicroK8s, &api.Config{CurrentContext: "microk8s", Contexts: microK8sContexts}},
{EnvMicroK8s, &api.Config{CurrentContext: "microk8s-dev-cluster-1", Contexts: microK8sPrefixContexts}},
{EnvCRC, &api.Config{CurrentContext: "api-crc-testing", Contexts: crcContexts}},
{EnvCRC, &api.Config{CurrentContext: "api-crc-testing:6443", Contexts: crcPrefixContexts}},
{EnvK3D, &api.Config{CurrentContext: "default", Contexts: k3dContexts}},
{EnvKIND5, &api.Config{CurrentContext: "default", Contexts: kind5NamedClusterContexts}},
{EnvKIND6, &api.Config{CurrentContext: "kind-custom-name", Contexts: kind6Contexts}},
Expand Down

0 comments on commit 7e94878

Please sign in to comment.