Beispiel #1
0
        public async Task ProcessAsync(IDispatchTarget target, NamespacedName key, ReconcileData data, CancellationToken cancellationToken)
        {
            try
            {
                var message = new Message
                {
                    MessageType = MessageType.Update,
                    Key         = $"{key.Namespace}:{key.Name}"
                };
                var context = new YarpIngressContext(data.Ingress, data.ServiceList, data.EndpointsList);
                YarpParser.CovertFromKubernetesIngress(context);

                message.Cluster = context.Clusters;
                message.Routes  = context.Routes;

                var bytes = JsonSerializer.SerializeToUtf8Bytes(message);

                _logger.LogInformation(JsonSerializer.Serialize(message));

                await _dispatcher.SendAsync(target, bytes, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex.Message);
                throw;
            }
        }
Beispiel #2
0
    public async Task ProcessAsync(CancellationToken cancellationToken)
    {
        try
        {
            var ingresses = _cache.GetIngresses().ToArray();

            var configContext = new YarpConfigContext();

            foreach (var ingress in ingresses)
            {
                if (_cache.TryGetReconcileData(new NamespacedName(ingress.Metadata.NamespaceProperty, ingress.Metadata.Name), out var data))
                {
                    var ingressContext = new YarpIngressContext(ingress, data.ServiceList, data.EndpointsList);
                    YarpParser.ConvertFromKubernetesIngress(ingressContext, configContext);
                }
            }

            var clusters = configContext.BuildClusterConfig();

            _logger.LogInformation(JsonSerializer.Serialize(configContext.Routes));
            _logger.LogInformation(JsonSerializer.Serialize(clusters));

            await _updateConfig.UpdateAsync(configContext.Routes, clusters, cancellationToken).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            _logger.LogWarning(ex, "Uncaught exception occured while reconciling");
            throw;
        }
    }
Beispiel #3
0
        public async Task ParsingTests(string name)
        {
            var(ingress, endpoints) = await GetKubernetesInfo(name).ConfigureAwait(false);

            var context = new YarpIngressContext(ingress, endpoints);

            YarpParser.CovertFromKubernetesIngress(context);

            VerifyClusters(JsonSerializer.Serialize(context.Clusters), name);
            VerifyRoutes(JsonSerializer.Serialize(context.Routes), name);
        }
Beispiel #4
0
    public async Task ParsingTests(string name)
    {
        var cache = await GetKubernetesInfo(name).ConfigureAwait(false);

        var configContext = new YarpConfigContext();
        var ingresses     = cache.GetIngresses().ToArray();

        foreach (var ingress in ingresses)
        {
            if (cache.TryGetReconcileData(new NamespacedName(ingress.Metadata.NamespaceProperty, ingress.Metadata.Name), out var data))
            {
                var ingressContext = new YarpIngressContext(ingress, data.ServiceList, data.EndpointsList);
                YarpParser.ConvertFromKubernetesIngress(ingressContext, configContext);
            }
        }

        VerifyClusters(JsonSerializer.Serialize(configContext.BuildClusterConfig()), name);
        VerifyRoutes(JsonSerializer.Serialize(configContext.Routes), name);
    }
Beispiel #5
0
    public async Task ProcessAsync(CancellationToken cancellationToken)
    {
        try
        {
            var ingresses = _cache.GetIngresses().ToArray();

            var message = new Message
            {
                MessageType = MessageType.Update,
                Key         = string.Empty,
            };

            var configContext = new YarpConfigContext();

            foreach (var ingress in ingresses)
            {
                if (_cache.TryGetReconcileData(new NamespacedName(ingress.Metadata.NamespaceProperty, ingress.Metadata.Name), out var data))
                {
                    var ingressContext = new YarpIngressContext(ingress, data.ServiceList, data.EndpointsList);
                    YarpParser.ConvertFromKubernetesIngress(ingressContext, configContext);
                }
            }

            message.Cluster = configContext.BuildClusterConfig();
            message.Routes  = configContext.Routes;

            var bytes = JsonSerializer.SerializeToUtf8Bytes(message);

            _logger.LogInformation(JsonSerializer.Serialize(message));

            await _dispatcher.SendAsync(null, bytes, cancellationToken).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            _logger.LogWarning(ex.Message);
            throw;
        }
    }
    public async Task ParsingTests(string name)
    {
        var ingressClass = KubeResourceGenerator.CreateIngressClass("yarp", "microsoft.com/ingress-yarp", true);
        var cache        = await GetKubernetesInfo(name, ingressClass).ConfigureAwait(false);

        var configContext = new YarpConfigContext();
        var ingresses     = cache.GetIngresses().ToArray();

        foreach (var ingress in ingresses)
        {
            if (cache.TryGetReconcileData(new NamespacedName(ingress.Metadata.NamespaceProperty, ingress.Metadata.Name), out var data))
            {
                var ingressContext = new YarpIngressContext(ingress, data.ServiceList, data.EndpointsList);
                YarpParser.ConvertFromKubernetesIngress(ingressContext, configContext);
            }
        }
        var options = new JsonSerializerOptions {
            Converters = { new JsonStringEnumConverter() }
        };

        VerifyClusters(JsonSerializer.Serialize(configContext.BuildClusterConfig(), options), name);
        VerifyRoutes(JsonSerializer.Serialize(configContext.Routes, options), name);
    }