Пример #1
0
 public PingPongNetwork(Construct scope, string id, PingPongNetworkProps props = null) : base(scope, id)
 {
     PingPongVpc       = AddVpc(id, props);
     CloudmapNamespace = CreateCloudMapNamespace(id, PingPongVpc);
     AppMesh           = AddMesh(id);
     PingRouter        = AddVirtualRouter(id, "ping", AppMesh);
     PongRouter        = AddVirtualRouter(id, "pong", AppMesh);
     PingService       = AddVirtualService(id, "ping", AppMesh, PingRouter, CloudmapNamespace);
     PongService       = AddVirtualService(id, "pong", AppMesh, PongRouter, CloudmapNamespace);
 }
Пример #2
0
        public async Task ConfigureDevAsync()
        {
            await SyncContext.Clear;

            Log.LogInfo("Configuring cluster SSO for development.");

            // wait for cluster info to be set
            await NeonHelper.WaitForAsync(async() =>
            {
                await SyncContext.Clear;

                return(ClusterInfo != null);
            },
                                          timeout : TimeSpan.FromSeconds(60),
                                          pollInterval : TimeSpan.FromMilliseconds(250));

            try
            {
                var secret = await Kubernetes.ReadNamespacedSecretAsync("neon-sso-dex", KubeNamespace.NeonSystem);

                SetEnvironmentVariable("SSO_CLIENT_SECRET", Encoding.UTF8.GetString(secret.Data["KUBERNETES_CLIENT_SECRET"]));

                // Configure cluster callback url to allow local dev

                var dexConfigMap = await Kubernetes.ReadNamespacedConfigMapAsync("neon-sso-dex", KubeNamespace.NeonSystem);

                var dexConfig    = NeonHelper.YamlDeserializeViaJson <DexConfig>(dexConfigMap.Data["config.yaml"]);
                var clientConfig = dexConfig.StaticClients.Where(c => c.Id == "kubernetes").First();

                if (!clientConfig.RedirectUris.Contains("http://localhost:11001/oauth2/callback"))
                {
                    clientConfig.RedirectUris.Add("http://localhost:11001/oauth2/callback");
                    dexConfigMap.Data["config.yaml"] = NeonHelper.ToLinuxLineEndings(NeonHelper.YamlSerialize(dexConfig));
                    await Kubernetes.ReplaceNamespacedConfigMapAsync(dexConfigMap, dexConfigMap.Metadata.Name, KubeNamespace.NeonSystem);
                }

                Log.LogInfo("SSO configured.");
            }
            catch (Exception e)
            {
                Log.LogError("Error configuring SSO", e);
            }

            Log.LogInfo("Configure metrics.");

            var virtualServices = await Kubernetes.ListNamespacedCustomObjectAsync <VirtualService>(KubeNamespace.NeonIngress);

            if (!virtualServices.Items.Any(vs => vs.Name() == "metrics-external"))
            {
                var virtualService = new VirtualService()
                {
                    Metadata = new V1ObjectMeta()
                    {
                        Name = "metrics-external",
                        NamespaceProperty = KubeNamespace.NeonIngress
                    },
                    Spec = new VirtualServiceSpec()
                    {
                        Gateways = new List <string>()
                        {
                            "neoncluster-gateway"
                        },
                        Hosts = new List <string>()
                        {
                            $"metrics.{ClusterInfo.Domain}"
                        },
                        Http = new List <HTTPRoute>()
                        {
                            new HTTPRoute()
                            {
                                Match = new List <HTTPMatchRequest>()
                                {
                                    new HTTPMatchRequest()
                                    {
                                        Uri = new StringMatch()
                                        {
                                            Prefix = "/"
                                        }
                                    }
                                },
                                Route = new List <HTTPRouteDestination>()
                                {
                                    new HTTPRouteDestination()
                                    {
                                        Destination = new Destination()
                                        {
                                            Host = "mimir-query-frontend.neon-monitor.svc.cluster.local",
                                            Port = new PortSelector()
                                            {
                                                Number = 8080
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                await Kubernetes.CreateNamespacedCustomObjectAsync <VirtualService>(virtualService, virtualService.Name(), KubeNamespace.NeonIngress);
            }
            SetEnvironmentVariable("METRICS_HOST", $"https://metrics.{ClusterInfo.Domain}");
        }
Пример #3
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);
            }
        }