Exemplo n.º 1
0
        public IngressController(
            ICache cache,
            IReconciler reconciler,
            IResourceInformer <V1Ingress> ingressInformer,
            IResourceInformer <V1Service> serviceInformer,
            IResourceInformer <V1Endpoints> endpointsInformer,
            IHostApplicationLifetime hostApplicationLifetime,
            ILogger <IngressController> logger)
            : base(hostApplicationLifetime, logger)
        {
            if (ingressInformer is null)
            {
                throw new ArgumentNullException(nameof(ingressInformer));
            }

            if (serviceInformer is null)
            {
                throw new ArgumentNullException(nameof(serviceInformer));
            }

            if (endpointsInformer is null)
            {
                throw new ArgumentNullException(nameof(endpointsInformer));
            }

            if (hostApplicationLifetime is null)
            {
                throw new ArgumentNullException(nameof(hostApplicationLifetime));
            }

            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _registrations = new[]
            {
                ingressInformer.Register(Notification),
                serviceInformer.Register(Notification),
                endpointsInformer.Register(Notification),
            };

            _queue = new RateLimitingQueue <QueueItem>(new MaxOfRateLimiter <QueueItem>(
                                                           new BucketRateLimiter <QueueItem>(
                                                               limiter: new Limiter(
                                                                   limit: new Limit(perSecond: 10),
                                                                   burst: 100)),
                                                           new ItemExponentialFailureRateLimiter <QueueItem>(
                                                               baseDelay: TimeSpan.FromMilliseconds(5),
                                                               maxDelay: TimeSpan.FromSeconds(10))));

            _cache      = cache ?? throw new ArgumentNullException(nameof(cache));
            _reconciler = reconciler ?? throw new ArgumentNullException(nameof(reconciler));
            _reconciler.OnAttach(TargetAttached);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reconcile an array with another array
        /// </summary>
        /// <typeparam name="T">The type of the arrays.</typeparam>
        /// <param name="self">The array to serve as the base</param>
        /// <param name="others">The array to reconcile with</param>
        /// <param name="reconciler">The IReconciler with the ability to perform the callbacks for reconciliation</param>
        /// <returns></returns>
        public static void Reconcile <T>(ref T[] self, T[] others, IReconciler <T> reconciler)
        {
            int index1 = 0;
            int index2 = 0;
            var added  = new List <T>();

            if (others.Length == 0) // Delete All
            {
                self = new T[0];
                return;
            }
            if (self.Length == 0) // Add All
            {
                foreach (var other in others)
                {
                    added.Add(reconciler.Add(other));
                }
            }
            else
            {
                while (index1 < self.Length && index2 < others.Length)
                {
                    int compare = reconciler.Compare(self[index1], others[index2]);
                    if (compare == 0)
                    {
                        self[index1] = reconciler.Update(self[index1], others[index2]);
                        index1++;
                        index2++;
                    }
                    else if (compare < 0)
                    {
                        reconciler.Delete(ref self, index1);
                        index1++;
                    }
                    else if (compare > 0)
                    {
                        //Add
                        added.Add(reconciler.Add(others[index2]));
                        index2++;
                    }
                }
            }

            int addedCount = added.Count;

            Array.Resize(ref self, self.Length + addedCount);
            for (int i = 0; i < addedCount; i++)
            {
                self[index1 + i] = added[i];
            }
        }
Exemplo n.º 3
0
    public IngressController(
        ICache cache,
        IReconciler reconciler,
        IResourceInformer <V1Ingress> ingressInformer,
        IResourceInformer <V1Service> serviceInformer,
        IResourceInformer <V1Endpoints> endpointsInformer,
        IHostApplicationLifetime hostApplicationLifetime,
        ILogger <IngressController> logger)
        : base(hostApplicationLifetime, logger)
    {
        if (ingressInformer is null)
        {
            throw new ArgumentNullException(nameof(ingressInformer));
        }

        if (serviceInformer is null)
        {
            throw new ArgumentNullException(nameof(serviceInformer));
        }

        if (endpointsInformer is null)
        {
            throw new ArgumentNullException(nameof(endpointsInformer));
        }

        if (hostApplicationLifetime is null)
        {
            throw new ArgumentNullException(nameof(hostApplicationLifetime));
        }

        if (logger is null)
        {
            throw new ArgumentNullException(nameof(logger));
        }

        _registrations = new[]
        {
            ingressInformer.Register(Notification),
            serviceInformer.Register(Notification),
            endpointsInformer.Register(Notification),
        };

        _queue = new ProcessingRateLimitedQueue <QueueItem>(perSecond: 0.5, burst: 1);

        _cache      = cache ?? throw new ArgumentNullException(nameof(cache));
        _reconciler = reconciler ?? throw new ArgumentNullException(nameof(reconciler));
        _reconciler.OnAttach(TargetAttached);

        _ingressChangeQueueItem = new QueueItem("Ingress Change", null);
    }
 public Application(IConsoleLogger logger, IReconciler reconciler)
 {
     _logger     = logger;
     _reconciler = reconciler;
 }