Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidatingAdmissionWebhook issue demonstration #21

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions artifacts/example/rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ spec:
serviceAccountName: apiserver
containers:
- name: wardle-server
image: kube-sample-apiserver:latest
imagePullPolicy: Never
command: [ "/kube-sample-apiserver", "--etcd-servers=http://localhost:2379" ]
image: yiyangc91/kube-sample-apiserver:latest
imagePullPolicy: Always
command: [ "/kube-sample-apiserver", "--etcd-servers=http://localhost:2379", "--admission-control=ValidatingAdmissionWebhook"]
- name: etcd
image: quay.io/coreos/etcd:v3.1.11
19 changes: 19 additions & 0 deletions artifacts/example/webhookconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
name: warble-webhook
webhooks:
- name: warbles.k8s.io
clientConfig:
url: https://192.168.64.1/
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNORENDQWFFQ0VBS3RabjVPUmY1ZVYyODhtQmxlM2NBd0RRWUpLb1pJaHZjTkFRRUNCUUF3WHpFTE1Ba0cKQTFVRUJoTUNWVk14SURBZUJnTlZCQW9URjFKVFFTQkVZWFJoSUZObFkzVnlhWFI1TENCSmJtTXVNUzR3TEFZRApWUVFMRXlWVFpXTjFjbVVnVTJWeWRtVnlJRU5sY25ScFptbGpZWFJwYjI0Z1FYVjBhRzl5YVhSNU1CNFhEVGswCk1URXdPVEF3TURBd01Gb1hEVEV3TURFd056SXpOVGsxT1Zvd1h6RUxNQWtHQTFVRUJoTUNWVk14SURBZUJnTlYKQkFvVEYxSlRRU0JFWVhSaElGTmxZM1Z5YVhSNUxDQkpibU11TVM0d0xBWURWUVFMRXlWVFpXTjFjbVVnVTJWeQpkbVZ5SUVObGNuUnBabWxqWVhScGIyNGdRWFYwYUc5eWFYUjVNSUdiTUEwR0NTcUdTSWIzRFFFQkFRVUFBNEdKCkFEQ0JoUUorQUpMT2VzR3VnejVhcW9tRFY2d2xBWFlNcmE2T0xEZk82elY0WkZRRDVZUkFVY20vandqaWlvSUkKMGhhR04xWHBzU0VDclhab2dab0Zva3ZKU3lWbUlsWnNpQWVQOTRGWmJZUUhaWEFUY1hZK20zZE00MUNKVnBoSQp1UjJuS1JvVExrb1JXWndlRmRWSlZDeHpPbW1Dc1pjNW5HMXdaMGpsM1MzV3lCNTdBZ01CQUFFd0RRWUpLb1pJCmh2Y05BUUVDQlFBRGZnQmwzWDdoc3V5dzRqcmc3SEZHbWhrUnVOUEhvTFFEUUNZQ1BnbWM0Ukt6MFZyMk42VzMKWVFPMld4WnBPOFpFQ0F5SVV3eHJsMG5IUGpYY2JMbTdxdDljdXpvdmsyQzJxVXROOGlEM3pWOS9aSHVPM0FCYwoxL3AzeWprV1dXOE82dE8xZzM5TlRVSldkclRKWHdUNE9QanIwbDkxWDgxNy9PV09nSHo4VUE9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t
rules:
- operations:
- CREATE
apiGroups:
- 'wardle.k8s.io'
apiVersions:
- v1alpha1
resources:
- flunders
failurePolicy: Fail
18 changes: 18 additions & 0 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ limitations under the License.
package apiserver

import (
admissionv1beta1 "k8s.io/api/admission/v1beta1"
"k8s.io/apimachinery/pkg/apimachinery/announced"
"k8s.io/apimachinery/pkg/apimachinery/registered"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/version"
"k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server"
Expand All @@ -42,8 +44,24 @@ var (
Codecs = serializer.NewCodecFactory(Scheme)
)

func AdmissionInstall(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) {
if err := announced.NewGroupMetaFactory(
&announced.GroupMetaFactoryArgs{
GroupName: admissionv1beta1.GroupName,
VersionPreferenceOrder: []string{admissionv1beta1.SchemeGroupVersion.Version},
RootScopedKinds: sets.NewString("AdmissionReview"),
},
announced.VersionToSchemeFunc{
admissionv1beta1.SchemeGroupVersion.Version: admissionv1beta1.AddToScheme,
},
).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil {
panic(err)
}
}

func init() {
install.Install(groupFactoryRegistry, registry, Scheme)
AdmissionInstall(groupFactoryRegistry, registry, Scheme)

// we need to add the options to empty v1
// TODO fix the server code to avoid this
Expand Down