forked from k3s-io/k3s
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an integration test for flannel-backend=none
Signed-off-by: Manuel Buil <[email protected]>
- Loading branch information
1 parent
86f1021
commit efdeada
Showing
2 changed files
with
91 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
This test verifies that even if we use flannel-backend=none, kube-api starts correctly so that it can | ||
accept the custom CNI plugin manifest. We want to catch regressions in which kube-api is unresponsive. | ||
To do so we check for 25s that we can consistently query kube-api. We check that pods are in pending | ||
state, which is what should happen if there is no cni plugin | ||
*/ | ||
package integration | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
testutil "github.com/k3s-io/k3s/tests/integration" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var server *testutil.K3sServer | ||
var flannelNoneServerArgs = []string{ | ||
"--flannel-backend=none", | ||
} | ||
var testLock int | ||
|
||
var _ = BeforeSuite(func() { | ||
logrus.Infof("TESTING - testutil.IsExistingServer(): %v", testutil.IsExistingServer()) | ||
logrus.Infof("TESTING - os.Getenv(CI): %v", os.Getenv("CI")) | ||
if !testutil.IsExistingServer() { | ||
var err error | ||
testLock, err = testutil.K3sTestLock() | ||
Expect(err).ToNot(HaveOccurred()) | ||
server, err = testutil.K3sStartServer(flannelNoneServerArgs...) | ||
Expect(err).ToNot(HaveOccurred()) | ||
} | ||
}) | ||
|
||
var _ = Describe("flannel-backend=none", Ordered, func() { | ||
BeforeEach(func() { | ||
if testutil.IsExistingServer() && !testutil.ServerArgsPresent(flannelNoneServerArgs) { | ||
Skip("Test needs k3s server with: " + strings.Join(flannelNoneServerArgs, " ")) | ||
} | ||
}) | ||
When("Pods can be queried and their status is Pending", func() { | ||
It("checks pods status", func() { | ||
// Wait for pods to come up before running the real test | ||
Eventually(func() int { | ||
pods, err := testutil.ParsePods("kube-system", metav1.ListOptions{}) | ||
logrus.Infof("TESTING - This is the err: %v", err) | ||
return len(pods) | ||
}, "180s", "5s").Should(BeNumerically(">", 0)) | ||
|
||
|
||
pods, err := testutil.ParsePods("kube-system", metav1.ListOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Pods should remain in Pending state because there is no network plugin | ||
Consistently(func () bool { | ||
for _, pod := range pods { | ||
if !strings.Contains(string(pod.Status.Phase), "Pending") { | ||
return false | ||
} | ||
} | ||
return true | ||
}, "25s").Should(BeTrue()) | ||
}) | ||
}) | ||
}) | ||
|
||
var failed bool | ||
var _ = AfterEach(func() { | ||
failed = failed || CurrentSpecReport().Failed() | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
if !testutil.IsExistingServer() && os.Getenv("CI") != "true" { | ||
if failed { | ||
testutil.K3sSaveLog(server, false) | ||
} | ||
Expect(testutil.K3sKillServer(server)).To(Succeed()) | ||
Expect(testutil.K3sCleanup(testLock, "")).To(Succeed()) | ||
} | ||
}) | ||
|
||
func Test_Integrationflannelnone(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "flannel-backend=none Suite") | ||
} |