sigs.k8s.io/cluster-api-provider-aws@v1.5.5/test/e2e/shared/temp.go (about) 1 //go:build e2e 2 // +build e2e 3 4 /* 5 Copyright 2020 The Kubernetes Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package shared 21 22 import ( 23 "context" 24 "os" 25 "path/filepath" 26 27 . "github.com/onsi/ginkgo" 28 . "github.com/onsi/gomega" 29 "sigs.k8s.io/yaml" 30 31 "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config" 32 "sigs.k8s.io/cluster-api/test/framework" 33 "sigs.k8s.io/cluster-api/test/framework/clusterctl" 34 ) 35 36 // NOTE: these are temporary local functions as the CAPI e2e framework assumes kubeadm 37 // in a number of places. These can be removed when the following is fixed: 38 // https://github.com/kubernetes-sigs/cluster-api/issues/3983 39 40 type InitManagementClusterAndWatchControllerLogsInput struct { 41 ClusterProxy framework.ClusterProxy 42 ClusterctlConfigPath string 43 InfrastructureProviders []string 44 BootstrapProviders []string 45 ControlPlaneProviders []string 46 LogFolder string 47 DisableMetricsCollection bool 48 } 49 50 func InitManagementClusterAndWatchControllerLogs(ctx context.Context, input InitManagementClusterAndWatchControllerLogsInput, intervals ...interface{}) { 51 Expect(ctx).NotTo(BeNil(), "ctx is required for InitManagementClusterAndWatchControllerLogs") 52 Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling InitManagementClusterAndWatchControllerLogs") 53 Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling InitManagementClusterAndWatchControllerLogs") 54 Expect(input.InfrastructureProviders).ToNot(BeEmpty(), "Invalid argument. input.InfrastructureProviders can't be empty when calling InitManagementClusterAndWatchControllerLogs") 55 Expect(os.MkdirAll(input.LogFolder, 0755)).To(Succeed(), "Invalid argument. input.LogFolder can't be created for InitManagementClusterAndWatchControllerLogs") 56 57 client := input.ClusterProxy.GetClient() 58 controllersDeployments := framework.GetControllerDeployments(context.TODO(), framework.GetControllerDeploymentsInput{ 59 Lister: client, 60 }) 61 if len(controllersDeployments) == 0 { 62 clusterctl.Init(context.TODO(), clusterctl.InitInput{ 63 // pass reference to the management cluster hosting this test 64 KubeconfigPath: input.ClusterProxy.GetKubeconfigPath(), 65 // pass the clusterctl generate file that points to the local provider repository created for this test 66 ClusterctlConfigPath: input.ClusterctlConfigPath, 67 // setup the desired list of providers for a single-tenant management cluster 68 CoreProvider: config.ClusterAPIProviderName, 69 BootstrapProviders: input.BootstrapProviders, 70 ControlPlaneProviders: input.ControlPlaneProviders, 71 InfrastructureProviders: input.InfrastructureProviders, 72 // setup clusterctl logs folder 73 LogFolder: input.LogFolder, 74 }) 75 } 76 77 By("Waiting for provider controllers to be running") 78 controllersDeployments = framework.GetControllerDeployments(context.TODO(), framework.GetControllerDeploymentsInput{ 79 Lister: client, 80 }) 81 Expect(controllersDeployments).ToNot(BeEmpty(), "The list of controller deployments should not be empty") 82 for _, deployment := range controllersDeployments { 83 framework.WaitForDeploymentsAvailable(context.TODO(), framework.WaitForDeploymentsAvailableInput{ 84 Getter: client, 85 Deployment: deployment, 86 }, intervals...) 87 88 // Start streaming logs from all controller providers 89 framework.WatchDeploymentLogs(context.TODO(), framework.WatchDeploymentLogsInput{ 90 GetLister: client, 91 ClientSet: input.ClusterProxy.GetClientSet(), 92 Deployment: deployment, 93 LogPath: filepath.Join(input.LogFolder, "controllers"), 94 }) 95 96 if input.DisableMetricsCollection { 97 return 98 } 99 framework.WatchPodMetrics(ctx, framework.WatchPodMetricsInput{ 100 GetLister: client, 101 ClientSet: input.ClusterProxy.GetClientSet(), 102 Deployment: deployment, 103 MetricsPath: filepath.Join(input.LogFolder, "controllers"), 104 }) 105 } 106 } 107 108 func localLoadE2EConfig(configPath string) *clusterctl.E2EConfig { 109 configData, err := os.ReadFile(configPath) //nolint:gosec 110 Expect(err).ToNot(HaveOccurred(), "Failed to read the e2e test config file") 111 Expect(configData).ToNot(BeEmpty(), "The e2e test config file should not be empty") 112 113 config := &clusterctl.E2EConfig{} 114 Expect(yaml.Unmarshal(configData, config)).To(Succeed(), "Failed to convert the e2e test config file to yaml") 115 116 config.Defaults() 117 config.AbsPaths(filepath.Dir(configPath)) 118 119 // TODO: this is the reason why we can't use this at present for the EKS tests 120 // Expect(config.Validate()).To(Succeed(), "The e2e test config file is not valid") 121 122 return config 123 }