Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ vendor/
*.bak
*.log
.deploy-work/
.test-work/

# Environment files
.env
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ test-coverage: test ## Run tests and generate HTML coverage report

.PHONY: e2e
e2e: build ## Run all E2E tests
./$(BINARY_NAME) test
TESTDATA_DIR=$(PWD)/testdata ./$(BINARY_NAME) test

.PHONY: e2e-ci
e2e-ci: build ## Run E2E tests with CI configuration
mkdir -p $(OUTPUT_DIR)
./$(BINARY_NAME) test --configs ci --junit-report $(OUTPUT_DIR)/junit.xml
TESTDATA_DIR=$(PWD)/testdata ./$(BINARY_NAME) test --configs ci --junit-report $(OUTPUT_DIR)/junit.xml

##@ Code Quality

Expand Down
189 changes: 189 additions & 0 deletions e2e/adapter/adapter_failover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package adapter

import (
"context"
"os"

"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" //nolint:staticcheck // dot import for test readability

"github.com/openshift-hyperfleet/hyperfleet-e2e/pkg/api/openapi"
"github.com/openshift-hyperfleet/hyperfleet-e2e/pkg/client"
"github.com/openshift-hyperfleet/hyperfleet-e2e/pkg/helper"
"github.com/openshift-hyperfleet/hyperfleet-e2e/pkg/labels"
)

var _ = ginkgo.Describe("[Suite: adapter-failures][negative] Adapter framework can detect and report failures to cluster API endpoints",
ginkgo.Label(labels.Tier1),
func() {
var (
h *helper.Helper
chartPath string
baseDeployOpts helper.AdapterDeploymentOptions
)

ginkgo.BeforeEach(func(ctx context.Context) {
h = helper.New()

// Clone adapter Helm chart repository (shared across all tests)
ginkgo.By("Clone adapter Helm chart repository")
var cleanupChart func() error
var err error
chartPath, cleanupChart, err = h.CloneHelmChart(ctx, helper.HelmChartCloneOptions{
Component: "adapter",
RepoURL: h.Cfg.AdapterDeployment.ChartRepo,
Ref: h.Cfg.AdapterDeployment.ChartRef,
ChartPath: h.Cfg.AdapterDeployment.ChartPath,
WorkDir: helper.TestWorkDir,
})
Expect(err).NotTo(HaveOccurred(), "failed to clone adapter Helm chart")
ginkgo.GinkgoWriter.Printf("Cloned adapter chart to: %s\n", chartPath)

// Ensure chart cleanup after test
ginkgo.DeferCleanup(func(ctx context.Context) {
ginkgo.By("Cleanup cloned Helm chart")
if err := cleanupChart(); err != nil {
ginkgo.GinkgoWriter.Printf("Warning: failed to cleanup chart: %v\n", err)
}
})

// Set up base deployment options with common fields
baseDeployOpts = helper.AdapterDeploymentOptions{
Namespace: h.Cfg.Namespace,
ChartPath: chartPath,
}
})

ginkgo.It("should detect invalid K8s resource and report failure with clear error message",
func(ctx context.Context) {
// Test-specific adapter configuration
adapterName := "cl-invalid-resource"

// Set environment variable for envsubst expansion in values.yaml
err := os.Setenv("ADAPTER_NAME", adapterName)
Expect(err).NotTo(HaveOccurred(), "failed to set ADAPTER_NAME environment variable")
ginkgo.DeferCleanup(func() {
_ = os.Unsetenv("ADAPTER_NAME")
})

// Generate unique release name for this deployment
releaseName := helper.GenerateAdapterReleaseName(helper.ResourceTypeClusters, adapterName)

// Deploy the test adapter with invalid K8s resource configuration
ginkgo.By("Deploy test adapter with invalid K8s resource configuration")

// Create deployment options from base and add test-specific fields
deployOpts := baseDeployOpts
deployOpts.ReleaseName = releaseName
deployOpts.AdapterName = adapterName

err = h.DeployAdapter(ctx, deployOpts)
// Ensure adapter cleanup happens after this test
ginkgo.DeferCleanup(func(ctx context.Context) {
ginkgo.By("Uninstall test adapter")
if err := h.UninstallAdapter(ctx, releaseName, h.Cfg.Namespace); err != nil {
ginkgo.GinkgoWriter.Printf("Warning: failed to uninstall adapter %s: %v\n", releaseName, err)
} else {
ginkgo.GinkgoWriter.Printf("Successfully uninstalled adapter: %s\n", releaseName)
}
})
Expect(err).NotTo(HaveOccurred(), "failed to deploy test adapter")
ginkgo.GinkgoWriter.Printf("Successfully deployed adapter: %s (release: %s)\n", adapterName, releaseName)

// Create cluster after adapter is deployed
ginkgo.By("Create test cluster")
cluster, err := h.Client.CreateClusterFromPayload(ctx, h.TestDataPath("payloads/clusters/cluster-request.json"))
Expect(err).NotTo(HaveOccurred(), "failed to create cluster")
Expect(cluster.Id).NotTo(BeNil(), "cluster ID should be generated")
Expect(cluster.Name).NotTo(BeEmpty(), "cluster name should be present")
clusterID := *cluster.Id
clusterName := cluster.Name
ginkgo.GinkgoWriter.Printf("Created cluster ID: %s, Name: %s\n", clusterID, clusterName)

// Ensure cluster cleanup happens after this test
ginkgo.DeferCleanup(func(ctx context.Context) {
ginkgo.By("Cleanup test cluster " + clusterID)
if err := h.CleanupTestCluster(ctx, clusterID); err != nil {
ginkgo.GinkgoWriter.Printf("Warning: failed to cleanup cluster %s: %v\n", clusterID, err)
}
})

ginkgo.By("Verify initial status of cluster")
// Verify initial conditions are False
// Use Eventually to handle async condition propagation
Eventually(func(g Gomega) {
cluster, err = h.Client.GetCluster(ctx, clusterID)
g.Expect(err).NotTo(HaveOccurred(), "failed to get cluster")
g.Expect(cluster.Status).NotTo(BeNil(), "cluster status should be present")

hasReadyFalse := h.HasResourceCondition(cluster.Status.Conditions,
client.ConditionTypeReady, openapi.ResourceConditionStatusFalse)
g.Expect(hasReadyFalse).To(BeTrue(),
"initial cluster conditions should have Ready=False")

hasAvailableFalse := h.HasResourceCondition(cluster.Status.Conditions,
client.ConditionTypeAvailable, openapi.ResourceConditionStatusFalse)
g.Expect(hasAvailableFalse).To(BeTrue(),
"initial cluster conditions should have Available=False")
}, h.Cfg.Timeouts.Adapter.Processing, h.Cfg.Polling.Interval).Should(Succeed())

ginkgo.By("Verify adapter execution detects failure and reports error")
// Wait for adapter to process the cluster and report failure status
Eventually(func(g Gomega) {
statuses, err := h.Client.GetClusterStatuses(ctx, clusterID)
g.Expect(err).NotTo(HaveOccurred(), "failed to get cluster statuses")
g.Expect(statuses.Items).NotTo(BeEmpty(), "adapter should have reported status")

// Find the test adapter status
var adapterStatus *openapi.AdapterStatus
for i, adapter := range statuses.Items {
if adapter.Adapter == adapterName {
adapterStatus = &statuses.Items[i]
break
}
}

g.Expect(adapterStatus).NotTo(BeNil(),
"adapter %s should be present in adapter statuses", adapterName)

// Validate adapter metadata
g.Expect(adapterStatus.CreatedTime).NotTo(BeZero(),
"adapter should have valid created_time")
g.Expect(adapterStatus.LastReportTime).NotTo(BeZero(),
"adapter should have valid last_report_time")
g.Expect(adapterStatus.ObservedGeneration).To(Equal(int32(1)),
"adapter should have observed_generation=1")

// Find Available condition
var availableCondition *openapi.AdapterCondition
for i, condition := range adapterStatus.Conditions {
if condition.Type == client.ConditionTypeAvailable {
availableCondition = &adapterStatus.Conditions[i]
break
}
}

g.Expect(availableCondition).NotTo(BeNil(),
"adapter should have Available condition")

// Verify Available condition reports failure
g.Expect(availableCondition.Status).To(Equal(openapi.AdapterConditionStatusFalse),
"adapter Available condition should be False due to invalid K8s resource")

// Verify error details are present in reason and message
g.Expect(availableCondition.Reason).NotTo(BeNil(),
"adapter Available condition should have reason")
g.Expect(*availableCondition.Reason).NotTo(BeEmpty(),
"adapter Available condition reason should not be empty")

g.Expect(availableCondition.Message).NotTo(BeNil(),
"adapter Available condition should have message")
g.Expect(*availableCondition.Message).NotTo(BeEmpty(),
"adapter Available condition message should not be empty")

}, h.Cfg.Timeouts.Adapter.Processing, h.Cfg.Polling.Interval).Should(Succeed())

ginkgo.GinkgoWriter.Printf("Successfully validated adapter failure detection and reporting\n")
})
},
)
2 changes: 1 addition & 1 deletion e2e/adapter/adapter_with_maestro.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = ginkgo.Describe("[Suite: adapter][maestro-transport] Adapter Framework -
ginkgo.BeforeEach(func(ctx context.Context) {
h = helper.New()
// Create cluster for all tests in this suite
cluster, err := h.Client.CreateClusterFromPayload(ctx, "testdata/payloads/clusters/cluster-request.json")
cluster, err := h.Client.CreateClusterFromPayload(ctx, h.TestDataPath("payloads/clusters/cluster-request.json"))
Expect(err).NotTo(HaveOccurred(), "failed to create cluster")
Expect(cluster.Id).NotTo(BeNil(), "cluster ID should be generated")
Expect(cluster.Name).NotTo(BeEmpty(), "cluster name should be present")
Expand Down
2 changes: 1 addition & 1 deletion e2e/cluster/creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = ginkgo.Describe("[Suite: cluster][baseline] Cluster Resource Type Lifecy
h = helper.New()

// Create cluster for all tests in this suite
cluster, err := h.Client.CreateClusterFromPayload(ctx, "testdata/payloads/clusters/cluster-request.json")
cluster, err := h.Client.CreateClusterFromPayload(ctx, h.TestDataPath("payloads/clusters/cluster-request.json"))
Expect(err).NotTo(HaveOccurred(), "failed to create cluster")
Expect(cluster.Id).NotTo(BeNil(), "cluster ID should be generated")
Expect(cluster.Name).NotTo(BeEmpty(), "cluster name should be present")
Expand Down
4 changes: 2 additions & 2 deletions e2e/nodepool/creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ var _ = ginkgo.Describe("[Suite: nodepool][baseline] NodePool Resource Type Life

// Get or create cluster for nodepool tests
var err error
clusterID, err = h.GetTestCluster(ctx, "testdata/payloads/clusters/cluster-request.json")
clusterID, err = h.GetTestCluster(ctx, h.TestDataPath("payloads/clusters/cluster-request.json"))
Expect(err).NotTo(HaveOccurred(), "failed to get test cluster")
ginkgo.GinkgoWriter.Printf("Using cluster ID: %s\n", clusterID)

// Create nodepool for all tests in this suite
nodepool, err := h.Client.CreateNodePoolFromPayload(ctx, clusterID, "testdata/payloads/nodepools/nodepool-request.json")
nodepool, err := h.Client.CreateNodePoolFromPayload(ctx, clusterID, h.TestDataPath("payloads/nodepools/nodepool-request.json"))
Expect(err).NotTo(HaveOccurred(), "failed to create nodepool")
Expect(nodepool.Id).NotTo(BeNil(), "nodepool ID should be generated")
Expect(nodepool.Name).NotTo(BeEmpty(), "nodepool name should be present")
Expand Down
17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,59 @@ require (
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.44.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/net v0.47.0 // indirect
Expand All @@ -66,6 +82,7 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
Expand Down
Loading