Skip to content

Commit

Permalink
Merge pull request #170 from doitintl/admissionregistration-v1beta1
Browse files Browse the repository at this point in the history
feat: Cover deprecated `admissionregistration.k8s.io/v1beta1` API group
  • Loading branch information
stepanstipl authored Jun 16, 2021
2 parents 6ac1b3e + 1868e16 commit 9f5888f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions fixtures/mutatingwebhookconfiguration-v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: admissionregistration.k8s.io/v1beta1
kind: MutatingWebhookConfiguration
metadata:
name: test
namespace: my-namespace
webhooks:
- name: test.example.com
clientConfig:
service:
name: webhook
namespace: test
path: "/"
rules:
- operations: [ "CREATE" ]
apiGroups: [""]
apiVersions: ["v1"]
resources: ["pods"]
17 changes: 17 additions & 0 deletions fixtures/validatingwebhookconfiguration-v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: test
namespace: my-namespace
webhooks:
- name: test.example.com
clientConfig:
service:
name: webhook
namespace: test
path: "/"
rules:
- operations: [ "CREATE" ]
apiGroups: [""]
apiVersions: ["v1"]
resources: ["pods"]
2 changes: 2 additions & 0 deletions pkg/collector/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func (c *ClusterCollector) Get() ([]map[string]interface{}, error) {
schema.GroupVersionResource{Group: "certificates.k8s.io", Version: "v1", Resource: "certificatesigningrequests"},
schema.GroupVersionResource{Group: "apiregistration.k8s.io", Version: "v1", Resource: "apiservices"},
schema.GroupVersionResource{Group: "apiextensions.k8s.io", Version: "v1", Resource: "customresourcedefinitions"},
schema.GroupVersionResource{Group: "admissionregistration.k8s.io", Version: "v1", Resource: "mutatingwebhookconfigurations"},
schema.GroupVersionResource{Group: "admissionregistration.k8s.io", Version: "v1", Resource: "validatingwebhookconfigurations"},
}
gvrs = append(gvrs, c.additionalResources...)

Expand Down
10 changes: 10 additions & 0 deletions pkg/rules/rego/deprecated-1-22.rego
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ deprecated_api(kind, api_version) = api {
"new": "apiextensions.k8s.io/v1",
"since": "1.16",
},
"MutatingWebhookConfiguration": {
"old": ["admissionregistration.k8s.io/v1beta1"],
"new": "admissionregistration.k8s.io/v1",
"since": "1.16",
},
"ValidatingWebhookConfiguration": {
"old": ["admissionregistration.k8s.io/v1beta1"],
"new": "admissionregistration.k8s.io/v1",
"since": "1.16",
},
}

deprecated_apis[kind].old[_] == api_version
Expand Down
2 changes: 2 additions & 0 deletions test/rules_122_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func TestRego122(t *testing.T) {
{"TokenReview", []string{"../fixtures/tokenreview-v1beta1.yaml"}, []string{"TokenReview"}},
{"APIService", []string{"../fixtures/apiservice-v1beta1.yaml"}, []string{"APIService"}},
{"CustomResourceDefinition", []string{"../fixtures/customresourcedefinition-v1beta1.yaml"}, []string{"CustomResourceDefinition"}},
{"MutatingWebhookConfiguration", []string{"../fixtures/mutatingwebhookconfiguration-v1beta1.yaml"}, []string{"MutatingWebhookConfiguration"}},
{"ValidatingWebhookConfiguration", []string{"../fixtures/validatingwebhookconfiguration-v1beta1.yaml"}, []string{"ValidatingWebhookConfiguration"}},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 9f5888f

Please sign in to comment.