Skip to content

Commit

Permalink
feat: Prefer embedded-cluster over k0s when detecting distro (#1544)
Browse files Browse the repository at this point in the history
* feat: Prefer embedded-cluster over k0s when detecting distro

* Implement check for embedded cluster detection
  • Loading branch information
banjoh authored May 15, 2024
1 parent 224d55b commit 78bbea1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/analyze/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
}
}

// If k0s and embedded-cluster are both found, prefer embedded-cluster
if foundProviders.k0s && foundProviders.embeddedCluster {
stringProvider = "embedded-cluster"
}

return foundProviders, stringProvider
}

Expand Down
47 changes: 47 additions & 0 deletions pkg/analyze/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Test_compareDistributionConditionalToActual(t *testing.T) {
Expand Down Expand Up @@ -167,3 +169,48 @@ func Test_mustNormalizeDistributionName(t *testing.T) {
})
}
}

func TestParseNodesForProviders(t *testing.T) {
tests := []struct {
name string
nodes []corev1.Node
wantProviders providers
wantProviderString string
}{
{
name: "embedded-cluster",
nodes: []corev1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Name: "embedded-cluster",
Labels: map[string]string{
"beta.kubernetes.io/arch": "amd64",
"beta.kubernetes.io/os": "linux",
"kots.io/embedded-cluster-role": "total-1",
"kots.io/embedded-cluster-role-0": "management",
"kubernetes.io/arch": "amd64",
"kubernetes.io/hostname": "evans-vm1",
"kubernetes.io/os": "linux",
"management": "true",
"node-role.kubernetes.io/control-plane": "true",
"node.k0sproject.io/role": "control-plane",
},
},
},
},
wantProviders: providers{embeddedCluster: true, k0s: true},
wantProviderString: "embedded-cluster",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
providers, stringProvider := ParseNodesForProviders(tt.nodes)
assert.Equalf(t, tt.wantProviders, providers,
"ParseNodesForProviders() gotProviders = %v, providers %v", providers, tt.wantProviders,
)
assert.Equalf(t, tt.wantProviderString, stringProvider,
"ParseNodesForProviders() gotStringProvider = %v, stringProvider %v", stringProvider, tt.wantProviderString,
)
})
}
}

0 comments on commit 78bbea1

Please sign in to comment.