Skip to content

Commit

Permalink
small bugfixes for test implementation, tested against infra
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes94 committed Dec 17, 2024
1 parent d7b23d7 commit 22c1b7b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
emailsender-manifests.yaml
central-chart/
pids-port-forward
# temp files created by multicluster e2e tests
cluster-list.json
cluster-list2.json
fm-dataplane-config.yaml
# Ignore uploaded files in development
/storage/*

Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@ test/e2e: $(GINKGO_BIN)
./e2e/...
.PHONY: test/e2e

test/e2e/multicluster: $(GINKGO_BIN)
CLUSTER_ID=1234567890abcdef1234567890abcdef \
ENABLE_CENTRAL_EXTERNAL_CERTIFICATE=$(ENABLE_CENTRAL_EXTERNAL_CERTIFICATE) \
GITOPS_CONFIG_PATH=$(GITOPS_CONFIG_FILE) \
RUN_MULTICLUSTER_E2E=true
$(GINKGO_BIN) -r $(GINKGO_FLAGS) \
--randomize-suites \
--fail-on-pending --keep-going \
--cover --coverprofile=cover.profile \
--race --trace \
--json-report=e2e-report.json \
--timeout=$(TEST_TIMEOUT) \
--poll-progress-after=5m \
./e2e/multicluster
.PHONY: test/e2e/multicluster

# Deploys the necessary applications to the selected cluster and runs e2e tests inside the container
# Useful for debugging Openshift CI runs locally
test/deploy/e2e-dockerized:
Expand Down
10 changes: 0 additions & 10 deletions e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/stackrox/acs-fleet-manager/e2e/testutil"
"github.com/stackrox/acs-fleet-manager/fleetshard/config"
"github.com/stackrox/acs-fleet-manager/fleetshard/pkg/k8s"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public"
"github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager"
"github.com/stackrox/rox/operator/apis/platform/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -113,15 +112,6 @@ func enableTestsGroup(testName string, envName string, defaultValue string) bool
return false
}

func obtainCentralRequest(ctx context.Context, client *fleetmanager.Client, id string, request *public.CentralRequest) error {
centralRequest, _, err := client.PublicAPI().GetCentralById(ctx, id)
if err != nil {
return err
}
*request = centralRequest
return nil
}

func assertStoredSecrets(ctx context.Context, privateAPI fleetmanager.PrivateAPI, centralRequestID string, expected []string) func() error {
return func() error {
privateCentral, _, err := privateAPI.GetCentral(ctx, centralRequestID)
Expand Down
12 changes: 6 additions & 6 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ var _ = Describe("Central", Ordered, func() {
It("should not expose URLs until the routes are created", func() {
testutil.SkipIf(!routesEnabled, skipRouteMsg)
var centralRequest public.CentralRequest
Expect(obtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
Expect(testutil.ObtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
To(Succeed())
Expect(centralRequest.CentralUIURL).To(BeEmpty())
Expect(centralRequest.CentralDataURL).To(BeEmpty())
Expand All @@ -175,7 +175,7 @@ var _ = Describe("Central", Ordered, func() {
testutil.SkipIf(!routesEnabled, skipRouteMsg)

var centralRequest public.CentralRequest
Expect(obtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
Expect(testutil.ObtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
To(Succeed())

var reencryptRoute openshiftRouteV1.Route
Expand Down Expand Up @@ -207,7 +207,7 @@ var _ = Describe("Central", Ordered, func() {
testutil.SkipIf(!dnsEnabled, testutil.SkipDNSMsg)

var centralRequest public.CentralRequest
Expect(obtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
Expect(testutil.ObtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
To(Succeed())

var reencryptIngress openshiftRouteV1.RouteIngress
Expand Down Expand Up @@ -355,7 +355,7 @@ var _ = Describe("Central", Ordered, func() {
It("should delete external DNS entries", func() {
testutil.SkipIf(!dnsEnabled, testutil.SkipDNSMsg)
var centralRequest public.CentralRequest
Expect(obtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
Expect(testutil.ObtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
To(Succeed())
dnsRecordsLoader := dns.NewRecordsLoader(route53Client, centralRequest)
Eventually(dnsRecordsLoader.LoadDNSRecords).
Expand Down Expand Up @@ -435,7 +435,7 @@ var _ = Describe("Central", Ordered, func() {
It("should delete external DNS entries", func() {
testutil.SkipIf(!dnsEnabled, testutil.SkipDNSMsg)
var centralRequest public.CentralRequest
Expect(obtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
Expect(testutil.ObtainCentralRequest(ctx, client, centralRequestID, &centralRequest)).
To(Succeed())
dnsRecordsLoader := dns.NewRecordsLoader(route53Client, centralRequest)
Eventually(dnsRecordsLoader.LoadDNSRecords).
Expand Down Expand Up @@ -479,7 +479,7 @@ var _ = Describe("Central", Ordered, func() {
WithTimeout(extendedWaitTimeout).
WithPolling(defaultPolling).
Should(Succeed())
Expect(obtainCentralRequest(ctx, client, centralRequestID, &readyCentralRequest)).
Expect(testutil.ObtainCentralRequest(ctx, client, centralRequestID, &readyCentralRequest)).
To(Succeed())
})

Expand Down
15 changes: 11 additions & 4 deletions e2e/multicluster/multicluster_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ var _ = Describe("Central Migration Test", Ordered, func() {

It("should have DNS CNAME records for cluster1 routes", func() {
testutil.SkipIf(!dnsEnabled, testutil.SkipDNSMsg)
testutil.ObtainCentralRequest(context.Background(), fleetmanagerClient, centralRequest.Id, &centralRequest)

dnsRecordsLoader := dns.NewRecordsLoader(route53Client, centralRequest)
routeService := k8s.NewRouteService(cluster1KubeClient, routeConfig)

Expand Down Expand Up @@ -145,7 +147,7 @@ var _ = Describe("Central Migration Test", Ordered, func() {

Describe("CentralRequest post migration", func() {
It("should be assigned to cluster2", func() {
assertClusterAssignment(cluster1ID, centralRequest.Id, fleetmanagerAdminClient)
assertClusterAssignment(cluster2ID, centralRequest.Id, fleetmanagerAdminClient)
})
It("should reach the ready state", func() {
Eventually(testutil.AssertCentralRequestReady(context.Background(), fleetmanagerClient, centralRequest.Id)).
Expand All @@ -155,6 +157,8 @@ var _ = Describe("Central Migration Test", Ordered, func() {
})
It("should have DNS CNAME records for cluster2 routes", func() {
testutil.SkipIf(!dnsEnabled, testutil.SkipDNSMsg)
testutil.ObtainCentralRequest(context.Background(), fleetmanagerClient, centralRequest.Id, &centralRequest)

dnsRecordsLoader := dns.NewRecordsLoader(route53Client, centralRequest)
routeService := k8s.NewRouteService(cluster2KubeClient, routeConfig)

Expand Down Expand Up @@ -207,6 +211,9 @@ var _ = Describe("Central Migration Test", Ordered, func() {
Eventually(func() (int, error) {
_, res, err := fleetmanagerClient.PublicAPI().GetCentralById(context.Background(), centralRequest.Id)
if res != nil {
if res.StatusCode == 404 {
return res.StatusCode, nil
}
return res.StatusCode, err
}

Expand Down Expand Up @@ -265,10 +272,10 @@ func getClusterAssignment(centralID string, adminAPI fleetmanager.AdminAPI) (str
}

func getNamespace(name string, kubeClient ctrlClient.Client) (*corev1.Namespace, error) {
var namespace *corev1.Namespace
if err := kubeClient.Get(context.Background(), ctrlClient.ObjectKey{Name: name}, namespace); err != nil {
var namespace corev1.Namespace
if err := kubeClient.Get(context.Background(), ctrlClient.ObjectKey{Name: name}, &namespace); err != nil {
return nil, fmt.Errorf("getting namespace %q: %w", name, err)
}

return namespace, nil
return &namespace, nil
}
4 changes: 4 additions & 0 deletions e2e/multicluster/multicluster_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ var (
)

func TestMulticlusterE2E(t *testing.T) {
if os.Getenv("RUN_MULTICLUSTER_E2E") != "true" {
t.Skip("Skip multicluster e2e tests. Set RUN_MULTICLUSTER_E2E=true env variable to enable e2e tests.")
}

RegisterFailHandler(Fail)
RunSpecs(t, "ACSCS Multicluster Suite")
}
Expand Down
13 changes: 13 additions & 0 deletions e2e/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
package testutil

import (
"context"
"fmt"
"os"
"time"

. "github.com/onsi/ginkgo/v2"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public"
"github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager"
)

const defaultTimeout = 5 * time.Minute
Expand Down Expand Up @@ -48,3 +51,13 @@ func SkipIf(condition bool, message string) {
Skip(message, 1)
}
}

// ObtainCentralRequest queries fleet-manager public API for the CentralRequest with id and stores in in the given pointer
func ObtainCentralRequest(ctx context.Context, client *fleetmanager.Client, id string, request *public.CentralRequest) error {
centralRequest, _, err := client.PublicAPI().GetCentralById(ctx, id)
if err != nil {
return fmt.Errorf("failed to obtain CentralRequest: %w", err)
}
*request = centralRequest
return nil
}
1 change: 1 addition & 0 deletions internal/dinosaur/pkg/presenters/admin_dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ func PresentDinosaurRequestAdminEndpoint(request *dbapi.CentralRequest, _ accoun
FailedReason: request.FailedReason,
InstanceType: request.InstanceType,
Traits: request.Traits,
ClusterId: request.ClusterID,
}, nil
}

0 comments on commit 22c1b7b

Please sign in to comment.