Skip to content

Commit

Permalink
feat: Detect k0s distribution in analyser (#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Apr 25, 2024
1 parent f18b5d7 commit 6aaba59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/analyze/distribution.go
Expand Up @@ -28,6 +28,7 @@ type providers struct {
k3s bool
oke bool
kind bool
k0s bool
}

type Provider int
Expand All @@ -49,6 +50,7 @@ const (
k3s Provider = iota
oke Provider = iota
kind Provider = iota
k0s Provider = iota
)

type AnalyzeDistribution struct {
Expand Down Expand Up @@ -134,6 +136,10 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
foundProviders.oke = true
stringProvider = "oke"
}
if k == "node.k0sproject.io/role" {
foundProviders.k0s = true
stringProvider = "k0s"
}
}

for k := range node.ObjectMeta.Annotations {
Expand Down Expand Up @@ -343,6 +349,8 @@ func compareDistributionConditionalToActual(conditional string, actual providers
isMatch = actual.oke
case kind:
isMatch = actual.kind
case k0s:
isMatch = actual.k0s
}

switch parts[0] {
Expand Down Expand Up @@ -387,6 +395,8 @@ func mustNormalizeDistributionName(raw string) Provider {
return oke
case "kind":
return kind
case "k0s":
return k0s
}

return unknown
Expand Down
8 changes: 8 additions & 0 deletions pkg/analyze/distribution_test.go
Expand Up @@ -47,6 +47,14 @@ func Test_compareDistributionConditionalToActual(t *testing.T) {
},
expected: true,
},
{
name: "== k0s when k0s is found",
conditional: "== k0s",
input: providers{
k0s: true,
},
expected: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit 6aaba59

Please sign in to comment.