@@ -12,7 +12,6 @@ import (
1212 "path/filepath"
1313
1414 "github.com/spf13/cobra"
15- "github.com/spf13/pflag"
1615 "go.uber.org/zap"
1716
1817 "github.com/ava-labs/avalanchego/tests"
@@ -24,7 +23,10 @@ import (
2423
2524const cliVersion = "0.0.1"
2625
27- var errNetworkDirRequired = fmt .Errorf ("--network-dir or %s are required" , tmpnet .NetworkDirEnvName )
26+ var (
27+ errNetworkDirRequired = fmt .Errorf ("--network-dir or %s is required" , tmpnet .NetworkDirEnvName )
28+ errKubeconfigRequired = errors .New ("--kubeconfig is required" )
29+ )
2830
2931func main () {
3032 var (
@@ -226,10 +228,7 @@ func main() {
226228 )
227229 rootCmd .AddCommand (checkLogsCmd )
228230
229- var (
230- kubeConfigPath string
231- kubeConfigContext string
232- )
231+ var kubeconfigVars * flags.KubeconfigVars
233232 startKindClusterCmd := & cobra.Command {
234233 Use : "start-kind-cluster" ,
235234 Short : "Starts a local kind cluster with an integrated registry" ,
@@ -240,10 +239,15 @@ func main() {
240239 if err != nil {
241240 return err
242241 }
243- return tmpnet .StartKindCluster (ctx , log , kubeConfigPath , kubeConfigContext )
242+ // A valid kubeconfig is required for local kind usage but this is not validated by KubeconfigVars
243+ // since unlike kind, tmpnet usage may involve an implicit in-cluster config.
244+ if len (kubeconfigVars .Path ) == 0 {
245+ return errKubeconfigRequired
246+ }
247+ return tmpnet .StartKindCluster (ctx , log , kubeconfigVars .Path , kubeconfigVars .Context )
244248 },
245249 }
246- SetKubeConfigFlags (startKindClusterCmd .PersistentFlags (), & kubeConfigPath , & kubeConfigContext )
250+ kubeconfigVars = flags . NewKubeconfigFlagSetVars (startKindClusterCmd .PersistentFlags ())
247251 rootCmd .AddCommand (startKindClusterCmd )
248252
249253 if err := rootCmd .Execute (); err != nil {
@@ -252,18 +256,3 @@ func main() {
252256 }
253257 os .Exit (0 )
254258}
255-
256- func SetKubeConfigFlags (flagSet * pflag.FlagSet , kubeConfigPath * string , kubeConfigContext * string ) {
257- flagSet .StringVar (
258- kubeConfigPath ,
259- "kubeconfig" ,
260- os .Getenv ("KUBECONFIG" ),
261- "The path to a kubernetes configuration file for the target cluster" ,
262- )
263- flagSet .StringVar (
264- kubeConfigContext ,
265- "kubeconfig-context" ,
266- "" ,
267- "The path to a kubernetes configuration file for the target cluster" ,
268- )
269- }
0 commit comments