// LoadClientConfig loads the client config from file if the file exists,
// otherwise will load from environment variables.
func LoadClientConfig(cf string) (*api.CalicoAPIConfig, error) {
	if _, err := os.Stat(cf); err != nil {
		log.Infof("Config file cannot be read - reading config from environment")
		cf = ""
	}

	return client.LoadClientConfig(cf)
}
Example #2
0
func initializeClient() {
	var err error

	if config, err = datastoreClient.LoadClientConfig(""); err != nil {
		panic(err)
	}
	if client, err = datastoreClient.New(*config); err != nil {
		panic(err)
	}

	if os.Getenv("CALICO_DEBUG") != "" {
		log.SetLevel(log.DebugLevel)
		log.Debugln("Debug logging enabled")
	}
}
// main performs startup operations for a node.
// For now, this only creates the ClusterGUID.  Ultimately,
// all of the function from startup.py will be moved here.
func main() {
	// Build a Calico client.
	log.Info("Creating Calico client")
	cfg, err := client.LoadClientConfig("")
	if err != nil {
		panic(fmt.Sprintf("Error loading config: %s", err))
	}
	c, err := backend.NewClient(*cfg)
	if err != nil {
		panic(fmt.Sprintf("Error creating client: %s", err))
	}
	log.Info("Ensuring datastore is initialized")
	err = c.EnsureInitialized()
	if err != nil {
		panic(fmt.Sprintf("Error initializing datastore: %s", err))
	}
	log.Info("Datastore is initialized")

	// Make sure we have a global cluster ID set.
	log.Info("Ensuring a cluster guid is set")
	ensureClusterGuid(c)
}