Exemple #1
0
        /// <summary>
        /// Creates a virtual <see cref="V1Service"/> for the specified <see cref="Broker"/>
        /// </summary>
        /// <param name="broker">The <see cref="Broker"/> to deploy</param>
        /// <returns>A new awaitable <see cref="Task"/></returns>
        protected virtual async Task CreateBrokerVirtualServiceAsync(Broker broker)
        {
            VirtualService virtualService;

            try
            {
                this.Logger.LogInformation("Creating a new istio virtual service for the broker with name '{resourceName}'...", broker.Name());
                V1ObjectMeta       metadata = new V1ObjectMeta(name: $"{broker.Name()}-vs", namespaceProperty: broker.Namespace());
                VirtualServiceSpec spec     = new VirtualServiceSpec()
                {
                    Hosts = new List <string>()
                    {
                        broker.Name()
                    },
                    Http = new List <HttpRoute>()
                    {
                        new HttpRoute()
                        {
                            Headers = new Headers()
                            {
                                Request = new HeadersOperations()
                                {
                                    Add = new Dictionary <string, string>()
                                    {
                                        { EventingDefaults.Headers.Channel, broker.Spec.Channel }
                                    }
                                }
                            },
                            Route = new List <HttpRouteDestination>()
                            {
                                new HttpRouteDestination()
                                {
                                    Destination = new Destination(broker.Name())
                                    {
                                        Port = new PortSelector(80)
                                    }
                                }
                            }
                        }
                    }
                };
                virtualService = new VirtualService(metadata, spec);
                await this.KubernetesClient.CreateNamespacedCustomObjectAsync(virtualService, broker.Namespace());

                this.Logger.LogInformation("A new istio virtual service for the broker with name '{resourceName}' has been successfully created.", broker.Name());
            }
            catch (HttpOperationException ex)
            {
                this.Logger.LogError($"An error occured while creating the istio virtual service for the broker with name '{{resourceName}}': the server responded with a non-success status code '{{statusCode}}'.{Environment.NewLine}Details: {{responseContent}}", broker.Name(), ex.Response.StatusCode, ex.Response.Content);
                return;
            }
            try
            {
                this.Logger.LogInformation("Updating the status of the broker with name '{resourceName}'...", broker.Name());
                broker.Status = new BrokerStatus()
                {
                    Url = $"http://{broker.Name()}.{broker.Namespace()}.svc.cluster.local"
                };
                await this.KubernetesClient.ReplaceNamespacedCustomObjectStatusAsync(broker, broker.ApiGroup(), broker.ApiGroupVersion(), broker.Namespace(), BrokerDefinition.PLURAL, broker.Name());

                this.Logger.LogInformation("The status of the broker with name '{resourceName}' has been successfully updated", broker.Name());
            }
            catch (HttpOperationException ex)
            {
                this.Logger.LogError($"An error occured while updating the status of the CRD '{{resourceKind}}' with name '{{resourceName}}': the server responded with a non-success status code '{{statusCode}}'.{Environment.NewLine}Details: {{responseContent}}", broker.Kind, broker.Name(), ex.Response.StatusCode, ex.Response.Content);
            }
        }