github.com/oam-dev/cluster-gateway@v1.9.0/e2e/framework/context.go (about)

     1  package framework
     2  
     3  import (
     4  	"flag"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"k8s.io/klog/v2"
     9  )
    10  
    11  var context = &E2EContext{}
    12  
    13  type E2EContext struct {
    14  	HubKubeConfig  string
    15  	TestCluster    string
    16  	IsOCMInstalled bool
    17  }
    18  
    19  func ParseFlags() {
    20  	registerFlags()
    21  	flag.Parse()
    22  	defaultFlags()
    23  	validateFlags()
    24  }
    25  
    26  func registerFlags() {
    27  	flag.StringVar(&context.HubKubeConfig,
    28  		"hub-kubeconfig",
    29  		os.Getenv("KUBECONFIG"),
    30  		"Path to kubeconfig of the hub cluster.")
    31  	flag.StringVar(&context.TestCluster,
    32  		"test-cluster",
    33  		"",
    34  		"The target cluster to run the e2e suite.")
    35  	flag.BoolVar(&context.IsOCMInstalled,
    36  		"ocm-installed",
    37  		false,
    38  		"Is the test running inside OCM environment")
    39  }
    40  
    41  func defaultFlags() {
    42  	if len(context.HubKubeConfig) == 0 {
    43  		home := os.Getenv("HOME")
    44  		if len(home) > 0 {
    45  			context.HubKubeConfig = filepath.Join(home, ".kube", "config")
    46  		}
    47  	}
    48  }
    49  
    50  func validateFlags() {
    51  	if len(context.HubKubeConfig) == 0 {
    52  		klog.Fatalf("--hub-kubeconfig is required")
    53  	}
    54  	if len(context.TestCluster) == 0 {
    55  		klog.Fatalf("--test-cluster is required")
    56  	}
    57  }