From 08f9450f6637caade16eba930959362d36557929 Mon Sep 17 00:00:00 2001 From: Kyle Squizzato Date: Thu, 5 Sep 2024 08:06:25 -0700 Subject: [PATCH] Rename deployment package to managedcluster Signed-off-by: Kyle Squizzato --- test/e2e/e2e_test.go | 42 +++++++++---------- .../managedcluster.go} | 28 ++++++------- .../resources/aws-hosted-cp.yaml.tpl | 0 .../resources/aws-standalone-cp.yaml.tpl | 0 .../validate_deleted.go | 2 +- .../validate_deployed.go | 2 +- test/utils/utils.go | 4 ++ 7 files changed, 39 insertions(+), 39 deletions(-) rename test/{deployment/deployment.go => managedcluster/managedcluster.go} (69%) rename test/{deployment => managedcluster}/resources/aws-hosted-cp.yaml.tpl (100%) rename test/{deployment => managedcluster}/resources/aws-standalone-cp.yaml.tpl (100%) rename test/{deployment => managedcluster}/validate_deleted.go (99%) rename test/{deployment => managedcluster}/validate_deployed.go (99%) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 7d27c93dd..695e104ba 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -30,8 +30,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" - "github.com/Mirantis/hmc/test/deployment" "github.com/Mirantis/hmc/test/kubeclient" + "github.com/Mirantis/hmc/test/managedcluster" "github.com/Mirantis/hmc/test/utils" ) @@ -67,13 +67,13 @@ var _ = Describe("controller", Ordered, func() { return err } - for _, provider := range []deployment.ProviderType{ - deployment.ProviderCAPI, - deployment.ProviderAWS, - deployment.ProviderAzure, + for _, provider := range []managedcluster.ProviderType{ + managedcluster.ProviderCAPI, + managedcluster.ProviderAWS, + managedcluster.ProviderAzure, } { // Ensure only one controller pod is running. - if err := verifyControllerUp(kc, deployment.GetProviderLabel(provider), string(provider)); err != nil { + if err := verifyControllerUp(kc, managedcluster.GetProviderLabel(provider), string(provider)); err != nil { return err } } @@ -112,7 +112,7 @@ var _ = Describe("controller", Ordered, func() { // as well as the output of clusterctl to store as artifacts. if CurrentSpecReport().Failed() { By("collecting failure logs from controllers") - collectLogArtifacts(kc, clusterName, deployment.ProviderAWS, deployment.ProviderCAPI) + collectLogArtifacts(kc, clusterName, managedcluster.ProviderAWS, managedcluster.ProviderCAPI) } // Delete the deployments if they were created. @@ -132,15 +132,15 @@ var _ = Describe("controller", Ordered, func() { ExpectWithOffset(2, err).NotTo(HaveOccurred()) }) - for _, template := range []deployment.Template{deployment.TemplateAWSStandaloneCP, deployment.TemplateAWSHostedCP} { + for _, template := range []managedcluster.Template{managedcluster.TemplateAWSStandaloneCP, managedcluster.TemplateAWSHostedCP} { It(fmt.Sprintf("should work with an AWS provider and %s template", template), func() { - if template == deployment.TemplateAWSHostedCP { + if template == managedcluster.TemplateAWSHostedCP { // TODO: Create AWS resources for hosted control plane. Skip("AWS hosted control plane not yet implemented") } By("creating a Deployment") - d := deployment.GetUnstructuredDeployment(deployment.ProviderAWS, template) + d := managedcluster.GetUnstructured(managedcluster.ProviderAWS, template) clusterName = d.GetName() deleteFunc, err = kc.CreateDeployment(context.Background(), d) @@ -148,14 +148,14 @@ var _ = Describe("controller", Ordered, func() { By("waiting for infrastructure providers to deploy successfully") Eventually(func() error { - return deployment.VerifyProviderDeployed(context.Background(), kc, clusterName) + return managedcluster.VerifyProviderDeployed(context.Background(), kc, clusterName) }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) By("verify the deployment deletes successfully") err = deleteFunc() Expect(err).NotTo(HaveOccurred()) Eventually(func() error { - return deployment.VerifyProviderDeleted(context.Background(), kc, clusterName) + return managedcluster.VerifyProviderDeleted(context.Background(), kc, clusterName) }).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) }) } @@ -197,13 +197,13 @@ func verifyControllerUp(kc *kubeclient.KubeClient, labelSelector string, name st // CAPI controller and the provider controller(s) as well as output from clusterctl // and stores them in the test/e2e directory as artifacts. If it fails it // produces a warning message to the GinkgoWriter, but does not fail the test. -func collectLogArtifacts(kc *kubeclient.KubeClient, clusterName string, providerTypes ...deployment.ProviderType) { +func collectLogArtifacts(kc *kubeclient.KubeClient, clusterName string, providerTypes ...managedcluster.ProviderType) { GinkgoHelper() filterLabels := []string{hmcControllerLabel} for _, providerType := range providerTypes { - filterLabels = append(filterLabels, deployment.GetProviderLabel(providerType)) + filterLabels = append(filterLabels, managedcluster.GetProviderLabel(providerType)) } for _, label := range filterLabels { @@ -217,14 +217,14 @@ func collectLogArtifacts(kc *kubeclient.KubeClient, clusterName string, provider }) podLogs, err := req.Stream(context.Background()) if err != nil { - warnError(fmt.Errorf("failed to get log stream for pod %s: %w", pod.Name, err)) + utils.WarnError(fmt.Errorf("failed to get log stream for pod %s: %w", pod.Name, err)) continue } defer podLogs.Close() //nolint:errcheck output, err := os.Create(fmt.Sprintf("./test/e2e/%s.log", pod.Name)) if err != nil { - warnError(fmt.Errorf("failed to create log file for pod %s: %w", pod.Name, err)) + utils.WarnError(fmt.Errorf("failed to create log file for pod %s: %w", pod.Name, err)) continue } defer output.Close() //nolint:errcheck @@ -232,7 +232,7 @@ func collectLogArtifacts(kc *kubeclient.KubeClient, clusterName string, provider r := bufio.NewReader(podLogs) _, err = r.WriteTo(output) if err != nil { - warnError(fmt.Errorf("failed to write log file for pod %s: %w", pod.Name, err)) + utils.WarnError(fmt.Errorf("failed to write log file for pod %s: %w", pod.Name, err)) } } } @@ -241,16 +241,12 @@ func collectLogArtifacts(kc *kubeclient.KubeClient, clusterName string, provider "describe", "cluster", clusterName, "--namespace", namespace, "--show-conditions=all") output, err := utils.Run(cmd) if err != nil { - warnError(fmt.Errorf("failed to get clusterctl log: %w", err)) + utils.WarnError(fmt.Errorf("failed to get clusterctl log: %w", err)) return } err = os.WriteFile(filepath.Join("test/e2e", "clusterctl.log"), output, 0644) if err != nil { - warnError(fmt.Errorf("failed to write clusterctl log: %w", err)) + utils.WarnError(fmt.Errorf("failed to write clusterctl log: %w", err)) } } - -func warnError(err error) { - _, _ = fmt.Fprintf(GinkgoWriter, "Warning: %v\n", err) -} diff --git a/test/deployment/deployment.go b/test/managedcluster/managedcluster.go similarity index 69% rename from test/deployment/deployment.go rename to test/managedcluster/managedcluster.go index 102f65812..28783ea5d 100644 --- a/test/deployment/deployment.go +++ b/test/managedcluster/managedcluster.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package deployment +package managedcluster import ( _ "embed" @@ -45,18 +45,18 @@ const ( ) //go:embed resources/aws-standalone-cp.yaml.tpl -var awsStandaloneCPDeploymentTemplateBytes []byte +var awsStandaloneCPManagedClusterTemplateBytes []byte //go:embed resources/aws-hosted-cp.yaml.tpl -var awsHostedCPDeploymentTemplateBytes []byte +var awsHostedCPManagedClusterTemplateBytes []byte func GetProviderLabel(provider ProviderType) string { return fmt.Sprintf("%s=%s", providerLabel, provider) } -// GetUnstructuredDeployment returns an unstructured deployment object based on -// the provider and template. -func GetUnstructuredDeployment(provider ProviderType, templateName Template) *unstructured.Unstructured { +// GetUnstructured returns an unstructured ManagedCluster object based on the +// provider and template. +func GetUnstructured(provider ProviderType, templateName Template) *unstructured.Unstructured { GinkgoHelper() generatedName := uuid.New().String()[:8] + "-e2e-test" @@ -64,27 +64,27 @@ func GetUnstructuredDeployment(provider ProviderType, templateName Template) *un switch provider { case ProviderAWS: - Expect(os.Setenv("DEPLOYMENT_NAME", generatedName)).NotTo(HaveOccurred()) + Expect(os.Setenv("MANAGED_CLUSTER_NAME", generatedName)).NotTo(HaveOccurred()) - var deploymentTemplateBytes []byte + var managedClusterTemplateBytes []byte switch templateName { case TemplateAWSStandaloneCP: - deploymentTemplateBytes = awsStandaloneCPDeploymentTemplateBytes + managedClusterTemplateBytes = awsStandaloneCPManagedClusterTemplateBytes case TemplateAWSHostedCP: - deploymentTemplateBytes = awsHostedCPDeploymentTemplateBytes + managedClusterTemplateBytes = awsHostedCPManagedClusterTemplateBytes default: Fail(fmt.Sprintf("unsupported AWS template: %s", templateName)) } - deploymentConfigBytes, err := envsubst.Bytes(deploymentTemplateBytes) + managedClusterConfigBytes, err := envsubst.Bytes(managedClusterTemplateBytes) Expect(err).NotTo(HaveOccurred(), "failed to substitute environment variables") - var deploymentConfig map[string]interface{} + var managedClusterConfig map[string]interface{} - err = yaml.Unmarshal(deploymentConfigBytes, &deploymentConfig) + err = yaml.Unmarshal(managedClusterConfigBytes, &managedClusterConfig) Expect(err).NotTo(HaveOccurred(), "failed to unmarshal deployment config") - return &unstructured.Unstructured{Object: deploymentConfig} + return &unstructured.Unstructured{Object: managedClusterConfig} default: Fail(fmt.Sprintf("unsupported provider: %s", provider)) } diff --git a/test/deployment/resources/aws-hosted-cp.yaml.tpl b/test/managedcluster/resources/aws-hosted-cp.yaml.tpl similarity index 100% rename from test/deployment/resources/aws-hosted-cp.yaml.tpl rename to test/managedcluster/resources/aws-hosted-cp.yaml.tpl diff --git a/test/deployment/resources/aws-standalone-cp.yaml.tpl b/test/managedcluster/resources/aws-standalone-cp.yaml.tpl similarity index 100% rename from test/deployment/resources/aws-standalone-cp.yaml.tpl rename to test/managedcluster/resources/aws-standalone-cp.yaml.tpl diff --git a/test/deployment/validate_deleted.go b/test/managedcluster/validate_deleted.go similarity index 99% rename from test/deployment/validate_deleted.go rename to test/managedcluster/validate_deleted.go index cca0bdaeb..dc5712a9f 100644 --- a/test/deployment/validate_deleted.go +++ b/test/managedcluster/validate_deleted.go @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -package deployment +package managedcluster import ( "context" diff --git a/test/deployment/validate_deployed.go b/test/managedcluster/validate_deployed.go similarity index 99% rename from test/deployment/validate_deployed.go rename to test/managedcluster/validate_deployed.go index f7e6f14a7..f6423fb2b 100644 --- a/test/deployment/validate_deployed.go +++ b/test/managedcluster/validate_deployed.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package deployment +package managedcluster import ( "context" diff --git a/test/utils/utils.go b/test/utils/utils.go index e6283fa74..4e0d767f4 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -178,3 +178,7 @@ func ValidateObjectNamePrefix(unstrObj *unstructured.Unstructured, clusterName s func ObjKindName(unstrObj *unstructured.Unstructured) (string, string) { return unstrObj.GetKind(), unstrObj.GetName() } + +func WarnError(err error) { + _, _ = fmt.Fprintf(GinkgoWriter, "Warning: %v\n", err) +}