-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from cybozu-go/delete-host-veth-if-exists
Delete host-side veth if exists in CNI ADD.
- Loading branch information
Showing
10 changed files
with
216 additions
and
11 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
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
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
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,7 @@ | ||
// +build !failures | ||
|
||
package cni | ||
|
||
const injectFailures = false | ||
|
||
func panicForFirstRun(name string) {} |
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,31 @@ | ||
// +build failures | ||
|
||
package cni | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
const injectFailures = true | ||
|
||
// panicForFirstRun panics at least for the first run. | ||
// This "first" is judged against the lifetime of "/tmp" files. | ||
// This does not consider race conditions. | ||
func panicForFirstRun(name string) { | ||
fileName := filepath.Join("/tmp", "coil_failures_"+name) | ||
|
||
_, err := os.Stat(fileName) | ||
if err == nil { | ||
return | ||
} | ||
if !os.IsNotExist(err) { | ||
panic(err) | ||
} | ||
|
||
_, err = os.Create(fileName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
panic("injected failure: " + name) | ||
} |
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
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
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,89 @@ | ||
package mtest | ||
|
||
import ( | ||
"crypto/sha1" | ||
"encoding/hex" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// TestPodStartup tests pod startup, especially under failure injection. | ||
func TestPodStartup() { | ||
BeforeEach(func() { | ||
initializeCoil() | ||
coilctlSafe("pool", "create", "default", "10.0.1.0/24", "2") | ||
}) | ||
AfterEach(cleanCoil) | ||
|
||
It("should confirm successful creation of CKE-managed pods", func() { | ||
By("waiting for cluster-dns pods to become ready") | ||
Eventually(func() error { | ||
stdout, stderr, err := kubectl("get", "-n", "kube-system", "deployment", "cluster-dns", "-o", "json") | ||
if err != nil { | ||
return fmt.Errorf("err=%v, stdout=%s, stderr=%s", err, stdout, stderr) | ||
} | ||
|
||
deployment := new(appsv1.Deployment) | ||
err = json.Unmarshal(stdout, deployment) | ||
if err != nil { | ||
return fmt.Errorf("err=%v, stdout=%s", err, stdout) | ||
} | ||
|
||
if deployment.Status.ReadyReplicas != 2 { | ||
return errors.New("ReadyReplicas != 2") | ||
} | ||
return nil | ||
}).Should(Succeed()) | ||
}) | ||
|
||
It("should starts up pod on half-cleaned node", func() { | ||
By("making uncleaned veth artificially") | ||
h := sha1.New() | ||
h.Write([]byte("mtest.foo")) | ||
vethName := "veth" + hex.EncodeToString(h.Sum(nil))[:11] | ||
execSafeAt(node1, "sudo", "ip", "netns", "add", "foo") | ||
execSafeAt(node1, "sudo", "ip", "netns", "exec", "foo", "ip", "link", "add", "eth0", "type", "veth", "peer", "name", vethName) | ||
execSafeAt(node1, "sudo", "ip", "netns", "exec", "foo", "ip", "link", "set", vethName, "netns", "1") | ||
|
||
By("creating pod with specific name on specific node") | ||
podYAML := ` | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: foo | ||
namespace: mtest | ||
spec: | ||
nodeName: %s | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
` | ||
stdout, stderr, err := kubectlWithInput([]byte(fmt.Sprintf(podYAML, node1)), "apply", "-f", "-") | ||
Expect(err).NotTo(HaveOccurred(), "stdout: %s, stderr: %s", stdout, stderr) | ||
|
||
By("waiting for pod to become ready") | ||
Eventually(func() error { | ||
stdout, stderr, err := kubectl("get", "pod", "foo", "-o", "json") | ||
if err != nil { | ||
return fmt.Errorf("err=%v, stdout=%s, stderr=%s", err, stdout, stderr) | ||
} | ||
|
||
pod := new(corev1.Pod) | ||
err = json.Unmarshal(stdout, pod) | ||
if err != nil { | ||
return fmt.Errorf("err=%v, stdout=%s", err, stdout) | ||
} | ||
|
||
if pod.Status.Phase != corev1.PodRunning { | ||
return errors.New("Phase != Running") | ||
} | ||
return nil | ||
}).Should(Succeed()) | ||
}) | ||
} |
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,28 @@ | ||
package mtest | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/cybozu-go/coil/mtest" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestMtest(t *testing.T) { | ||
if os.Getenv("SSH_PRIVKEY") == "" { | ||
t.Skip("no SSH_PRIVKEY envvar") | ||
} | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Multi-host test for coil") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
mtest.RunBeforeSuite() | ||
}) | ||
|
||
// This must be the only top-level test container. | ||
// Other tests and test containers must be listed in this. | ||
var _ = Describe("Test CKE functions", func() { | ||
mtest.FailuresSuite() | ||
}) |
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