feat: Detect k0s distribution in analyser (#1527)

This commit is contained in:
Evans Mungai
2024-04-25 15:29:37 +01:00
committed by GitHub
parent f18b5d754e
commit 6aaba59ebd
2 changed files with 18 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ type providers struct {
k3s bool
oke bool
kind bool
k0s bool
}
type Provider int
@@ -49,6 +50,7 @@ const (
k3s Provider = iota
oke Provider = iota
kind Provider = iota
k0s Provider = iota
)
type AnalyzeDistribution struct {
@@ -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 {
@@ -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] {
@@ -387,6 +395,8 @@ func mustNormalizeDistributionName(raw string) Provider {
return oke
case "kind":
return kind
case "k0s":
return k0s
}
return unknown

View File

@@ -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) {