Exemple #1
0
        public async Task BuildIngressOperator_Feedback_Async()
        {
            var builder  = FakeOperators.BuildIngressOperator(this.host.Services);
            var feedback = Assert.Single(builder.FeedbackLoops);

            var context = new ChildOperatorContext <WebDriverSession, V1Ingress>(
                new WebDriverSession()
            {
                Status = new WebDriverSessionStatus(),
            },
                new V1Ingress()
            {
                Status = new V1IngressStatus()
                {
                    LoadBalancer = new V1LoadBalancerStatus()
                    {
                        Ingress = new V1LoadBalancerIngress[] { new V1LoadBalancerIngress() },
                    },
                },
            },
                this.host.Services);

            var result = await feedback(context, default).ConfigureAwait(false);

            Assert.Collection(
                result.ParentFeedback.Operations,
                o =>
            {
                Assert.Equal(OperationType.Add, o.OperationType);
                Assert.Equal("/status/ingressReady", o.path);
                Assert.Equal(true, o.value);
            });
            Assert.Null(result.ChildFeedback);
        }
Exemple #2
0
        public async Task BuildIngressOperator_NoFeedback_Async(ChildOperatorContext <WebDriverSession, V1Ingress> context)
        {
            var builder  = FakeOperators.BuildIngressOperator(this.host.Services);
            var feedback = Assert.Single(builder.FeedbackLoops);

            Assert.Null(await feedback(context, default).ConfigureAwait(false));
        }
Exemple #3
0
        public async Task FakeOperatorLifecycle_IntegrationTest_Success_Async()
        {
            const string name = "fake-operator-success-lifecycle";

            var kubernetes = this.host.Services.GetRequiredService<KubernetesClient>();
            var loggerFactory = this.host.Services.GetRequiredService<ILoggerFactory>();
            var logger = loggerFactory.CreateLogger(name);

            var podOperator = FakeOperators.BuildPodOperator(this.host.Services).Build();
            var serviceOperator = FakeOperators.BuildServiceOperator(this.host.Services).Build();
            var ingressOperator = FakeOperators.BuildIngressOperator(this.host.Services).Build();

            // Create a session and monitor the progress of the session.
            var sessionClient = kubernetes.GetClient<WebDriverSession>();
            var podClient = kubernetes.GetClient<V1Pod>();
            var serviceClient = kubernetes.GetClient<V1Service>();
            var ingressClient = kubernetes.GetClient<V1Ingress>();

            await Task.WhenAll(
                sessionClient.TryDeleteAsync(name, TimeSpan.FromMinutes(1), default),
                podClient.TryDeleteAsync(name, TimeSpan.FromMinutes(1), default),
                serviceClient.TryDeleteAsync(name, TimeSpan.FromMinutes(1), default),
                ingressClient.TryDeleteAsync(name, TimeSpan.FromMinutes(1), default)).ConfigureAwait(false);

            var sessionWatcher = sessionClient.WatchAsync(
                $"metadata.name={name}",
                null,
                resourceVersion: null,
                resourceVersionMatch: null,
                (eventType, session) =>
                {
                    if (session.Metadata.Name != name)
                    {
                        return Task.FromResult(WatchResult.Continue);
                    }

                    switch (eventType)
                    {
                        case k8s.WatchEventType.Modified when session.Status != null:
                            logger.LogInformation($"{DateTime.Now}: Session: {session.Status.SessionReady}, Service: {session.Status.ServiceReady} Ingress: {session.Status.IngressReady}.");
                            if (session.Status.IngressReady && session.Status.ServiceReady && session.Status.SessionReady)
                            {
                                return Task.FromResult(WatchResult.Stop);
                            }

                            break;
                    }
Exemple #4
0
        public void BuildIngressOperator_ConfiguresIngress_Test(int sessionPort)
        {
            var builder = FakeOperators.BuildIngressOperator(this.host.Services);

            var session = new WebDriverSession()
            {
                Metadata = new V1ObjectMeta()
                {
                    Name = "my-session",
                },
                Status = new WebDriverSessionStatus()
                {
                    SessionId   = "1234",
                    SessionPort = sessionPort,
                },
            };

            var ingress = new V1Ingress();

            builder.ChildFactory(session, ingress);

            var rule = Assert.Single(ingress.Spec.Rules);
            var path = Assert.Single(rule.Http.Paths);

            Assert.Equal("/wd/hub/session/my-session/", path.Path);
            Assert.Equal("Prefix", path.PathType);
            Assert.Equal("my-session", path.Backend.Service.Name);
            Assert.Equal(sessionPort, path.Backend.Service.Port.Number);

            Assert.NotNull(ingress.Metadata?.Annotations);
            Assert.Collection(
                ingress.Metadata.Annotations,
                a =>
            {
                Assert.Equal(Annotations.RequestModifier, a.Key);
                Assert.Equal("ReplacePathRegex: /wd/hub/session/my-session/(.*) /wd/hub/session/1234/$1", a.Value);
            },
                a =>
            {
                Assert.Equal(Annotations.IngressClass, a.Key);
                Assert.Equal("traefik", a.Value);
            });
        }
Exemple #5
0
        public void BuildIngressOperator_SimpleProperties_Test()
        {
            var builder = FakeOperators.BuildIngressOperator(this.host.Services);

            // Name, namespace and labels
            Assert.Collection(
                builder.Configuration.ChildLabels,
                l =>
            {
                Assert.Equal(Annotations.ManagedBy, l.Key);
                Assert.Equal("WebDriverSession-IngressOperator", l.Value);
            });

            Assert.Equal("WebDriverSession-IngressOperator", builder.Configuration.OperatorName);
            Assert.Null(builder.Configuration.ParentLabelSelector);

            // Parent Filter: only sessions with a session id
            Assert.False(builder.ParentFilter(new WebDriverSession()));
            Assert.False(builder.ParentFilter(new WebDriverSession()
            {
                Status = new WebDriverSessionStatus()
            }));
            Assert.True(builder.ParentFilter(new WebDriverSession()
            {
                Status = new WebDriverSessionStatus()
                {
                    SessionId = "1234"
                }
            }));

            // Child factory
            Assert.NotNull(builder.ChildFactory);

            // Feedback loop
            Assert.NotEmpty(builder.FeedbackLoops);
        }
Exemple #6
0
 public void BuildIngressOperator_Null_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () => FakeOperators.BuildIngressOperator(null));
 }