private async Task <ICache> GetKubernetesInfo(string name) { var cache = new IngressCache(); var typeMap = new Dictionary <string, Type>(); typeMap.Add("networking.k8s.io/v1/Ingress", typeof(V1Ingress)); typeMap.Add("v1/Service", typeof(V1Service)); typeMap.Add("v1/Endpoints", typeof(V1Endpoints)); var kubeObjects = await Yaml.LoadAllFromFileAsync(Path.Combine("testassets", name, "ingress.yaml"), typeMap).ConfigureAwait(false); foreach (var obj in kubeObjects) { if (obj is V1Ingress ingress) { cache.Update(WatchEventType.Added, ingress); } else if (obj is V1Service service) { cache.Update(WatchEventType.Added, service); } else if (obj is V1Endpoints endpoints) { cache.Update(WatchEventType.Added, endpoints); } } return(cache); }
private async Task <ICache> GetKubernetesInfo(string name, V1IngressClass ingressClass) { var mockLogger = new Mock <ILogger <IngressCache> >(); var mockOptions = new Mock <IOptions <YarpOptions> >(); mockOptions.SetupGet(o => o.Value).Returns(new YarpOptions { ControllerClass = "microsoft.com/ingress-yarp" }); var cache = new IngressCache(mockOptions.Object, mockLogger.Object); var typeMap = new Dictionary <string, Type>(); typeMap.Add("networking.k8s.io/v1/Ingress", typeof(V1Ingress)); typeMap.Add("v1/Service", typeof(V1Service)); typeMap.Add("v1/Endpoints", typeof(V1Endpoints)); if (ingressClass is not null) { cache.Update(WatchEventType.Added, ingressClass); } var kubeObjects = await Yaml.LoadAllFromFileAsync(Path.Combine("testassets", name, "ingress.yaml"), typeMap).ConfigureAwait(false); foreach (var obj in kubeObjects) { if (obj is V1Ingress ingress) { cache.Update(WatchEventType.Added, ingress); } else if (obj is V1Service service) { cache.Update(WatchEventType.Added, service); } else if (obj is V1Endpoints endpoints) { cache.Update(WatchEventType.Added, endpoints); } } return(cache); }
public void IngressWithClassAnnotationTests(string ingressClassName, string controllerName, bool?isDefault, int expectedIngressCount) { // Arrange if (controllerName is not null) { var ingressClass = KubeResourceGenerator.CreateIngressClass(ingressClassName, controllerName, isDefault); _cacheUnderTest.Update(WatchEventType.Added, ingressClass); } var ingress = KubeResourceGenerator.CreateIngress("ingress-with-class", "ns-test", "yarp"); // Act var change = _cacheUnderTest.Update(WatchEventType.Added, ingress); // Assert var ingresses = _cacheUnderTest.GetIngresses().ToArray(); Assert.Equal(expectedIngressCount != 0, change); Assert.Equal(expectedIngressCount, ingresses.Length); }