コード例 #1
0
        private async Task <(IngressData, List <Endpoints>)> GetKubernetesInfo(string name)
        {
            var typeMap = new Dictionary <string, Type>();

            typeMap.Add("networking.k8s.io/v1/Ingress", typeof(V1Ingress));
            typeMap.Add("v1/Endpoints", typeof(V1Endpoints));

            var kubeObjects = await Yaml.LoadAllFromFileAsync(Path.Combine("testassets", name, "ingress.yaml"), typeMap).ConfigureAwait(false);

            IngressData ingressData  = default;
            var         endpointList = new List <Endpoints>();

            foreach (var obj in kubeObjects)
            {
                if (obj is V1Ingress ingress)
                {
                    ingressData = new IngressData(ingress);
                }
                else if (obj is V1Endpoints endpoints)
                {
                    endpointList.Add(new Endpoints(endpoints));
                }
            }

            return(ingressData, endpointList);
        }
コード例 #2
0
 public ReconcileData(IngressData ingress, List <Endpoints> endpoints)
 {
     Ingress       = ingress;
     EndpointsList = endpoints;
 }
コード例 #3
0
 public YarpIngressContext(IngressData ingress, List <ServiceData> services, List <Endpoints> endpoints)
 {
     Ingress   = ingress;
     Services  = services;
     Endpoints = endpoints;
 }
コード例 #4
0
    public void Update(WatchEventType eventType, V1Ingress ingress)
    {
        if (ingress is null)
        {
            throw new ArgumentNullException(nameof(ingress));
        }

        var serviceNames = ImmutableList <string> .Empty;

        if (eventType == WatchEventType.Added || eventType == WatchEventType.Modified)
        {
            // If the ingress exists, list out the related services
            var spec           = ingress.Spec;
            var defaultBackend = spec?.DefaultBackend;
            var defaultService = defaultBackend?.Service;
            if (!string.IsNullOrEmpty(defaultService?.Name))
            {
                serviceNames = serviceNames.Add(defaultService.Name);
            }

            foreach (var rule in spec.Rules ?? Enumerable.Empty <V1IngressRule>())
            {
                var http = rule.Http;
                foreach (var path in http.Paths ?? Enumerable.Empty <V1HTTPIngressPath>())
                {
                    var backend = path.Backend;
                    var service = backend.Service;

                    if (!serviceNames.Contains(service.Name))
                    {
                        serviceNames = serviceNames.Add(service.Name);
                    }
                }
            }
        }

        var ingressName = ingress.Name();

        lock (_sync)
        {
            var serviceNamesPrevious = ImmutableList <string> .Empty;
            if (eventType == WatchEventType.Added || eventType == WatchEventType.Modified)
            {
                // If the ingress exists then remember details

                _ingressData[ingressName] = new IngressData(ingress);

                if (_ingressToServiceNames.TryGetValue(ingressName, out serviceNamesPrevious))
                {
                    _ingressToServiceNames[ingressName] = serviceNames;
                }
                else
                {
                    serviceNamesPrevious = ImmutableList <string> .Empty;
                    _ingressToServiceNames.Add(ingressName, serviceNames);
                }
            }
            else if (eventType == WatchEventType.Deleted)
            {
                // otherwise clear out details

                _ingressData.Remove(ingressName);

                if (_ingressToServiceNames.TryGetValue(ingressName, out serviceNamesPrevious))
                {
                    _ingressToServiceNames.Remove(ingressName);
                }
            }

            // update cross-reference for new ingress-to-services linkage not previously known
            foreach (var serviceName in serviceNames)
            {
                if (!serviceNamesPrevious.Contains(serviceName))
                {
                    if (_serviceToIngressNames.TryGetValue(serviceName, out var ingressNamesPrevious))
                    {
                        _serviceToIngressNames[serviceName] = _serviceToIngressNames[serviceName].Add(ingressName);
                    }
                    else
                    {
                        _serviceToIngressNames.Add(serviceName, ImmutableList <string> .Empty.Add(ingressName));
                    }
                }
            }

            // remove cross-reference for previous ingress-to-services linkage no longer present
            foreach (var serviceName in serviceNamesPrevious)
            {
                if (!serviceNames.Contains(serviceName))
                {
                    _serviceToIngressNames[serviceName] = _serviceToIngressNames[serviceName].Remove(ingressName);
                }
            }
        }
    }
コード例 #5
0
 public YarpIngressContext(IngressData ingress, List <Endpoints> endpoints)
 {
     Ingress   = ingress;
     Endpoints = endpoints;
 }
コード例 #6
0
 public ReconcileData(IngressData ingress, List <ServiceData> services, List <Endpoints> endpoints)
 {
     Ingress       = ingress;
     ServiceList   = services;
     EndpointsList = endpoints;
 }