-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from doitintl/125-runtime-class
feat: Cover deprecated `node.k8s.io/v1beta1` API group
- Loading branch information
Showing
8 changed files
with
105 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: node.k8s.io/v1beta1 | ||
kind: RuntimeClass | ||
metadata: | ||
name: my-class | ||
handler: my-cri |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package deprecated120 | ||
package deprecated122 | ||
|
||
main[return] { | ||
resource := input[_] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package deprecated125 | ||
|
||
main[return] { | ||
resource := input[_] | ||
api := deprecated_resource(resource) | ||
return := { | ||
"Name": resource.metadata.name, | ||
# Namespace does not have to be defined in case of local manifests | ||
"Namespace": get_default(resource.metadata, "namespace", "<undefined>"), | ||
"Kind": resource.kind, | ||
"ApiVersion": api.old, | ||
"ReplaceWith": api.new, | ||
"RuleSet": "Deprecated APIs removed in 1.25", | ||
"Since": api.since, | ||
} | ||
} | ||
|
||
deprecated_resource(r) = api { | ||
api := deprecated_api(r.kind, r.apiVersion) | ||
} | ||
|
||
deprecated_api(kind, api_version) = api { | ||
deprecated_apis = {"RuntimeClass": { | ||
"old": ["node.k8s.io/v1beta1"], | ||
"new": "node.k8s.io/v1", | ||
"since": "1.20", | ||
}} | ||
|
||
deprecated_apis[kind].old[_] == api_version | ||
|
||
api := { | ||
"old": api_version, | ||
"new": deprecated_apis[kind].new, | ||
"since": deprecated_apis[kind].since, | ||
} | ||
} | ||
|
||
get_default(val, key, _) = val[key] | ||
|
||
get_default(val, key, fallback) = fallback { | ||
not val[key] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/doitintl/kube-no-trouble/pkg/collector" | ||
) | ||
|
||
type resourceFixtureTestCase struct { | ||
name string | ||
fixturePaths []string | ||
expectedKinds []string | ||
} | ||
|
||
func testReourcesUsingFixtures(t *testing.T, testCases []resourceFixtureTestCase) { | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
c, err := collector.NewFileCollector( | ||
&collector.FileOpts{Filenames: tc.fixturePaths}, | ||
) | ||
|
||
if err != nil { | ||
t.Errorf("Expected to succeed for %s, failed: %s", tc.fixturePaths, err) | ||
} | ||
|
||
manifests, err := c.Get() | ||
if err != nil { | ||
t.Errorf("Expected to succeed for %s, failed: %s", tc.fixturePaths, err) | ||
} else if len(manifests) != len(tc.expectedKinds) { | ||
t.Errorf("Expected to get %d, got %d", len(tc.expectedKinds), len(manifests)) | ||
} | ||
|
||
for i := range manifests { | ||
if manifests[i]["kind"] != tc.expectedKinds[i] { | ||
t.Errorf("Expected to get %s, instead got: %s", tc.expectedKinds[i], manifests[i]["kind"]) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRego125(t *testing.T) { | ||
testCases := []resourceFixtureTestCase{ | ||
{"RuntimeClass", []string{"../fixtures/runtimeclass-v1beta1.yaml"}, []string{"RuntimeClass"}}, | ||
} | ||
|
||
testReourcesUsingFixtures(t, testCases) | ||
} |