Skip to content

Commit

Permalink
Clean shutdown of dualstack integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-t committed May 28, 2022
1 parent 8a95939 commit 411c319
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 223 deletions.
37 changes: 13 additions & 24 deletions test/integration/dualstack/dualstack_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,31 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
"k8s.io/kubernetes/pkg/controller/endpoint"
"k8s.io/kubernetes/pkg/controller/endpointslice"
"k8s.io/kubernetes/test/integration/framework"
netutils "k8s.io/utils/net"
)

func TestDualStackEndpoints(t *testing.T) {
// Create an IPv4IPv6 dual stack control-plane
serviceCIDR := "10.0.0.0/16"
secondaryServiceCIDR := "2001:db8:1::/48"
secondaryServiceCIDR := "2001:db8:1::/112"
labelMap := func() map[string]string {
return map[string]string{"foo": "bar"}
}

cfg := framework.NewIntegrationTestControlPlaneConfig()
_, cidr, err := netutils.ParseCIDRSloppy(serviceCIDR)
if err != nil {
t.Fatalf("Bad cidr: %v", err)
}
cfg.ExtraConfig.ServiceIPRange = *cidr

_, secCidr, err := netutils.ParseCIDRSloppy(secondaryServiceCIDR)
if err != nil {
t.Fatalf("Bad cidr: %v", err)
}
cfg.ExtraConfig.SecondaryServiceIPRange = *secCidr

_, s, closeFn := framework.RunAnAPIServer(cfg)
defer closeFn()

client := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL})
client, _, tearDownFn := framework.StartTestServer(t, framework.TestServerSetup{
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
opts.ServiceClusterIPRanges = fmt.Sprintf("%s,%s", serviceCIDR, secondaryServiceCIDR)
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
},
})
defer tearDownFn()

// Wait until the default "kubernetes" service is created.
if err = wait.Poll(250*time.Millisecond, time.Minute, func() (bool, error) {
if err := wait.Poll(250*time.Millisecond, time.Minute, func() (bool, error) {
_, err := client.CoreV1().Services(metav1.NamespaceDefault).Get(context.TODO(), "kubernetes", metav1.GetOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return false, err
Expand Down Expand Up @@ -156,8 +145,8 @@ func TestDualStackEndpoints(t *testing.T) {

for i, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
ns := framework.CreateTestingNamespace(fmt.Sprintf("test-endpointslice-dualstack-%d", i), t)
defer framework.DeleteTestingNamespace(ns, t)
ns := framework.CreateNamespaceOrDie(client, fmt.Sprintf("test-endpointslice-dualstack-%d", i), t)
defer framework.DeleteNamespaceOrDie(client, ns, t)

// Create a pod with labels
pod := &v1.Pod{
Expand Down
Loading

0 comments on commit 411c319

Please sign in to comment.