Skip to content

Commit

Permalink
Change e2e test to use custom ports
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohlool committed Apr 8, 2019
1 parent 8702550 commit 1afc25d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
8 changes: 7 additions & 1 deletion test/e2e/apimachinery/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ import (
"k8s.io/kubernetes/test/e2e/framework"
imageutils "k8s.io/kubernetes/test/utils/image"
samplev1alpha1 "k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1"
"k8s.io/utils/pointer"

. "github.com/onsi/ginkgo"
)

var serverAggregatorVersion = utilversion.MustParseSemantic("v1.10.0")

const (
aggregatorServicePort = 7443
)

var _ = SIGDescribe("Aggregator", func() {
var ns string
var c clientset.Interface
Expand Down Expand Up @@ -266,7 +271,7 @@ func TestSampleAPIServer(f *framework.Framework, image string) {
Ports: []v1.ServicePort{
{
Protocol: "TCP",
Port: 443,
Port: aggregatorServicePort,
TargetPort: intstr.FromInt(443),
},
},
Expand Down Expand Up @@ -317,6 +322,7 @@ func TestSampleAPIServer(f *framework.Framework, image string) {
Service: &apiregistrationv1beta1.ServiceReference{
Namespace: namespace,
Name: "sample-api",
Port: pointer.Int32Ptr(aggregatorServicePort),
},
Group: "wardle.k8s.io",
Version: "v1alpha1",
Expand Down
10 changes: 7 additions & 3 deletions test/e2e/apimachinery/crd_conversion_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/utils/crd"
imageutils "k8s.io/kubernetes/test/utils/image"
"k8s.io/utils/pointer"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -44,6 +45,7 @@ const (
secretCRDName = "sample-custom-resource-conversion-webhook-secret"
deploymentCRDName = "sample-crd-conversion-webhook-deployment"
serviceCRDName = "e2e-test-crd-conversion-webhook"
serviceCRDPort = 9443
roleBindingCRDName = "crd-conversion-webhook-auth-reader"
)

Expand Down Expand Up @@ -107,7 +109,8 @@ var _ = SIGDescribe("CustomResourceConversionWebhook [Feature:CustomResourceWebh
Service: &v1beta1.ServiceReference{
Namespace: f.Namespace.Name,
Name: serviceCRDName,
Path: strPtr("/crdconvert"),
Path: pointer.StringPtr("/crdconvert"),
Port: pointer.Int32Ptr(serviceCRDPort),
}})
if err != nil {
return
Expand All @@ -123,7 +126,8 @@ var _ = SIGDescribe("CustomResourceConversionWebhook [Feature:CustomResourceWebh
Service: &v1beta1.ServiceReference{
Namespace: f.Namespace.Name,
Name: serviceCRDName,
Path: strPtr("/crdconvert"),
Path: pointer.StringPtr("/crdconvert"),
Port: pointer.Int32Ptr(serviceCRDPort),
}})
if err != nil {
return
Expand Down Expand Up @@ -268,7 +272,7 @@ func deployCustomResourceWebhookAndService(f *framework.Framework, image string,
Ports: []v1.ServicePort{
{
Protocol: "TCP",
Port: 443,
Port: serviceCRDPort,
TargetPort: intstr.FromInt(443),
},
},
Expand Down
28 changes: 22 additions & 6 deletions test/e2e/apimachinery/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/utils/crd"
imageutils "k8s.io/kubernetes/test/utils/image"
"k8s.io/utils/pointer"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -50,6 +51,7 @@ const (
secretName = "sample-webhook-secret"
deploymentName = "sample-webhook-deployment"
serviceName = "e2e-test-webhook"
servicePort = 8443
roleBindingName = "webhook-auth-reader"

// The webhook configuration names should not be reused between test instances.
Expand Down Expand Up @@ -208,17 +210,17 @@ var _ = SIGDescribe("AdmissionWebhook", func() {
policyIgnore := v1beta1.Ignore

By("Setting timeout (1s) shorter than webhook latency (5s)")
slowWebhookCleanup := registerSlowWebhook(f, context, &policyFail, int32Ptr(1))
slowWebhookCleanup := registerSlowWebhook(f, context, &policyFail, pointer.Int32Ptr(1))
testSlowWebhookTimeoutFailEarly(f)
slowWebhookCleanup()

By("Having no error when timeout is shorter than webhook latency and failure policy is ignore")
slowWebhookCleanup = registerSlowWebhook(f, context, &policyIgnore, int32Ptr(1))
slowWebhookCleanup = registerSlowWebhook(f, context, &policyIgnore, pointer.Int32Ptr(1))
testSlowWebhookTimeoutNoError(f)
slowWebhookCleanup()

By("Having no error when timeout is longer than webhook latency")
slowWebhookCleanup = registerSlowWebhook(f, context, &policyFail, int32Ptr(10))
slowWebhookCleanup = registerSlowWebhook(f, context, &policyFail, pointer.Int32Ptr(10))
testSlowWebhookTimeoutNoError(f)
slowWebhookCleanup()

Expand Down Expand Up @@ -368,7 +370,7 @@ func deployWebhookAndService(f *framework.Framework, image string, context *cert
Ports: []v1.ServicePort{
{
Protocol: "TCP",
Port: 443,
Port: servicePort,
TargetPort: intstr.FromInt(443),
},
},
Expand All @@ -384,8 +386,6 @@ func deployWebhookAndService(f *framework.Framework, image string, context *cert

func strPtr(s string) *string { return &s }

func int32Ptr(i int32) *int32 { return &i }

func registerWebhook(f *framework.Framework, context *certContext) func() {
client := f.ClientSet
By("Registering the webhook via the AdmissionRegistration API")
Expand Down Expand Up @@ -417,6 +417,7 @@ func registerWebhook(f *framework.Framework, context *certContext) func() {
Namespace: namespace,
Name: serviceName,
Path: strPtr("/pods"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -446,6 +447,7 @@ func registerWebhook(f *framework.Framework, context *certContext) func() {
Namespace: namespace,
Name: serviceName,
Path: strPtr("/configmaps"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -496,6 +498,7 @@ func registerWebhookForAttachingPod(f *framework.Framework, context *certContext
Namespace: namespace,
Name: serviceName,
Path: strPtr("/pods/attach"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -539,6 +542,7 @@ func registerMutatingWebhookForConfigMap(f *framework.Framework, context *certCo
Namespace: namespace,
Name: serviceName,
Path: strPtr("/mutating-configmaps"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand All @@ -558,6 +562,7 @@ func registerMutatingWebhookForConfigMap(f *framework.Framework, context *certCo
Namespace: namespace,
Name: serviceName,
Path: strPtr("/mutating-configmaps"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -614,6 +619,7 @@ func registerMutatingWebhookForPod(f *framework.Framework, context *certContext)
Namespace: namespace,
Name: serviceName,
Path: strPtr("/mutating-pods"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -786,6 +792,7 @@ func failingWebhook(namespace, name string) v1beta1.Webhook {
Namespace: namespace,
Name: serviceName,
Path: strPtr("/configmaps"),
Port: pointer.Int32Ptr(servicePort),
},
// Without CA bundle, the call to webhook always fails
CABundle: nil,
Expand Down Expand Up @@ -892,6 +899,7 @@ func registerValidatingWebhookForWebhookConfigurations(f *framework.Framework, c
Namespace: namespace,
Name: serviceName,
Path: strPtr("/always-deny"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -944,6 +952,7 @@ func registerMutatingWebhookForWebhookConfigurations(f *framework.Framework, con
Namespace: namespace,
Name: serviceName,
Path: strPtr("/add-label"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -997,6 +1006,7 @@ func testWebhooksForWebhookConfigurations(f *framework.Framework) {
// but because the failure policy is ignore, it will
// have no effect on admission requests.
Path: strPtr(""),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: nil,
},
Expand Down Expand Up @@ -1044,6 +1054,7 @@ func testWebhooksForWebhookConfigurations(f *framework.Framework) {
// but because the failure policy is ignore, it will
// have no effect on admission requests.
Path: strPtr(""),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: nil,
},
Expand Down Expand Up @@ -1213,6 +1224,7 @@ func registerWebhookForCustomResource(f *framework.Framework, context *certConte
Namespace: namespace,
Name: serviceName,
Path: strPtr("/custom-resource"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -1254,6 +1266,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
Namespace: namespace,
Name: serviceName,
Path: strPtr("/mutating-custom-resource"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand All @@ -1273,6 +1286,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
Namespace: namespace,
Name: serviceName,
Path: strPtr("/mutating-custom-resource"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -1401,6 +1415,7 @@ func registerValidatingWebhookForCRD(f *framework.Framework, context *certContex
Namespace: namespace,
Name: serviceName,
Path: strPtr("/crd"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down Expand Up @@ -1512,6 +1527,7 @@ func registerSlowWebhook(f *framework.Framework, context *certContext, policy *v
Namespace: namespace,
Name: serviceName,
Path: strPtr("/always-allow-delay-5s"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
},
Expand Down

0 comments on commit 1afc25d

Please sign in to comment.