From 754004fd33737e3e7a85e14fd703202bf2f1df6f Mon Sep 17 00:00:00 2001 From: Humair Khan Date: Tue, 24 Oct 2023 17:45:42 -0400 Subject: [PATCH] Clean up integration test suite. Use constant variables. Remove unused variables in kind tests. Consistent yaml formatting. Clarify readme. Signed-off-by: Humair Khan --- .github/workflows/kind-integration.yml | 3 -- Makefile | 3 +- config/overlays/kind-tests/kustomization.yaml | 14 ++--- tests/README.md | 5 +- tests/suite_test.go | 51 ++++++++++++------- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/.github/workflows/kind-integration.yml b/.github/workflows/kind-integration.yml index 6c3ca8d7c..7b30055f7 100644 --- a/.github/workflows/kind-integration.yml +++ b/.github/workflows/kind-integration.yml @@ -20,9 +20,6 @@ concurrency: env: IMAGE_REPO_DSPO: data-science-pipelines-operator - QUAY_ORG: hukhan - QUAY_ID: ${{ secrets.QUAY_ID }} - QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} DSPA_NAMESPACE: test-dspa DSPA_NAME: test-dspa DSPA_DEPLOY_WAIT_TIMEOUT: 300 diff --git a/Makefile b/Makefile index bce0333dc..b34d97557 100644 --- a/Makefile +++ b/Makefile @@ -195,7 +195,8 @@ argoundeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/c .PHONY: undeploy-kind undeploy-kind: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. - cd config/overlays/kind-tests && kustomize edit set namespace ${OPERATOR_NS} + cd config/overlays/kind-tests \ + && kustomize edit set namespace ${OPERATOR_NS} kustomize build config/overlays/kind-tests | kubectl delete --ignore-not-found=$(ignore-not-found) -f - ##@ Build Dependencies diff --git a/config/overlays/kind-tests/kustomization.yaml b/config/overlays/kind-tests/kustomization.yaml index 53cef8e69..b4959b1c7 100644 --- a/config/overlays/kind-tests/kustomization.yaml +++ b/config/overlays/kind-tests/kustomization.yaml @@ -2,12 +2,12 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namespace: odh-applications resources: -- ../../base + - ../../base patchesStrategicMerge: -- img_patch.yaml -- res_patch.yaml -- user_patch.yaml + - img_patch.yaml + - res_patch.yaml + - user_patch.yaml images: -- name: controller - newName: quay.io/opendatahub/data-science-pipelines-operator - newTag: main + - name: controller + newName: quay.io/opendatahub/data-science-pipelines-operator + newTag: main diff --git a/tests/README.md b/tests/README.md index 3461d1197..17a806646 100644 --- a/tests/README.md +++ b/tests/README.md @@ -26,16 +26,17 @@ afterwards. # Adjust the following as needed KUBECONFIG_PATH=$HOME/.kube/config # this is usually the default TARGET_CLUSTER=...(e.g. https://api.hukhan.dev.datahub.redhat.com:6443, you can retrieve this via `oc whoami --show-server`) -TARGET_NAMESPACE=dspa +TARGET_NAMESPACE=dspa # Do not use the same namespace as where DSPO is deployed (otherwise you will encounter some failed tests that verify DSPA deployment). git clone git@github.com:opendatahub-io/data-science-pipelines-operator.git ${DSPO_REPO} # Make sure DSPO is already deployed, if not then run: +oc new-project odh-applications make deploy make integrationtest \ K8SAPISERVERHOST=${TARGET_CLUSTER} \ - DSPANAMESPACE=${NAMESPACE} \ + DSPANAMESPACE=${TARGET_NAMESPACE} \ KUBECONFIGPATH=${KUBECONFIG_PATH} ``` diff --git a/tests/suite_test.go b/tests/suite_test.go index 597263a5c..48990e451 100644 --- a/tests/suite_test.go +++ b/tests/suite_test.go @@ -66,9 +66,22 @@ var ( ) var ( - DefaultDeployTimeout time.Duration - DefaultPollInterval time.Duration - DefaultDeleteTimeout time.Duration + DeployTimeout time.Duration + PollInterval time.Duration + DeleteTimeout time.Duration +) + +const ( + DefaultKubeConfigPath = "~/.kube/config" + Defaultk8sApiServerHost = "localhost:6443" + DefaultDSPANamespace = "default" + DefaultDeployTimeout = 240 + DefaultPollInterval = 2 + DefaultDeleteTimeout = 120 + DefaultPortforwardLocalPort = 8888 + DefaultSkipDeploy = false + DefaultSkipCleanup = false + DefaultDSPAPath = "" ) type ClientManager struct { @@ -94,23 +107,23 @@ func TestAPIs(t *testing.T) { // Register flags in an init function. This ensures they are registered _before_ `go test` calls flag.Parse() func init() { - flag.StringVar(&kubeconfig, "kubeconfig", "~/.kube/config", "The path to the kubeconfig.") - flag.StringVar(&k8sApiServerHost, "k8sApiServerHost", "localhost:6443", "The k8s cluster api server host.") - flag.StringVar(&DSPAPath, "DSPAPath", "", "The DSP resource file to deploy for testing.") - flag.StringVar(&DSPANamespace, "DSPANamespace", "default", "The namespace to deploy DSPA.") + flag.StringVar(&kubeconfig, "kubeconfig", DefaultKubeConfigPath, "The path to the kubeconfig.") + flag.StringVar(&k8sApiServerHost, "k8sApiServerHost", Defaultk8sApiServerHost, "The k8s cluster api server host.") + flag.StringVar(&DSPAPath, "DSPAPath", DefaultDSPAPath, "The DSP resource file to deploy for testing.") + flag.StringVar(&DSPANamespace, "DSPANamespace", DefaultDSPANamespace, "The namespace to deploy DSPA.") - flag.DurationVar(&DefaultDeployTimeout, "DefaultDeployTimeout", 240, "Seconds to wait for deployments. Consider increasing this on resource starved environments.") - DefaultDeployTimeout *= time.Second - flag.DurationVar(&DefaultPollInterval, "DefaultPollInterval", 2, "Seconds to wait before retrying fetches to the api server.") - DefaultPollInterval *= time.Second - flag.DurationVar(&DefaultDeleteTimeout, "DefaultDeleteTimeout", 120, "Seconds to wait for deployment deletions. Consider increasing this on resource starved environments.") - DefaultDeleteTimeout *= time.Second + flag.DurationVar(&DeployTimeout, "DeployTimeout", DefaultDeployTimeout, "Seconds to wait for deployments. Consider increasing this on resource starved environments.") + DeployTimeout *= time.Second + flag.DurationVar(&PollInterval, "PollInterval", DefaultPollInterval, "Seconds to wait before retrying fetches to the api server.") + PollInterval *= time.Second + flag.DurationVar(&DeleteTimeout, "DeleteTimeout", DefaultDeleteTimeout, "Seconds to wait for deployment deletions. Consider increasing this on resource starved environments.") + DeleteTimeout *= time.Second - flag.IntVar(&PortforwardLocalPort, "PortforwardLocalPort", 8888, "Local port to use for port forwarding dspa server.") + flag.IntVar(&PortforwardLocalPort, "PortforwardLocalPort", DefaultPortforwardLocalPort, "Local port to use for port forwarding dspa server.") - flag.BoolVar(&skipDeploy, "skipDeploy", false, "Skip DSPA deployment. Use this if you have already "+ + flag.BoolVar(&skipDeploy, "skipDeploy", DefaultSkipDeploy, "Skip DSPA deployment. Use this if you have already "+ "manually deployed a DSPA, and want to skip this part.") - flag.BoolVar(&skipCleanup, "skipCleanup", false, "Skip DSPA cleanup.") + flag.BoolVar(&skipCleanup, "skipCleanup", DefaultSkipCleanup, "Skip DSPA cleanup.") } var _ = BeforeSuite(func() { @@ -147,9 +160,9 @@ var _ = BeforeSuite(func() { if !skipDeploy { loggr.Info("Deploying DSPA...") - systemsTesttUtil.DeployDSPA(ctx, clientmgr.k8sClient, DSPA, DSPANamespace, DefaultDeployTimeout, DefaultPollInterval) + systemsTesttUtil.DeployDSPA(ctx, clientmgr.k8sClient, DSPA, DSPANamespace, DeployTimeout, PollInterval) loggr.Info("Waiting for DSPA pods to ready...") - systemsTesttUtil.WaitForDSPAReady(ctx, clientmgr.k8sClient, DSPA.Name, DSPANamespace, DefaultDeployTimeout, DefaultPollInterval) + systemsTesttUtil.WaitForDSPAReady(ctx, clientmgr.k8sClient, DSPA.Name, DSPANamespace, DeployTimeout, PollInterval) loggr.Info("DSPA Deployed.") } @@ -185,7 +198,7 @@ var _ = BeforeEach(func() { var _ = AfterSuite(func() { if !skipCleanup { - systemsTesttUtil.DeleteDSPA(ctx, clientmgr.k8sClient, DSPA.Name, DSPANamespace, DefaultDeployTimeout, DefaultPollInterval) + systemsTesttUtil.DeleteDSPA(ctx, clientmgr.k8sClient, DSPA.Name, DSPANamespace, DeployTimeout, PollInterval) } forwarderResult.Close() })