Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ipv6 startup fail #81870 #87108

Merged
merged 8 commits into from
May 6, 2024
12 changes: 9 additions & 3 deletions pkg/services/apiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ import (
"net"
"path/filepath"
"strconv"
"strings"

"github.com/grafana/grafana/pkg/services/apiserver/options"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/setting"
)

func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o *options.Options) {
func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o *options.Options) error {
defaultLogLevel := 0
ip := net.ParseIP(cfg.HTTPAddr)
ipStr := strings.TrimSuffix(strings.TrimPrefix(cfg.HTTPAddr, "["), "]")
yincongcyincong marked this conversation as resolved.
Show resolved Hide resolved
ip := net.ParseIP(ipStr)
if ip == nil {
return fmt.Errorf("invalid IP address: %s", ipStr)
}
apiURL := cfg.AppURL
port, err := strconv.Atoi(cfg.HTTPPort)
if err != nil {
Expand All @@ -27,7 +32,7 @@ func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o
apiURL = fmt.Sprintf("https://%s:%d", ip, port)
}

host := fmt.Sprintf("%s:%d", ip, port)
host := net.JoinHostPort(ipStr, strconv.Itoa(port))

apiserverCfg := cfg.SectionWithEnvOverrides("grafana-apiserver")

Expand All @@ -54,4 +59,5 @@ func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o
o.ExtraOptions.ExternalAddress = host
o.ExtraOptions.APIURL = apiURL
o.ExtraOptions.Verbosity = apiserverCfg.Key("log_level").MustInt(defaultLogLevel)
return nil
}
7 changes: 5 additions & 2 deletions pkg/services/apiserver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ func (s *service) start(ctx context.Context) error {
}

o := grafanaapiserveroptions.NewOptions(Codecs.LegacyCodec(groupVersions...))
applyGrafanaConfig(s.cfg, s.features, o)
err := applyGrafanaConfig(s.cfg, s.features, o)
if err != nil {
return err
}

if errs := o.Validate(); len(errs) != 0 {
// TODO: handle multiple errors
Expand Down Expand Up @@ -286,7 +289,7 @@ func (s *service) start(ctx context.Context) error {
}

// Add OpenAPI specs for each group+version
err := builder.SetupConfig(
err = builder.SetupConfig(
Scheme,
serverConfig,
builders,
Expand Down