コード例 #1
0
        private async Task OnWatcherStateChanged <TS, TSL>(ManagedWatcher <TS, TSL, WatcherEvent <TS> > sender,
                                                           ManagedWatcherStateUpdate update) where TS : class, IKubernetesObject
        {
            var tag = sender.Tag ?? string.Empty;

            switch (update.State)
            {
            case ManagedWatcherState.Closed:
                _logger.LogDebug("{type} watcher {tag} {state}", typeof(TS).Name, tag, update.State);
                await _secretsWatcher.Stop();

                await _eventQueue.WaitAndClear();

                await _secretsWatcher.Start();

                break;

            case ManagedWatcherState.Faulted:
                _logger.LogError(update.Exception, "{type} watcher {tag} {state}", typeof(TS).Name, tag,
                                 update.State);
                break;

            default:
                _logger.LogDebug("{type} watcher {tag} {state}", typeof(TS).Name, tag, update.State);
                break;
            }
        }
コード例 #2
0
        private async Task OnWatcherStateChanged <TResource, TResourceList>(
            ManagedWatcher <TResource, TResourceList, WatcherEvent <TResource> > sender,
            ManagedWatcherStateUpdate update) where TResource : class, IKubernetesObject
        {
            switch (update.State)
            {
            case ManagedWatcherState.Closed:
                _logger.LogDebug("{type} watcher {state}", typeof(TResource).Name, update.State);
                await _secretsWatcher.Stop();

                await _certificateWatcher.Stop();

                await _eventQueue.WaitAndClear();

                await _secretsWatcher.Start();

                await _certificateWatcher.Start();

                break;

            case ManagedWatcherState.Faulted:
                _logger.LogError(update.Exception, "{type} watcher {state}", typeof(TResource).Name,
                                 update.State);
                break;

            default:
                _logger.LogDebug("{type} watcher {state}", typeof(TResource).Name, update.State);
                break;
            }
        }
コード例 #3
0
        private async Task OnWatcherStateChanged <TGenericResource, TGenericResourceList>(
            ManagedWatcher <TGenericResource, TGenericResourceList, WatcherEvent <TGenericResource> > sender,
            ManagedWatcherStateUpdate update) where TGenericResource : class, IKubernetesObject
        {
            switch (update.State)
            {
            case ManagedWatcherState.Closed:
                _logger.LogDebug("{type} watcher {state}", typeof(TGenericResource).Name, update.State);
                await WatchersStop();

                ReflectionsClear();
                await WatchersStart();

                break;

            case ManagedWatcherState.Faulted:
                _logger.LogError(update.Exception, "{type} watcher {state}", typeof(TGenericResource).Name,
                                 update.State);
                break;

            default:
                _logger.LogDebug("{type} watcher {state}", typeof(TGenericResource).Name, update.State);
                break;
            }
        }
コード例 #4
0
        public CertManagerMonitor(ILogger <CertManagerMonitor> logger,
                                  ManagedWatcher <Certificate, object> certificateWatcher,
                                  ManagedWatcher <V1Secret, V1SecretList> secretsWatcher,
                                  IKubernetes apiClient,
                                  IMediator mediator)
        {
            _logger             = logger;
            _certificateWatcher = certificateWatcher;
            _secretsWatcher     = secretsWatcher;
            _apiClient          = apiClient;
            _mediator           = mediator;

            _eventQueue = new FeederQueue <WatcherEvent>(OnEvent, OnEventHandlingError);


            _secretsWatcher.OnStateChanged      = OnWatcherStateChanged;
            _secretsWatcher.EventHandlerFactory = e =>
            {
                if (e.Item.Type.StartsWith("helm.sh"))
                {
                    return(Task.CompletedTask);
                }

                return(_eventQueue.FeedAsync(new InternalSecretWatcherEvent
                {
                    Item = e.Item,
                    Type = e.Type,
                    CertificateResourceDefinitionVersion = _version
                }));
            };
            _secretsWatcher.RequestFactory = async c =>
                                             await c.ListSecretForAllNamespacesWithHttpMessagesAsync(watch : true,
                                                                                                     timeoutSeconds : Requests.WatcherTimeout);

            _certManagerTimer.Elapsed += (_, __) => _monitorTriggerChannel.Writer.TryWrite(new object());
            _certManagerTimer.Interval = 5_000;


            _certificateWatcher.OnStateChanged      = OnWatcherStateChanged;
            _certificateWatcher.EventHandlerFactory = e =>
                                                      _eventQueue.FeedAsync(new InternalCertificateWatcherEvent {
                Item = e.Item, Type = e.Type
            });
            _certificateWatcher.RequestFactory = async client =>
                                                 await client.ListClusterCustomObjectWithHttpMessagesAsync(
                CertManagerConstants.CrdGroup, _version, CertManagerConstants.CertificatePlural, watch : true,
                timeoutSeconds : Requests.WatcherTimeout);
        }
コード例 #5
0
        public FortiMirror(ILogger <FortiMirror> logger,
                           ManagedWatcher <V1Secret, V1SecretList> secretsWatcher,
                           IKubernetes apiClient)
        {
            _logger         = logger;
            _secretsWatcher = secretsWatcher;
            _apiClient      = apiClient;

            _eventQueue = new FeederQueue <WatcherEvent <V1Secret> >(OnEvent, OnEventHandlingError);


            _secretsWatcher.OnStateChanged      = OnWatcherStateChanged;
            _secretsWatcher.EventHandlerFactory = e => _eventQueue.FeedAsync(e);
            _secretsWatcher.RequestFactory      = async c =>
                                                  await c.ListSecretForAllNamespacesWithHttpMessagesAsync(watch : true);
        }
コード例 #6
0
        public Monitor(ILogger <Monitor> logger,
                       ManagedWatcher <V1CustomResourceDefinition, V1CustomResourceDefinitionList> crdV1Watcher,
                       Func <ManagedWatcher <Certificate, object> > certificatesWatcherFactory,
                       ManagedWatcher <V1Secret, V1SecretList> secretsWatcher,
                       IKubernetes apiClient,
                       IMediator mediator)
        {
            _logger       = logger;
            _crdV1Watcher = crdV1Watcher;
            _certificatesWatcherFactory = certificatesWatcherFactory;
            _secretsWatcher             = secretsWatcher;
            _apiClient = apiClient;
            _mediator  = mediator;

            _eventQueue = new FeederQueue <WatcherEvent>(OnEvent, OnEventHandlingError);


            _secretsWatcher.OnStateChanged      = OnWatcherStateChanged;
            _secretsWatcher.EventHandlerFactory = e =>
                                                  _eventQueue.FeedAsync(new InternalSecretWatcherEvent
            {
                Item = e.Item,
                Type = e.Type,
                CertificateResourceDefinitionVersions = _certificatesWatchers.Keys.ToList()
            });
            _secretsWatcher.RequestFactory = async c =>
                                             await c.ListSecretForAllNamespacesWithHttpMessagesAsync(watch : true,
                                                                                                     timeoutSeconds : Requests.DefaultTimeout);


            _crdV1Watcher.EventHandlerFactory = OnCrdEventV1;
            _crdV1Watcher.RequestFactory      = async c =>
                                                await c.ListCustomResourceDefinitionWithHttpMessagesAsync(watch : true,
                                                                                                          timeoutSeconds : Requests.DefaultTimeout);

            _crdV1Watcher.OnStateChanged = OnCrdWatcherStateChanged;

            _v1Beta1CrdMonitorTimer.Elapsed += (_, __) => Onv1Beta1CrdRefresh();
            _v1Beta1CrdMonitorTimer.Interval = 30_000;
        }
コード例 #7
0
        protected ResourceMirror(ILogger logger, IKubernetes client,
                                 ManagedWatcher <TResource, TResourceList> resourceWatcher,
                                 ManagedWatcher <V1Namespace, V1NamespaceList> namespaceWatcher)
        {
            _logger = logger;
            _client = client;

            _resourceWatcher  = resourceWatcher;
            _namespaceWatcher = namespaceWatcher;

            _eventQueue = new FeederQueue <WatcherEvent>(OnEvent, OnEventHandlingError);


            _resourceWatcher.EventHandlerFactory = e => _eventQueue.FeedAsync(e);
            _resourceWatcher.RequestFactory      = OnResourceWatcher;
            _resourceWatcher.OnStateChanged      = OnWatcherStateChanged;

            _namespaceWatcher.EventHandlerFactory = e => _eventQueue.FeedAsync(e);
            _namespaceWatcher.RequestFactory      = async api =>
                                                    await api.ListNamespaceWithHttpMessagesAsync(watch : true);

            _namespaceWatcher.OnStateChanged = OnWatcherStateChanged;
        }
コード例 #8
0
        private async Task OnWatcherStateChanged <TResource, TResourceList>(
            ManagedWatcher <TResource, TResourceList, WatcherEvent <TResource> > sender,
            ManagedWatcherStateUpdate update) where TResource : class, IKubernetesObject
        {
            var tag = sender.Tag ?? string.Empty;

            switch (update.State)
            {
            case ManagedWatcherState.Closed:
                _logger.LogDebug("{type} watcher {tag} {state}", typeof(TResource).Name, tag, update.State);
                await _secretsWatcher.Stop();

                foreach (var certificatesWatcher in _certificatesWatchers.Values)
                {
                    await certificatesWatcher.Stop();
                }

                await _eventQueue.WaitAndClear();

                await _secretsWatcher.Start();

                foreach (var certificatesWatcher in _certificatesWatchers.Values)
                {
                    await certificatesWatcher.Start();
                }
                break;

            case ManagedWatcherState.Faulted:
                _logger.LogError(update.Exception, "{type} watcher {tag} {state}", typeof(TResource).Name, tag,
                                 update.State);
                break;

            default:
                _logger.LogDebug("{type} watcher {tag} {state}", typeof(TResource).Name, tag, update.State);
                break;
            }
        }
コード例 #9
0
 public Mirror(ILogger <Mirror> logger, IKubernetes client,
               ManagedWatcher <V1ConfigMap, V1ConfigMapList> configMapWatcher,
               ManagedWatcher <V1Namespace, V1NamespaceList> namespaceWatcher)
     : base(logger, client, configMapWatcher, namespaceWatcher)
 {
 }
コード例 #10
0
 public Mirror(ILogger <Mirror> logger, IKubernetes client,
               ManagedWatcher <V1Secret, V1SecretList> secretWatcher,
               ManagedWatcher <V1Namespace, V1NamespaceList> namespaceWatcher)
     : base(logger, client, secretWatcher, namespaceWatcher)
 {
 }