Skip to content

Commit

Permalink
Move apiregistration & admissionregistration to v1 (#1918)
Browse files Browse the repository at this point in the history
This moves our APIService, ValidatingWebhookConfiguration and
MutatingWebhookConfiguration from v1betav1 to v1

This includes moving the Go library references as well.

Work on #1799

Co-authored-by: Robert Bailey <[email protected]>
  • Loading branch information
markmandel and roberthbailey authored Dec 9, 2020
1 parent e7a5b7d commit df18f48
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 208 deletions.
12 changes: 9 additions & 3 deletions install/helm/agones/templates/extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{{- $cert := genSignedCert $cn nil (list $altName1 $altName2) 3650 $ca }}
---
{{- if .Values.agones.registerApiService }}
apiVersion: apiregistration.k8s.io/v1beta1
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1.allocation.agones.dev
Expand All @@ -44,7 +44,7 @@ spec:
{{- end}}
{{- if .Values.agones.registerWebhooks }}
---
apiVersion: admissionregistration.k8s.io/v1beta1
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: agones-validation-webhook
Expand All @@ -56,6 +56,9 @@ metadata:
heritage: {{ .Release.Service }}
webhooks:
- name: validations.agones.dev
admissionReviewVersions:
- v1
sideEffects: None
failurePolicy: Fail
clientConfig:
service:
Expand Down Expand Up @@ -98,7 +101,7 @@ webhooks:
- UPDATE

---
apiVersion: admissionregistration.k8s.io/v1beta1
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: agones-mutation-webhook
Expand All @@ -110,6 +113,9 @@ metadata:
heritage: {{ .Release.Service }}
webhooks:
- name: mutations.agones.dev
admissionReviewVersions:
- v1
sideEffects: None
failurePolicy: Fail
clientConfig:
service:
Expand Down
12 changes: 9 additions & 3 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ spec:
readOnly: true
---
# Source: agones/templates/extensions.yaml
apiVersion: apiregistration.k8s.io/v1beta1
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1.allocation.agones.dev
Expand Down Expand Up @@ -1846,7 +1846,7 @@ spec:
# Default allocation client secret
---
# Source: agones/templates/extensions.yaml
apiVersion: admissionregistration.k8s.io/v1beta1
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: agones-mutation-webhook
Expand All @@ -1858,6 +1858,9 @@ metadata:
heritage: Helm
webhooks:
- name: mutations.agones.dev
admissionReviewVersions:
- v1
sideEffects: None
failurePolicy: Fail
clientConfig:
service:
Expand Down Expand Up @@ -1886,7 +1889,7 @@ globalDefault: false
description: "This priority class should be used for Agones service pods only."
---
# Source: agones/templates/extensions.yaml
apiVersion: admissionregistration.k8s.io/v1beta1
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: agones-validation-webhook
Expand All @@ -1898,6 +1901,9 @@ metadata:
heritage: Helm
webhooks:
- name: validations.agones.dev
admissionReviewVersions:
- v1
sideEffects: None
failurePolicy: Fail
clientConfig:
service:
Expand Down
8 changes: 4 additions & 4 deletions pkg/fleetautoscalers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/heptiolabs/healthcheck"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
admv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
extclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
Expand Down Expand Up @@ -94,8 +94,8 @@ func NewController(
c.recorder = eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "fleetautoscaler-controller"})

kind := autoscalingv1.Kind("FleetAutoscaler")
wh.AddHandler("/validate", kind, admv1beta1.Create, c.validationHandler)
wh.AddHandler("/validate", kind, admv1beta1.Update, c.validationHandler)
wh.AddHandler("/validate", kind, admissionv1.Create, c.validationHandler)
wh.AddHandler("/validate", kind, admissionv1.Update, c.validationHandler)

autoscaler.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.workerqueue.Enqueue,
Expand Down Expand Up @@ -138,7 +138,7 @@ func (c *Controller) loggerForFleetAutoscaler(fas *autoscalingv1.FleetAutoscaler

// validationHandler will intercept when a FleetAutoscaler is created, and
// validate its settings.
func (c *Controller) validationHandler(review admv1beta1.AdmissionReview) (admv1beta1.AdmissionReview, error) {
func (c *Controller) validationHandler(review admissionv1.AdmissionReview) (admissionv1.AdmissionReview, error) {
obj := review.Request.Object
fas := &autoscalingv1.FleetAutoscaler{}
err := json.Unmarshal(obj.Raw, fas)
Expand Down
26 changes: 13 additions & 13 deletions pkg/fleetautoscalers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/heptiolabs/healthcheck"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
admv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
admregv1b "k8s.io/api/admissionregistration/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -757,40 +757,40 @@ func newFakeController() (*Controller, agtesting.Mocks) {
return c, m
}

func newAdmissionReview(fas autoscalingv1.FleetAutoscaler) (admv1beta1.AdmissionReview, error) {
func newAdmissionReview(fas autoscalingv1.FleetAutoscaler) (admissionv1.AdmissionReview, error) {
raw, err := json.Marshal(fas)
if err != nil {
return admv1beta1.AdmissionReview{}, err
return admissionv1.AdmissionReview{}, err
}
review := admv1beta1.AdmissionReview{
Request: &admv1beta1.AdmissionRequest{
review := admissionv1.AdmissionReview{
Request: &admissionv1.AdmissionRequest{
Kind: gvk,
Operation: admv1beta1.Create,
Operation: admissionv1.Create,
Object: runtime.RawExtension{
Raw: raw,
},
Namespace: "default",
},
Response: &admv1beta1.AdmissionResponse{Allowed: true},
Response: &admissionv1.AdmissionResponse{Allowed: true},
}
return review, err
}

func newInvalidAdmissionReview() (admv1beta1.AdmissionReview, error) {
func newInvalidAdmissionReview() (admissionv1.AdmissionReview, error) {
raw, err := json.Marshal([]byte(`1`))
if err != nil {
return admv1beta1.AdmissionReview{}, err
return admissionv1.AdmissionReview{}, err
}
review := admv1beta1.AdmissionReview{
Request: &admv1beta1.AdmissionRequest{
review := admissionv1.AdmissionReview{
Request: &admissionv1.AdmissionRequest{
Kind: gvk,
Operation: admv1beta1.Create,
Operation: admissionv1.Create,
Object: runtime.RawExtension{
Raw: raw,
},
Namespace: "default",
},
Response: &admv1beta1.AdmissionResponse{Allowed: true},
Response: &admissionv1.AdmissionResponse{Allowed: true},
}
return review, nil
}
14 changes: 7 additions & 7 deletions pkg/fleets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/mattbaird/jsonpatch"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
admv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
extclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
Expand Down Expand Up @@ -99,9 +99,9 @@ func NewController(
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
c.recorder = eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "fleet-controller"})

wh.AddHandler("/mutate", agonesv1.Kind("Fleet"), admv1beta1.Create, c.creationMutationHandler)
wh.AddHandler("/validate", agonesv1.Kind("Fleet"), admv1beta1.Create, c.creationValidationHandler)
wh.AddHandler("/validate", agonesv1.Kind("Fleet"), admv1beta1.Update, c.creationValidationHandler)
wh.AddHandler("/mutate", agonesv1.Kind("Fleet"), admissionv1.Create, c.creationMutationHandler)
wh.AddHandler("/validate", agonesv1.Kind("Fleet"), admissionv1.Create, c.creationValidationHandler)
wh.AddHandler("/validate", agonesv1.Kind("Fleet"), admissionv1.Update, c.creationValidationHandler)

fInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.workerqueue.Enqueue,
Expand All @@ -128,7 +128,7 @@ func NewController(
// the default values on the Fleet
// Should only be called on fleet create operations.
// nolint:dupl
func (c *Controller) creationMutationHandler(review admv1beta1.AdmissionReview) (admv1beta1.AdmissionReview, error) {
func (c *Controller) creationMutationHandler(review admissionv1.AdmissionReview) (admissionv1.AdmissionReview, error) {
c.baseLogger.WithField("review", review).Debug("creationMutationHandler")

obj := review.Request.Object
Expand Down Expand Up @@ -159,7 +159,7 @@ func (c *Controller) creationMutationHandler(review admv1beta1.AdmissionReview)

c.loggerForFleet(fleet).WithField("patch", string(jsn)).Infof("patch created!")

pt := admv1beta1.PatchTypeJSONPatch
pt := admissionv1.PatchTypeJSONPatch
review.Response.PatchType = &pt
review.Response.Patch = jsn

Expand All @@ -168,7 +168,7 @@ func (c *Controller) creationMutationHandler(review admv1beta1.AdmissionReview)

// creationValidationHandler that validates a Fleet when it is created
// Should only be called on Fleet create and Update operations.
func (c *Controller) creationValidationHandler(review admv1beta1.AdmissionReview) (admv1beta1.AdmissionReview, error) {
func (c *Controller) creationValidationHandler(review admissionv1.AdmissionReview) (admissionv1.AdmissionReview, error) {
c.baseLogger.WithField("review", review).Debug("creationValidationHandler")

obj := review.Request.Object
Expand Down
14 changes: 7 additions & 7 deletions pkg/fleets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
admv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -423,7 +423,7 @@ func TestControllerCreationMutationHandler(t *testing.T) {
result, err := c.creationMutationHandler(review)
require.NoError(t, err)
assert.True(t, result.Response.Allowed)
assert.Equal(t, admv1beta1.PatchTypeJSONPatch, *result.Response.PatchType)
assert.Equal(t, admissionv1.PatchTypeJSONPatch, *result.Response.PatchType)

patch := &jsonpatch.ByPath{}
err = json.Unmarshal(result.Response.Patch, patch)
Expand Down Expand Up @@ -1370,18 +1370,18 @@ func defaultGSSpec() *agonesv1.GameServerTemplateSpec {
}
}

func getAdmissionReview(raw []byte) admv1beta1.AdmissionReview {
func getAdmissionReview(raw []byte) admissionv1.AdmissionReview {
gvk := metav1.GroupVersionKind(agonesv1.SchemeGroupVersion.WithKind("Fleet"))

return admv1beta1.AdmissionReview{
Request: &admv1beta1.AdmissionRequest{
return admissionv1.AdmissionReview{
Request: &admissionv1.AdmissionRequest{
Kind: gvk,
Operation: admv1beta1.Create,
Operation: admissionv1.Create,
Object: runtime.RawExtension{
Raw: raw,
},
},
Response: &admv1beta1.AdmissionResponse{Allowed: true},
Response: &admissionv1.AdmissionResponse{Allowed: true},
}
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/gameservers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/mattbaird/jsonpatch"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
admv1beta1 "k8s.io/api/admission/v1beta1"
admissionv1 "k8s.io/api/admission/v1"
corev1 "k8s.io/api/core/v1"
extclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
Expand Down Expand Up @@ -149,8 +149,8 @@ func NewController(
health.AddLivenessCheck("gameserver-creation-workerqueue", healthcheck.Check(c.creationWorkerQueue.Healthy))
health.AddLivenessCheck("gameserver-deletion-workerqueue", healthcheck.Check(c.deletionWorkerQueue.Healthy))

wh.AddHandler("/mutate", agonesv1.Kind("GameServer"), admv1beta1.Create, c.creationMutationHandler)
wh.AddHandler("/validate", agonesv1.Kind("GameServer"), admv1beta1.Create, c.creationValidationHandler)
wh.AddHandler("/mutate", agonesv1.Kind("GameServer"), admissionv1.Create, c.creationMutationHandler)
wh.AddHandler("/validate", agonesv1.Kind("GameServer"), admissionv1.Create, c.creationValidationHandler)

gsInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.enqueueGameServerBasedOnState,
Expand Down Expand Up @@ -219,7 +219,7 @@ func fastRateLimiter() workqueue.RateLimiter {
// the default values on the GameServer
// Should only be called on gameserver create operations.
// nolint:dupl
func (c *Controller) creationMutationHandler(review admv1beta1.AdmissionReview) (admv1beta1.AdmissionReview, error) {
func (c *Controller) creationMutationHandler(review admissionv1.AdmissionReview) (admissionv1.AdmissionReview, error) {
obj := review.Request.Object
gs := &agonesv1.GameServer{}
err := json.Unmarshal(obj.Raw, gs)
Expand Down Expand Up @@ -247,7 +247,7 @@ func (c *Controller) creationMutationHandler(review admv1beta1.AdmissionReview)
return review, errors.Wrapf(err, "error creating json for patch for GameServer %s", gs.ObjectMeta.Name)
}

pt := admv1beta1.PatchTypeJSONPatch
pt := admissionv1.PatchTypeJSONPatch
review.Response.PatchType = &pt
review.Response.Patch = jsonPatch

Expand All @@ -268,7 +268,7 @@ func (c *Controller) loggerForGameServer(gs *agonesv1.GameServer) *logrus.Entry

// creationValidationHandler that validates a GameServer when it is created
// Should only be called on gameserver create operations.
func (c *Controller) creationValidationHandler(review admv1beta1.AdmissionReview) (admv1beta1.AdmissionReview, error) {
func (c *Controller) creationValidationHandler(review admissionv1.AdmissionReview) (admissionv1.AdmissionReview, error) {
obj := review.Request.Object
gs := &agonesv1.GameServer{}
err := json.Unmarshal(obj.Raw, gs)
Expand Down
Loading

0 comments on commit df18f48

Please sign in to comment.