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

            var context = new ChildOperatorContext <WebDriverSession, V1Service>(
                new WebDriverSession()
            {
                Status = new WebDriverSessionStatus(),
            },
                new V1Service()
            {
            },
                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/serviceReady", o.path);
                Assert.Equal(true, o.value);
            });
            Assert.Null(result.ChildFeedback);
        }
Exemple #2
0
        public async Task BuildServiceOperator_NoFeedback_Async(ChildOperatorContext <WebDriverSession, V1Service> context)
        {
            var builder  = FakeOperators.BuildServiceOperator(this.host.Services);
            var feedback = Assert.Single(builder.FeedbackLoops);

            Assert.Null(await feedback(context, default).ConfigureAwait(false));
        }
Exemple #3
0
        public void BuildServiceOperator_ConfiguresService_Test(int sessionPort)
        {
            var builder = FakeOperators.BuildServiceOperator(this.host.Services);

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

            var service = new V1Service();

            builder.ChildFactory(session, service);

            Assert.Collection(
                service.Spec.Selector,
                l =>
            {
                Assert.Equal(Annotations.SessionName, l.Key);
                Assert.Equal("my-session", l.Value);
            });

            var port = Assert.Single(service.Spec.Ports);

            Assert.Equal(sessionPort, port.TargetPort);
            Assert.Equal(sessionPort, port.Port);
        }
Exemple #4
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 #5
0
        public void BuildServiceOperator_SimpleProperties_Test()
        {
            var builder = FakeOperators.BuildServiceOperator(this.host.Services);

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

            Assert.Equal("WebDriverSession-ServiceOperator", 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 BuildServiceOperator_Null_Throws()
 {
     Assert.Throws <ArgumentNullException>("services", () => FakeOperators.BuildServiceOperator(null));
 }