@@ -260,33 +260,45 @@ func configureTLS(opts *server.Options) {
260
260
}
261
261
262
262
func configureClusterOpts (opts * server.Options ) error {
263
- if opts .ClusterListenStr == "" {
263
+ // If we don't have cluster defined in the configuration
264
+ // file and no cluster listen string override, but we do
265
+ // have a routes override, we need to report misconfiguration.
266
+ if opts .ClusterListenStr == "" && opts .ClusterHost == "" &&
267
+ opts .ClusterPort == 0 {
264
268
if opts .RoutesStr != "" {
265
269
server .PrintAndDie ("Solicited routes require cluster capabilities, e.g. --cluster." )
266
270
}
267
271
return nil
268
272
}
269
273
270
- clusterURL , err := url .Parse (opts .ClusterListenStr )
271
- h , p , err := net .SplitHostPort (clusterURL .Host )
272
- if err != nil {
273
- return err
274
- }
275
- opts .ClusterHost = h
276
- _ , err = fmt .Sscan (p , & opts .ClusterPort )
277
- if err != nil {
278
- return err
279
- }
280
-
281
- if clusterURL .User != nil {
282
- pass , hasPassword := clusterURL .User .Password ()
283
- if ! hasPassword {
284
- return fmt .Errorf ("Expected cluster password to be set." )
274
+ // If cluster flag override, process it
275
+ if opts .ClusterListenStr != "" {
276
+ clusterURL , err := url .Parse (opts .ClusterListenStr )
277
+ h , p , err := net .SplitHostPort (clusterURL .Host )
278
+ if err != nil {
279
+ return err
280
+ }
281
+ opts .ClusterHost = h
282
+ _ , err = fmt .Sscan (p , & opts .ClusterPort )
283
+ if err != nil {
284
+ return err
285
285
}
286
- opts .ClusterPassword = pass
287
286
288
- user := clusterURL .User .Username ()
289
- opts .ClusterUsername = user
287
+ if clusterURL .User != nil {
288
+ pass , hasPassword := clusterURL .User .Password ()
289
+ if ! hasPassword {
290
+ return fmt .Errorf ("Expected cluster password to be set." )
291
+ }
292
+ opts .ClusterPassword = pass
293
+
294
+ user := clusterURL .User .Username ()
295
+ opts .ClusterUsername = user
296
+ } else {
297
+ // Since we override from flag and there is no user/pwd, make
298
+ // sure we clear what we may have gotten from config file.
299
+ opts .ClusterUsername = ""
300
+ opts .ClusterPassword = ""
301
+ }
290
302
}
291
303
292
304
// If we have routes but no config file, fill in here.
0 commit comments