Skip to content

Commit de70e52

Browse files
committed
initialize string maps to avoid nil pointer panics
1 parent a4ae811 commit de70e52

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ Example:
120120
app.Version(version + "\nbuild time: " + buildstamp + "\nGit ref: " + githash)
121121
app.DefaultEnvars()
122122

123+
// initialize Masters map to avoid nil map assignment
124+
cfg.Masters = make(map[string]string)
125+
123126
// Flags related to Kubernetes
124127
app.Flag("master", "The Kubernetes API server to connect to (default: auto-detect)").Default("").StringMapVar(&cfg.Masters)
125128
app.Flag("kubeconfig", "Retrieve target cluster configuration from a Kubernetes configuration file (default: auto-detect)").Default(defaultConfig.KubeConfig).StringVar(&cfg.KubeConfig)
@@ -199,7 +202,7 @@ func newKubeClients(cfg *Config) map[string]kubernetes.Interface {
199202
kubeconfig = clientcmd.RecommendedHomeFile
200203
}
201204
log.Debugf("use config file %s", kubeconfig)
202-
var clients map[string]kubernetes.Interface
205+
clients := map[string]kubernetes.Interface{}
203206
for cluster, master := range cfg.Masters {
204207
clients[cluster] = newKubeClient(cfg, master, kubeconfig)
205208
}

0 commit comments

Comments
 (0)