Exemplo n.º 1
0
        public SecretConfigurationProvider(string?namespaceSelector, string?labelSelector, string?separator, bool reloadOnChange, bool decodeData = true)
        {
            _namespaceSelector = namespaceSelector ?? string.Empty;
            _labelSelector     = labelSelector ?? string.Empty;
            _separator         = separator ?? "__";
            _decodeData        = decodeData;
            KubernetesClientConfiguration config;

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

            if (!reloadOnChange)
            {
                return;
            }

            var secretResponse = _client.ListNamespacedSecretWithHttpMessagesAsync(_namespaceSelector, labelSelector: _labelSelector, watch: true).Result;

            secretResponse.Watch <V1Secret, V1SecretList>((type, item) =>
            {
                if (type.Equals(WatchEventType.Modified))
                {
                    Load(true);
                }
            });
        }