Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid loading preflight checks in web server mode. #1692

Closed
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
5 changes: 1 addition & 4 deletions internal/clientsholder/clientsholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package clientsholder
import (
"errors"
"fmt"
"os"
"time"

clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion pkg/certsuite/certsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposed long term solution at: #1696

preflight.LoadChecks()
}
}
Expand Down
Loading