Skip to content

Commit

Permalink
Refactor e2e suite setup to make it more customizable
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Demicev <alexandr.demicev@suse.com>
  • Loading branch information
alexander-demicev committed Jul 29, 2024
1 parent 2ae0681 commit 57a316b
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 194 deletions.
1 change: 1 addition & 0 deletions test/e2e/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const (
RancherTurtlesNamespace = "rancher-turtles-system"
RancherNamespace = "cattle-system"
NginxIngressNamespace = "ingress-nginx"
NginxIngressDeployment = "ingress-nginx-controller"
)

const (
Expand Down
47 changes: 28 additions & 19 deletions test/e2e/suites/embedded-capi-disabled-v3/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,45 +84,50 @@ var _ = BeforeSuite(func() {
By(fmt.Sprintf("Loading the e2e test configuration from %q", flagVals.ConfigPath))
e2eConfig = e2e.LoadE2EConfig(flagVals.ConfigPath)

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)
ingressType := testenv.NgrokIngress
dockerUsername := ""
dockerPassword := ""
var customClusterProvider testenv.CustomClusterProvider

if flagVals.UseEKS {
Expect(flagVals.IsolatedMode).To(BeFalse(), "You cannot use eks with isolated")
dockerUsername = os.Getenv("GITHUB_USERNAME")
Expect(dockerUsername).NotTo(BeEmpty(), "Github username is required")
dockerPassword = os.Getenv("GITHUB_TOKEN")
Expect(dockerPassword).NotTo(BeEmpty(), "Github token is required")
customClusterProvider = testenv.EKSBootsrapCluster
Expect(customClusterProvider).NotTo(BeNil(), "EKS custom cluster provider is required")
ingressType = testenv.EKSNginxIngress
}

if flagVals.IsolatedMode {
ingressType = testenv.CustomIngress
}

By(fmt.Sprintf("Creating a clusterctl config into %q", flagVals.ArtifactFolder))
clusterctlConfigPath = e2e.CreateClusterctlLocalRepository(ctx, e2eConfig, filepath.Join(flagVals.ArtifactFolder, "repository"))

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)

setupClusterResult = testenv.SetupTestCluster(ctx, testenv.SetupTestClusterInput{
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
UseEKS: flagVals.UseEKS,
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
CustomClusterProvider: customClusterProvider,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

testenv.RancherDeployIngress(ctx, testenv.RancherDeployIngressInput{
BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy,
HelmBinaryPath: flagVals.HelmBinaryPath,
HelmExtraValuesPath: filepath.Join(flagVals.HelmExtraValuesDir, "deploy-rancher-ingress.yaml"),
IsolatedMode: flagVals.IsolatedMode,
UseEKS: flagVals.UseEKS,
NginxIngress: e2e.NginxIngress,
NginxIngressNamespace: e2e.NginxIngressNamespace,
IngressType: ingressType,
CustomIngress: e2e.NginxIngress,
CustomIngressNamespace: e2e.NginxIngressNamespace,
CustomIngressDeployment: e2e.NginxIngressDeployment,
IngressWaitInterval: e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-rancher"),
NgrokApiKey: e2eConfig.GetVariable(e2e.NgrokApiKeyVar),
NgrokAuthToken: e2eConfig.GetVariable(e2e.NgrokAuthTokenVar),
Expand All @@ -132,6 +137,10 @@ var _ = BeforeSuite(func() {
DefaultIngressClassPatch: e2e.IngressClassPatch,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

if flagVals.UseEKS {
By("Getting ingress hostname")
svcRes := &testenv.WaitForServiceIngressHostnameResult{}
Expand Down
47 changes: 28 additions & 19 deletions test/e2e/suites/embedded-capi-disabled/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,45 +85,50 @@ var _ = BeforeSuite(func() {
By(fmt.Sprintf("Loading the e2e test configuration from %q", flagVals.ConfigPath))
e2eConfig = e2e.LoadE2EConfig(flagVals.ConfigPath)

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)
ingressType := testenv.NgrokIngress
dockerUsername := ""
dockerPassword := ""
var customClusterProvider testenv.CustomClusterProvider

if flagVals.UseEKS {
Expect(flagVals.IsolatedMode).To(BeFalse(), "You cannot use eks with isolated")
dockerUsername = os.Getenv("GITHUB_USERNAME")
Expect(dockerUsername).NotTo(BeEmpty(), "Github username is required")
dockerPassword = os.Getenv("GITHUB_TOKEN")
Expect(dockerPassword).NotTo(BeEmpty(), "Github token is required")
customClusterProvider = testenv.EKSBootsrapCluster
Expect(customClusterProvider).NotTo(BeNil(), "EKS custom cluster provider is required")
ingressType = testenv.EKSNginxIngress
}

if flagVals.IsolatedMode {
ingressType = testenv.CustomIngress
}

By(fmt.Sprintf("Creating a clusterctl config into %q", flagVals.ArtifactFolder))
clusterctlConfigPath = e2e.CreateClusterctlLocalRepository(ctx, e2eConfig, filepath.Join(flagVals.ArtifactFolder, "repository"))

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)

setupClusterResult = testenv.SetupTestCluster(ctx, testenv.SetupTestClusterInput{
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
UseEKS: flagVals.UseEKS,
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
CustomClusterProvider: customClusterProvider,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

testenv.RancherDeployIngress(ctx, testenv.RancherDeployIngressInput{
BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy,
HelmBinaryPath: flagVals.HelmBinaryPath,
HelmExtraValuesPath: filepath.Join(flagVals.HelmExtraValuesDir, "deploy-rancher-ingress.yaml"),
IsolatedMode: flagVals.IsolatedMode,
UseEKS: flagVals.UseEKS,
NginxIngress: e2e.NginxIngress,
NginxIngressNamespace: e2e.NginxIngressNamespace,
IngressType: ingressType,
CustomIngress: e2e.NginxIngress,
CustomIngressNamespace: e2e.NginxIngressNamespace,
CustomIngressDeployment: e2e.NginxIngressDeployment,
IngressWaitInterval: e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-rancher"),
NgrokApiKey: e2eConfig.GetVariable(e2e.NgrokApiKeyVar),
NgrokAuthToken: e2eConfig.GetVariable(e2e.NgrokAuthTokenVar),
Expand All @@ -133,6 +138,10 @@ var _ = BeforeSuite(func() {
DefaultIngressClassPatch: e2e.IngressClassPatch,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

if flagVals.UseEKS {
By("Getting ingress hostname")
svcRes := &testenv.WaitForServiceIngressHostnameResult{}
Expand Down
47 changes: 28 additions & 19 deletions test/e2e/suites/import-gitops-v3/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,45 +84,50 @@ var _ = BeforeSuite(func() {
By(fmt.Sprintf("Loading the e2e test configuration from %q", flagVals.ConfigPath))
e2eConfig = e2e.LoadE2EConfig(flagVals.ConfigPath)

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)
ingressType := testenv.NgrokIngress
dockerUsername := ""
dockerPassword := ""
var customClusterProvider testenv.CustomClusterProvider

if flagVals.UseEKS {
Expect(flagVals.IsolatedMode).To(BeFalse(), "You cannot use eks with isolated")
dockerUsername = os.Getenv("GITHUB_USERNAME")
Expect(dockerUsername).NotTo(BeEmpty(), "Github username is required")
dockerPassword = os.Getenv("GITHUB_TOKEN")
Expect(dockerPassword).NotTo(BeEmpty(), "Github token is required")
customClusterProvider = testenv.EKSBootsrapCluster
Expect(customClusterProvider).NotTo(BeNil(), "EKS custom cluster provider is required")
ingressType = testenv.EKSNginxIngress
}

if flagVals.IsolatedMode {
ingressType = testenv.CustomIngress
}

By(fmt.Sprintf("Creating a clusterctl config into %q", flagVals.ArtifactFolder))
clusterctlConfigPath = e2e.CreateClusterctlLocalRepository(ctx, e2eConfig, filepath.Join(flagVals.ArtifactFolder, "repository"))

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)

setupClusterResult = testenv.SetupTestCluster(ctx, testenv.SetupTestClusterInput{
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
UseEKS: flagVals.UseEKS,
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
CustomClusterProvider: customClusterProvider,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

testenv.RancherDeployIngress(ctx, testenv.RancherDeployIngressInput{
BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy,
HelmBinaryPath: flagVals.HelmBinaryPath,
HelmExtraValuesPath: filepath.Join(flagVals.HelmExtraValuesDir, "deploy-rancher-ingress.yaml"),
IsolatedMode: flagVals.IsolatedMode,
UseEKS: flagVals.UseEKS,
NginxIngress: e2e.NginxIngress,
NginxIngressNamespace: e2e.NginxIngressNamespace,
IngressType: ingressType,
CustomIngress: e2e.NginxIngress,
CustomIngressNamespace: e2e.NginxIngressNamespace,
CustomIngressDeployment: e2e.NginxIngressDeployment,
IngressWaitInterval: e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-rancher"),
NgrokApiKey: e2eConfig.GetVariable(e2e.NgrokApiKeyVar),
NgrokAuthToken: e2eConfig.GetVariable(e2e.NgrokAuthTokenVar),
Expand All @@ -132,6 +137,10 @@ var _ = BeforeSuite(func() {
DefaultIngressClassPatch: e2e.IngressClassPatch,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

if flagVals.UseEKS {
By("Getting ingress hostname")
svcRes := &testenv.WaitForServiceIngressHostnameResult{}
Expand Down
47 changes: 28 additions & 19 deletions test/e2e/suites/import-gitops/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,45 +87,50 @@ var _ = BeforeSuite(func() {
By(fmt.Sprintf("Loading the e2e test configuration from %q", flagVals.ConfigPath))
e2eConfig = e2e.LoadE2EConfig(flagVals.ConfigPath)

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)
ingressType := testenv.NgrokIngress
dockerUsername := ""
dockerPassword := ""
var customClusterProvider testenv.CustomClusterProvider

if flagVals.UseEKS {
Expect(flagVals.IsolatedMode).To(BeFalse(), "You cannot use eks with isolated")
dockerUsername = os.Getenv("GITHUB_USERNAME")
Expect(dockerUsername).NotTo(BeEmpty(), "Github username is required")
dockerPassword = os.Getenv("GITHUB_TOKEN")
Expect(dockerPassword).NotTo(BeEmpty(), "Github token is required")
customClusterProvider = testenv.EKSBootsrapCluster
Expect(customClusterProvider).NotTo(BeNil(), "EKS custom cluster provider is required")
ingressType = testenv.EKSNginxIngress
}

if flagVals.IsolatedMode {
ingressType = testenv.CustomIngress
}

By(fmt.Sprintf("Creating a clusterctl config into %q", flagVals.ArtifactFolder))
clusterctlConfigPath = e2e.CreateClusterctlLocalRepository(ctx, e2eConfig, filepath.Join(flagVals.ArtifactFolder, "repository"))

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)

setupClusterResult = testenv.SetupTestCluster(ctx, testenv.SetupTestClusterInput{
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
UseEKS: flagVals.UseEKS,
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
CustomClusterProvider: customClusterProvider,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

testenv.RancherDeployIngress(ctx, testenv.RancherDeployIngressInput{
BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy,
HelmBinaryPath: flagVals.HelmBinaryPath,
HelmExtraValuesPath: filepath.Join(flagVals.HelmExtraValuesDir, "deploy-rancher-ingress.yaml"),
IsolatedMode: flagVals.IsolatedMode,
UseEKS: flagVals.UseEKS,
NginxIngress: e2e.NginxIngress,
NginxIngressNamespace: e2e.NginxIngressNamespace,
IngressType: ingressType,
CustomIngress: e2e.NginxIngress,
CustomIngressNamespace: e2e.NginxIngressNamespace,
CustomIngressDeployment: e2e.NginxIngressDeployment,
IngressWaitInterval: e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-rancher"),
NgrokApiKey: e2eConfig.GetVariable(e2e.NgrokApiKeyVar),
NgrokAuthToken: e2eConfig.GetVariable(e2e.NgrokAuthTokenVar),
Expand All @@ -135,6 +140,10 @@ var _ = BeforeSuite(func() {
DefaultIngressClassPatch: e2e.IngressClassPatch,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

if flagVals.UseEKS {
By("Getting ingress hostname")
svcRes := &testenv.WaitForServiceIngressHostnameResult{}
Expand Down
44 changes: 28 additions & 16 deletions test/e2e/suites/migrate-gitops/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,39 @@ var _ = BeforeSuite(func() {
clusterctlConfigPath = e2e.CreateClusterctlLocalRepository(ctx, e2eConfig, filepath.Join(flagVals.ArtifactFolder, "repository"))

hostName = e2eConfig.GetVariable(e2e.RancherHostnameVar)
ingressType := testenv.NgrokIngress
var customClusterProvider testenv.CustomClusterProvider

setupClusterResult = testenv.SetupTestCluster(ctx, testenv.SetupTestClusterInput{
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
UseEKS: flagVals.UseEKS,
})
if flagVals.UseEKS {
customClusterProvider = testenv.EKSBootsrapCluster
Expect(customClusterProvider).NotTo(BeNil(), "EKS custom cluster provider is required")
ingressType = testenv.EKSNginxIngress
}

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
ingressType = testenv.CustomIngress
}

setupClusterResult = testenv.SetupTestCluster(ctx, testenv.SetupTestClusterInput{
UseExistingCluster: flagVals.UseExistingCluster,
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
Scheme: e2e.InitScheme(),
ArtifactFolder: flagVals.ArtifactFolder,
KubernetesVersion: e2eConfig.GetVariable(e2e.KubernetesManagementVersionVar),
IsolatedMode: flagVals.IsolatedMode,
HelmBinaryPath: flagVals.HelmBinaryPath,
CustomClusterProvider: customClusterProvider,
})

testenv.RancherDeployIngress(ctx, testenv.RancherDeployIngressInput{
BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy,
HelmBinaryPath: flagVals.HelmBinaryPath,
HelmExtraValuesPath: filepath.Join(flagVals.HelmExtraValuesDir, "deploy-rancher-ingress.yaml"),
IsolatedMode: flagVals.IsolatedMode,
UseEKS: flagVals.UseEKS,
NginxIngress: e2e.NginxIngress,
NginxIngressNamespace: e2e.NginxIngressNamespace,
IngressType: ingressType,
CustomIngress: e2e.NginxIngress,
CustomIngressNamespace: e2e.NginxIngressNamespace,
CustomIngressDeployment: e2e.NginxIngressDeployment,
IngressWaitInterval: e2eConfig.GetIntervals(setupClusterResult.BootstrapClusterProxy.GetName(), "wait-rancher"),
NgrokApiKey: e2eConfig.GetVariable(e2e.NgrokApiKeyVar),
NgrokAuthToken: e2eConfig.GetVariable(e2e.NgrokAuthTokenVar),
Expand All @@ -125,6 +133,10 @@ var _ = BeforeSuite(func() {
DefaultIngressClassPatch: e2e.IngressClassPatch,
})

if flagVals.IsolatedMode {
hostName = setupClusterResult.IsolatedHostName
}

rancherInput := testenv.DeployRancherInput{
BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy,
HelmBinaryPath: flagVals.HelmBinaryPath,
Expand Down
Loading

0 comments on commit 57a316b

Please sign in to comment.