mirror of
https://github.com/minio/minio.git
synced 2024-12-25 14:45:54 -05:00
Improve env var config error reporting (#18549)
Improve env var config error Env vars that were set on current server but not on remotes were not reported in errors. Add these.
This commit is contained in:
parent
ce62980d4e
commit
bea0b050cd
@ -20,12 +20,14 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7/pkg/set"
|
"github.com/minio/minio-go/v7/pkg/set"
|
||||||
@ -82,7 +84,11 @@ func (s1 ServerSystemConfig) Diff(s2 ServerSystemConfig) error {
|
|||||||
ep.Platform, s2.MinioEndpoints[i].Platform)
|
ep.Platform, s2.MinioEndpoints[i].Platform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(s1.MinioEnv, s2.MinioEnv) {
|
if reflect.DeepEqual(s1.MinioEnv, s2.MinioEnv) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Report differences in environment variables.
|
||||||
var missing []string
|
var missing []string
|
||||||
var mismatching []string
|
var mismatching []string
|
||||||
for k, v := range s1.MinioEnv {
|
for k, v := range s1.MinioEnv {
|
||||||
@ -93,12 +99,25 @@ func (s1 ServerSystemConfig) Diff(s2 ServerSystemConfig) error {
|
|||||||
mismatching = append(mismatching, k)
|
mismatching = append(mismatching, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var extra []string
|
||||||
|
for k := range s2.MinioEnv {
|
||||||
|
_, ok := s1.MinioEnv[k]
|
||||||
|
if !ok {
|
||||||
|
extra = append(extra, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg := "Expected same MINIO_ environment variables and values across all servers: "
|
||||||
|
if len(missing) > 0 {
|
||||||
|
msg += fmt.Sprintf(`Missing environment values: %v. `, missing)
|
||||||
|
}
|
||||||
if len(mismatching) > 0 {
|
if len(mismatching) > 0 {
|
||||||
return fmt.Errorf(`Expected same MINIO_ environment variables and values across all servers: Missing environment values: %s / Mismatch environment values: %s`, missing, mismatching)
|
msg += fmt.Sprintf(`Mismatching environment values: %v. `, mismatching)
|
||||||
}
|
}
|
||||||
return fmt.Errorf(`Expected same MINIO_ environment variables and values across all servers: Missing environment values: %s`, missing)
|
if len(extra) > 0 {
|
||||||
|
msg += fmt.Sprintf(`Extra environment values: %v. `, extra)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
return errors.New(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
var skipEnvs = map[string]struct{}{
|
var skipEnvs = map[string]struct{}{
|
||||||
|
Loading…
Reference in New Issue
Block a user