github.com/cilium/cilium@v1.16.2/test/config/config.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package config 5 6 import ( 7 "flag" 8 "os" 9 "strings" 10 "time" 11 ) 12 13 const ( 14 RegistryDomain = "docker.io" 15 RegistrySecretName = "regcred" 16 ) 17 18 // CiliumTestConfigType holds all of the configurable elements of the testsuite 19 type CiliumTestConfigType struct { 20 Reprovision bool 21 // HoldEnvironment leaves the test infrastructure in place on failure 22 HoldEnvironment bool 23 // PassCLIEnvironment passes through the environment invoking the gingko 24 // tests. When false all subcommands are executed with an empty environment, 25 // including PATH. 26 PassCLIEnvironment bool 27 SSHConfig string 28 ShowCommands bool 29 TestScope string 30 SkipLogGathering bool 31 CiliumImage string 32 CiliumTag string 33 CiliumOperatorImage string 34 CiliumOperatorTag string 35 CiliumOperatorSuffix string 36 HubbleRelayImage string 37 HubbleRelayTag string 38 ProvisionK8s bool 39 Timeout time.Duration 40 Kubeconfig string 41 KubectlPath string 42 RegistryCredentials string 43 // Multinode enables the running of tests that involve more than one 44 // node. If false, some tests will silently skip multinode checks. 45 Multinode bool 46 RunQuarantined bool 47 Help bool 48 } 49 50 // CiliumTestConfig holds the global configuration of commandline flags 51 // in the ginkgo-based testing environment. 52 var CiliumTestConfig = CiliumTestConfigType{} 53 54 // ParseFlags parses commandline flags relevant to testing. 55 func (c *CiliumTestConfigType) ParseFlags() { 56 flagset := flag.NewFlagSet("cilium", flag.ExitOnError) 57 flagset.BoolVar(&c.Reprovision, "cilium.provision", true, 58 "Provision Vagrant boxes and Cilium before running test") 59 flagset.BoolVar(&c.HoldEnvironment, "cilium.holdEnvironment", false, 60 "On failure, hold the environment in its current state") 61 flagset.BoolVar(&c.PassCLIEnvironment, "cilium.passCLIEnvironment", false, 62 "Pass the environment invoking ginkgo, including PATH, to subcommands") 63 flagset.BoolVar(&c.SkipLogGathering, "cilium.skipLogs", false, 64 "skip gathering logs if a test fails") 65 flagset.StringVar(&c.SSHConfig, "cilium.SSHConfig", "", 66 "Specify a custom command to fetch SSH configuration (eg: 'vagrant ssh-config')") 67 flagset.BoolVar(&c.ShowCommands, "cilium.showCommands", false, 68 "Output which commands are ran to stdout") 69 flagset.StringVar(&c.TestScope, "cilium.testScope", "", 70 "Specifies scope of test to be ran (k8s, runtime)") 71 flagset.StringVar(&c.CiliumImage, "cilium.image", "", 72 "Specifies which image of cilium to use during tests") 73 flagset.StringVar(&c.CiliumTag, "cilium.tag", "", 74 "Specifies which tag of cilium to use during tests") 75 flagset.StringVar(&c.CiliumOperatorImage, "cilium.operator-image", "", 76 "Specifies which image of cilium-operator to use during tests") 77 flagset.StringVar(&c.CiliumOperatorTag, "cilium.operator-tag", "", 78 "Specifies which tag of cilium-operator to use during tests") 79 flagset.StringVar(&c.CiliumOperatorSuffix, "cilium.operator-suffix", "-ci", 80 "Specifies a suffix to append to operator image after cloud-specific suffix") 81 flagset.StringVar(&c.HubbleRelayImage, "cilium.hubble-relay-image", "", 82 "Specifies which image of hubble-relay to use during tests") 83 flagset.StringVar(&c.HubbleRelayTag, "cilium.hubble-relay-tag", "", 84 "Specifies which tag of hubble-relay to use during tests") 85 flagset.BoolVar(&c.ProvisionK8s, "cilium.provision-k8s", true, 86 "Specifies whether Kubernetes should be deployed and installed via kubeadm or not") 87 flagset.DurationVar(&c.Timeout, "cilium.timeout", 24*time.Hour, 88 "Specifies timeout for test run") 89 flagset.StringVar(&c.Kubeconfig, "cilium.kubeconfig", "", 90 "Kubeconfig to be used for k8s tests") 91 flagset.StringVar(&c.KubectlPath, "cilium.kubectl-path", "/tmp/kubectl", 92 "Path that holds version-specific kubectl binaries") 93 flagset.StringVar(&c.RegistryCredentials, "cilium.registryCredentials", "", 94 "Registry credentials to be used to download images") 95 flagset.BoolVar(&c.Multinode, "cilium.multinode", true, 96 "Enable tests across multiple nodes. If disabled, such tests may silently pass") 97 flagset.BoolVar(&c.RunQuarantined, "cilium.runQuarantined", false, 98 "Run tests that are under quarantine.") 99 flagset.BoolVar(&c.Help, "cilium.help", false, "Display this help message.") 100 101 args := make([]string, 0, len(os.Args)) 102 for index, flag := range os.Args { 103 if flag == "-cilium.help" { 104 flagset.PrintDefaults() 105 os.Exit(1) 106 } else if strings.Contains(flag, "-cilium") { 107 args = append(args, flag) 108 os.Args[index] = "" 109 } 110 } 111 112 flagset.Parse(args) 113 }