diff --git a/internal/clientsholder/clientsholder.go b/internal/clientsholder/clientsholder.go index 066f28930..a78331339 100644 --- a/internal/clientsholder/clientsholder.go +++ b/internal/clientsholder/clientsholder.go @@ -19,7 +19,6 @@ package clientsholder import ( "errors" "fmt" - "os" "time" clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" @@ -147,13 +146,11 @@ func ClearTestClientsHolder() { // GetClientsHolder returns the singleton ClientsHolder object. func GetClientsHolder(filenames ...string) *ClientsHolder { - const exitUsage = 2 if clientsHolder.ready { return &clientsHolder } if len(filenames) == 0 { - logrus.Errorf("Please provide a valid kubeconfig. Either set the KUBECONFIG environment variable or alternatively copy a kube config to $HOME/.kube/config") - os.Exit(exitUsage) + return nil } clientsHolder, err := newClientsHolder(filenames...) if err != nil { diff --git a/main.go b/main.go index 5a050c4d6..e0075e996 100644 --- a/main.go +++ b/main.go @@ -183,8 +183,16 @@ func main() { fmt.Printf("Log file: %s\n", logFileName) fmt.Printf("\n") + webServerMode := *serverModeFlag + _ = clientsholder.GetClientsHolder(getK8sClientsConfigFileNames()...) + client := clientsholder.GetClientsHolder(getK8sClientsConfigFileNames()...) + if !webServerMode && client == nil { + logrus.Fatalf("Please provide a valid kubeconfig. Either set the KUBECONFIG environment variable or alternatively copy a kube config to $HOME/.kube/config") + } + + certsuite.SetWebServerMode(*serverModeFlag) certsuite.LoadChecksDB(*labelsFlag) if *listFlag { diff --git a/pkg/certsuite/certsuite.go b/pkg/certsuite/certsuite.go index ac933f6a1..ca2d8959a 100644 --- a/pkg/certsuite/certsuite.go +++ b/pkg/certsuite/certsuite.go @@ -24,6 +24,14 @@ import ( "github.com/test-network-function/cnf-certification-test/pkg/provider" ) +var ( + webServerMode bool +) + +func SetWebServerMode(serverMode bool) { + webServerMode = serverMode +} + func LoadChecksDB(labelsExpr string) { accesscontrol.LoadChecks() certification.LoadChecks() @@ -35,7 +43,9 @@ func LoadChecksDB(labelsExpr string) { platform.LoadChecks() operator.LoadChecks() - if preflight.ShouldRun(labelsExpr) { + // Avoid loading preflight checks in webserver mode, since the app may start + // without any kubeconfig file provided. + if !webServerMode && preflight.ShouldRun(labelsExpr) { preflight.LoadChecks() } }