Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: AnyISalIn <anyisalin@gmail.com>
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package admission | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
admissionv1 "k8s.io/api/admission/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
var _ = Describe("Defaulter Handler", func() { | ||
|
||
It("should return ok if received delete verb in defaulter handler", func() { | ||
obj := &TestDefaulter{} | ||
handler := DefaultingWebhookFor(obj) | ||
|
||
resp := handler.Handle(context.TODO(), Request{ | ||
AdmissionRequest: admissionv1.AdmissionRequest{ | ||
Operation: admissionv1.Delete, | ||
OldObject: runtime.RawExtension{ | ||
Raw: []byte("{}"), | ||
}, | ||
}, | ||
}) | ||
Expect(resp.Allowed).Should(BeTrue()) | ||
Expect(resp.Result.Code).Should(Equal(int32(http.StatusOK))) | ||
}) | ||
|
||
}) | ||
|
||
// TestDefaulter. | ||
var _ runtime.Object = &TestDefaulter{} | ||
|
||
type TestDefaulter struct { | ||
Replica int `json:"replica,omitempty"` | ||
} | ||
|
||
var testDefaulterGVK = schema.GroupVersionKind{Group: "foo.test.org", Version: "v1", Kind: "TestDefaulter"} | ||
|
||
func (d *TestDefaulter) GetObjectKind() schema.ObjectKind { return d } | ||
func (d *TestDefaulter) DeepCopyObject() runtime.Object { | ||
return &TestDefaulter{ | ||
Replica: d.Replica, | ||
} | ||
} | ||
|
||
func (d *TestDefaulter) GroupVersionKind() schema.GroupVersionKind { | ||
return testDefaulterGVK | ||
} | ||
|
||
func (d *TestDefaulter) SetGroupVersionKind(gvk schema.GroupVersionKind) {} | ||
|
||
var _ runtime.Object = &TestDefaulterList{} | ||
|
||
type TestDefaulterList struct{} | ||
|
||
func (*TestDefaulterList) GetObjectKind() schema.ObjectKind { return nil } | ||
func (*TestDefaulterList) DeepCopyObject() runtime.Object { return nil } | ||
|
||
func (d *TestDefaulter) Default() { | ||
if d.Replica < 2 { | ||
d.Replica = 2 | ||
} | ||
} |