diff --git a/Makefile b/Makefile index ccb568288..c382a8867 100644 --- a/Makefile +++ b/Makefile @@ -199,7 +199,7 @@ KIND_CLUSTER_NAME ?= hmc-dev KIND_NETWORK ?= kind REGISTRY_NAME ?= hmc-local-registry REGISTRY_PORT ?= 5001 -REGISTRY_REPO ?= oci://$(REGISTRY_NAME):5000/charts +REGISTRY_REPO ?= oci://127.0.0.1:$(REGISTRY_PORT)/charts DEV_PROVIDER ?= aws REGISTRY_IS_OCI = $(shell echo $(REGISTRY_REPO) | grep -q oci && echo true || echo false) CLUSTER_NAME ?= $(shell $(YQ) '.metadata.name' ./config/dev/deployment.yaml) @@ -245,9 +245,13 @@ hmc-deploy: helm .PHONY: dev-deploy dev-deploy: ## Deploy HMC helm chart to the K8s cluster specified in ~/.kube/config. - $(YQ) eval -i '.image.repository = "$(IMG_REPO)"' config/dev/hmc_values.yaml - $(YQ) eval -i '.image.tag = "$(IMG_TAG)"' config/dev/hmc_values.yaml - $(YQ) eval -i '.controller.defaultRegistryURL = "$(REGISTRY_REPO)"' config/dev/hmc_values.yaml + @$(YQ) eval -i '.image.repository = "$(IMG_REPO)"' config/dev/hmc_values.yaml + @$(YQ) eval -i '.image.tag = "$(IMG_TAG)"' config/dev/hmc_values.yaml + @if [ "$(REGISTRY_REPO)" = "oci://127.0.0.1:$(REGISTRY_PORT)/charts" ]; then \ + $(YQ) eval -i '.controller.defaultRegistryURL = "oci://$(REGISTRY_NAME):5000/charts"' config/dev/hmc_values.yaml; \ + else \ + $(YQ) eval -i '.controller.defaultRegistryURL = "$(REGISTRY_REPO)"' config/dev/hmc_values.yaml; \ + fi; \ $(MAKE) hmc-deploy HMC_VALUES=config/dev/hmc_values.yaml $(KUBECTL) rollout restart -n $(NAMESPACE) deployment/hmc-controller-manager diff --git a/config/dev/hmc_values.yaml b/config/dev/hmc_values.yaml index e81bfc3dc..6ae56befa 100644 --- a/config/dev/hmc_values.yaml +++ b/config/dev/hmc_values.yaml @@ -1,5 +1,6 @@ image: repository: hmc/controller + tag: latest controller: defaultRegistryURL: oci://hmc-local-registry:5000/charts insecureRegistry: true diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 825db4cda..a8f4d7eb6 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -119,6 +119,8 @@ var _ = Describe("controller", Ordered, func() { It("should work with an AWS provider", func() { // Deploy a standalone cluster and verify it is running/ready. + // Deploy standalone with an xlarge instance since it will also be + // hosting the hosted cluster. GinkgoT().Setenv(managedcluster.EnvVarAWSInstanceType, "t3.xlarge") GinkgoT().Setenv(managedcluster.EnvVarInstallBeachHeadServices, "false") @@ -129,8 +131,9 @@ var _ = Describe("controller", Ordered, func() { standaloneDeleteFunc = kc.CreateManagedCluster(context.Background(), sd) templateBy(managedcluster.TemplateAWSStandaloneCP, "waiting for infrastructure to deploy successfully") + resourcesToValidate := managedcluster.NewDeployedValidation() Eventually(func() error { - return managedcluster.VerifyProviderDeployed(context.Background(), kc, clusterName) + return managedcluster.VerifyProviderDeployed(context.Background(), kc, clusterName, resourcesToValidate) }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) templateBy(managedcluster.TemplateAWSHostedCP, "installing controller and templates on standalone cluster") @@ -195,19 +198,26 @@ var _ = Describe("controller", Ordered, func() { // Verify the hosted cluster is running/ready. templateBy(managedcluster.TemplateAWSHostedCP, "waiting for infrastructure to deploy successfully") + resourcesToValidate = managedcluster.NewDeployedValidation() Eventually(func() error { - return managedcluster.VerifyProviderDeployed(context.Background(), standaloneClient, hdName) + return managedcluster.VerifyProviderDeployed( + context.Background(), standaloneClient, hdName, resourcesToValidate, + ) }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) - // Delete the hosted ManagedCluster and verify it is removed. // FIXME: Do not test hosted-cp deletion until #242 is // resolved as it will just get stuck. - // templateBy(managedcluster.TemplateAWSHostedCP, "deleting the ManagedCluster") - // err = hostedDeleteFunc() - // Expect(err).NotTo(HaveOccurred()) - // Eventually(func() error { - // return managedcluster.VerifyProviderDeleted(context.Background(), standaloneClient, hdName) - // }).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + /* + // Delete the hosted ManagedCluster and verify it is removed. + templateBy(managedcluster.TemplateAWSHostedCP, "deleting the ManagedCluster") + err = hostedDeleteFunc() + Expect(err).NotTo(HaveOccurred()) + + resourcesToValidate = managedcluster.NewDeletionValidation() + Eventually(func() error { + return managedcluster.VerifyProviderDeleted(context.Background(), standaloneClient, hdName) + }).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + */ // Now delete the standalone ManagedCluster and verify it is // removed, it is deleted last since it is the basis for the hosted @@ -215,9 +225,14 @@ var _ = Describe("controller", Ordered, func() { templateBy(managedcluster.TemplateAWSStandaloneCP, "deleting the ManagedCluster") err = standaloneDeleteFunc() Expect(err).NotTo(HaveOccurred()) + + resourcesToValidate = managedcluster.NewDeletionValidation() Eventually(func() error { - return managedcluster.VerifyProviderDeleted(context.Background(), kc, clusterName) - }).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + return managedcluster.VerifyProviderDeleted( + context.Background(), kc, clusterName, resourcesToValidate, + ) + }).WithTimeout(10 * time.Minute).WithPolling(10 * + time.Second).Should(Succeed()) }) }) }) diff --git a/test/managedcluster/validate_deleted.go b/test/managedcluster/validate_deleted.go index dc5712a9f..990c262e2 100644 --- a/test/managedcluster/validate_deleted.go +++ b/test/managedcluster/validate_deleted.go @@ -23,17 +23,21 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) -var deletionValidators = map[string]resourceValidationFunc{ - "clusters": validateClusterDeleted, - "machinedeployments": validateMachineDeploymentsDeleted, - "control-planes": validateK0sControlPlanesDeleted, +func NewDeletionValidation() map[string]resourceValidationFunc { + return map[string]resourceValidationFunc{ + "clusters": validateClusterDeleted, + "machinedeployments": validateMachineDeploymentsDeleted, + "control-planes": validateK0sControlPlanesDeleted, + } } // VerifyProviderDeleted is a provider-agnostic verification that checks // to ensure generic resources managed by the provider have been deleted. // It is intended to be used in conjunction with an Eventually block. -func VerifyProviderDeleted(ctx context.Context, kc *kubeclient.KubeClient, clusterName string) error { - return verifyProviderAction(ctx, kc, clusterName, deletionValidators, +func VerifyProviderDeleted( + ctx context.Context, kc *kubeclient.KubeClient, clusterName string, + resourcesToValidate map[string]resourceValidationFunc) error { + return verifyProviderAction(ctx, kc, clusterName, resourcesToValidate, []string{"clusters", "machinedeployments", "control-planes"}) } diff --git a/test/managedcluster/validate_deployed.go b/test/managedcluster/validate_deployed.go index b1e4b96c5..1d6ab438a 100644 --- a/test/managedcluster/validate_deployed.go +++ b/test/managedcluster/validate_deployed.go @@ -34,19 +34,23 @@ import ( // resource. type resourceValidationFunc func(context.Context, *kubeclient.KubeClient, string) error -var resourceValidators = map[string]resourceValidationFunc{ - "clusters": validateCluster, - "machines": validateMachines, - "control-planes": validateK0sControlPlanes, - "csi-driver": validateCSIDriver, - "ccm": validateCCM, +func NewDeployedValidation() map[string]resourceValidationFunc { + return map[string]resourceValidationFunc{ + "clusters": validateCluster, + "machines": validateMachines, + "control-planes": validateK0sControlPlanes, + "csi-driver": validateCSIDriver, + "ccm": validateCCM, + } } // VerifyProviderDeployed is a provider-agnostic verification that checks // to ensure generic resources managed by the provider have been deleted. // It is intended to be used in conjunction with an Eventually block. -func VerifyProviderDeployed(ctx context.Context, kc *kubeclient.KubeClient, clusterName string) error { - return verifyProviderAction(ctx, kc, clusterName, resourceValidators, +func VerifyProviderDeployed( + ctx context.Context, kc *kubeclient.KubeClient, clusterName string, + resourceValidationMap map[string]resourceValidationFunc) error { + return verifyProviderAction(ctx, kc, clusterName, resourceValidationMap, []string{"clusters", "machines", "control-planes", "csi-driver", "ccm"}) }