func Kubecontexts()

in grpc-xds/control-plane-go/pkg/config/informers.go [42:63]


func Kubecontexts(logger logr.Logger) ([]informers.Kubecontext, error) {
	configDir, exists := os.LookupEnv("CONFIG_DIR")
	if !exists {
		configDir = defaultConfigDir
	}
	informersConfigFilePath := filepath.Join(configDir, informersConfigFile)
	logger.V(4).Info("Loading informer configuration", "filepath", informersConfigFilePath)
	yamlBytes, err := os.ReadFile(informersConfigFilePath)
	if err != nil {
		return nil, fmt.Errorf("could not read informer configurations from file %s: %w", informersConfigFilePath, err)
	}
	var kubecontexts []informers.Kubecontext
	err = yaml.Unmarshal(yamlBytes, &kubecontexts)
	if err != nil {
		return nil, fmt.Errorf("could not unmarshal informer configuration YAML file contents [%s]: %w", yamlBytes, err)
	}
	if err := validateKubeContexts(kubecontexts); err != nil {
		return nil, fmt.Errorf("informer configuration validation failed: %w", err)
	}
	logger.V(2).Info("Informer", "configurations", kubecontexts)
	return kubecontexts, err
}