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; } }
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); }
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); }