2024-02-01 16:27:30 -06:00
|
|
|
package apiserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/apiserver/options"
|
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
)
|
|
|
|
|
2024-05-06 13:17:03 -05:00
|
|
|
func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o *options.Options) error {
|
2024-02-01 16:27:30 -06:00
|
|
|
defaultLogLevel := 0
|
|
|
|
ip := net.ParseIP(cfg.HTTPAddr)
|
2024-05-06 13:17:03 -05:00
|
|
|
if ip == nil {
|
|
|
|
return fmt.Errorf("invalid IP address: %s", cfg.HTTPAddr)
|
|
|
|
}
|
2024-02-01 16:27:30 -06:00
|
|
|
apiURL := cfg.AppURL
|
|
|
|
port, err := strconv.Atoi(cfg.HTTPPort)
|
|
|
|
if err != nil {
|
|
|
|
port = 3000
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.Env == setting.Dev {
|
|
|
|
defaultLogLevel = 10
|
|
|
|
port = 6443
|
2024-10-17 13:15:57 -05:00
|
|
|
ip = net.ParseIP("0.0.0.0")
|
2024-02-01 16:27:30 -06:00
|
|
|
apiURL = fmt.Sprintf("https://%s:%d", ip, port)
|
|
|
|
}
|
|
|
|
|
2024-05-06 13:17:03 -05:00
|
|
|
host := net.JoinHostPort(cfg.HTTPAddr, strconv.Itoa(port))
|
2024-02-01 16:27:30 -06:00
|
|
|
|
2024-02-12 14:59:35 -06:00
|
|
|
apiserverCfg := cfg.SectionWithEnvOverrides("grafana-apiserver")
|
|
|
|
|
|
|
|
o.RecommendedOptions.Etcd.StorageConfig.Transport.ServerList = apiserverCfg.Key("etcd_servers").Strings(",")
|
2024-02-01 16:27:30 -06:00
|
|
|
|
|
|
|
o.RecommendedOptions.SecureServing.BindAddress = ip
|
|
|
|
o.RecommendedOptions.SecureServing.BindPort = port
|
|
|
|
o.RecommendedOptions.Authentication.RemoteKubeConfigFileOptional = true
|
|
|
|
o.RecommendedOptions.Authorization.RemoteKubeConfigFileOptional = true
|
|
|
|
|
2024-08-13 14:28:17 -05:00
|
|
|
o.KubeAggregatorOptions.ProxyClientCertFile = apiserverCfg.Key("proxy_client_cert_file").MustString("")
|
|
|
|
o.KubeAggregatorOptions.ProxyClientKeyFile = apiserverCfg.Key("proxy_client_key_file").MustString("")
|
2024-02-12 14:59:35 -06:00
|
|
|
|
2024-08-13 14:28:17 -05:00
|
|
|
o.KubeAggregatorOptions.APIServiceCABundleFile = apiserverCfg.Key("apiservice_ca_bundle_file").MustString("")
|
|
|
|
o.KubeAggregatorOptions.RemoteServicesFile = apiserverCfg.Key("remote_services_file").MustString("")
|
2024-02-29 19:29:05 -06:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
o.RecommendedOptions.Admission = nil
|
|
|
|
o.RecommendedOptions.CoreAPI = nil
|
|
|
|
|
2024-02-12 14:59:35 -06:00
|
|
|
o.StorageOptions.StorageType = options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeLegacy)))
|
2024-03-05 12:34:47 -06:00
|
|
|
o.StorageOptions.DataPath = apiserverCfg.Key("storage_path").MustString(filepath.Join(cfg.DataPath, "grafana-apiserver"))
|
2024-03-13 09:17:26 -05:00
|
|
|
o.StorageOptions.Address = apiserverCfg.Key("address").MustString(o.StorageOptions.Address)
|
2024-10-17 05:18:29 -05:00
|
|
|
o.StorageOptions.BlobStoreURL = apiserverCfg.Key("blob_url").MustString(o.StorageOptions.BlobStoreURL)
|
2024-08-30 04:59:42 -05:00
|
|
|
|
|
|
|
// unified storage configs look like
|
|
|
|
// [unified_storage.<group>.<resource>]
|
|
|
|
// config = <value>
|
|
|
|
unifiedStorageCfg := cfg.UnifiedStorage
|
|
|
|
o.StorageOptions.UnifiedStorageConfig = unifiedStorageCfg
|
2024-07-11 15:23:31 -05:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
o.ExtraOptions.DevMode = features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerEnsureKubectlAccess)
|
|
|
|
o.ExtraOptions.ExternalAddress = host
|
|
|
|
o.ExtraOptions.APIURL = apiURL
|
2024-02-12 14:59:35 -06:00
|
|
|
o.ExtraOptions.Verbosity = apiserverCfg.Key("log_level").MustInt(defaultLogLevel)
|
2024-05-06 13:17:03 -05:00
|
|
|
return nil
|
2024-02-01 16:27:30 -06:00
|
|
|
}
|