From ccd3fcdd8268304f8edfa4d6a9308c335ed8bcbb Mon Sep 17 00:00:00 2001 From: Alexandre Lamarre Date: Mon, 13 Jan 2025 14:53:00 -0500 Subject: [PATCH] [WIP] importing images for integration CI Signed-off-by: Alexandre Lamarre --- .github/workflows/integration.yaml | 7 +++++-- go.mod | 1 + go.sum | 3 +++ .../helm-project-operator/e2e_suite_test.go | 19 +++++++++++++------ internal/helm-project-operator/e2e_test.go | 9 ++++----- scripts/integration | 2 +- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index fc468bf8..35ce1fcd 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -63,9 +63,12 @@ jobs: - name : Validate build run : ./scripts/validate-ci - name : Package helm-project-operator - run : BUILD_TARGET=helm-project-operator ./scripts/package + run : | + BUILD_TARGET=helm-project-operator ./scripts/package + source ./scripts/version + k3d image import -c test-cluster $IMAGE - name : Run e2e tests run : | - ./scripts/integration + KUBECONFIG=$KUBECONFIG ./scripts/integration env: KUBECONFIG: ${{ github.workspace }}/kubeconfig.yaml \ No newline at end of file diff --git a/go.mod b/go.mod index e6cbd3a6..20c19180 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 github.com/k3s-io/helm-controller v0.16.6-0.20241210112214-b40937ee695b github.com/kralicky/kmatch v0.0.0-20240603031752-4aaff7842056 + github.com/novln/docker-parser v1.0.0 github.com/onsi/ginkgo/v2 v2.22.2 github.com/onsi/gomega v1.36.2 github.com/rancher/lasso v0.0.0-20241202185148-04649f379358 diff --git a/go.sum b/go.sum index c734c4c1..fcfdcbec 100644 --- a/go.sum +++ b/go.sum @@ -162,6 +162,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/novln/docker-parser v1.0.0 h1:PjEBd9QnKixcWczNGyEdfUrP6GR0YUilAqG7Wksg3uc= +github.com/novln/docker-parser v1.0.0/go.mod h1:oCeM32fsoUwkwByB5wVjsrsVQySzPWkl3JdlTn1txpE= github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU= github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk= github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8= @@ -216,6 +218,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= diff --git a/internal/helm-project-operator/e2e_suite_test.go b/internal/helm-project-operator/e2e_suite_test.go index b6b200ad..b2e7dc5a 100644 --- a/internal/helm-project-operator/e2e_suite_test.go +++ b/internal/helm-project-operator/e2e_suite_test.go @@ -8,6 +8,7 @@ import ( "time" k3shelmv1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1" + dockerparse "github.com/novln/docker-parser" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" lockerv1alpha1 "github.com/rancher/prometheus-federator/internal/helm-locker/pkg/apis/helm.cattle.io/v1alpha1" @@ -44,14 +45,18 @@ var ( type TestSpec struct { Kubeconfig string `env:"KUBECONFIG,required"` - // HpoImage string `env:"IMAGE,required"` + HpoImage string `env:"IMAGE,required"` + + image *dockerparse.Reference } func (t *TestSpec) Validate() error { var errs []error - // if _, err := dockerparser.Parse(t.HpoImage); err != nil { - // errs = append(errs, err) - // } + im, err := dockerparse.Parse(t.HpoImage) + if err != nil { + errs = append(errs, err) + } + t.image = im if _, err := os.Stat(t.Kubeconfig); err != nil { errs = append(errs, err) } @@ -62,11 +67,13 @@ func (t *TestSpec) Validate() error { return nil } +var ( + ts = TestSpec{} +) + var _ = BeforeSuite(func() { - ts := TestSpec{} Expect(env.Parse(&ts)).To(Succeed(), "Could not parse test spec from environment variables") Expect(ts.Validate()).To(Succeed(), "Invalid input e2e test spec") - ctxCa, ca := context.WithCancel(context.Background()) DeferCleanup(func() { ca() diff --git a/internal/helm-project-operator/e2e_test.go b/internal/helm-project-operator/e2e_test.go index 59f02970..531ae72e 100644 --- a/internal/helm-project-operator/e2e_test.go +++ b/internal/helm-project-operator/e2e_test.go @@ -108,7 +108,6 @@ func newHelmInstaller(opts ...helmInstallerOption) *helmInstaller { opt(&h.helmInstallOptions) } return h - } func helmInstallerDefaultOptions() helmInstallOptions { @@ -228,9 +227,9 @@ var _ = Describe("E2E helm project operator tests", Ordered, Label("kubernetes") WithCreateNamespace(), WithNamespace(chartNs), WithReleaseName("helm-project-operator"), - WithChartRegistry("./charts/helm-project-operator"), - WithValue("image.repository", "rancher/helm-project-operator"), - WithValue("image.tag", "dev"), + WithChartRegistry("../../packages/helm-project-operator/charts"), + WithValue("image.repository", ts.image.Repository()), + WithValue("image.tag", ts.image.Tag()), WithValue("helmController.enabled", "true"), ) cmd, err := helmInstaller.build() @@ -252,7 +251,7 @@ var _ = Describe("E2E helm project operator tests", Ordered, Label("kubernetes") Eventually(Object(deploy)).Should(ExistAnd( HaveMatchingContainer(And( HaveName("helm-project-operator"), - HaveImage("rancher/helm-project-operator:dev"), + HaveImage(fmt.Sprintf("%s:%s", ts.image.Registry(), ts.image.Tag())), )), )) diff --git a/scripts/integration b/scripts/integration index 319d0093..ef3c900b 100755 --- a/scripts/integration +++ b/scripts/integration @@ -7,4 +7,4 @@ cd $(dirname $0)/.. echo "Starting integration tests" echo "Running integration tests for $BUILD_TARGET" -KUBECONFIG=$KUBECONFIG go test -cover ./... --ginkgo.label-filter 'kubernetes' +KUBECONFIG=$KUBECONFIG IMAGE=$IMAGE go test -cover ./... --ginkgo.label-filter 'kubernetes'