Skip to content

Commit

Permalink
feat: distribution analyzer support for kind (#1521)
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh authored Apr 6, 2024
1 parent 123d17a commit 6f7acec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/preflight/sample-preflight.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ spec:
- pass:
when: "== oke"
message: OKE is a supported distribution
- pass:
when: "== kind"
message: Kind is a supported distribution
- warn:
message: Unable to determine the distribution of Kubernetes
- nodeResources:
Expand Down
10 changes: 10 additions & 0 deletions pkg/analyze/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type providers struct {
rke2 bool
k3s bool
oke bool
kind bool
}

type Provider int
Expand All @@ -47,6 +48,7 @@ const (
rke2 Provider = iota
k3s Provider = iota
oke Provider = iota
kind Provider = iota
)

type AnalyzeDistribution struct {
Expand Down Expand Up @@ -162,6 +164,10 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
foundProviders.ibm = true
stringProvider = "ibm"
}
if strings.HasPrefix(node.Spec.ProviderID, "kind:") {
foundProviders.kind = true
stringProvider = "kind"
}
}

if foundMaster {
Expand Down Expand Up @@ -335,6 +341,8 @@ func compareDistributionConditionalToActual(conditional string, actual providers
isMatch = actual.k3s
case oke:
isMatch = actual.oke
case kind:
isMatch = actual.kind
}

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

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

0 comments on commit 6f7acec

Please sign in to comment.