@@ -12,7 +12,6 @@ import (
12
12
"path/filepath"
13
13
14
14
"github.com/spf13/cobra"
15
- "github.com/spf13/pflag"
16
15
"go.uber.org/zap"
17
16
18
17
"github.com/ava-labs/avalanchego/tests"
@@ -24,7 +23,10 @@ import (
24
23
25
24
const cliVersion = "0.0.1"
26
25
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
+ )
28
30
29
31
func main () {
30
32
var (
@@ -226,10 +228,7 @@ func main() {
226
228
)
227
229
rootCmd .AddCommand (checkLogsCmd )
228
230
229
- var (
230
- kubeConfigPath string
231
- kubeConfigContext string
232
- )
231
+ var kubeconfigVars * flags.KubeconfigVars
233
232
startKindClusterCmd := & cobra.Command {
234
233
Use : "start-kind-cluster" ,
235
234
Short : "Starts a local kind cluster with an integrated registry" ,
@@ -240,10 +239,15 @@ func main() {
240
239
if err != nil {
241
240
return err
242
241
}
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 )
244
248
},
245
249
}
246
- SetKubeConfigFlags (startKindClusterCmd .PersistentFlags (), & kubeConfigPath , & kubeConfigContext )
250
+ kubeconfigVars = flags . NewKubeconfigFlagSetVars (startKindClusterCmd .PersistentFlags ())
247
251
rootCmd .AddCommand (startKindClusterCmd )
248
252
249
253
if err := rootCmd .Execute (); err != nil {
@@ -252,18 +256,3 @@ func main() {
252
256
}
253
257
os .Exit (0 )
254
258
}
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