Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/clusterdefaults/clusterdefaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
ClusterTypeMinikube
// ClusterTypeK3s represents a K3s cluster
ClusterTypeK3s
// ClusterTypeCRC represents a CRC (CodeReady Containers) cluster
ClusterTypeCRC
)

// String returns the string representation of a ClusterType
Expand All @@ -29,6 +31,8 @@ func (ct ClusterType) String() string {
return "minikube"
case ClusterTypeK3s:
return "k3s"
case ClusterTypeCRC:
return "crc"
default:
return "unknown"
}
Expand Down Expand Up @@ -139,6 +143,11 @@ func (d *defaultDetector) Detect(kubeContext string) ClusterType {
return ClusterTypeK3s
}

// CRC (CodeReady Containers) contexts start with "crc" or contain "-crc-"/"_crc_" as a segment
if strings.HasPrefix(contextLower, "crc") || strings.Contains(contextLower, "-crc-") || strings.Contains(contextLower, "-crc:") {
return ClusterTypeCRC
}

return ClusterTypeUnknown
}

Expand Down Expand Up @@ -198,6 +207,13 @@ func getDefaultsForClusterType(clusterType ClusterType) (DeploymentDefaults, boo
PortForwardEnabled: true,
}, true

case ClusterTypeCRC:
return DeploymentDefaults{
Resources: "small",
Exposure: "none",
PortForwardEnabled: true,
}, true

default:
return DeploymentDefaults{}, false
}
Expand Down
52 changes: 52 additions & 0 deletions internal/clusterdefaults/clusterdefaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ func TestDefaultDetector_Detect(t *testing.T) {
kubeContext: "KIND-test",
want: ClusterTypeKind,
},
{
name: "crc cluster with admin context",
kubeContext: "crc-admin",
want: ClusterTypeCRC,
},
{
name: "crc cluster with api prefix",
kubeContext: "api-crc-testing:6443",
want: ClusterTypeCRC,
},
{
name: "crc cluster with uppercase",
kubeContext: "CRC-admin",
want: ClusterTypeCRC,
},
{
name: "crc cluster bare name",
kubeContext: "crc",
want: ClusterTypeCRC,
},
{
name: "not crc - incidental substring",
kubeContext: "acrc-cluster",
want: ClusterTypeUnknown,
},
{
name: "not crc - encrypted in name",
kubeContext: "my-encrypted-cluster",
want: ClusterTypeUnknown,
},
}

detector := &defaultDetector{}
Expand Down Expand Up @@ -108,6 +138,17 @@ func TestDefaultApplicator_Apply(t *testing.T) {
wantPortForward: true,
wantChanged: true,
},
{
name: "crc cluster",
clusterType: ClusterTypeCRC,
resources: "default",
exposure: "loadbalancer",
portForwardEnabled: false,
wantResources: "small",
wantExposure: "none",
wantPortForward: true,
wantChanged: true,
},
}

applicator := &defaultApplicator{}
Expand Down Expand Up @@ -158,6 +199,16 @@ func TestManager_ApplyConvenienceDefaults(t *testing.T) {
wantExposure: "none",
wantPortForward: true,
},
{
name: "crc cluster detection and defaults",
kubeContext: "crc-admin",
resources: "default",
exposure: "loadbalancer",
portForwardEnabled: false,
wantResources: "small",
wantExposure: "none",
wantPortForward: true,
},
{
name: "gke cluster no changes",
kubeContext: "gke_project_zone_cluster",
Expand Down Expand Up @@ -203,6 +254,7 @@ func TestClusterType_String(t *testing.T) {
{ClusterTypeKind, "kind"},
{ClusterTypeMinikube, "minikube"},
{ClusterTypeK3s, "k3s"},
{ClusterTypeCRC, "crc"},
{ClusterTypeUnknown, "unknown"},
}

Expand Down
Loading