Pass Context to StartTestServer

Signed-off-by: Kante Yin <kerthcet@gmail.com>
This commit is contained in:
Kante Yin
2023-03-31 12:19:26 +08:00
committed by kerthcet
parent 2d866ec2fc
commit a7035f5459
42 changed files with 754 additions and 473 deletions

View File

@@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/controlplane"
"k8s.io/kubernetes/pkg/controlplane/reconcilers"
"k8s.io/kubernetes/test/integration/framework"
"k8s.io/kubernetes/test/utils/ktesting"
)
func TestWebhookLoopback(t *testing.T) {
@@ -41,7 +42,11 @@ func TestWebhookLoopback(t *testing.T) {
called := int32(0)
client, _, tearDownFn := framework.StartTestServer(t, framework.TestServerSetup{
_, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
client, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
},
ModifyServerConfig: func(config *controlplane.Config) {
@@ -67,7 +72,7 @@ func TestWebhookLoopback(t *testing.T) {
fail := admissionregistrationv1.Fail
noSideEffects := admissionregistrationv1.SideEffectClassNone
_, err := client.AdmissionregistrationV1().MutatingWebhookConfigurations().Create(context.TODO(), &admissionregistrationv1.MutatingWebhookConfiguration{
_, err := client.AdmissionregistrationV1().MutatingWebhookConfigurations().Create(ctx, &admissionregistrationv1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{Name: "webhooktest.example.com"},
Webhooks: []admissionregistrationv1.MutatingWebhook{{
Name: "webhooktest.example.com",
@@ -88,7 +93,7 @@ func TestWebhookLoopback(t *testing.T) {
}
err = wait.PollImmediate(100*time.Millisecond, 30*time.Second, func() (done bool, err error) {
_, err = client.CoreV1().ConfigMaps("default").Create(context.TODO(), &v1.ConfigMap{
_, err = client.CoreV1().ConfigMaps("default").Create(ctx, &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: "webhook-test"},
Data: map[string]string{"invalid key": "value"},
}, metav1.CreateOptions{})