public V1Service Build(HealthCheckResource resource)
        {
            var meta = new V1ObjectMeta
            {
                Name            = $"{resource.Spec.Name}-svc",
                OwnerReferences = new List <V1OwnerReference> {
                    resource.CreateOwnerReference()
                },
                Labels = new Dictionary <string, string>
                {
                    ["app"] = resource.Spec.Name
                },
            };

            var spec = new V1ServiceSpec
            {
                Selector = new Dictionary <string, string>
                {
                    ["app"] = resource.Spec.Name
                },
                Type  = resource.Spec.ServiceType ?? Constants.DefaultServiceType,
                Ports = new List <V1ServicePort> {
                    new V1ServicePort {
                        Name       = "httport",
                        Port       = int.Parse(resource.Spec.PortNumber ?? Constants.DefaultPort),
                        TargetPort = 80
                    }
                }
            };

            return(new V1Service(metadata: meta, spec: spec));
        }
        private V1Service ServiceBody(string name)
        {
            V1Service service = new V1Service();

            service.ApiVersion = "v1";
            service.Kind       = "Service";
            service.Metadata   = new V1ObjectMeta()
            {
                Name = name
            };


            var serviceSpec = new V1ServiceSpec()
            {
                Type = "LoadBalancer", Ports = new List <V1ServicePort>(), Selector = new Dictionary <string, string>()
            };

            serviceSpec.Ports.Add(new V1ServicePort()
            {
                Name = "main", Port = 25565
            });
            serviceSpec.Ports.Add(new V1ServicePort()
            {
                Name = "openhackcheck", Port = 25575
            });
            serviceSpec.Selector.Add("run", name);

            service.Spec = serviceSpec;
            return(service);
        }
Esempio n. 3
0
        public static V1Service CreateService(string id)
        {
            var spec = new V1ServiceSpec()
            {
                Type     = "LoadBalancer",
                Selector = new Dictionary <string, string>()
                {
                    { "pod-name", $"minecraft-pod-{id}" }
                },
                Ports = new List <V1ServicePort>()
                {
                    new V1ServicePort(80, "padrao", protocol: "TCP", targetPort: 25565),
                    new V1ServicePort(443, "ssl", protocol: "TCP", targetPort: 25575),
                    new V1ServicePort(25565, "padrao-mc", protocol: "TCP", targetPort: 25565),
                    new V1ServicePort(25575, "rcon", protocol: "TCP", targetPort: 25575),
                }
            };

            var metadata = new V1ObjectMeta()
            {
                Name = $"minecraft-service-{id}"
            };

            return(new V1Service(V1Service.KubeApiVersion, V1Service.KubeKind, metadata, spec));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates an external name <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 CreateBrokerExternalNameServiceAsync(Broker broker)
        {
            V1Service service;

            try
            {
                this.Logger.LogInformation("Creating a new external name service for the broker with name '{resourceName}'...", broker.Name());
                V1ObjectMeta  metadata = new V1ObjectMeta(name: broker.Name());
                V1ServiceSpec spec     = new V1ServiceSpec()
                {
                    Type         = KubernetesDefaults.ServiceTypes.ExternalName,
                    ExternalName = $"gateway.{this.Options.Pod.Namespace}.svc.cluster.local",
                    Ports        = new List <V1ServicePort>()
                    {
                        new V1ServicePort(80, name: "http")
                    }
                };
                service = new V1Service(KubernetesDefaults.ApiVersions.V1, KubernetesDefaults.Kinds.Service, metadata, spec);
                await this.KubernetesClient.CreateNamespacedServiceAsync(service, broker.Namespace());

                this.Logger.LogInformation("A new external name 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 external name 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;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new <see cref="V1Service"/> for the specified <see cref="Resources.Channel"/>
        /// </summary>
        /// <param name="channel">The <see cref="Resources.Channel"/> to deploy</param>
        /// <returns>A new awaitable <see cref="Task"/></returns>
        protected virtual async Task CreateChannelServiceAsync(Resources.Channel channel)
        {
            V1Service service;

            try
            {
                this.Logger.LogInformation("Creating a new service for the channel with name '{resourceName}'...", channel.Name());
                V1ObjectMeta serviceMetadata = new V1ObjectMeta();
                serviceMetadata.Name = channel.Name();
                serviceMetadata.NamespaceProperty = channel.Namespace();
                serviceMetadata.Labels            = new Dictionary <string, string>()
                {
                    { "app", channel.Name() },
                    { "type", "channel" }
                };
                V1ServiceSpec serviceSpec = new V1ServiceSpec();
                serviceSpec.Ports = new List <V1ServicePort>()
                {
                    new V1ServicePort(80, name: "http")
                };
                serviceSpec.Selector = new Dictionary <string, string>()
                {
                    { "app", channel.Name() }
                };
                service = new V1Service(KubernetesDefaults.ApiVersions.V1, KubernetesDefaults.Kinds.Service, serviceMetadata, serviceSpec);
                await this.KubernetesClient.CreateNamespacedServiceAsync(service, channel.Namespace());

                this.Logger.LogInformation("A new service for the channel with name '{resourceName}' has been successfully created.", channel.Name());
            }
            catch (HttpOperationException ex)
            {
                this.Logger.LogError($"An error occured while creating the service for the channel with name '{{resourceName}}': the server responded with a non-success status code '{{statusCode}}'.{Environment.NewLine}Details: {{responseContent}}", channel.Name(), ex.Response.StatusCode, ex.Response.Content);
                throw;
            }
        }
Esempio n. 6
0
        public V1Service Build(HealthCheckResource resource)
        {
            var meta = new V1ObjectMeta
            {
                Name            = $"{resource.Spec.Name}-svc",
                OwnerReferences = new List <V1OwnerReference> {
                    resource.CreateOwnerReference()
                },
                Annotations = new Dictionary <string, string>(),
                Labels      = new Dictionary <string, string>
                {
                    ["app"] = resource.Spec.Name
                },
            };

            var spec = new V1ServiceSpec
            {
                Selector = new Dictionary <string, string>
                {
                    ["app"] = resource.Spec.Name
                },
                Type  = resource.Spec.ServiceType ?? Constants.DefaultServiceType,
                Ports = new List <V1ServicePort> {
                    new V1ServicePort {
                        Name       = "httport",
                        Port       = int.Parse(resource.Spec.PortNumber ?? Constants.DefaultPort),
                        TargetPort = 80
                    }
                }
            };

            foreach (var annotation in resource.Spec.ServiceAnnotations)
            {
                _logger.LogInformation("Adding annotation {Annotation} to ui service with value {AnnotationValue}", annotation.Name, annotation.Value);
                meta.Annotations.Add(annotation.Name, annotation.Value);
            }

            return(new V1Service(metadata: meta, spec: spec));
        }