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));
        }
 public V1ConfigMap Build(HealthCheckResource resource)
 {
     return(new V1ConfigMap
     {
         BinaryData = new Dictionary <string, byte[]>
         {
             [Constants.STYLE_SHEET_NAME] = Encoding.UTF8.GetBytes(resource.Spec.StylesheetContent)
         },
         Metadata = new V1ObjectMeta
         {
             OwnerReferences = new List <V1OwnerReference>
             {
                 resource.CreateOwnerReference(),
             },
             NamespaceProperty = resource.Metadata.NamespaceProperty,
             Name = $"{resource.Spec.Name}-config"
         }
     });
 }
 public V1Secret Build(HealthCheckResource resource)
 {
     return(new V1Secret
     {
         Metadata = new V1ObjectMeta
         {
             Name = $"{resource.Spec.Name}-secret",
             NamespaceProperty = resource.Metadata.NamespaceProperty,
             OwnerReferences = new List <V1OwnerReference> {
                 resource.CreateOwnerReference()
             },
             Labels = new Dictionary <string, string>
             {
                 ["app"] = resource.Spec.Name
             }
         },
         Data = new Dictionary <string, byte[]>
         {
             ["key"] = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())
         }
     });
 }
Ejemplo n.º 4
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));
        }
        public V1Deployment Build(HealthCheckResource resource)
        {
            var metadata = new V1ObjectMeta
            {
                OwnerReferences = new List <V1OwnerReference> {
                    resource.CreateOwnerReference()
                },
                Annotations = new Dictionary <string, string>(),
                Labels      = new Dictionary <string, string>
                {
                    ["app"] = resource.Spec.Name
                },
                Name = $"{resource.Spec.Name}-deploy",
                NamespaceProperty = resource.Metadata.NamespaceProperty
            };

            var uiContainer = new V1Container
            {
                ImagePullPolicy = resource.Spec.ImagePullPolicy ?? Constants.DEFAULT_PULL_POLICY,
                Name            = Constants.POD_NAME,
                Image           = resource.Spec.Image ?? Constants.IMAGE_NAME,
                Ports           = new List <V1ContainerPort>
                {
                    new V1ContainerPort(80)
                },
                Env = new List <V1EnvVar>
                {
                    new V1EnvVar("enable_push_endpoint", "true"),
                    new V1EnvVar("push_endpoint_secret", valueFrom: new V1EnvVarSource(secretKeyRef: new V1SecretKeySelector("key", $"{resource.Spec.Name}-secret"))),
                    new V1EnvVar("Logging__LogLevel__Default", "Debug"),
                    new V1EnvVar("Logging__LogLevel__Microsoft", "Warning"),
                    new V1EnvVar("Logging__LogLevel__System", "Warning"),
                    new V1EnvVar("Logging__LogLevel__HealthChecks", "Information")
                }
            };

            uiContainer.MapCustomUIPaths(resource, _operatorDiagnostics);

            var spec = new V1DeploymentSpec
            {
                Selector = new V1LabelSelector
                {
                    MatchLabels = new Dictionary <string, string>
                    {
                        ["app"] = resource.Spec.Name
                    }
                },
                Replicas = 1,
                Template = new V1PodTemplateSpec
                {
                    Metadata = new V1ObjectMeta
                    {
                        Labels = new Dictionary <string, string>
                        {
                            ["app"] = resource.Spec.Name
                        },
                    },
                    Spec = new V1PodSpec
                    {
                        Containers = new List <V1Container>
                        {
                            uiContainer
                        }
                    }
                }
            };

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

            var specification = spec.Template.Spec;
            var container     = specification.Containers.First();

            for (int i = 0; i < resource.Spec.Webhooks.Count; i++)
            {
                var webhook = resource.Spec.Webhooks[i];
                _logger.LogInformation("Adding webhook configuration for webhook {Webhook}", webhook.Name);

                container.Env.Add(new V1EnvVar($"HealthChecksUI__Webhooks__{i}__Name", webhook.Name));
                container.Env.Add(new V1EnvVar($"HealthChecksUI__Webhooks__{i}__Uri", webhook.Uri));
                container.Env.Add(new V1EnvVar($"HealthChecksUI__Webhooks__{i}__Payload", webhook.Payload));
                container.Env.Add(new V1EnvVar($"HealthChecksUI__Webhooks__{i}__RestoredPayload", webhook.RestoredPayload));
            }

            if (resource.HasBrandingConfigured())
            {
                const string volumeName = "healthchecks-volume";

                if (specification.Volumes == null)
                {
                    specification.Volumes = new List <V1Volume>();
                }
                if (container.VolumeMounts == null)
                {
                    container.VolumeMounts = new List <V1VolumeMount>();
                }

                specification.Volumes.Add(new V1Volume(name: volumeName,
                                                       configMap: new V1ConfigMapVolumeSource(name: $"{resource.Spec.Name}-config")));

                container.Env.Add(new V1EnvVar("ui_stylesheet", $"{Constants.STYLES_PATH}/{Constants.STYLE_SHEET_NAME}"));
                container.VolumeMounts.Add(new V1VolumeMount($"/app/{Constants.STYLES_PATH}", volumeName));
            }

            return(new V1Deployment(metadata: metadata, spec: spec));
        }
Ejemplo n.º 6
0
        public V1Deployment Build(HealthCheckResource resource)
        {
            var metadata = new V1ObjectMeta
            {
                OwnerReferences = new List <V1OwnerReference> {
                    resource.CreateOwnerReference()
                },
                Labels = new Dictionary <string, string>
                {
                    ["app"] = resource.Spec.Name
                },
                Name = $"{resource.Spec.Name}-deploy",
                NamespaceProperty = resource.Metadata.NamespaceProperty
            };

            var spec = new V1DeploymentSpec
            {
                Selector = new V1LabelSelector
                {
                    MatchLabels = new Dictionary <string, string>
                    {
                        ["app"] = resource.Spec.Name
                    }
                },
                Replicas = 1,
                Template = new V1PodTemplateSpec
                {
                    Metadata = new V1ObjectMeta
                    {
                        Labels = new Dictionary <string, string>
                        {
                            ["app"] = resource.Spec.Name
                        }
                    },
                    Spec = new V1PodSpec
                    {
                        Containers = new List <V1Container>
                        {
                            new V1Container
                            {
                                ImagePullPolicy = resource.Spec.ImagePullPolicy ?? Constants.DefaultPullPolicy,
                                Name            = Constants.PodName,
                                Image           = resource.Spec.Image ?? Constants.ImageName,
                                Ports           = new List <V1ContainerPort>
                                {
                                    new V1ContainerPort(80)
                                },
                                Env = new List <V1EnvVar>
                                {
                                    new V1EnvVar("ui_path", resource.Spec.UiPath ?? Constants.DefaultUIPath),
                                    new V1EnvVar("enable_push_endpoint", "true"),
                                    new V1EnvVar("push_endpoint_secret", valueFrom: new V1EnvVarSource(secretKeyRef: new V1SecretKeySelector("key", $"{resource.Spec.Name}-secret"))),
                                    new V1EnvVar("Logging__LogLevel__Default", "Debug"),
                                    new V1EnvVar("Logging__LogLevel__Microsoft", "Warning"),
                                    new V1EnvVar("Logging__LogLevel__System", "Warning"),
                                    new V1EnvVar("Logging__LogLevel__HealthChecks", "Information")
                                }
                            }
                        }
                    }
                }
            };

            return(new V1Deployment(metadata: metadata, spec: spec));
        }
Ejemplo n.º 7
0
        public V1Deployment Build(HealthCheckResource resource)
        {
            var metadata = new V1ObjectMeta
            {
                OwnerReferences = new List <V1OwnerReference> {
                    resource.CreateOwnerReference()
                },
                Annotations = new Dictionary <string, string>(),
                Labels      = new Dictionary <string, string>
                {
                    ["app"] = resource.Spec.Name
                },
                Name = $"{resource.Spec.Name}-deploy",
                NamespaceProperty = resource.Metadata.NamespaceProperty
            };

            var spec = new V1DeploymentSpec
            {
                Selector = new V1LabelSelector
                {
                    MatchLabels = new Dictionary <string, string>
                    {
                        ["app"] = resource.Spec.Name
                    }
                },
                Replicas = 1,
                Template = new V1PodTemplateSpec
                {
                    Metadata = new V1ObjectMeta
                    {
                        Labels = new Dictionary <string, string>
                        {
                            ["app"] = resource.Spec.Name
                        },
                    },
                    Spec = new V1PodSpec
                    {
                        Containers = new List <V1Container>
                        {
                            new V1Container
                            {
                                ImagePullPolicy = resource.Spec.ImagePullPolicy ?? Constants.DefaultPullPolicy,
                                Name            = Constants.PodName,
                                Image           = resource.Spec.Image ?? Constants.ImageName,
                                Ports           = new List <V1ContainerPort>
                                {
                                    new V1ContainerPort(80)
                                },
                                Env = new List <V1EnvVar>
                                {
                                    new V1EnvVar("ui_path", resource.Spec.UiPath ?? Constants.DefaultUIPath),
                                    new V1EnvVar("enable_push_endpoint", "true"),
                                    new V1EnvVar("push_endpoint_secret", valueFrom: new V1EnvVarSource(secretKeyRef: new V1SecretKeySelector("key", $"{resource.Spec.Name}-secret"))),
                                    new V1EnvVar("Logging__LogLevel__Default", "Debug"),
                                    new V1EnvVar("Logging__LogLevel__Microsoft", "Warning"),
                                    new V1EnvVar("Logging__LogLevel__System", "Warning"),
                                    new V1EnvVar("Logging__LogLevel__HealthChecks", "Information")
                                }
                            }
                        }
                    }
                }
            };

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

            if (resource.HasBrandingConfigured())
            {
                var specification = spec.Template.Spec;
                var container     = specification.Containers.First();
                var volumeName    = "healthchecks-volume";

                if (specification.Volumes == null)
                {
                    specification.Volumes = new List <V1Volume>();
                }
                if (container.VolumeMounts == null)
                {
                    container.VolumeMounts = new List <V1VolumeMount>();
                }

                specification.Volumes.Add(new V1Volume(name: volumeName,
                                                       configMap: new V1ConfigMapVolumeSource(name: $"{resource.Spec.Name}-config")));

                container.Env.Add(new V1EnvVar("ui_stylesheet", $"{Constants.StylesPath}/{Constants.StyleSheetName}"));
                container.VolumeMounts.Add(new V1VolumeMount($"/app/{Constants.StylesPath}", volumeName));
            }

            return(new V1Deployment(metadata: metadata, spec: spec));
        }