-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding test for installing and deleting virtual cluster from kubectl
- Loading branch information
Sowmya viswam
authored and
Sowmya viswam
committed
Aug 2, 2024
1 parent
04edf4b
commit 35ac965
Showing
3 changed files
with
112 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package e2evclusterinstall | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"time" | ||
|
||
"github.com/loft-sh/vcluster/pkg/platform/random" | ||
"github.com/loft-sh/vcluster/test/framework" | ||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
) | ||
|
||
const ( | ||
pollingInterval = time.Second * 2 | ||
pollingDurationLong = time.Minute * 2 | ||
vclusterRepo = "https://charts.loft.sh" | ||
filePath = "../commonValues.yaml" | ||
outputFile = "output.yaml" | ||
) | ||
|
||
var _ = ginkgo.Describe("Deploy and Delete vCluster", func() { | ||
ginkgo.It("should deploy a vCluster using kubectl and delete it using kubectl", func() { | ||
vClusterName := "t-cluster-" + random.String(6) | ||
vClusterNamespace := "t-ns-" + random.String(6) | ||
file, err := os.Create(outputFile) | ||
framework.ExpectNoError(err) | ||
defer file.Close() | ||
|
||
createNamespaceCmd := exec.Command("kubectl", "create", "namespace", vClusterNamespace) | ||
err = createNamespaceCmd.Run() | ||
framework.ExpectNoError(err) | ||
|
||
helmCmd := exec.Command("helm", "template", vClusterName, "vcluster", "--repo", vclusterRepo, "-n", vClusterNamespace, "-f", filePath) | ||
helmCmd.Stdout = file | ||
err = helmCmd.Run() | ||
framework.ExpectNoError(err) | ||
|
||
kubectlCmd := exec.Command("kubectl", "apply", "-f", outputFile) | ||
err = kubectlCmd.Run() | ||
framework.ExpectNoError(err) | ||
|
||
gomega.Eventually(func() bool { | ||
|
||
checkCmd := exec.Command("vcluster", "list") | ||
output, err := checkCmd.CombinedOutput() | ||
framework.ExpectNoError(err) | ||
return err == nil && strings.Contains(string(output), vClusterName) && strings.Contains(string(output), "Running") | ||
}).WithPolling(pollingInterval).WithTimeout(pollingDurationLong).Should(gomega.BeTrue()) | ||
|
||
deleteCmd := exec.Command("kubectl", "delete", "-f", outputFile) | ||
err = deleteCmd.Run() | ||
framework.ExpectNoError(err) | ||
|
||
gomega.Eventually(func() bool { | ||
|
||
checkCmd := exec.Command("vcluster", "list") | ||
output, err := checkCmd.CombinedOutput() | ||
framework.ExpectNoError(err) | ||
return err == nil && !strings.Contains(string(output), vClusterName) | ||
}).WithPolling(pollingInterval).WithTimeout(pollingDurationLong).Should(gomega.BeTrue()) | ||
|
||
}) | ||
}) |
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 e2evclusterinstall | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
) | ||
|
||
func TestRunE2ETests(t *testing.T) { | ||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
ginkgo.RunSpecs(t, "Vcluster Install and Delete Suite") | ||
} |