From 88677c254b3c81783787c60157edfee52ea08961 Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Fri, 19 Sep 2025 13:09:03 +0200 Subject: [PATCH 1/9] ci: preparation of go code decoupling --- .gitignore | 8 +-- go.mod | 2 +- {test/pkg/api => pkg}/api.go | 8 +-- {test/pkg => pkg}/argo/application.go | 0 {test/pkg => pkg}/argo/argo.go | 3 +- pkg/client.go | 40 ++++++++++++ {test/pkg/git => pkg}/git.go | 2 +- {test/pkg/helm => pkg}/helm.go | 11 ++-- .../manifest/manifest.go => pkg/kustomize.go | 7 ++- {test/pkg/test => pkg}/test.go | 63 +++++-------------- test/argo_cd_test.go | 27 ++++---- test/argo_rollouts_test.go | 22 +++---- test/cert_manager_test.go | 23 ++++--- test/cloudflare_tunnel_test.go | 23 +++---- test/http_echo_server_test.go | 28 ++++----- test/istio_test.go | 34 +++++----- test/k3s_system_upgrade_controller_test.go | 28 ++++----- test/kargo_test.go | 26 ++++---- test/kured_test.go | 20 +++--- test/main_test.go | 5 +- test/prometheus_test.go | 28 ++++----- test/sealed_secrets_test.go | 22 +++---- test/storage_test.go | 47 +++++++------- 23 files changed, 230 insertions(+), 247 deletions(-) rename {test/pkg/api => pkg}/api.go (96%) rename {test/pkg => pkg}/argo/application.go (100%) rename {test/pkg => pkg}/argo/argo.go (99%) create mode 100644 pkg/client.go rename {test/pkg/git => pkg}/git.go (96%) rename {test/pkg/helm => pkg}/helm.go (92%) rename test/pkg/manifest/manifest.go => pkg/kustomize.go (97%) rename {test/pkg/test => pkg}/test.go (82%) diff --git a/.gitignore b/.gitignore index d5a66362..f354e865 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ kubeconfig hosts.yml vendor/* -tls.crt -tls.key -public-key-cert.pem -**/kind-logs \ No newline at end of file +*.crt +*.key +*.pem +**/kind-logs diff --git a/go.mod b/go.mod index f63c4c96..b3e6f499 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module test +module e2eutils go 1.24.0 diff --git a/test/pkg/api/api.go b/pkg/api.go similarity index 96% rename from test/pkg/api/api.go rename to pkg/api.go index a0822246..7bd9786d 100644 --- a/test/pkg/api/api.go +++ b/pkg/api.go @@ -1,8 +1,9 @@ -package api +package e2eutils import ( "context" "errors" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -12,7 +13,6 @@ import ( "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" "sigs.k8s.io/e2e-framework/klient/k8s" - "test/test/pkg/test" ) func Apply(clientset kubernetes.Clientset, object runtime.Object) error { @@ -33,7 +33,7 @@ func Apply(clientset kubernetes.Clientset, object runtime.Object) error { _, err := createPersistentVolumeClaim(clientset, *object.(*corev1.PersistentVolumeClaim)) return err case *unstructured.Unstructured: - dynClient, err := test.GetDynClient() + dynClient, err := GetDynClient() if err != nil { return err } @@ -75,7 +75,7 @@ func createPersistentVolumeClaim(clientset kubernetes.Clientset, object corev1.P } func getResourceName(object unstructured.Unstructured) (string, error) { - discoveryClient, err := test.GetDiscoveryClient() + discoveryClient, err := GetDiscoveryClient() if err != nil { return "", errors.New("Failed to get discovery client " + err.Error()) } diff --git a/test/pkg/argo/application.go b/pkg/argo/application.go similarity index 100% rename from test/pkg/argo/application.go rename to pkg/argo/application.go diff --git a/test/pkg/argo/argo.go b/pkg/argo/argo.go similarity index 99% rename from test/pkg/argo/argo.go rename to pkg/argo/argo.go index c84e3284..c014c513 100644 --- a/test/pkg/argo/argo.go +++ b/pkg/argo/argo.go @@ -5,9 +5,10 @@ import ( "io" "net/http" "os" - "sigs.k8s.io/yaml" "strconv" "strings" + + "sigs.k8s.io/yaml" ) func GetArgoApplication(applicationYaml string) (Application, error) { diff --git a/pkg/client.go b/pkg/client.go new file mode 100644 index 00000000..e0dfe91e --- /dev/null +++ b/pkg/client.go @@ -0,0 +1,40 @@ +package e2eutils + +import ( + "k8s.io/client-go/discovery" + "k8s.io/client-go/dynamic" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" + "sigs.k8s.io/e2e-framework/klient" + "sigs.k8s.io/e2e-framework/pkg/envconf" +) + +func GetClient() klient.Client { + cfg := envconf.Config{} + return cfg.Client() +} + +func GetRestConfig() *rest.Config { + client := GetClient() + return client.RESTConfig() +} + +func GetClientSet() (*kubernetes.Clientset, error) { + kubeConfig := GetRestConfig() + clientSet, err := kubernetes.NewForConfig(kubeConfig) + if err != nil { + return nil, err + } + + return clientSet, nil +} + +func GetDynClient() (*dynamic.DynamicClient, error) { + kubeConfig := GetRestConfig() + return dynamic.NewForConfig(kubeConfig) +} + +func GetDiscoveryClient() (*discovery.DiscoveryClient, error) { + kubeConfig := GetRestConfig() + return discovery.NewDiscoveryClientForConfig(kubeConfig) +} diff --git a/test/pkg/git/git.go b/pkg/git.go similarity index 96% rename from test/pkg/git/git.go rename to pkg/git.go index f82ce500..4a785713 100644 --- a/test/pkg/git/git.go +++ b/pkg/git.go @@ -1,4 +1,4 @@ -package git +package e2eutils import ( "os/exec" diff --git a/test/pkg/helm/helm.go b/pkg/helm.go similarity index 92% rename from test/pkg/helm/helm.go rename to pkg/helm.go index f9618954..7f6f4745 100644 --- a/test/pkg/helm/helm.go +++ b/pkg/helm.go @@ -1,11 +1,12 @@ -package helm +package e2eutils import ( + "e2eutils/pkg/argo" "fmt" "os" - "sigs.k8s.io/e2e-framework/third_party/helm" "strings" - "test/test/pkg/argo" + + "sigs.k8s.io/e2e-framework/third_party/helm" ) type HelmOptions struct { @@ -34,7 +35,7 @@ func AddHelmRepository(helmMgr *helm.Manager, helmRepoUrl string, helmChartName return nil } -func helmifyApp(app argo.ApplicationSource, namespace string) (HelmOptions, error) { +func helmifyArgoApp(app argo.ApplicationSource, namespace string) (HelmOptions, error) { fullChartName := getFullChartName(app.Chart, app.Chart) helmOciRepository := "" @@ -90,7 +91,7 @@ func helmValuesToFile(applicationSource argo.ApplicationSource) error { } func DeployHelmChart(helmMgr *helm.Manager, applicationSource argo.ApplicationSource, namespace string) error { - helmOptions, err := helmifyApp(applicationSource, namespace) + helmOptions, err := helmifyArgoApp(applicationSource, namespace) if err != nil { return err } diff --git a/test/pkg/manifest/manifest.go b/pkg/kustomize.go similarity index 97% rename from test/pkg/manifest/manifest.go rename to pkg/kustomize.go index b3cf68e1..9190b362 100644 --- a/test/pkg/manifest/manifest.go +++ b/pkg/kustomize.go @@ -1,14 +1,15 @@ -package manifest +package e2eutils import ( "context" + "e2eutils/pkg/argo" "os" + "strings" + "sigs.k8s.io/e2e-framework/klient/decoder" "sigs.k8s.io/e2e-framework/klient/k8s" "sigs.k8s.io/kustomize/api/krusty" "sigs.k8s.io/kustomize/kyaml/filesys" - "strings" - "test/test/pkg/argo" ) func GetKubernetesManifests(argoApplication argo.Application) ([]k8s.Object, error) { diff --git a/test/pkg/test/test.go b/pkg/test.go similarity index 82% rename from test/pkg/test/test.go rename to pkg/test.go index 3f359c29..22a14c32 100644 --- a/test/pkg/test/test.go +++ b/pkg/test.go @@ -1,8 +1,14 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg/argo" "errors" + "log/slog" + "reflect" + "strings" + "time" + snapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -10,27 +16,16 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" - "log/slog" - "reflect" "sigs.k8s.io/e2e-framework/klient" "sigs.k8s.io/e2e-framework/klient/k8s" "sigs.k8s.io/e2e-framework/klient/wait" "sigs.k8s.io/e2e-framework/klient/wait/conditions" - "sigs.k8s.io/e2e-framework/pkg/envconf" - "strings" - "test/test/pkg/argo" - "test/test/pkg/git" - "test/test/pkg/helm" - "test/test/pkg/manifest" - "time" ) -func PrepareTest(gitRepository string, applicationYaml string) (argo.Application, argo.Application, []k8s.Object, error) { - currGitBranch, err := git.GetCurrentGitBranch() +func PrepareArgoApp(gitRepository string, applicationYaml string) (argo.Application, argo.Application, []k8s.Object, error) { + currGitBranch, err := GetCurrentGitBranch() if err != nil { return argo.Application{}, argo.Application{}, nil, err } @@ -41,7 +36,7 @@ func PrepareTest(gitRepository string, applicationYaml string) (argo.Application return argo.Application{}, argo.Application{}, nil, err } - objects, err := manifest.GetKubernetesManifests(current) + objects, err := GetKubernetesManifests(current) if err != nil { return current, argo.Application{}, nil, err } @@ -54,7 +49,7 @@ func PrepareTest(gitRepository string, applicationYaml string) (argo.Application return argo.Application{}, argo.Application{}, nil, err } - objects, err := manifest.GetKubernetesManifests(update) + objects, err := GetKubernetesManifests(update) if err != nil { return argo.Application{}, argo.Application{}, nil, err } @@ -78,16 +73,16 @@ func PrepareTest(gitRepository string, applicationYaml string) (argo.Application } func deployHelmChart(applicationSource argo.ApplicationSource, namespace string, kubeConfigFile string) error { - helmMgr := helm.GetHelmManager(kubeConfigFile) + helmMgr := GetHelmManager(kubeConfigFile) if !strings.Contains(applicationSource.RepoURL, "oci://") { - err := helm.AddHelmRepository(helmMgr, applicationSource.RepoURL, applicationSource.Chart) + err := AddHelmRepository(helmMgr, applicationSource.RepoURL, applicationSource.Chart) if err != nil { return err } } - err := helm.DeployHelmChart(helmMgr, applicationSource, namespace) + err := DeployHelmChart(helmMgr, applicationSource, namespace) if err != nil { return err } @@ -124,36 +119,6 @@ func DeployHelmCharts(kubeConfigFile string, argoApplication argo.Application) e return nil } -func GetClient() (klient.Client, error) { - cfg := envconf.Config{} - return cfg.Client(), nil -} - -func GetRestConfig() *rest.Config { - client, _ := GetClient() - return client.RESTConfig() -} - -func GetClientSet() (*kubernetes.Clientset, error) { - kubeConfig := GetRestConfig() - clientSet, err := kubernetes.NewForConfig(kubeConfig) - if err != nil { - return nil, err - } - - return clientSet, nil -} - -func GetDynClient() (*dynamic.DynamicClient, error) { - kubeConfig := GetRestConfig() - return dynamic.NewForConfig(kubeConfig) -} - -func GetDiscoveryClient() (*discovery.DiscoveryClient, error) { - kubeConfig := GetRestConfig() - return discovery.NewDiscoveryClientForConfig(kubeConfig) -} - func CheckJobsCompleted(ctx context.Context, client klient.Client, namespace string) error { kubeConfig := client.RESTConfig() clientSet, err := kubernetes.NewForConfig(kubeConfig) diff --git a/test/argo_cd_test.go b/test/argo_cd_test.go index b7b7b08c..e3e2e82f 100644 --- a/test/argo_cd_test.go +++ b/test/argo_cd_test.go @@ -1,50 +1,49 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "test/test/pkg/test" - "testing" ) func TestArgoCd(t *testing.T) { - current, update, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/argo-cd.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/argo-cd.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() install := features. New("Deploying Argo CD Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), current) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), current) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) assert.NoError(t, err) return ctx }). Assess("Jobs run successfully", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.CheckJobsCompleted(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.CheckJobsCompleted(ctx, client, current.Spec.Destination.Namespace) assert.NoError(t, err) return ctx }). Feature() + upgrade := features. New("Upgrading Argo CD Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { @@ -52,21 +51,21 @@ func TestArgoCd(t *testing.T) { t.SkipNow() } - err := test.DeployHelmCharts(cfg.KubeconfigFile(), update) + err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), update) assert.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) assert.NoError(t, err) return ctx }). Assess("Jobs run successfully", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.CheckJobsCompleted(ctx, client, update.Spec.Destination.Namespace) + err := e2eutils.CheckJobsCompleted(ctx, client, update.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/argo_rollouts_test.go b/test/argo_rollouts_test.go index 042bb21b..49366007 100644 --- a/test/argo_rollouts_test.go +++ b/test/argo_rollouts_test.go @@ -1,38 +1,36 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "test/test/pkg/test" - "testing" ) func TestArgoRollouts(t *testing.T) { - current, update, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/argo-rollouts.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/argo-rollouts.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() install := features. New("Deploying Argo Rollouts Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), current) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), current) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) assert.NoError(t, err) return ctx @@ -46,14 +44,14 @@ func TestArgoRollouts(t *testing.T) { t.SkipNow() } - err := test.DeployHelmCharts(cfg.KubeconfigFile(), update) + err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), update) assert.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/cert_manager_test.go b/test/cert_manager_test.go index acaf1940..16982646 100644 --- a/test/cert_manager_test.go +++ b/test/cert_manager_test.go @@ -1,41 +1,40 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "testing" + "github.com/stretchr/testify/require" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "test/test/pkg/test" - "testing" ) func TestCertManager(t *testing.T) { - current, update, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/cert-manager.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/cert-manager.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() install := features. New("Deploying Cert Manager Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), current) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), current) require.NoError(t, err) return ctx }). Assess("Deployment became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Feature() + upgrade := features. New("Upgrading Cert Manager Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { @@ -43,14 +42,14 @@ func TestCertManager(t *testing.T) { t.SkipNow() } - err = test.DeployHelmCharts(cfg.KubeconfigFile(), update) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), update) require.NoError(t, err) return ctx }). Assess("Testing Cert Manager upgrade became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) require.NoError(t, err) return ctx diff --git a/test/cloudflare_tunnel_test.go b/test/cloudflare_tunnel_test.go index 28199805..2df517c6 100644 --- a/test/cloudflare_tunnel_test.go +++ b/test/cloudflare_tunnel_test.go @@ -1,8 +1,12 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" "fmt" + "strings" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/api/apps/v1" @@ -10,10 +14,6 @@ import ( "sigs.k8s.io/e2e-framework/klient/k8s" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "strings" - "test/test/pkg/api" - "test/test/pkg/test" - "testing" ) func TestCloudflareTunnel(t *testing.T) { @@ -24,17 +24,14 @@ metadata: name: %s ` - current, _, additionalManifests, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/cloudflare-tunnel.yaml") + current, _, additionalManifests, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/cloudflare-tunnel.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() - clientSet, err := test.GetClientSet() + clientSet, err := e2eutils.GetClientSet() if err != nil { t.Fatalf("Failed to get kubernetes clientSet #%v", err) } @@ -70,14 +67,14 @@ metadata: t.Fatalf("No objects to deploy %v", objectList) } - err = api.ApplyAll(*clientSet, objectList) + err = e2eutils.ApplyAll(*clientSet, objectList) require.NoError(t, err) return ctx }). Assess("Deployment became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/http_echo_server_test.go b/test/http_echo_server_test.go index c7d2a844..0ac17f19 100644 --- a/test/http_echo_server_test.go +++ b/test/http_echo_server_test.go @@ -1,18 +1,18 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "os" + "strings" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "os" "sigs.k8s.io/e2e-framework/klient/decoder" "sigs.k8s.io/e2e-framework/klient/k8s" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "strings" - "test/test/pkg/api" - "test/test/pkg/test" - "testing" ) func TestHttpEchoServer(t *testing.T) { @@ -22,15 +22,9 @@ kind: Namespace metadata: name: http-echo-server ` - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } - - clientSet, err := test.GetClientSet() - if err != nil { - t.Fatalf("Failed to get kubernetes clientSet #%v", err) - } + client := e2eutils.GetClient() + clientSet, err := e2eutils.GetClientSet() + require.NoError(t, err) var objectList []k8s.Object install := features. @@ -55,14 +49,14 @@ metadata: t.Fatalf("No objects to deploy %v", objectList) } - err = api.ApplyAll(*clientSet, objectList) + err = e2eutils.ApplyAll(*clientSet, objectList) require.NoError(t, err) return ctx }). Assess("Deployment became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DeploymentBecameReady(ctx, client, "http-echo-server") + err := e2eutils.DeploymentBecameReady(ctx, client, "http-echo-server") assert.NoError(t, err) return ctx diff --git a/test/istio_test.go b/test/istio_test.go index 68b47ea3..d2cee247 100644 --- a/test/istio_test.go +++ b/test/istio_test.go @@ -1,51 +1,49 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "log" + "testing" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" - "log" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "test/test/pkg/test" - "testing" ) func TestIstio(t *testing.T) { - istioCurrent, istioUpdate, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/istio.yaml") + istioCurrent, istioUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/istio.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } - gatewayCurrent, gatewayUpdate, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/istio-gateway.yaml") + gatewayCurrent, gatewayUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/istio-gateway.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() install := features. New("Deploying Istio Helm Charts Collection"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), istioCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), istioCurrent) require.NoError(t, err) - err = test.DeployHelmCharts(cfg.KubeconfigFile(), gatewayCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), gatewayCurrent) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, istioCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, istioCurrent.Spec.Destination.Namespace) require.NoError(t, err) - err = test.DeploymentBecameReady(ctx, client, gatewayCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, gatewayCurrent.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -99,20 +97,20 @@ func TestIstio(t *testing.T) { t.SkipNow() } - err = test.DeployHelmCharts(cfg.KubeconfigFile(), istioUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), istioUpdate) require.NoError(t, err) - err = test.DeployHelmCharts(cfg.KubeconfigFile(), gatewayUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), gatewayUpdate) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, istioUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, istioUpdate.Spec.Destination.Namespace) require.NoError(t, err) - err = test.DeploymentBecameReady(ctx, client, gatewayUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, gatewayUpdate.Spec.Destination.Namespace) require.NoError(t, err) return ctx diff --git a/test/k3s_system_upgrade_controller_test.go b/test/k3s_system_upgrade_controller_test.go index d2779be8..19465616 100644 --- a/test/k3s_system_upgrade_controller_test.go +++ b/test/k3s_system_upgrade_controller_test.go @@ -1,28 +1,26 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "testing" + "time" + "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" "sigs.k8s.io/yaml" - "test/test/pkg/api" - "test/test/pkg/manifest" - "test/test/pkg/test" - "testing" - "time" ) func TestK3sSystemUpgradeController(t *testing.T) { - current, update, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/k3s-system-upgrade-controller.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/k3s-system-upgrade-controller.yaml") require.NoError(t, err) - clientSet, err := test.GetClientSet() + clientSet, err := e2eutils.GetClientSet() require.NoError(t, err) - client, err := test.GetClient() - require.NoError(t, err) + client := e2eutils.GetClient() var kustomization []string var namespace string @@ -31,9 +29,9 @@ func TestK3sSystemUpgradeController(t *testing.T) { New("Kustomization"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { if update.Spec.Sources != nil { - kustomization, err = manifest.BuildKustomization(update.Spec.Sources[0].Path) + kustomization, err = e2eutils.BuildKustomization(update.Spec.Sources[0].Path) } else { - kustomization, err = manifest.BuildKustomization(current.Spec.Sources[0].Path) + kustomization, err = e2eutils.BuildKustomization(current.Spec.Sources[0].Path) } require.NoError(t, err) @@ -51,7 +49,7 @@ func TestK3sSystemUpgradeController(t *testing.T) { } namespace = object.GetName() - err = api.Apply(*clientSet, &object) + err = e2eutils.Apply(*clientSet, &object) require.NoError(t, err) // give k8s api some time to create a resource @@ -67,7 +65,7 @@ func TestK3sSystemUpgradeController(t *testing.T) { continue } - err = api.Apply(*clientSet, &object) + err = e2eutils.Apply(*clientSet, &object) require.NoError(t, err) // give k8s api some time to create a resource @@ -78,7 +76,7 @@ func TestK3sSystemUpgradeController(t *testing.T) { }). Assess("Deployment became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, namespace) require.NoError(t, err) return ctx diff --git a/test/kargo_test.go b/test/kargo_test.go index 501fe43f..edd334b6 100644 --- a/test/kargo_test.go +++ b/test/kargo_test.go @@ -1,30 +1,28 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "test/test/pkg/test" - "testing" ) func TestKargo(t *testing.T) { - kargoCurrent, kargoUpdate, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/kargo.yaml") + kargoCurrent, kargoUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/kargo.yaml") if err != nil { t.Fatalf("Failed to prepare kargo test #%v", err) } - certCurrent, _, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/cert-manager.yaml") + certCurrent, _, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/cert-manager.yaml") if err != nil { t.Fatalf("Failed to prepare cert-manager #%v", err) } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() install := features. New("Deploying Kargo.io Helm Chart"). @@ -34,17 +32,17 @@ func TestKargo(t *testing.T) { } // kargo depends on cert-manager crds - err = test.DeployHelmCharts(cfg.KubeconfigFile(), certCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), certCurrent) require.NoError(t, err) - err = test.DeployHelmCharts(cfg.KubeconfigFile(), kargoCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), kargoCurrent) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DeploymentBecameReady(ctx, client, kargoCurrent.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, kargoCurrent.Spec.Destination.Namespace) assert.NoError(t, err) return ctx @@ -61,14 +59,14 @@ func TestKargo(t *testing.T) { kargoUpdate.Spec.Sources[index].RepoURL = "oci://" + kargoUpdate.Spec.Sources[index].RepoURL + "/" + kargoUpdate.Spec.Sources[index].Chart } - err := test.DeployHelmCharts(cfg.KubeconfigFile(), kargoUpdate) + err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), kargoUpdate) assert.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DeploymentBecameReady(ctx, client, kargoUpdate.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, kargoUpdate.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/kured_test.go b/test/kured_test.go index c68eb3b5..292e00c2 100644 --- a/test/kured_test.go +++ b/test/kured_test.go @@ -1,33 +1,33 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "test/test/pkg/test" - "testing" ) func TestKured(t *testing.T) { - current, update, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/kured.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/kured.yaml") require.NoError(t, err) - client, err := test.GetClient() - require.NoError(t, err) + client := e2eutils.GetClient() install := features. New("Deploying Kured Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), current) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), current) require.NoError(t, err) return ctx }). Assess("DaemonSet became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DaemonSetBecameReady(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.DaemonSetBecameReady(ctx, client, current.Spec.Destination.Namespace) assert.NoError(t, err) return ctx @@ -41,14 +41,14 @@ func TestKured(t *testing.T) { t.SkipNow() } - err := test.DeployHelmCharts(cfg.KubeconfigFile(), update) + err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), update) assert.NoError(t, err) return ctx }). Assess("DaemonSet became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := test.DaemonSetBecameReady(ctx, client, update.Spec.Destination.Namespace) + err := e2eutils.DaemonSetBecameReady(ctx, client, update.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/main_test.go b/test/main_test.go index 6d93da64..25777265 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -1,13 +1,14 @@ -package test +package e2eutils import ( "fmt" "os" + "testing" + "sigs.k8s.io/e2e-framework/pkg/env" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/envfuncs" "sigs.k8s.io/e2e-framework/support/kind" - "testing" ) var ( diff --git a/test/prometheus_test.go b/test/prometheus_test.go index dabbfbdf..1b84bc54 100644 --- a/test/prometheus_test.go +++ b/test/prometheus_test.go @@ -1,17 +1,18 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "strings" + "testing" + "github.com/stretchr/testify/require" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "strings" - "test/test/pkg/test" - "testing" ) func TestPrometheus(t *testing.T) { - promCurrent, promUpdate, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/prometheus.yaml") + promCurrent, promUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/prometheus.yaml") if err != nil { t.Fatalf("Failed to prepare prometheus test #%v", err) } @@ -90,29 +91,26 @@ func TestPrometheus(t *testing.T) { promUpdate.Spec.Sources[i].Helm.Values = source.Helm.Values } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() install := features. New("Deploying Prometheus Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), promCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), promCurrent) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, promCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, promCurrent.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Daemonsets became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DaemonSetBecameReady(ctx, client, promCurrent.Spec.Destination.Namespace) + err = e2eutils.DaemonSetBecameReady(ctx, client, promCurrent.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -126,21 +124,21 @@ func TestPrometheus(t *testing.T) { t.SkipNow() } - err = test.DeployHelmCharts(cfg.KubeconfigFile(), promUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), promUpdate) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, promUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, promUpdate.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Daemonsets became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DaemonSetBecameReady(ctx, client, promUpdate.Spec.Destination.Namespace) + err = e2eutils.DaemonSetBecameReady(ctx, client, promUpdate.Spec.Destination.Namespace) require.NoError(t, err) return ctx diff --git a/test/sealed_secrets_test.go b/test/sealed_secrets_test.go index cb7432b5..df5417f9 100644 --- a/test/sealed_secrets_test.go +++ b/test/sealed_secrets_test.go @@ -1,36 +1,34 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "testing" + "github.com/stretchr/testify/require" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "test/test/pkg/test" - "testing" ) func TestSealedSecrets(t *testing.T) { - sealedCurrent, sealedUpdate, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/sealed-secrets.yaml") + sealedCurrent, sealedUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/sealed-secrets.yaml") if err != nil { t.Fatalf("Failed to prepare sealed secret test #%v", err) } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() install := features. New("Deploying Sealed Secrets Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), sealedCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), sealedCurrent) require.NoError(t, err) return ctx }). Assess("Deployment became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, sealedCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, sealedCurrent.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -43,14 +41,14 @@ func TestSealedSecrets(t *testing.T) { t.SkipNow() } - err = test.DeployHelmCharts(cfg.KubeconfigFile(), sealedUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), sealedUpdate) require.NoError(t, err) return ctx }). Assess("Testing Sealed Secrets upgrade became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, sealedUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, sealedUpdate.Spec.Destination.Namespace) require.NoError(t, err) return ctx diff --git a/test/storage_test.go b/test/storage_test.go index 624dda27..ff08813b 100644 --- a/test/storage_test.go +++ b/test/storage_test.go @@ -1,15 +1,15 @@ -package test +package e2eutils import ( "context" + "e2eutils/pkg" + "strings" + "testing" + "github.com/stretchr/testify/require" "sigs.k8s.io/e2e-framework/klient/decoder" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "strings" - "test/test/pkg/api" - "test/test/pkg/test" - "testing" ) func TestStorage(t *testing.T) { @@ -28,22 +28,19 @@ spec: storageClassName: longhorn ` - scCurrent, scUpdate, _, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/snapshot-controller.yaml") + scCurrent, scUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/snapshot-controller.yaml") if err != nil { t.Fatalf("Failed to prepare shanpshot controller test #%v", err) } - longhornCurrent, longhornUpdate, manifest, err := test.PrepareTest(gitRepository, "../kubernetes-services/templates/longhorn.yaml") + longhornCurrent, longhornUpdate, manifest, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/longhorn.yaml") if err != nil { t.Fatalf("Failed to prepare longhorn csi #%v", err) } - client, err := test.GetClient() - if err != nil { - t.Fatalf("Failed to get kubernetes client #%v", err) - } + client := e2eutils.GetClient() - clientSet, err := test.GetClientSet() + clientSet, err := e2eutils.GetClientSet() if err != nil { t.Fatalf("Failed to get kubernetes clientSet #%v", err) } @@ -80,38 +77,38 @@ csi: }). Assess("Deploying CSI Helm Charts", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), scCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), scCurrent) require.NoError(t, err) - err = test.DeployHelmCharts(cfg.KubeconfigFile(), longhornCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), longhornCurrent) require.NoError(t, err) return ctx }). Assess("Longhorn DaemonSet became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DaemonSetBecameReady(ctx, client, longhornCurrent.Spec.Destination.Namespace) + err = e2eutils.DaemonSetBecameReady(ctx, client, longhornCurrent.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, longhornCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, longhornCurrent.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Snapshot Controller Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = test.DeploymentBecameReady(ctx, client, scCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, scCurrent.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Deploy Snapshot Class", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = api.ApplyAll(*clientSet, manifest) + err = e2eutils.ApplyAll(*clientSet, manifest) require.NoError(t, err) return ctx @@ -119,10 +116,10 @@ csi: Assess("Deploy PVC", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { pvcObject, err := decoder.DecodeAll(ctx, strings.NewReader(pvc)) - err = api.ApplyAll(*clientSet, pvcObject) + err = e2eutils.ApplyAll(*clientSet, pvcObject) require.NoError(t, err) - err = test.PersistentVolumeClaimIsBound(ctx, client, "default") + err = e2eutils.PersistentVolumeClaimIsBound(ctx, client, "default") require.NoError(t, err) return ctx @@ -136,7 +133,7 @@ csi: } if scUpdate.Spec.Sources != nil { - err = test.DeployHelmCharts(cfg.KubeconfigFile(), scUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), scUpdate) require.NoError(t, err) } @@ -165,7 +162,7 @@ csi: -1, ) - err = test.DeployHelmCharts(cfg.KubeconfigFile(), longhornUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), longhornUpdate) require.NoError(t, err) } return ctx @@ -176,7 +173,7 @@ csi: t.SkipNow() } - err = test.DaemonSetBecameReady(ctx, client, longhornUpdate.Spec.Destination.Namespace) + err = e2eutils.DaemonSetBecameReady(ctx, client, longhornUpdate.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -187,7 +184,7 @@ csi: t.SkipNow() } - err = test.DeploymentBecameReady(ctx, client, longhornUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, longhornUpdate.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -198,7 +195,7 @@ csi: t.SkipNow() } - err = test.DeploymentBecameReady(ctx, client, scUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, scUpdate.Spec.Destination.Namespace) require.NoError(t, err) return ctx From e1087e7252920f3f9c5c53f645f9256cf3f4ee5f Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Fri, 19 Sep 2025 17:23:15 +0200 Subject: [PATCH 2/9] chore: some cleanups --- .../templates/argo-rollouts.yaml | 2 +- pkg/helm.go | 114 ------------------ pkg/helm/helm.go | 90 ++++++++++++++ pkg/kustomize.go | 8 +- pkg/test.go | 45 ++++--- test/k3s_system_upgrade_controller_test.go | 1 - 6 files changed, 115 insertions(+), 145 deletions(-) delete mode 100644 pkg/helm.go create mode 100644 pkg/helm/helm.go diff --git a/kubernetes-services/templates/argo-rollouts.yaml b/kubernetes-services/templates/argo-rollouts.yaml index fad10a96..d6ad5732 100644 --- a/kubernetes-services/templates/argo-rollouts.yaml +++ b/kubernetes-services/templates/argo-rollouts.yaml @@ -23,4 +23,4 @@ spec: prune: true selfHeal: true syncOptions: - - CreateNamespace=true \ No newline at end of file + - CreateNamespace=true diff --git a/pkg/helm.go b/pkg/helm.go deleted file mode 100644 index 7f6f4745..00000000 --- a/pkg/helm.go +++ /dev/null @@ -1,114 +0,0 @@ -package e2eutils - -import ( - "e2eutils/pkg/argo" - "fmt" - "os" - "strings" - - "sigs.k8s.io/e2e-framework/third_party/helm" -) - -type HelmOptions struct { - Name string `default:""` - Namespace string `default:""` - Chart string `default:""` - Version string `default:""` - Values string `default:""` - OciRepository string `default:""` -} - -func GetHelmManager(kubeConfigFile string) *helm.Manager { - return helm.New(kubeConfigFile) -} - -func AddHelmRepository(helmMgr *helm.Manager, helmRepoUrl string, helmChartName string) error { - err := helmMgr.RunRepo(helm.WithArgs( - "add --force-update", - helmChartName, - helmRepoUrl, - )) - if err != nil { - return err - } - - return nil -} - -func helmifyArgoApp(app argo.ApplicationSource, namespace string) (HelmOptions, error) { - fullChartName := getFullChartName(app.Chart, app.Chart) - helmOciRepository := "" - - if strings.Contains(app.RepoURL, "oci://") { - fullChartName = "" - helmOciRepository = app.RepoURL - } - - helmValues := make(map[int]string, 2) - if app.Helm != nil { - err := helmValuesToFile(app) - if err != nil { - return HelmOptions{}, err - } - - helmValues[0] = "-f" - helmValues[1] = "/tmp/helm-values.txt" - } - - helmOptions := HelmOptions{ - Name: app.Chart, - Chart: fullChartName, - Namespace: namespace, - Version: app.TargetRevision, - Values: helmValues[0] + " " + helmValues[1], - OciRepository: helmOciRepository, - } - - return helmOptions, nil -} - -func getFullChartName(helmRepoName string, helmChart string) string { - return fmt.Sprintf("%s/%s", helmRepoName, helmChart) -} - -func helmValuesToFile(applicationSource argo.ApplicationSource) error { - helmValues, err := os.Create("/tmp/helm-values.txt") - if err != nil { - return err - } - - _, err = helmValues.WriteString(applicationSource.Helm.Values) - if err != nil { - return err - } - - err = helmValues.Close() - if err != nil { - return err - } - - return nil -} - -func DeployHelmChart(helmMgr *helm.Manager, applicationSource argo.ApplicationSource, namespace string) error { - helmOptions, err := helmifyArgoApp(applicationSource, namespace) - if err != nil { - return err - } - - err = helmMgr.RunUpgrade( - helm.WithArgs("--install"), - helm.WithName(helmOptions.Name), - helm.WithNamespace(helmOptions.Namespace), - helm.WithChart(helmOptions.Chart), - helm.WithVersion(helmOptions.Version), - helm.WithArgs("--create-namespace"), - helm.WithArgs(helmOptions.Values), - helm.WithArgs(helmOptions.OciRepository), - ) - if err != nil { - return err - } - - return nil -} diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go new file mode 100644 index 00000000..d26e009c --- /dev/null +++ b/pkg/helm/helm.go @@ -0,0 +1,90 @@ +package helm + +import ( + "fmt" + "os" + "path/filepath" + "strings" + + "e2eutils/pkg/argo" + + "sigs.k8s.io/e2e-framework/third_party/helm" +) + +type HelmArguments struct { + Name string + Namespace string + Chart string + Version string + ValuesFilePath string + OciRepository string +} + +func NewHelmManager(kubeConfigFile string) *helm.Manager { + return helm.New(kubeConfigFile) +} + +func AddHelmRepository(helmMgr *helm.Manager, repoURL, chartName string) error { + return helmMgr.RunRepo(helm.WithArgs("add", "--force-update", chartName, repoURL)) +} + +func DeployHelmChart(helmMgr *helm.Manager, src argo.ApplicationSource, namespace string) error { + opts, err := buildHelmArguments(src, namespace) + if err != nil { + return fmt.Errorf("building helm options: %w", err) + } + + options := []helm.Option{ + helm.WithName(opts.Name), + helm.WithNamespace(opts.Namespace), + helm.WithChart(opts.Chart), + helm.WithVersion(opts.Version), + helm.WithArgs("--install", "--create-namespace"), + } + + if opts.ValuesFilePath != "" { + options = append(options, helm.WithArgs("-f", opts.ValuesFilePath)) + } + + if err := helmMgr.RunUpgrade(options...); err != nil { + return fmt.Errorf("helm upgrade/install failed: %w", err) + } + + return nil +} + +func buildHelmArguments(src argo.ApplicationSource, namespace string) (*HelmArguments, error) { + opts := &HelmArguments{ + Name: src.Chart, + Namespace: namespace, + Version: src.TargetRevision, + } + + if strings.HasPrefix(src.RepoURL, "oci://") { + base := strings.TrimSuffix(src.RepoURL, "/") + opts.Chart = fmt.Sprintf("%s/%s", base, src.Chart) + opts.OciRepository = "" + } else { + opts.Chart = fmt.Sprintf("%s/%s", src.Chart, src.Chart) + } + + if src.Helm != nil && src.Helm.Values != "" { + valuesFilePath, err := writeValuesFile(src.Chart, src.TargetRevision, src.Helm.Values) + if err != nil { + return nil, fmt.Errorf("writing values file: %w", err) + } + opts.ValuesFilePath = valuesFilePath + } + + return opts, nil +} + +func writeValuesFile(chart, revision, valuesContent string) (string, error) { + valuesFilePath := fmt.Sprintf("values-%s-%s.yaml", chart, revision) + filePath := filepath.Join(os.TempDir(), valuesFilePath) + if err := os.WriteFile(filePath, []byte(valuesContent), 0o600); err != nil { + return "", err + } + + return filePath, nil +} diff --git a/pkg/kustomize.go b/pkg/kustomize.go index 9190b362..c99874ba 100644 --- a/pkg/kustomize.go +++ b/pkg/kustomize.go @@ -16,15 +16,13 @@ func GetKubernetesManifests(argoApplication argo.Application) ([]k8s.Object, err var objects []k8s.Object var err error - if argoApplication.Spec.Source != nil { - if argoApplication.Spec.Source.Path == "" { - return nil, nil - } - + if argoApplication.Spec.Source != nil && argoApplication.Spec.Source.Path != "" { objects, err = prepareKubernetesManifests(*argoApplication.Spec.Source) if err != nil { return nil, err } + + return objects, nil } var source argo.ApplicationSource diff --git a/pkg/test.go b/pkg/test.go index 22a14c32..9af8c793 100644 --- a/pkg/test.go +++ b/pkg/test.go @@ -3,6 +3,7 @@ package e2eutils import ( "context" "e2eutils/pkg/argo" + "e2eutils/pkg/helm" "errors" "log/slog" "reflect" @@ -72,30 +73,8 @@ func PrepareArgoApp(gitRepository string, applicationYaml string) (argo.Applicat return current, update, objects, nil } -func deployHelmChart(applicationSource argo.ApplicationSource, namespace string, kubeConfigFile string) error { - helmMgr := GetHelmManager(kubeConfigFile) - - if !strings.Contains(applicationSource.RepoURL, "oci://") { - err := AddHelmRepository(helmMgr, applicationSource.RepoURL, applicationSource.Chart) - if err != nil { - return err - } - } - - err := DeployHelmChart(helmMgr, applicationSource, namespace) - if err != nil { - return err - } - - return nil -} - func DeployHelmCharts(kubeConfigFile string, argoApplication argo.Application) error { - if argoApplication.Spec.Source != nil { - if argoApplication.Spec.Source.Chart == "" { - return nil - } - + if argoApplication.Spec.Source != nil && argoApplication.Spec.Source.Chart != "" { err := deployHelmChart(*argoApplication.Spec.Source, argoApplication.Spec.Destination.Namespace, kubeConfigFile) if err != nil { return errors.New(err.Error()) @@ -119,6 +98,24 @@ func DeployHelmCharts(kubeConfigFile string, argoApplication argo.Application) e return nil } +func deployHelmChart(applicationSource argo.ApplicationSource, namespace string, kubeConfigFile string) error { + helmMgr := helm.NewHelmManager(kubeConfigFile) + + if !strings.HasPrefix(applicationSource.RepoURL, "oci://") { + err := helm.AddHelmRepository(helmMgr, applicationSource.RepoURL, applicationSource.Chart) + if err != nil { + return err + } + } + + err := helm.DeployHelmChart(helmMgr, applicationSource, namespace) + if err != nil { + return err + } + + return nil +} + func CheckJobsCompleted(ctx context.Context, client klient.Client, namespace string) error { kubeConfig := client.RESTConfig() clientSet, err := kubernetes.NewForConfig(kubeConfig) @@ -183,7 +180,7 @@ func DaemonSetBecameReady(ctx context.Context, client klient.Client, namespace s return err } - daemonSetList, err := clientSet.AppsV1().DaemonSets(namespace).List(context.TODO(), metav1.ListOptions{}) + daemonSetList, err := clientSet.AppsV1().DaemonSets(namespace).List(ctx, metav1.ListOptions{}) if err != nil { return err } diff --git a/test/k3s_system_upgrade_controller_test.go b/test/k3s_system_upgrade_controller_test.go index 19465616..a931fabc 100644 --- a/test/k3s_system_upgrade_controller_test.go +++ b/test/k3s_system_upgrade_controller_test.go @@ -48,7 +48,6 @@ func TestK3sSystemUpgradeController(t *testing.T) { continue } - namespace = object.GetName() err = e2eutils.Apply(*clientSet, &object) require.NoError(t, err) From 43f8e335412d7c43e5b74af35adb9ef84c3197bc Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Fri, 19 Sep 2025 18:30:35 +0200 Subject: [PATCH 3/9] fix: get rid of kargo.io --- kubernetes-services/templates/kargo.yaml | 30 --------- pkg/helm/helm.go | 52 ++++++---------- test/kargo_test.go | 77 ------------------------ 3 files changed, 17 insertions(+), 142 deletions(-) delete mode 100644 kubernetes-services/templates/kargo.yaml delete mode 100644 test/kargo_test.go diff --git a/kubernetes-services/templates/kargo.yaml b/kubernetes-services/templates/kargo.yaml deleted file mode 100644 index 5366ddce..00000000 --- a/kubernetes-services/templates/kargo.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: kargo - namespace: argo-cd - finalizers: - - resources-finalizer.argocd.argoproj.io -spec: - destination: - server: https://kubernetes.default.svc - namespace: kargo - project: kubernetes - sources: - - chart: kargo - repoURL: ghcr.io/akuity/kargo-charts - targetRevision: 1.5.3 - helm: - values: | - api: - # hardcoded login credentials - # in production systems should use oidc! - adminAccount: - passwordHash: "$2a$12$/fHRdnXaUYBicfR0BsKh/.el6l4O/o.fEeGI7yyOjchEIfYj5Mh.K" - tokenSigningKey: AbAugOWkStfbwczR8wQooceM3 - syncPolicy: - automated: - prune: true - selfHeal: true - syncOptions: - - CreateNamespace=true \ No newline at end of file diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index d26e009c..b5c99643 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -11,15 +11,6 @@ import ( "sigs.k8s.io/e2e-framework/third_party/helm" ) -type HelmArguments struct { - Name string - Namespace string - Chart string - Version string - ValuesFilePath string - OciRepository string -} - func NewHelmManager(kubeConfigFile string) *helm.Manager { return helm.New(kubeConfigFile) } @@ -29,43 +20,33 @@ func AddHelmRepository(helmMgr *helm.Manager, repoURL, chartName string) error { } func DeployHelmChart(helmMgr *helm.Manager, src argo.ApplicationSource, namespace string) error { - opts, err := buildHelmArguments(src, namespace) + opts, err := buildHelmOptions(src, namespace) if err != nil { return fmt.Errorf("building helm options: %w", err) } - options := []helm.Option{ - helm.WithName(opts.Name), - helm.WithNamespace(opts.Namespace), - helm.WithChart(opts.Chart), - helm.WithVersion(opts.Version), - helm.WithArgs("--install", "--create-namespace"), - } - - if opts.ValuesFilePath != "" { - options = append(options, helm.WithArgs("-f", opts.ValuesFilePath)) - } - - if err := helmMgr.RunUpgrade(options...); err != nil { + if err := helmMgr.RunUpgrade(opts...); err != nil { return fmt.Errorf("helm upgrade/install failed: %w", err) } return nil } -func buildHelmArguments(src argo.ApplicationSource, namespace string) (*HelmArguments, error) { - opts := &HelmArguments{ - Name: src.Chart, - Namespace: namespace, - Version: src.TargetRevision, - } - +func buildHelmOptions(src argo.ApplicationSource, namespace string) ([]helm.Option, error) { + chart := "" if strings.HasPrefix(src.RepoURL, "oci://") { base := strings.TrimSuffix(src.RepoURL, "/") - opts.Chart = fmt.Sprintf("%s/%s", base, src.Chart) - opts.OciRepository = "" + chart = fmt.Sprintf("%s/%s", base, src.Chart) } else { - opts.Chart = fmt.Sprintf("%s/%s", src.Chart, src.Chart) + chart = fmt.Sprintf("%s/%s", src.Chart, src.Chart) + } + + options := []helm.Option{ + helm.WithName(src.Chart), + helm.WithNamespace(namespace), + helm.WithChart(chart), + helm.WithVersion(src.TargetRevision), + helm.WithArgs("--install", "--create-namespace"), } if src.Helm != nil && src.Helm.Values != "" { @@ -73,10 +54,11 @@ func buildHelmArguments(src argo.ApplicationSource, namespace string) (*HelmArgu if err != nil { return nil, fmt.Errorf("writing values file: %w", err) } - opts.ValuesFilePath = valuesFilePath + + options = append(options, helm.WithArgs("-f", valuesFilePath)) } - return opts, nil + return options, nil } func writeValuesFile(chart, revision, valuesContent string) (string, error) { diff --git a/test/kargo_test.go b/test/kargo_test.go deleted file mode 100644 index edd334b6..00000000 --- a/test/kargo_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package e2eutils - -import ( - "context" - "e2eutils/pkg" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "sigs.k8s.io/e2e-framework/pkg/envconf" - "sigs.k8s.io/e2e-framework/pkg/features" -) - -func TestKargo(t *testing.T) { - kargoCurrent, kargoUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/kargo.yaml") - if err != nil { - t.Fatalf("Failed to prepare kargo test #%v", err) - } - - certCurrent, _, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/cert-manager.yaml") - if err != nil { - t.Fatalf("Failed to prepare cert-manager #%v", err) - } - - client := e2eutils.GetClient() - - install := features. - New("Deploying Kargo.io Helm Chart"). - Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - for index, _ := range kargoCurrent.Spec.Sources { - kargoCurrent.Spec.Sources[index].RepoURL = "oci://" + kargoCurrent.Spec.Sources[index].RepoURL + "/" + kargoCurrent.Spec.Sources[index].Chart - } - - // kargo depends on cert-manager crds - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), certCurrent) - require.NoError(t, err) - - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), kargoCurrent) - require.NoError(t, err) - - return ctx - }). - Assess("Deployments became ready", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DeploymentBecameReady(ctx, client, kargoCurrent.Spec.Destination.Namespace) - assert.NoError(t, err) - - return ctx - }). - Feature() - upgrade := features. - New("Upgrading Kargo.io Helm Chart"). - Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if kargoUpdate.Spec.Sources == nil { - t.SkipNow() - } - - for index, _ := range kargoUpdate.Spec.Sources { - kargoUpdate.Spec.Sources[index].RepoURL = "oci://" + kargoUpdate.Spec.Sources[index].RepoURL + "/" + kargoUpdate.Spec.Sources[index].Chart - } - - err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), kargoUpdate) - assert.NoError(t, err) - - return ctx - }). - Assess("Deployments became ready", - func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DeploymentBecameReady(ctx, client, kargoUpdate.Spec.Destination.Namespace) - assert.NoError(t, err) - - return ctx - }). - Feature() - - ciTestEnv.Test(t, install, upgrade) -} From f10800bbb978382b3ff4cbc13d0e3af894c78d99 Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Sat, 20 Sep 2025 07:18:31 +0200 Subject: [PATCH 4/9] fix: cleanup kustomization --- pkg/kustomize.go | 40 +++++++++++++++++----- pkg/test.go | 10 +++--- test/k3s_system_upgrade_controller_test.go | 24 +++++-------- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/pkg/kustomize.go b/pkg/kustomize.go index c99874ba..25ff19a8 100644 --- a/pkg/kustomize.go +++ b/pkg/kustomize.go @@ -1,14 +1,19 @@ package e2eutils import ( + "bytes" "context" "e2eutils/pkg/argo" + "fmt" + "io" "os" - "strings" + "gopkg.in/yaml.v3" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/e2e-framework/klient/decoder" "sigs.k8s.io/e2e-framework/klient/k8s" "sigs.k8s.io/kustomize/api/krusty" + "sigs.k8s.io/kustomize/kyaml/errors" "sigs.k8s.io/kustomize/kyaml/filesys" ) @@ -50,20 +55,39 @@ func prepareKubernetesManifests(applicationSource argo.ApplicationSource) ([]k8s return objects, nil } -func BuildKustomization(path string) ([]string, error) { +func BuildKustomization(path string) ([]*unstructured.Unstructured, error) { fSys := filesys.MakeFsOnDisk() - kustomizationDir := "../" + path k := krusty.MakeKustomizer(krusty.MakeDefaultOptions()) - objects, err := k.Run(fSys, kustomizationDir) + resMap, err := k.Run(fSys, path) if err != nil { - return nil, err + return nil, fmt.Errorf("running kustomize: %w", err) } - yaml, err := objects.AsYaml() + yamlData, err := resMap.AsYaml() if err != nil { - return nil, err + return nil, fmt.Errorf("convert resmap to yaml: %w", err) } - return strings.Split(string(yaml), "---"), nil + dec := yaml.NewDecoder(bytes.NewReader(yamlData)) + + var objects []*unstructured.Unstructured + for { + var o unstructured.Unstructured + if err := dec.Decode(&o.Object); err != nil { + if errors.Is(err, io.EOF) { + break + } + return nil, fmt.Errorf("decode yaml: %w", err) + } + + // skip empty documents + if len(o.Object) == 0 { + continue + } + + objects = append(objects, &o) + } + + return objects, nil } diff --git a/pkg/test.go b/pkg/test.go index 9af8c793..52038520 100644 --- a/pkg/test.go +++ b/pkg/test.go @@ -117,7 +117,7 @@ func deployHelmChart(applicationSource argo.ApplicationSource, namespace string, } func CheckJobsCompleted(ctx context.Context, client klient.Client, namespace string) error { - kubeConfig := client.RESTConfig() + kubeConfig := GetRestConfig() clientSet, err := kubernetes.NewForConfig(kubeConfig) if err != nil { return err @@ -143,7 +143,7 @@ func CheckJobsCompleted(ctx context.Context, client klient.Client, namespace str } func DeploymentBecameReady(ctx context.Context, client klient.Client, namespace string) error { - kubeConfig := client.RESTConfig() + kubeConfig := GetRestConfig() clientSet, err := kubernetes.NewForConfig(kubeConfig) if err != nil { return err @@ -174,7 +174,7 @@ func DeploymentBecameReady(ctx context.Context, client klient.Client, namespace } func DaemonSetBecameReady(ctx context.Context, client klient.Client, namespace string) error { - kubeConfig := client.RESTConfig() + kubeConfig := GetRestConfig() clientSet, err := kubernetes.NewForConfig(kubeConfig) if err != nil { return err @@ -205,7 +205,7 @@ func DaemonSetBecameReady(ctx context.Context, client klient.Client, namespace s } func PersistentVolumeClaimIsBound(ctx context.Context, client klient.Client, namespace string) error { - kubeConfig := client.RESTConfig() + kubeConfig := GetRestConfig() clientSet, err := kubernetes.NewForConfig(kubeConfig) if err != nil { return err @@ -236,7 +236,7 @@ func PersistentVolumeClaimIsBound(ctx context.Context, client klient.Client, nam } func SnapshotIsReadyToUse(ctx context.Context, client klient.Client, namespace string) error { - kubeConfig := client.RESTConfig() + kubeConfig := GetRestConfig() dynClient, err := dynamic.NewForConfig(kubeConfig) if err != nil { return err diff --git a/test/k3s_system_upgrade_controller_test.go b/test/k3s_system_upgrade_controller_test.go index a931fabc..fead81ee 100644 --- a/test/k3s_system_upgrade_controller_test.go +++ b/test/k3s_system_upgrade_controller_test.go @@ -10,7 +10,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - "sigs.k8s.io/yaml" ) func TestK3sSystemUpgradeController(t *testing.T) { @@ -22,16 +21,16 @@ func TestK3sSystemUpgradeController(t *testing.T) { client := e2eutils.GetClient() - var kustomization []string + var kustomization []*unstructured.Unstructured var namespace string install := features. New("Kustomization"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { if update.Spec.Sources != nil { - kustomization, err = e2eutils.BuildKustomization(update.Spec.Sources[0].Path) + kustomization, err = e2eutils.BuildKustomization("../" + update.Spec.Sources[0].Path) } else { - kustomization, err = e2eutils.BuildKustomization(current.Spec.Sources[0].Path) + kustomization, err = e2eutils.BuildKustomization("../" + current.Spec.Sources[0].Path) } require.NoError(t, err) @@ -39,32 +38,25 @@ func TestK3sSystemUpgradeController(t *testing.T) { }). Assess("Deployment", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - for _, resource := range kustomization { - var object unstructured.Unstructured - err = yaml.Unmarshal([]byte(resource), &object.Object) - require.NoError(t, err) - + // deploy namespace + for _, object := range kustomization { if object.GetKind() != "Namespace" { continue } - err = e2eutils.Apply(*clientSet, &object) + err = e2eutils.Apply(*clientSet, object) require.NoError(t, err) // give k8s api some time to create a resource time.Sleep(100 * time.Millisecond) } - for _, resource := range kustomization { - var object unstructured.Unstructured - err = yaml.Unmarshal([]byte(resource), &object.Object) - require.NoError(t, err) - + for _, object := range kustomization { if object.GetKind() == "Namespace" { continue } - err = e2eutils.Apply(*clientSet, &object) + err = e2eutils.Apply(*clientSet, object) require.NoError(t, err) // give k8s api some time to create a resource From 2a71784e334fdf265584f9f692131fafa0ffb0fd Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Sat, 20 Sep 2025 08:15:51 +0200 Subject: [PATCH 5/9] ci: increase timeout --- .github/workflows/pull-request.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 7c9cef90..a765f1eb 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -130,7 +130,7 @@ jobs: - name: Golang Test Helper if: ${{ needs.analyze-changes.outputs.go_helper_any_changed == 'true' }} run: | - go test -v ./test + go test -v ./test -timeout 30m - name: Upload KinD logs if: always() From 4583b3eabfc9c29f032061b77134bbefcb7a406b Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Sat, 20 Sep 2025 08:16:11 +0200 Subject: [PATCH 6/9] fix: cleanup kustomization --- pkg/kustomize.go | 70 +++++++++++------------------------------------- pkg/manifest.go | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 54 deletions(-) create mode 100644 pkg/manifest.go diff --git a/pkg/kustomize.go b/pkg/kustomize.go index 25ff19a8..a7987508 100644 --- a/pkg/kustomize.go +++ b/pkg/kustomize.go @@ -2,91 +2,53 @@ package e2eutils import ( "bytes" - "context" - "e2eutils/pkg/argo" + "errors" "fmt" "io" - "os" + "strings" "gopkg.in/yaml.v3" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "sigs.k8s.io/e2e-framework/klient/decoder" - "sigs.k8s.io/e2e-framework/klient/k8s" "sigs.k8s.io/kustomize/api/krusty" - "sigs.k8s.io/kustomize/kyaml/errors" "sigs.k8s.io/kustomize/kyaml/filesys" ) -func GetKubernetesManifests(argoApplication argo.Application) ([]k8s.Object, error) { - var objects []k8s.Object - var err error - - if argoApplication.Spec.Source != nil && argoApplication.Spec.Source.Path != "" { - objects, err = prepareKubernetesManifests(*argoApplication.Spec.Source) - if err != nil { - return nil, err - } - - return objects, nil - } - - var source argo.ApplicationSource - for _, source = range argoApplication.Spec.Sources { - if source.Path == "" { - continue - } - - objects, err = prepareKubernetesManifests(source) - if err != nil { - return nil, err - } - } - - return objects, nil -} - -func prepareKubernetesManifests(applicationSource argo.ApplicationSource) ([]k8s.Object, error) { - realPath := os.DirFS("../" + applicationSource.Path) - - objects, err := decoder.DecodeAllFiles(context.TODO(), realPath, "*.yaml") - if err != nil { - return nil, err +func BuildKustomization(path string) ([]*unstructured.Unstructured, error) { + if strings.TrimSpace(path) == "" { + return nil, errors.New("kustomization path must not be empty") } - return objects, nil -} -func BuildKustomization(path string) ([]*unstructured.Unstructured, error) { - fSys := filesys.MakeFsOnDisk() - k := krusty.MakeKustomizer(krusty.MakeDefaultOptions()) + fs := filesys.MakeFsOnDisk() + kustomizer := krusty.MakeKustomizer(krusty.MakeDefaultOptions()) - resMap, err := k.Run(fSys, path) + resMap, err := kustomizer.Run(fs, path) if err != nil { - return nil, fmt.Errorf("running kustomize: %w", err) + return nil, fmt.Errorf("failed to run kustomize: %w", err) } yamlData, err := resMap.AsYaml() if err != nil { - return nil, fmt.Errorf("convert resmap to yaml: %w", err) + return nil, fmt.Errorf("failed to convert resource map to YAML: %w", err) } - dec := yaml.NewDecoder(bytes.NewReader(yamlData)) + decoder := yaml.NewDecoder(bytes.NewReader(yamlData)) var objects []*unstructured.Unstructured for { - var o unstructured.Unstructured - if err := dec.Decode(&o.Object); err != nil { + var obj unstructured.Unstructured + if err := decoder.Decode(&obj.Object); err != nil { if errors.Is(err, io.EOF) { break } - return nil, fmt.Errorf("decode yaml: %w", err) + return nil, fmt.Errorf("failed to decode YAML: %w", err) } // skip empty documents - if len(o.Object) == 0 { + if len(obj.Object) == 0 { continue } - objects = append(objects, &o) + objects = append(objects, &obj) } return objects, nil diff --git a/pkg/manifest.go b/pkg/manifest.go new file mode 100644 index 00000000..06aa2cb1 --- /dev/null +++ b/pkg/manifest.go @@ -0,0 +1,48 @@ +package e2eutils + +import ( + "context" + "e2eutils/pkg/argo" + "os" + + "sigs.k8s.io/e2e-framework/klient/decoder" + "sigs.k8s.io/e2e-framework/klient/k8s" +) + +func GetKubernetesManifests(argoApplication argo.Application) ([]k8s.Object, error) { + var objects []k8s.Object + var err error + + if argoApplication.Spec.Source != nil && argoApplication.Spec.Source.Path != "" { + objects, err = prepareKubernetesManifests(*argoApplication.Spec.Source) + if err != nil { + return nil, err + } + + return objects, nil + } + + var source argo.ApplicationSource + for _, source = range argoApplication.Spec.Sources { + if source.Path == "" { + continue + } + + objects, err = prepareKubernetesManifests(source) + if err != nil { + return nil, err + } + } + + return objects, nil +} + +func prepareKubernetesManifests(applicationSource argo.ApplicationSource) ([]k8s.Object, error) { + realPath := os.DirFS("../" + applicationSource.Path) + + objects, err := decoder.DecodeAllFiles(context.TODO(), realPath, "*.yaml") + if err != nil { + return nil, err + } + return objects, nil +} From e71591dfaa4a7a8a8be0cfee5ef890895fe6c878 Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Sat, 20 Sep 2025 11:16:35 +0200 Subject: [PATCH 7/9] fix: refactor test preparation --- pkg/argo/argo.go | 18 ++++++++++ pkg/manifest.go | 38 +++++++++----------- pkg/test.go | 40 +++++++++++++--------- test/argo_cd_test.go | 2 +- test/argo_rollouts_test.go | 4 +-- test/cert_manager_test.go | 2 +- test/cloudflare_tunnel_test.go | 2 +- test/istio_test.go | 4 +-- test/k3s_system_upgrade_controller_test.go | 2 +- test/kured_test.go | 2 +- test/prometheus_test.go | 2 +- test/sealed_secrets_test.go | 2 +- test/storage_test.go | 4 +-- 13 files changed, 71 insertions(+), 51 deletions(-) diff --git a/pkg/argo/argo.go b/pkg/argo/argo.go index c014c513..e87d92a6 100644 --- a/pkg/argo/argo.go +++ b/pkg/argo/argo.go @@ -50,3 +50,21 @@ func GetArgoApplicationFromGit(gitRepository string, applicationYaml string) (Ap return *argoApplication, nil } + +func GatherArgoAppPaths(app Application) ( + pathCollection []string, +) { + if app.Spec.Sources != nil { + for _, source := range app.Spec.Sources { + if source.Path != "" { + pathCollection = append(pathCollection, source.Path) + } + } + } + + if app.Spec.Source != nil && app.Spec.Source.Path != "" { + pathCollection = append(pathCollection, app.Spec.Source.Path) + } + + return pathCollection +} diff --git a/pkg/manifest.go b/pkg/manifest.go index 06aa2cb1..af1ac4c3 100644 --- a/pkg/manifest.go +++ b/pkg/manifest.go @@ -2,47 +2,43 @@ package e2eutils import ( "context" - "e2eutils/pkg/argo" + "errors" + "fmt" "os" + "path/filepath" "sigs.k8s.io/e2e-framework/klient/decoder" "sigs.k8s.io/e2e-framework/klient/k8s" ) -func GetKubernetesManifests(argoApplication argo.Application) ([]k8s.Object, error) { - var objects []k8s.Object - var err error - - if argoApplication.Spec.Source != nil && argoApplication.Spec.Source.Path != "" { - objects, err = prepareKubernetesManifests(*argoApplication.Spec.Source) - if err != nil { - return nil, err - } - - return objects, nil +func GetKubernetesManifests(ctx context.Context, pathCollection []string) ([]k8s.Object, error) { + if pathCollection == nil { + return nil, errors.New("kustomization pathCollection must not be empty") } - var source argo.ApplicationSource - for _, source = range argoApplication.Spec.Sources { - if source.Path == "" { + var objects []k8s.Object + for _, source := range pathCollection { + if source == "" { continue } - objects, err = prepareKubernetesManifests(source) + o, err := prepareKubernetesManifests(ctx, source) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to prepare manifests from source pathCollection %q: %w", source, err) } + objects = append(objects, o...) } return objects, nil } -func prepareKubernetesManifests(applicationSource argo.ApplicationSource) ([]k8s.Object, error) { - realPath := os.DirFS("../" + applicationSource.Path) +func prepareKubernetesManifests(ctx context.Context, path string) ([]k8s.Object, error) { + manifestPath := filepath.Join("..", path) + manifestFS := os.DirFS(manifestPath) - objects, err := decoder.DecodeAllFiles(context.TODO(), realPath, "*.yaml") + objects, err := decoder.DecodeAllFiles(ctx, manifestFS, "*.yaml") if err != nil { - return nil, err + return nil, fmt.Errorf("failed to decode YAML files from path %q: %w", manifestPath, err) } return objects, nil } diff --git a/pkg/test.go b/pkg/test.go index 52038520..7b267cbc 100644 --- a/pkg/test.go +++ b/pkg/test.go @@ -4,8 +4,7 @@ import ( "context" "e2eutils/pkg/argo" "e2eutils/pkg/helm" - "errors" - "log/slog" + "fmt" "reflect" "strings" "time" @@ -25,21 +24,31 @@ import ( "sigs.k8s.io/e2e-framework/klient/wait/conditions" ) -func PrepareArgoApp(gitRepository string, applicationYaml string) (argo.Application, argo.Application, []k8s.Object, error) { +func PrepareArgoApp(ctx context.Context, gitRepository string, applicationYaml string) ( + argo.Application, + argo.Application, + []k8s.Object, + error, +) { currGitBranch, err := GetCurrentGitBranch() if err != nil { return argo.Application{}, argo.Application{}, nil, err } + var objects []k8s.Object + if currGitBranch == "main" { current, err := argo.GetArgoApplication(applicationYaml) if err != nil { return argo.Application{}, argo.Application{}, nil, err } - objects, err := GetKubernetesManifests(current) - if err != nil { - return current, argo.Application{}, nil, err + currentPathCollection := argo.GatherArgoAppPaths(current) + if len(currentPathCollection) != 0 { + objects, err = GetKubernetesManifests(ctx, currentPathCollection) + if err != nil { + return current, argo.Application{}, nil, err + } } return current, argo.Application{}, objects, nil @@ -50,20 +59,17 @@ func PrepareArgoApp(gitRepository string, applicationYaml string) (argo.Applicat return argo.Application{}, argo.Application{}, nil, err } - objects, err := GetKubernetesManifests(update) - if err != nil { - return argo.Application{}, argo.Application{}, nil, err + updatePathCollection := argo.GatherArgoAppPaths(update) + if len(updatePathCollection) != 0 { + objects, err = GetKubernetesManifests(ctx, updatePathCollection) + if err != nil { + return argo.Application{}, argo.Application{}, nil, err + } } current, err := argo.GetArgoApplicationFromGit(gitRepository, applicationYaml) if err != nil { - slog.Warn( - "Failed to get current application from git", - "application", applicationYaml, - "branch", currGitBranch, - "error", err.Error(), - ) - return update, argo.Application{}, objects, nil + return update, argo.Application{}, objects, fmt.Errorf("failed to fetch current application %q from git: %w", applicationYaml, err) } if reflect.DeepEqual(current, update) { @@ -77,7 +83,7 @@ func DeployHelmCharts(kubeConfigFile string, argoApplication argo.Application) e if argoApplication.Spec.Source != nil && argoApplication.Spec.Source.Chart != "" { err := deployHelmChart(*argoApplication.Spec.Source, argoApplication.Spec.Destination.Namespace, kubeConfigFile) if err != nil { - return errors.New(err.Error()) + return err } return nil diff --git a/test/argo_cd_test.go b/test/argo_cd_test.go index e3e2e82f..c6e7a45d 100644 --- a/test/argo_cd_test.go +++ b/test/argo_cd_test.go @@ -12,7 +12,7 @@ import ( ) func TestArgoCd(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/argo-cd.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/argo-cd.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) diff --git a/test/argo_rollouts_test.go b/test/argo_rollouts_test.go index 49366007..66be9dea 100644 --- a/test/argo_rollouts_test.go +++ b/test/argo_rollouts_test.go @@ -12,10 +12,10 @@ import ( ) func TestArgoRollouts(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/argo-rollouts.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/argo-rollouts.yaml") if err != nil { - t.Fatalf("Failed to prepare test #%v", err) + t.Fatalf("Failed to prepare test: %v", err) } client := e2eutils.GetClient() diff --git a/test/cert_manager_test.go b/test/cert_manager_test.go index 16982646..721cab4a 100644 --- a/test/cert_manager_test.go +++ b/test/cert_manager_test.go @@ -11,7 +11,7 @@ import ( ) func TestCertManager(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/cert-manager.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/cert-manager.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } diff --git a/test/cloudflare_tunnel_test.go b/test/cloudflare_tunnel_test.go index 2df517c6..943f9b0a 100644 --- a/test/cloudflare_tunnel_test.go +++ b/test/cloudflare_tunnel_test.go @@ -24,7 +24,7 @@ metadata: name: %s ` - current, _, additionalManifests, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/cloudflare-tunnel.yaml") + current, _, additionalManifests, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/cloudflare-tunnel.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } diff --git a/test/istio_test.go b/test/istio_test.go index d2cee247..c473d3f5 100644 --- a/test/istio_test.go +++ b/test/istio_test.go @@ -15,12 +15,12 @@ import ( ) func TestIstio(t *testing.T) { - istioCurrent, istioUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/istio.yaml") + istioCurrent, istioUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/istio.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } - gatewayCurrent, gatewayUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/istio-gateway.yaml") + gatewayCurrent, gatewayUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/istio-gateway.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } diff --git a/test/k3s_system_upgrade_controller_test.go b/test/k3s_system_upgrade_controller_test.go index fead81ee..6d9a6068 100644 --- a/test/k3s_system_upgrade_controller_test.go +++ b/test/k3s_system_upgrade_controller_test.go @@ -13,7 +13,7 @@ import ( ) func TestK3sSystemUpgradeController(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/k3s-system-upgrade-controller.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/k3s-system-upgrade-controller.yaml") require.NoError(t, err) clientSet, err := e2eutils.GetClientSet() diff --git a/test/kured_test.go b/test/kured_test.go index 292e00c2..659a5c3d 100644 --- a/test/kured_test.go +++ b/test/kured_test.go @@ -12,7 +12,7 @@ import ( ) func TestKured(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/kured.yaml") + current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/kured.yaml") require.NoError(t, err) client := e2eutils.GetClient() diff --git a/test/prometheus_test.go b/test/prometheus_test.go index 1b84bc54..8889f305 100644 --- a/test/prometheus_test.go +++ b/test/prometheus_test.go @@ -12,7 +12,7 @@ import ( ) func TestPrometheus(t *testing.T) { - promCurrent, promUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/prometheus.yaml") + promCurrent, promUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/prometheus.yaml") if err != nil { t.Fatalf("Failed to prepare prometheus test #%v", err) } diff --git a/test/sealed_secrets_test.go b/test/sealed_secrets_test.go index df5417f9..4df8f024 100644 --- a/test/sealed_secrets_test.go +++ b/test/sealed_secrets_test.go @@ -11,7 +11,7 @@ import ( ) func TestSealedSecrets(t *testing.T) { - sealedCurrent, sealedUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/sealed-secrets.yaml") + sealedCurrent, sealedUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/sealed-secrets.yaml") if err != nil { t.Fatalf("Failed to prepare sealed secret test #%v", err) } diff --git a/test/storage_test.go b/test/storage_test.go index ff08813b..9e2bc2d0 100644 --- a/test/storage_test.go +++ b/test/storage_test.go @@ -28,12 +28,12 @@ spec: storageClassName: longhorn ` - scCurrent, scUpdate, _, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/snapshot-controller.yaml") + scCurrent, scUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/snapshot-controller.yaml") if err != nil { t.Fatalf("Failed to prepare shanpshot controller test #%v", err) } - longhornCurrent, longhornUpdate, manifest, err := e2eutils.PrepareArgoApp(gitRepository, "../kubernetes-services/templates/longhorn.yaml") + longhornCurrent, longhornUpdate, manifest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/longhorn.yaml") if err != nil { t.Fatalf("Failed to prepare longhorn csi #%v", err) } From 26f42c542448f9a87bbe6bf2980f88646601f97f Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Sat, 20 Sep 2025 13:11:55 +0200 Subject: [PATCH 8/9] fix: refactoring of test entry --- pkg/test.go | 81 +++++++++++++--------- test/argo_cd_test.go | 19 +++-- test/argo_rollouts_test.go | 12 ++-- test/cert_manager_test.go | 14 ++-- test/cloudflare_tunnel_test.go | 16 ++--- test/istio_test.go | 24 +++---- test/k3s_system_upgrade_controller_test.go | 8 +-- test/kured_test.go | 12 ++-- test/prometheus_test.go | 24 +++---- test/sealed_secrets_test.go | 14 ++-- test/storage_test.go | 62 ++++++++--------- 11 files changed, 150 insertions(+), 136 deletions(-) diff --git a/pkg/test.go b/pkg/test.go index 7b267cbc..ea63574e 100644 --- a/pkg/test.go +++ b/pkg/test.go @@ -4,7 +4,6 @@ import ( "context" "e2eutils/pkg/argo" "e2eutils/pkg/helm" - "fmt" "reflect" "strings" "time" @@ -24,59 +23,75 @@ import ( "sigs.k8s.io/e2e-framework/klient/wait/conditions" ) +type ArgoTest struct { + Current AppSettings + Update AppSettings +} + +type AppSettings struct { + Argo argo.Application + Objects []k8s.Object +} + func PrepareArgoApp(ctx context.Context, gitRepository string, applicationYaml string) ( - argo.Application, - argo.Application, - []k8s.Object, + ArgoTest, error, ) { currGitBranch, err := GetCurrentGitBranch() if err != nil { - return argo.Application{}, argo.Application{}, nil, err + return ArgoTest{}, err } - var objects []k8s.Object - - if currGitBranch == "main" { - current, err := argo.GetArgoApplication(applicationYaml) - if err != nil { - return argo.Application{}, argo.Application{}, nil, err - } + currentSettings, err := buildAppNode(ctx, applicationYaml) + if err != nil { + return ArgoTest{}, err + } - currentPathCollection := argo.GatherArgoAppPaths(current) - if len(currentPathCollection) != 0 { - objects, err = GetKubernetesManifests(ctx, currentPathCollection) - if err != nil { - return current, argo.Application{}, nil, err - } - } + argoTest := ArgoTest{ + Current: currentSettings, + } - return current, argo.Application{}, objects, nil + // when we are working on the main branch, we don't need to fetch the Update state + if currGitBranch == "main" { + return argoTest, nil } - update, err := argo.GetArgoApplication(applicationYaml) + updateSettings, err := buildAppNode(ctx, applicationYaml) if err != nil { - return argo.Application{}, argo.Application{}, nil, err + return ArgoTest{}, err } + argoTest.Update = updateSettings - updatePathCollection := argo.GatherArgoAppPaths(update) - if len(updatePathCollection) != 0 { - objects, err = GetKubernetesManifests(ctx, updatePathCollection) - if err != nil { - return argo.Application{}, argo.Application{}, nil, err - } + // if both nodes are equal, we don't need to test the update state + if reflect.DeepEqual(argoTest.Current, argoTest.Update) { + argoTest.Update = AppSettings{} } - current, err := argo.GetArgoApplicationFromGit(gitRepository, applicationYaml) + return argoTest, nil +} + +func buildAppNode(ctx context.Context, applicationYaml string) ( + AppSettings, + error, +) { + app, err := argo.GetArgoApplication(applicationYaml) if err != nil { - return update, argo.Application{}, objects, fmt.Errorf("failed to fetch current application %q from git: %w", applicationYaml, err) + return AppSettings{}, err } - if reflect.DeepEqual(current, update) { - return current, argo.Application{}, objects, nil + pathCollection := argo.GatherArgoAppPaths(app) + var objects []k8s.Object + if len(pathCollection) != 0 { + objects, err = GetKubernetesManifests(ctx, pathCollection) + if err != nil { + return AppSettings{}, err + } } - return current, update, objects, nil + return AppSettings{ + Argo: app, + Objects: objects, + }, nil } func DeployHelmCharts(kubeConfigFile string, argoApplication argo.Application) error { diff --git a/test/argo_cd_test.go b/test/argo_cd_test.go index c6e7a45d..e60fa05d 100644 --- a/test/argo_cd_test.go +++ b/test/argo_cd_test.go @@ -12,10 +12,9 @@ import ( ) func TestArgoCd(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/argo-cd.yaml") - + argoTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/argo-cd.yaml") if err != nil { - t.Fatalf("Failed to prepare test #%v", err) + t.Fatalf("Failed to prepare test: %v", err) } client := e2eutils.GetClient() @@ -23,21 +22,21 @@ func TestArgoCd(t *testing.T) { install := features. New("Deploying Argo CD Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), current) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), argoTest.Current.Argo) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, argoTest.Current.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx }). Assess("Jobs run successfully", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.CheckJobsCompleted(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.CheckJobsCompleted(ctx, client, argoTest.Current.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx @@ -47,25 +46,25 @@ func TestArgoCd(t *testing.T) { upgrade := features. New("Upgrading Argo CD Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if update.Spec.Sources == nil { + if argoTest.Update.Argo.Spec.Sources == nil { t.SkipNow() } - err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), update) + err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), argoTest.Update.Argo) assert.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, argoTest.Update.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx }). Assess("Jobs run successfully", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.CheckJobsCompleted(ctx, client, update.Spec.Destination.Namespace) + err := e2eutils.CheckJobsCompleted(ctx, client, argoTest.Update.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/argo_rollouts_test.go b/test/argo_rollouts_test.go index 66be9dea..48e1178b 100644 --- a/test/argo_rollouts_test.go +++ b/test/argo_rollouts_test.go @@ -12,7 +12,7 @@ import ( ) func TestArgoRollouts(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/argo-rollouts.yaml") + rolloutTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/argo-rollouts.yaml") if err != nil { t.Fatalf("Failed to prepare test: %v", err) @@ -23,14 +23,14 @@ func TestArgoRollouts(t *testing.T) { install := features. New("Deploying Argo Rollouts Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), current) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), rolloutTest.Current.Argo) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, rolloutTest.Current.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx @@ -40,18 +40,18 @@ func TestArgoRollouts(t *testing.T) { upgrade := features. New("Upgrading Argo Rollouts Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if update.Spec.Source == nil { + if rolloutTest.Update.Argo.Spec.Source == nil { t.SkipNow() } - err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), update) + err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), rolloutTest.Update.Argo) assert.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, rolloutTest.Update.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/cert_manager_test.go b/test/cert_manager_test.go index 721cab4a..b590bf4c 100644 --- a/test/cert_manager_test.go +++ b/test/cert_manager_test.go @@ -11,9 +11,9 @@ import ( ) func TestCertManager(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/cert-manager.yaml") + certTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/cert-manager.yaml") if err != nil { - t.Fatalf("Failed to prepare test #%v", err) + t.Fatalf("Failed to prepare test: %v", err) } client := e2eutils.GetClient() @@ -21,14 +21,14 @@ func TestCertManager(t *testing.T) { install := features. New("Deploying Cert Manager Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), current) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), certTest.Current.Argo) require.NoError(t, err) return ctx }). Assess("Deployment became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, certTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -38,18 +38,18 @@ func TestCertManager(t *testing.T) { upgrade := features. New("Upgrading Cert Manager Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if update.Spec.Sources == nil { + if certTest.Update.Argo.Spec.Sources == nil { t.SkipNow() } - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), update) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), certTest.Update.Argo) require.NoError(t, err) return ctx }). Assess("Testing Cert Manager upgrade became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, update.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, certTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx diff --git a/test/cloudflare_tunnel_test.go b/test/cloudflare_tunnel_test.go index 943f9b0a..e8f419e7 100644 --- a/test/cloudflare_tunnel_test.go +++ b/test/cloudflare_tunnel_test.go @@ -24,24 +24,24 @@ metadata: name: %s ` - current, _, additionalManifests, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/cloudflare-tunnel.yaml") + cloudflareTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/cloudflare-tunnel.yaml") if err != nil { - t.Fatalf("Failed to prepare test #%v", err) + t.Fatalf("Failed to prepare test: %v", err) } client := e2eutils.GetClient() clientSet, err := e2eutils.GetClientSet() if err != nil { - t.Fatalf("Failed to get kubernetes clientSet #%v", err) + t.Fatalf("Failed to get kubernetes clientSet: %v", err) } var objectList []k8s.Object install := features. New("Preparing Cloudflare Tunnel Test"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - cloudflareTunnelDeployment := additionalManifests[0].(*v1.Deployment) - cloudflareTunnelDeployment.ObjectMeta.Namespace = current.Spec.Destination.Namespace + cloudflareTunnelDeployment := cloudflareTest.Current.Objects[0].(*v1.Deployment) + cloudflareTunnelDeployment.ObjectMeta.Namespace = cloudflareTest.Current.Argo.Spec.Destination.Namespace // delete initContainers, we do not have the tunnel token in ci cloudflareTunnelDeployment.Spec.Template.Spec.InitContainers = nil @@ -54,10 +54,10 @@ metadata: objectList, err = decoder.DecodeAll(ctx, strings.NewReader(initYaml)) if err != nil { - t.Fatalf("Failed to decode namespace #%v", err) + t.Fatalf("Failed to decode namespace: %v", err) } - objectList = append(objectList, additionalManifests[0]) + objectList = append(objectList, cloudflareTest.Current.Objects[0]) return ctx }). @@ -74,7 +74,7 @@ metadata: }). Assess("Deployment became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DeploymentBecameReady(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.DeploymentBecameReady(ctx, client, cloudflareTest.Current.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/istio_test.go b/test/istio_test.go index c473d3f5..759df061 100644 --- a/test/istio_test.go +++ b/test/istio_test.go @@ -15,12 +15,12 @@ import ( ) func TestIstio(t *testing.T) { - istioCurrent, istioUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/istio.yaml") + istioTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/istio.yaml") if err != nil { - t.Fatalf("Failed to prepare test #%v", err) + t.Fatalf("Failed to prepare test: %v", err) } - gatewayCurrent, gatewayUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/istio-gateway.yaml") + gatewayTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/istio-gateway.yaml") if err != nil { t.Fatalf("Failed to prepare test #%v", err) } @@ -30,20 +30,20 @@ func TestIstio(t *testing.T) { install := features. New("Deploying Istio Helm Charts Collection"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), istioCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), istioTest.Current.Argo) require.NoError(t, err) - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), gatewayCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), gatewayTest.Current.Argo) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, istioCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, istioTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) - err = e2eutils.DeploymentBecameReady(ctx, client, gatewayCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, gatewayTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -93,24 +93,24 @@ func TestIstio(t *testing.T) { upgrade := features. New("Upgrading Istio Helm Charts Collection"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if istioUpdate.Spec.Sources == nil && gatewayUpdate.Spec.Sources == nil { + if istioTest.Update.Argo.Spec.Sources == nil && gatewayTest.Update.Argo.Spec.Sources == nil { t.SkipNow() } - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), istioUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), istioTest.Update.Argo) require.NoError(t, err) - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), gatewayUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), gatewayTest.Update.Argo) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, istioUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, istioTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) - err = e2eutils.DeploymentBecameReady(ctx, client, gatewayUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, gatewayTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx diff --git a/test/k3s_system_upgrade_controller_test.go b/test/k3s_system_upgrade_controller_test.go index 6d9a6068..9e905640 100644 --- a/test/k3s_system_upgrade_controller_test.go +++ b/test/k3s_system_upgrade_controller_test.go @@ -13,7 +13,7 @@ import ( ) func TestK3sSystemUpgradeController(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/k3s-system-upgrade-controller.yaml") + upgradeTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/k3s-system-upgrade-controller.yaml") require.NoError(t, err) clientSet, err := e2eutils.GetClientSet() @@ -27,10 +27,10 @@ func TestK3sSystemUpgradeController(t *testing.T) { install := features. New("Kustomization"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if update.Spec.Sources != nil { - kustomization, err = e2eutils.BuildKustomization("../" + update.Spec.Sources[0].Path) + if upgradeTest.Update.Argo.Spec.Sources != nil { + kustomization, err = e2eutils.BuildKustomization("../" + upgradeTest.Update.Argo.Spec.Sources[0].Path) } else { - kustomization, err = e2eutils.BuildKustomization("../" + current.Spec.Sources[0].Path) + kustomization, err = e2eutils.BuildKustomization("../" + upgradeTest.Current.Argo.Spec.Sources[0].Path) } require.NoError(t, err) diff --git a/test/kured_test.go b/test/kured_test.go index 659a5c3d..d2f67406 100644 --- a/test/kured_test.go +++ b/test/kured_test.go @@ -12,7 +12,7 @@ import ( ) func TestKured(t *testing.T) { - current, update, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/kured.yaml") + kuredTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/kured.yaml") require.NoError(t, err) client := e2eutils.GetClient() @@ -20,14 +20,14 @@ func TestKured(t *testing.T) { install := features. New("Deploying Kured Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), current) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), kuredTest.Current.Argo) require.NoError(t, err) return ctx }). Assess("DaemonSet became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DaemonSetBecameReady(ctx, client, current.Spec.Destination.Namespace) + err := e2eutils.DaemonSetBecameReady(ctx, client, kuredTest.Current.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx @@ -37,18 +37,18 @@ func TestKured(t *testing.T) { upgrade := features. New("Upgrading Kured Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if update.Spec.Source == nil { + if kuredTest.Update.Argo.Spec.Source == nil { t.SkipNow() } - err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), update) + err := e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), kuredTest.Update.Argo) assert.NoError(t, err) return ctx }). Assess("DaemonSet became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err := e2eutils.DaemonSetBecameReady(ctx, client, update.Spec.Destination.Namespace) + err := e2eutils.DaemonSetBecameReady(ctx, client, kuredTest.Update.Argo.Spec.Destination.Namespace) assert.NoError(t, err) return ctx diff --git a/test/prometheus_test.go b/test/prometheus_test.go index 8889f305..991ad4b8 100644 --- a/test/prometheus_test.go +++ b/test/prometheus_test.go @@ -12,12 +12,12 @@ import ( ) func TestPrometheus(t *testing.T) { - promCurrent, promUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/prometheus.yaml") + prometheusTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/prometheus.yaml") if err != nil { t.Fatalf("Failed to prepare prometheus test #%v", err) } - for i, source := range promCurrent.Spec.Sources { + for i, source := range prometheusTest.Current.Argo.Spec.Sources { if source.Chart == "" { continue } @@ -51,10 +51,10 @@ func TestPrometheus(t *testing.T) { -1, ) - promCurrent.Spec.Sources[i].Helm.Values = source.Helm.Values + prometheusTest.Current.Argo.Spec.Sources[i].Helm.Values = source.Helm.Values } - for i, source := range promUpdate.Spec.Sources { + for i, source := range prometheusTest.Update.Argo.Spec.Sources { if source.Chart == "" { continue } @@ -88,7 +88,7 @@ func TestPrometheus(t *testing.T) { -1, ) - promUpdate.Spec.Sources[i].Helm.Values = source.Helm.Values + prometheusTest.Update.Argo.Spec.Sources[i].Helm.Values = source.Helm.Values } client := e2eutils.GetClient() @@ -96,21 +96,21 @@ func TestPrometheus(t *testing.T) { install := features. New("Deploying Prometheus Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), promCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), prometheusTest.Current.Argo) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, promCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, prometheusTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Daemonsets became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DaemonSetBecameReady(ctx, client, promCurrent.Spec.Destination.Namespace) + err = e2eutils.DaemonSetBecameReady(ctx, client, prometheusTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -120,25 +120,25 @@ func TestPrometheus(t *testing.T) { upgrade := features. New("Upgrading Prometheus Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if promUpdate.Spec.Sources == nil { + if prometheusTest.Update.Argo.Spec.Sources == nil { t.SkipNow() } - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), promUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), prometheusTest.Update.Argo) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, promUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, prometheusTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Daemonsets became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DaemonSetBecameReady(ctx, client, promUpdate.Spec.Destination.Namespace) + err = e2eutils.DaemonSetBecameReady(ctx, client, prometheusTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx diff --git a/test/sealed_secrets_test.go b/test/sealed_secrets_test.go index 4df8f024..1258a9c7 100644 --- a/test/sealed_secrets_test.go +++ b/test/sealed_secrets_test.go @@ -11,9 +11,9 @@ import ( ) func TestSealedSecrets(t *testing.T) { - sealedCurrent, sealedUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/sealed-secrets.yaml") + sealedTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/sealed-secrets.yaml") if err != nil { - t.Fatalf("Failed to prepare sealed secret test #%v", err) + t.Fatalf("Failed to prepare sealed secret test: %v", err) } client := e2eutils.GetClient() @@ -21,14 +21,14 @@ func TestSealedSecrets(t *testing.T) { install := features. New("Deploying Sealed Secrets Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), sealedCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), sealedTest.Current.Argo) require.NoError(t, err) return ctx }). Assess("Deployment became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, sealedCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, sealedTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx @@ -37,18 +37,18 @@ func TestSealedSecrets(t *testing.T) { upgrade := features. New("Upgrading Sealed Secrets Helm Chart"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if sealedUpdate.Spec.Source == nil { + if sealedTest.Update.Argo.Spec.Source == nil { t.SkipNow() } - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), sealedUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), sealedTest.Update.Argo) require.NoError(t, err) return ctx }). Assess("Testing Sealed Secrets upgrade became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, sealedUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, sealedTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx diff --git a/test/storage_test.go b/test/storage_test.go index 9e2bc2d0..71be2c4f 100644 --- a/test/storage_test.go +++ b/test/storage_test.go @@ -28,14 +28,14 @@ spec: storageClassName: longhorn ` - scCurrent, scUpdate, _, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/snapshot-controller.yaml") + snapshotTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/snapshot-controller.yaml") if err != nil { - t.Fatalf("Failed to prepare shanpshot controller test #%v", err) + t.Fatalf("Failed to prepare shanpshot controller test: %v", err) } - longhornCurrent, longhornUpdate, manifest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/longhorn.yaml") + longhornTest, err := e2eutils.PrepareArgoApp(t.Context(), gitRepository, "../kubernetes-services/templates/longhorn.yaml") if err != nil { - t.Fatalf("Failed to prepare longhorn csi #%v", err) + t.Fatalf("Failed to prepare longhorn csi: %v", err) } client := e2eutils.GetClient() @@ -50,14 +50,14 @@ spec: Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { // in ci we run a single node instance of kind - longhornCurrent.Spec.Sources[0].Helm.Values = strings.Replace( - longhornCurrent.Spec.Sources[0].Helm.Values, + longhornTest.Current.Argo.Spec.Sources[0].Helm.Values = strings.Replace( + longhornTest.Current.Argo.Spec.Sources[0].Helm.Values, "defaultClassReplicaCount: 4", "defaultClassReplicaCount: 1", -1, ) - longhornCurrent.Spec.Sources[0].Helm.Values = ` + longhornTest.Current.Argo.Spec.Sources[0].Helm.Values = ` csi: attacherReplicaCount: 1 provisionerReplicaCount: 1 @@ -66,8 +66,8 @@ csi: ` // we also do not have prometheus - longhornCurrent.Spec.Sources[0].Helm.Values = strings.Replace( - longhornCurrent.Spec.Sources[0].Helm.Values, + longhornTest.Current.Argo.Spec.Sources[0].Helm.Values = strings.Replace( + longhornTest.Current.Argo.Spec.Sources[0].Helm.Values, "serviceMonitor:\n enabled: true", "serviceMonitor:\n enabled: false", -1, @@ -77,38 +77,38 @@ csi: }). Assess("Deploying CSI Helm Charts", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), scCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), snapshotTest.Current.Argo) require.NoError(t, err) - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), longhornCurrent) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), longhornTest.Current.Argo) require.NoError(t, err) return ctx }). Assess("Longhorn DaemonSet became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DaemonSetBecameReady(ctx, client, longhornCurrent.Spec.Destination.Namespace) + err = e2eutils.DaemonSetBecameReady(ctx, client, longhornTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, longhornCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, longhornTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Snapshot Controller Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.DeploymentBecameReady(ctx, client, scCurrent.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, snapshotTest.Current.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Deploy Snapshot Class", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - err = e2eutils.ApplyAll(*clientSet, manifest) + err = e2eutils.ApplyAll(*clientSet, longhornTest.Current.Objects) require.NoError(t, err) return ctx @@ -128,25 +128,25 @@ csi: upgrade := features. New("Upgrading CSI Helm Charts"). Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if longhornUpdate.Spec.Sources == nil && scUpdate.Spec.Sources == nil { + if longhornTest.Update.Argo.Spec.Sources == nil && snapshotTest.Update.Argo.Spec.Sources == nil { t.SkipNow() } - if scUpdate.Spec.Sources != nil { - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), scUpdate) + if snapshotTest.Update.Argo.Spec.Sources != nil { + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), snapshotTest.Update.Argo) require.NoError(t, err) } - if longhornUpdate.Spec.Sources != nil { + if longhornTest.Update.Argo.Spec.Sources != nil { // in ci we run a single node instance of kind - longhornUpdate.Spec.Sources[0].Helm.Values = strings.Replace( - longhornUpdate.Spec.Sources[0].Helm.Values, + longhornTest.Update.Argo.Spec.Sources[0].Helm.Values = strings.Replace( + longhornTest.Update.Argo.Spec.Sources[0].Helm.Values, "defaultClassReplicaCount: 4", "defaultClassReplicaCount: 1", -1, ) - longhornUpdate.Spec.Sources[0].Helm.Values = ` + longhornTest.Update.Argo.Spec.Sources[0].Helm.Values = ` csi: attacherReplicaCount: 1 provisionerReplicaCount: 1 @@ -155,47 +155,47 @@ csi: ` // we also do not have prometheus - longhornUpdate.Spec.Sources[0].Helm.Values = strings.Replace( - longhornUpdate.Spec.Sources[0].Helm.Values, + longhornTest.Update.Argo.Spec.Sources[0].Helm.Values = strings.Replace( + longhornTest.Update.Argo.Spec.Sources[0].Helm.Values, "serviceMonitor:\n enabled: true", "serviceMonitor:\n enabled: false", -1, ) - err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), longhornUpdate) + err = e2eutils.DeployHelmCharts(cfg.KubeconfigFile(), longhornTest.Update.Argo) require.NoError(t, err) } return ctx }). Assess("Longhorn DaemonSet became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if longhornUpdate.Spec.Sources == nil { + if longhornTest.Update.Argo.Spec.Sources == nil { t.SkipNow() } - err = e2eutils.DaemonSetBecameReady(ctx, client, longhornUpdate.Spec.Destination.Namespace) + err = e2eutils.DaemonSetBecameReady(ctx, client, longhornTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Longhorn Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if longhornUpdate.Spec.Sources == nil { + if longhornTest.Update.Argo.Spec.Sources == nil { t.SkipNow() } - err = e2eutils.DeploymentBecameReady(ctx, client, longhornUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, longhornTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx }). Assess("Snapshot Controller Deployments became ready", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - if scUpdate.Spec.Sources == nil { + if snapshotTest.Update.Argo.Spec.Sources == nil { t.SkipNow() } - err = e2eutils.DeploymentBecameReady(ctx, client, scUpdate.Spec.Destination.Namespace) + err = e2eutils.DeploymentBecameReady(ctx, client, snapshotTest.Update.Argo.Spec.Destination.Namespace) require.NoError(t, err) return ctx From 8f209b1d041b15eb934e1725434972833d30cf88 Mon Sep 17 00:00:00 2001 From: Adam Hukalowicz Date: Sat, 20 Sep 2025 14:53:15 +0200 Subject: [PATCH 9/9] fix: fetch current state from git repo --- pkg/argo/argo.go | 10 ++++++++-- pkg/test.go | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pkg/argo/argo.go b/pkg/argo/argo.go index e87d92a6..a9690afa 100644 --- a/pkg/argo/argo.go +++ b/pkg/argo/argo.go @@ -11,7 +11,10 @@ import ( "sigs.k8s.io/yaml" ) -func GetArgoApplication(applicationYaml string) (Application, error) { +func GetArgoApplication(applicationYaml string) ( + Application, + error, +) { yamlFile, err := os.ReadFile(applicationYaml) if err != nil { return Application{}, errors.New("Failed to open application yaml file " + applicationYaml + ". " + err.Error()) @@ -26,7 +29,10 @@ func GetArgoApplication(applicationYaml string) (Application, error) { return *argoApplication, nil } -func GetArgoApplicationFromGit(gitRepository string, applicationYaml string) (Application, error) { +func GetArgoApplicationFromGit(gitRepository string, applicationYaml string) ( + Application, + error, +) { baseUrl := gitRepository + strings.TrimPrefix(applicationYaml, "../") response, err := http.Get(baseUrl) if err != nil { diff --git a/pkg/test.go b/pkg/test.go index ea63574e..d2aee34d 100644 --- a/pkg/test.go +++ b/pkg/test.go @@ -37,12 +37,12 @@ func PrepareArgoApp(ctx context.Context, gitRepository string, applicationYaml s ArgoTest, error, ) { - currGitBranch, err := GetCurrentGitBranch() + workingBranch, err := GetCurrentGitBranch() if err != nil { return ArgoTest{}, err } - currentSettings, err := buildAppNode(ctx, applicationYaml) + currentSettings, err := buildAppNode(ctx, applicationYaml, gitRepository, "main") if err != nil { return ArgoTest{}, err } @@ -51,18 +51,17 @@ func PrepareArgoApp(ctx context.Context, gitRepository string, applicationYaml s Current: currentSettings, } - // when we are working on the main branch, we don't need to fetch the Update state - if currGitBranch == "main" { + // when we are working on the main branch, we don't want to fetch the Update state + if workingBranch == "main" { return argoTest, nil } - updateSettings, err := buildAppNode(ctx, applicationYaml) + argoTest.Update, err = buildAppNode(ctx, applicationYaml, gitRepository, workingBranch) if err != nil { return ArgoTest{}, err } - argoTest.Update = updateSettings - // if both nodes are equal, we don't need to test the update state + // if both nodes are equal, we don't want to test the update state if reflect.DeepEqual(argoTest.Current, argoTest.Update) { argoTest.Update = AppSettings{} } @@ -70,11 +69,19 @@ func PrepareArgoApp(ctx context.Context, gitRepository string, applicationYaml s return argoTest, nil } -func buildAppNode(ctx context.Context, applicationYaml string) ( +func buildAppNode(ctx context.Context, applicationYaml string, gitRepository string, branch string) ( AppSettings, error, ) { - app, err := argo.GetArgoApplication(applicationYaml) + var app argo.Application + var err error + + if branch == "main" { + app, err = argo.GetArgoApplicationFromGit(gitRepository, applicationYaml) + } else { + app, err = argo.GetArgoApplication(applicationYaml) + } + if err != nil { return AppSettings{}, err }