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
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func runDeploy(cmd *cobra.Command, args []string) error {
}

func configureConfig(log *logger.Logger, components component.Component, deploySettings *deployer.Config) error {
if deploySettings.Roxie.ClusterType == types.ClusterTypeUnknown {
if deploySettings.Roxie.ClusterType == "" {
clusterType := env.GetAutoDetectedClusterType()
log.Dimf("Detected cluster type: %v", clusterType)
deploySettings.Roxie.ClusterType = clusterType
Expand Down
24 changes: 6 additions & 18 deletions internal/clusterdefaults/clusterdefaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ func ApplyClusterDefaults(
// in the Config struct. Otherwise, `ApplyClusterDefaults` would not apply those to the caller-provided
// configuration.
func getDefaultsForClusterType(clusterType types.ClusterType) *deployer.Config {
switch clusterType {
case types.ClusterTypeKind, types.ClusterTypeMinikube, types.ClusterTypeK3s, types.ClusterTypeCRC:
switch {
case clusterType.IsLocal():
return &deployer.Config{
Central: deployer.CentralConfig{
Exposure: ptr.To(types.ExposureNone),
PortForwarding: ptr.To(true),
},
}

case types.ClusterTypeInfraGKE, types.ClusterTypeInfraOpenShift4:
case clusterType.IsGKE() || clusterType.IsOpenShift():
return &deployer.Config{
Central: deployer.CentralConfig{
Exposure: ptr.To(types.ExposureLoadBalancer),
Expand All @@ -68,23 +68,11 @@ func getDefaultsForClusterType(clusterType types.ClusterType) *deployer.Config {

// ResolveAutoResourceProfile resolves the "auto" resource profile depending on the cluster type.
func ResolveAutoResourceProfile(clusterType types.ClusterType) types.ResourceProfile {
switch clusterType {
case types.ClusterTypeKind:
switch {
case clusterType.IsLocal():
return types.ResourceProfileSmall

case types.ClusterTypeMinikube:
return types.ResourceProfileSmall

case types.ClusterTypeK3s:
return types.ResourceProfileSmall

case types.ClusterTypeCRC:
return types.ResourceProfileSmall

case types.ClusterTypeInfraOpenShift4:
return types.ResourceProfileMedium

case types.ClusterTypeInfraGKE:
case clusterType.IsGKE() || clusterType.IsOpenShift():
return types.ResourceProfileMedium

default:
Expand Down
12 changes: 11 additions & 1 deletion internal/clusterdefaults/clusterdefaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestClusterDefaults(t *testing.T) {
},
},
{
name: "gke cluster",
name: "infra gke cluster",
clusterType: types.ClusterTypeInfraGKE,
wantConfig: deployer.Config{
Central: deployer.CentralConfig{
Expand All @@ -82,6 +82,16 @@ func TestClusterDefaults(t *testing.T) {
},
},
},
{
name: "gke cluster",
clusterType: types.ClusterTypeGKE,
wantConfig: deployer.Config{
Central: deployer.CentralConfig{
Exposure: ptr.To(types.ExposureLoadBalancer),
PortForwarding: ptr.To(false),
},
},
},
{
name: "openshift cluster",
clusterType: types.ClusterTypeInfraOpenShift4,
Expand Down
3 changes: 3 additions & 0 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func DetectClusterType(config KubeConfig, apiResources []string) types.ClusterTy
if strings.HasPrefix(config.CurrentContext, "gke_acs-team-temp-dev") {
return types.ClusterTypeInfraGKE
}
if strings.HasPrefix(config.CurrentContext, "gke_") {
return types.ClusterTypeGKE
}

// Minikube clusters typically have context name "minikube".
if contextLower == "minikube" || strings.HasPrefix(contextLower, "minikube-") {
Expand Down
46 changes: 32 additions & 14 deletions internal/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stackrox/roxie/internal/types"
)

func TestDetectClusterType_GKE(t *testing.T) {
func TestDetectClusterType_InfraGKE(t *testing.T) {
config := KubeConfig{
CurrentContext: "gke_acs-team-temp-dev_us-central1-a_my-cluster",
Clusters: []KubeCluster{
Expand All @@ -26,7 +26,7 @@ func TestDetectClusterType_GKE(t *testing.T) {
}
}

func TestDetectClusterType_GKE_ExactMatch(t *testing.T) {
func TestDetectClusterType_InfraGKE_ExactMatch(t *testing.T) {
config := KubeConfig{
CurrentContext: "gke_acs-team-temp-dev",
Clusters: []KubeCluster{
Expand Down Expand Up @@ -172,20 +172,33 @@ func TestDetectClusterType_Minikube(t *testing.T) {
}

func TestDetectClusterType_GKE_DifferentProject(t *testing.T) {
config := KubeConfig{
CurrentContext: "gke_other-project_us-west1_cluster",
Clusters: []KubeCluster{
{
Name: "gke_cluster",
Server: "https://34.1.2.3",
},
tests := []struct {
name string
context string
}{
{
name: "arbitrary project",
context: "gke_other-project_us-west1_cluster",
},
{
name: "CI direct-gke via gke.sh (acs-san-stackroxci)",
context: "gke_acs-san-stackroxci_us-east4-b_rox-ci-qa-e2e-12345678",
},
}
apiResources := []string{"pods"}

result := DetectClusterType(config, apiResources)
if result != types.ClusterTypeUnknown {
t.Errorf("DetectClusterType() = %v (%s), want %v", result, result.String(), types.ClusterTypeUnknown)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config := KubeConfig{
CurrentContext: tt.context,
Clusters: []KubeCluster{
{
Name: "gke_cluster",
Server: "https://34.1.2.3",
},
},
}
result := DetectClusterType(config, []string{"pods"})
assert.Equal(t, types.ClusterTypeGKE, result)
})
}
}

Expand Down Expand Up @@ -288,6 +301,11 @@ func TestClusterTypeString(t *testing.T) {
clusterType types.ClusterType
want string
}{
{
name: "types.ClusterTypeGKE",
clusterType: types.ClusterTypeGKE,
want: "GKE",
},
{
name: "types.ClusterTypeInfraGKE",
clusterType: types.ClusterTypeInfraGKE,
Expand Down
12 changes: 9 additions & 3 deletions internal/types/cluster_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ type ClusterType string

const (
// ClusterTypeUnknown represents an unidentified cluster type
ClusterTypeUnknown ClusterType = ""
ClusterTypeUnknown ClusterType = "Unknown"
// ClusterTypeGKE represents a generic GKE cluster.
ClusterTypeGKE ClusterType = "GKE"
// ClusterTypeInfraGKE represents a GKE cluster created via Infra.
ClusterTypeInfraGKE ClusterType = "InfraGKE"
// ClusterTypeInfraOpenShift4 represents an OpenShift 4 cluster
Expand All @@ -24,6 +26,10 @@ const (
ClusterTypeCRC ClusterType = "CRC"
)

func (ct ClusterType) IsGKE() bool {
return ct == ClusterTypeInfraGKE || ct == ClusterTypeGKE
}

func (ct ClusterType) IsOpenShift() bool {
return ct == ClusterTypeInfraOpenShift4 || ct == ClusterTypeOpenShift4
}
Expand All @@ -35,15 +41,15 @@ func (ct ClusterType) String() string {
return "GKE (infra)"
case ClusterTypeInfraOpenShift4:
return "OpenShift4 (infra)"
case ClusterTypeUnknown:
return "Unknown"
default:
return string(ct)
}
}

func AllClusterTypes() []ClusterType {
return []ClusterType{
ClusterTypeUnknown,
ClusterTypeGKE,
ClusterTypeInfraGKE,
ClusterTypeKind,
ClusterTypeMinikube,
Expand Down
4 changes: 3 additions & 1 deletion internal/types/cluster_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TestClusterTypeMarshalYAML(t *testing.T) {
clusterType ClusterType
expected string
}{
{ClusterTypeGKE, "GKE"},
{ClusterTypeInfraGKE, "InfraGKE"},
{ClusterTypeInfraOpenShift4, "InfraOpenShift4"},
{ClusterTypeOpenShift4, "OpenShift4"},
Expand All @@ -35,14 +36,15 @@ func TestClusterTypeUnmarshalYAML(t *testing.T) {
input string
expected ClusterType
}{
{"GKE", ClusterTypeGKE},
{"InfraGKE", ClusterTypeInfraGKE},
{"InfraOpenShift4", ClusterTypeInfraOpenShift4},
{"OpenShift4", ClusterTypeOpenShift4},
{"Kind", ClusterTypeKind},
{"Minikube", ClusterTypeMinikube},
{"K3s", ClusterTypeK3s},
{"CRC", ClusterTypeCRC},
{"", ClusterTypeUnknown},
{"Unknown", ClusterTypeUnknown},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
Expand Down
Loading