Skip to content
Merged
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
25 changes: 24 additions & 1 deletion openshift/tests-extension/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,30 @@ func main() {
Long: "OLMv1 Tests Extension",
}

root.AddCommand(cmd.DefaultExtensionCommands(registry)...)
// Get all default commands from the extension framework
allCommands := cmd.DefaultExtensionCommands(registry)

// Add KUBECONFIG check to run-suite and run-test commands only.
// Other commands (list, info, images, update, completion, help) don't need KUBECONFIG.
for _, command := range allCommands {
// Identify run-suite and run-test commands by their Use field
if command.Use == "run-suite NAME" || command.Use == "run-test [-n NAME...] [NAME]" {
// Save the original RunE function
originalRunE := command.RunE

// Wrap it with KUBECONFIG check
command.RunE = func(cmd *cobra.Command, args []string) error {
// Check KUBECONFIG before running the test
if err := exutil.CheckKubeconfigSet(); err != nil {
return err
}
// Call the original RunE function
return originalRunE(cmd, args)
}
}
}

root.AddCommand(allCommands...)

if err := func() error {
return root.Execute()
Expand Down
7 changes: 0 additions & 7 deletions openshift/tests-extension/test/qe/util/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ import (
testdata "github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/pkg/bindata/qe"
)

func init() {
if KubeConfigPath() == "" {
fmt.Fprintf(os.Stderr, "Please set KUBECONFIG first!\n")
os.Exit(0)
}
}

// WaitForServiceAccount waits until the named service account gets fully
// provisioned
func WaitForServiceAccount(c corev1client.ServiceAccountInterface, name string, checkSecret bool) error {
Expand Down
17 changes: 17 additions & 0 deletions openshift/tests-extension/test/qe/util/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ import (
e2e "k8s.io/kubernetes/test/e2e/framework"
)

// CheckKubeconfigSet verifies that the KUBECONFIG environment variable is set and points to a valid file.
// This check is only required for commands that interact with a Kubernetes cluster (run-suite and run-test).
// Other commands (list, info, images, update, completion, help) do not require KUBECONFIG.
func CheckKubeconfigSet() error {
kubeconfig := os.Getenv("KUBECONFIG")
if kubeconfig == "" {
return fmt.Errorf("KUBECONFIG environment variable is not set.\nPlease set KUBECONFIG to point to your cluster configuration file.\nExample: export KUBECONFIG=/path/to/kubeconfig")
}

// Check if kubeconfig file exists
if _, err := os.Stat(kubeconfig); err != nil {
return fmt.Errorf("KUBECONFIG file does not exist: %s (error: %v)", kubeconfig, err)
}

return nil
}

// InitClusterEnv initializes the cluster environment for testing by setting up test framework and configuration
// This function will panic if initialization fails
func InitClusterEnv() {
Expand Down