diff --git a/test/framework/clusterctl/client.go b/test/framework/clusterctl/client.go index 698a7029e5d0..bb517bbb5213 100644 --- a/test/framework/clusterctl/client.go +++ b/test/framework/clusterctl/client.go @@ -33,6 +33,11 @@ import ( // Provide E2E friendly wrappers for the clusterctl client library. +const ( + // DefaultFlavor for ConfigClusterInput; use it for getting the cluster-template.yaml file. + DefaultFlavor = "" +) + // InitInput is the input for Init. type InitInput struct { LogPath string @@ -46,12 +51,12 @@ type InitInput struct { // Init calls clusterctl init with the list of providers defined in the local repository func Init(ctx context.Context, input InitInput) { - By(fmt.Sprintf("clusterctl init --core %s --bootstrap %s --control-plane %s --infrastructure %s", + fmt.Fprintf(GinkgoWriter, "clusterctl init --core %s --bootstrap %s --control-plane %s --infrastructure %s\n", input.CoreProvider, strings.Join(input.BootstrapProviders, ", "), strings.Join(input.ControlPlaneProviders, ", "), strings.Join(input.InfrastructureProviders, ", "), - )) + ) initOpt := clusterctlclient.InitOptions{ Kubeconfig: input.KubeconfigPath, @@ -75,32 +80,36 @@ type ConfigClusterInput struct { ClusterctlConfigPath string KubeconfigPath string InfrastructureProvider string + Namespace string ClusterName string KubernetesVersion string ControlPlaneMachineCount *int64 WorkerMachineCount *int64 + Flavor string } // ConfigCluster gets a workload cluster based on a template. func ConfigCluster(ctx context.Context, input ConfigClusterInput) []byte { - By(fmt.Sprintf("clusterctl config cluster %s --infrastructure %s --kubernetes-version %s --control-plane-machine-count %d --worker-machine-count %s", + fmt.Fprintf(GinkgoWriter, "clusterctl config cluster %s --infrastructure %s --kubernetes-version %s --control-plane-machine-count %d --worker-machine-count %d --flavor %s\n", input.ClusterName, - input.InfrastructureProvider, + valueOrDefault(input.InfrastructureProvider), input.KubernetesVersion, - input.ControlPlaneMachineCount, - input.WorkerMachineCount, - )) + *input.ControlPlaneMachineCount, + *input.WorkerMachineCount, + valueOrDefault(input.Flavor), + ) templateOptions := clusterctlclient.GetClusterTemplateOptions{ Kubeconfig: input.KubeconfigPath, ProviderRepositorySource: &clusterctlclient.ProviderRepositorySourceOptions{ InfrastructureProvider: input.InfrastructureProvider, - Flavor: "", + Flavor: input.Flavor, }, ClusterName: input.ClusterName, KubernetesVersion: input.KubernetesVersion, ControlPlaneMachineCount: input.ControlPlaneMachineCount, WorkerMachineCount: input.WorkerMachineCount, + TargetNamespace: input.Namespace, } clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, "clusterctl-config-cluster.log", input.LogPath) @@ -153,3 +162,10 @@ func getClusterctlClientWithLogger(configPath, logName, logPath string) (cluster Expect(err).ToNot(HaveOccurred(), "Failed to create the clusterctl client library") return c, log } + +func valueOrDefault(v string) string { + if v != "" { + return v + } + return "(default)" +} diff --git a/test/framework/clusterctl/e2e_config.go b/test/framework/clusterctl/e2e_config.go index 945967930d62..3f24b2161ae4 100644 --- a/test/framework/clusterctl/e2e_config.go +++ b/test/framework/clusterctl/e2e_config.go @@ -43,9 +43,6 @@ import ( type LoadE2EConfigInput struct { // ConfigPath for the e2e test. ConfigPath string - - // BasePath to be used as a base for relative paths in the e2e config file. - BasePath string } // LoadE2EConfig loads the configuration for the e2e test environment. @@ -58,7 +55,7 @@ func LoadE2EConfig(ctx context.Context, input LoadE2EConfigInput) *E2EConfig { Expect(yaml.Unmarshal(configData, config)).To(Succeed(), "Failed to convert the e2e test config file to yaml") config.Defaults() - config.AbsPaths(input.BasePath) + config.AbsPaths(filepath.Dir(input.ConfigPath)) Expect(config.Validate()).To(Succeed(), "The e2e test config file is not valid") @@ -325,20 +322,26 @@ func fileExists(filename string) bool { } // InfraProvider returns the infrastructure provider selected for running this E2E test. -func (c *E2EConfig) InfraProvider() string { - for _, providerConfig := range c.Providers { - if providerConfig.Type == string(clusterctlv1.InfrastructureProviderType) { - return providerConfig.Name +func (c *E2EConfig) InfraProviders() []string { + InfraProviders := []string{} + for _, provider := range c.Providers { + if provider.Type == string(clusterctlv1.InfrastructureProviderType) { + InfraProviders = append(InfraProviders, provider.Name) } } - panic("it is required to have an infra provider in the config") + return InfraProviders } -// IntervalsOrDefault returns the intervals to be applied to a Eventually operation. -func (c *E2EConfig) IntervalsOrDefault(key string, defaults ...interface{}) []interface{} { - intervals, ok := c.Intervals[key] +// GetIntervals returns the intervals to be applied to a Eventually operation. +// It searches for [spec]/[key] intervals first, and if it is not found, it searches +// for default/[key]. If also the default/[key] intervals are not found, +// ginkgo DefaultEventuallyTimeout and DefaultEventuallyPollingInterval are used. +func (c *E2EConfig) GetIntervals(spec, key string) []interface{} { + intervals, ok := c.Intervals[fmt.Sprintf("%s/%s", spec, key)] if !ok { - return defaults + if intervals, ok = c.Intervals[fmt.Sprintf("default/%s", key)]; !ok { + return nil + } } intervalsInterfaces := make([]interface{}, len(intervals)) for i := range intervals { diff --git a/test/framework/clusterctl/repository.go b/test/framework/clusterctl/repository.go index 0a8c720993dc..2d949563227f 100644 --- a/test/framework/clusterctl/repository.go +++ b/test/framework/clusterctl/repository.go @@ -34,17 +34,17 @@ import ( // CreateRepositoryInput is the input for CreateRepository. type CreateRepositoryInput struct { - ArtifactsPath string - E2EConfig *E2EConfig + RepositoryFolder string + E2EConfig *E2EConfig } // CreateRepository creates a clusterctl local repository based on the e2e test config, and the returns the path // to a clusterctl config file to be used for working with such repository. func CreateRepository(ctx context.Context, input CreateRepositoryInput) string { Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling CreateRepository") + Expect(os.MkdirAll(input.RepositoryFolder, 0755)).To(Succeed(), "Failed to create the clusterctl local repository folder %s", input.RepositoryFolder) providers := []providerConfig{} - repositoryPath := filepath.Join(input.ArtifactsPath, "repository") for _, provider := range input.E2EConfig.Providers { providerUrl := "" for _, version := range provider.Versions { @@ -54,7 +54,7 @@ func CreateRepository(ctx context.Context, input CreateRepositoryInput) string { manifest, err := generator.Manifests(ctx) Expect(err).ToNot(HaveOccurred(), "Failed to generate the manifest for %q / %q", providerLabel, version.Name) - sourcePath := filepath.Join(repositoryPath, providerLabel, version.Name) + sourcePath := filepath.Join(input.RepositoryFolder, providerLabel, version.Name) Expect(os.MkdirAll(sourcePath, 0755)).To(Succeed(), "Failed to create the clusterctl local repository folder for %q / %q", providerLabel, version.Name) filePath := filepath.Join(sourcePath, "components.yaml") @@ -80,12 +80,12 @@ func CreateRepository(ctx context.Context, input CreateRepositoryInput) string { } // set this path to an empty file under the repository path, so test can run in isolation without user's overrides kicking in - overridePath := filepath.Join(repositoryPath, "overrides") + overridePath := filepath.Join(input.RepositoryFolder, "overrides") Expect(os.MkdirAll(overridePath, 0755)).To(Succeed(), "Failed to create the clusterctl overrides folder %q", overridePath) // creates a clusterctl config file to be used for working with such repository clusterctlConfigFile := &clusterctlConfig{ - Path: filepath.Join(repositoryPath, "clusterctl-config.yaml"), + Path: filepath.Join(input.RepositoryFolder, "clusterctl-config.yaml"), Values: map[string]interface{}{ "providers": providers, "overridesFolder": overridePath,