-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
133 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ tmp-cni | |
k8s-install/scripts/tmp/ | ||
install_cni.test | ||
*.swp | ||
*.coverprofile |
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,13 @@ | ||
package main_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestCniPlugin(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "CniPlugin Suite") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,13 @@ | ||
package utils_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestUtils(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Utils Suite") | ||
} |
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,62 @@ | ||
package utils_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gexec" | ||
"github.com/projectcalico/cni-plugin/testutils" | ||
"github.com/projectcalico/cni-plugin/utils" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/vishvananda/netlink" | ||
) | ||
|
||
var _ = Describe("Utils", func() { | ||
cniVersion := os.Getenv("CNI_SPEC_VERSION") | ||
Describe("Run install-cni", func() { | ||
Context("container route already exists on the host", func() { | ||
netconf := fmt.Sprintf(` | ||
{ | ||
"cniVersion": "%s", | ||
"name": "net1", | ||
"type": "calico", | ||
"etcd_endpoints": "http://%s:2379", | ||
"hostname": "namedHostname", | ||
"datastore_type": "%s", | ||
"ipam": { | ||
"type": "host-local", | ||
"subnet": "10.0.0.0/8" | ||
}, | ||
"log_level":"debug" | ||
}`, cniVersion, os.Getenv("ETCD_IP"), os.Getenv("DATASTORE_TYPE")) | ||
|
||
It("route setup should be resilient to existing route", func() { | ||
By("creating a CNI networked container, which should also install the container route in the host namespace") | ||
containerID, session, _, _, _, contNs, err := testutils.CreateContainerWithId(netconf, "", testutils.TEST_DEFAULT_NS, "", "meep123") | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Eventually(session).Should(gexec.Exit()) | ||
|
||
// CNI plugin generates host side vEth name from containerID if used for "cni" orchestrator. | ||
hostVethName := "cali" + containerID[:utils.Min(11, len(containerID))] //"cali" + containerID | ||
hostVeth, err := netlink.LinkByName(hostVethName) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
result, err := testutils.GetResultForCurrent(session, cniVersion) | ||
if err != nil { | ||
log.Fatalf("Error getting result from the session: %v\n", err) | ||
} | ||
|
||
log.Printf("Unmarshalled result: %v\n", result) | ||
|
||
By("setting up the same route CNI plugin installed in the initial run for the hostVeth") | ||
err = utils.SetupRoutes(hostVeth, result) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
_, err = testutils.DeleteContainerWithId(netconf, contNs.Path(), "", testutils.TEST_DEFAULT_NS, containerID) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) | ||
}) |