Merge pull request #47998 from danehans/kubeadm_boot

Automatic merge from submit-queue

Adds IPv6 test case to kubeadm bootstrap

**What this PR does / why we need it**:
Adds IPv6 test cases in support of kubeadm bootstrap functionality. It's needed to ensure test cases cover IPv6 related networking scenarios.

**Which issue this PR fixes**
This PR is in support of Issue #1443 and Issue #47666

**Special notes for your reviewer**:
Additional PR's will follow to ensure kubeadm fully supports IPv6.

**Release note**:
```NONE
```

/area ipv6
This commit is contained in:
Kubernetes Submit Queue 2017-08-15 13:11:22 -07:00 committed by GitHub
commit df8287c91d

View File

@ -20,6 +20,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"testing" "testing"
"text/template"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
@ -28,10 +29,10 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
) )
const testConfig = `apiVersion: v1 var testConfigTempl = template.Must(template.New("test").Parse(`apiVersion: v1
clusters: clusters:
- cluster: - cluster:
server: https://10.128.0.6:6443 server: {{.Server}}
name: kubernetes name: kubernetes
contexts: contexts:
- context: - context:
@ -42,7 +43,7 @@ current-context: kubernetes-admin@kubernetes
kind: Config kind: Config
preferences: {} preferences: {}
users: users:
- name: kubernetes-admin` - name: kubernetes-admin`))
func TestCreateBootstrapConfigMapIfNotExists(t *testing.T) { func TestCreateBootstrapConfigMapIfNotExists(t *testing.T) {
tests := []struct { tests := []struct {
@ -71,32 +72,42 @@ func TestCreateBootstrapConfigMapIfNotExists(t *testing.T) {
}, },
} }
file, err := ioutil.TempFile("", "") servers := []struct {
if err != nil { Server string
t.Fatalf("could not create tempfile: %v", err) }{
{Server: "https://10.128.0.6:6443"},
{Server: "https://[2001:db8::6]:3446"},
} }
defer os.Remove(file.Name())
file.Write([]byte(testConfig)) for _, server := range servers {
file, err := ioutil.TempFile("", "")
for _, tc := range tests { if err != nil {
client := clientsetfake.NewSimpleClientset() t.Fatalf("could not create tempfile: %v", err)
if tc.createErr != nil {
client.PrependReactor("create", "configmaps", func(action core.Action) (bool, runtime.Object, error) {
return true, nil, tc.createErr
})
} }
if tc.updateErr != nil { defer os.Remove(file.Name())
client.PrependReactor("update", "configmaps", func(action core.Action) (bool, runtime.Object, error) {
return true, nil, tc.updateErr if err := testConfigTempl.Execute(file, server); err != nil {
}) t.Fatalf("could not write to tempfile: %v", err)
} }
err = CreateBootstrapConfigMapIfNotExists(client, file.Name()) if err := file.Close(); err != nil {
if tc.expectErr && err == nil { t.Fatalf("could not close tempfile: %v", err)
t.Errorf("CreateBootstrapConfigMapIfNotExists(%s) wanted error, got nil", tc.name) }
} else if !tc.expectErr && err != nil {
t.Errorf("CreateBootstrapConfigMapIfNotExists(%s) returned unexpected error: %v", tc.name, err) for _, tc := range tests {
client := clientsetfake.NewSimpleClientset()
if tc.createErr != nil {
client.PrependReactor("create", "configmaps", func(action core.Action) (bool, runtime.Object, error) {
return true, nil, tc.createErr
})
}
err := CreateBootstrapConfigMapIfNotExists(client, file.Name())
if tc.expectErr && err == nil {
t.Errorf("CreateBootstrapConfigMapIfNotExists(%s) wanted error, got nil", tc.name)
} else if !tc.expectErr && err != nil {
t.Errorf("CreateBootstrapConfigMapIfNotExists(%s) returned unexpected error: %v", tc.name, err)
}
} }
} }
} }