func getConfig()

in cmd/resmgr/main.go [181:265]


func getConfig(cfgFiles ...string) Config {
	log.WithField("files", cfgFiles).
		Info("Loading Resource Manager config")

	var cfg Config
	if err := config.Parse(&cfg, cfgFiles...); err != nil {
		log.WithError(err).Fatal("Cannot parse yaml config")
	}
	if *enableSentry {
		logging.ConfigureSentry(&cfg.SentryConfig)
	}

	// now, override any CLI flags in the loaded config.Config
	if len(*electionZkServers) > 0 {
		cfg.Election.ZKServers = *electionZkServers
	}
	if *httpPort != 0 {
		cfg.ResManager.HTTPPort = *httpPort
	}
	if *grpcPort != 0 {
		cfg.ResManager.GRPCPort = *grpcPort
	}
	if !*useCassandra {
		cfg.Storage.UseCassandra = false
	}
	if *cassandraHosts != nil && len(*cassandraHosts) > 0 {
		cfg.Storage.Cassandra.CassandraConn.ContactPoints = *cassandraHosts
	}
	if *cassandraStore != "" {
		cfg.Storage.Cassandra.StoreName = *cassandraStore
	}
	if *cassandraPort != 0 {
		cfg.Storage.Cassandra.CassandraConn.Port = *cassandraPort
	}
	if *datacenter != "" {
		cfg.Storage.Cassandra.CassandraConn.DataCenter = *datacenter
	}
	// Parse and setup peloton secrets
	if *pelotonSecretFile != "" {
		var secretsCfg config.PelotonSecretsConfig
		if err := config.Parse(&secretsCfg, *pelotonSecretFile); err != nil {
			log.WithError(err).
				WithField("peloton_secret_file", *pelotonSecretFile).
				Fatal("Cannot parse secret config")
		}
		cfg.Storage.Cassandra.CassandraConn.Username =
			secretsCfg.CassandraUsername
		cfg.Storage.Cassandra.CassandraConn.Password =
			secretsCfg.CassandraPassword
	}

	if *enablePreemption {
		cfg.ResManager.PreemptionConfig.Enabled = *enablePreemption
	}
	if *taskPreemptionPeriod != 0 {
		cfg.ResManager.PreemptionConfig.TaskPreemptionPeriod = *taskPreemptionPeriod
	}
	if *enableSLATracking {
		cfg.ResManager.RmTaskConfig.EnableSLATracking = *enableSLATracking
	}
	if *hostMgrAPIVersionStr != "" {
		hostMgrAPIVersion, err := api.ParseVersion(*hostMgrAPIVersionStr)
		if err != nil {
			log.WithError(err).Fatal("Failed to parse hostmgr-api-version")
		}
		cfg.ResManager.HostManagerAPIVersion = hostMgrAPIVersion
	}
	if cfg.ResManager.HostManagerAPIVersion == "" {
		cfg.ResManager.HostManagerAPIVersion = api.V0
	}

	// Parse and setup peloton auth
	if len(*authType) != 0 {
		cfg.Auth.AuthType = auth.Type(*authType)
		cfg.Auth.Path = *authConfigFile
	}
	if *useHostPool {
		cfg.ResManager.UseHostPool = *useHostPool
	}

	log.
		WithField("config", cfg).
		Info("Loaded Resource Manager config")
	return cfg
}