Ejemplo n.º 1
0
        public ConfigmapConfigurationProvider(string?namespaceSelector, string?labelSelector, string?separator, bool reloadOnChange)
        {
            _namespaceSelector = namespaceSelector ?? string.Empty;
            _labelSelector     = labelSelector ?? string.Empty;
            _separator         = separator ?? "__";
            KubernetesClientConfiguration config;

            try
            {
                config = KubernetesClientConfiguration.InClusterConfig();
            }
            catch
            {
                config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
            }
            _client = new k8s.Kubernetes(config);

            if (!reloadOnChange)
            {
                return;
            }
            var configMapsResponse = _client.ListNamespacedConfigMapWithHttpMessagesAsync(_namespaceSelector, labelSelector: _labelSelector, watch: true).Result;

            configMapsResponse.Watch <V1ConfigMap, V1ConfigMapList>((type, item) =>
            {
                if (type.Equals(WatchEventType.Modified))
                {
                    Load(true);
                }
            });
        }