protected CustomResource(CustomResourceDefinition definition, string @namespace, string name)
     : this(definition)
 {
     Metadata = new ObjectMetaV1
     {
         Namespace = @namespace,
         Name      = name
     };
 }
        private DeploymentV1Beta1 GetDeployment(string name, string image, double cpu, int memory, string port, string nameSpace, int min)
        {
            var deployment = new DeploymentV1Beta1();
            var metadata   = new ObjectMetaV1();

            metadata.Namespace = nameSpace;

            var labels = new System.Collections.Generic.Dictionary <string, string>();

            labels.Add("app", name);

            metadata.Labels = labels;

            deployment.Metadata      = metadata;
            deployment.Metadata.Name = name;

            deployment.Spec                         = new DeploymentSpecV1Beta1();
            deployment.Spec.Replicas                = min;
            deployment.Spec.Selector                = new LabelSelectorV1();
            deployment.Spec.Selector.MatchLabels    = labels;
            deployment.Spec.ProgressDeadlineSeconds = 60;

            deployment.Spec.Template                 = new PodTemplateSpecV1();
            deployment.Spec.Template.Metadata        = new ObjectMetaV1();
            deployment.Spec.Template.Metadata.Labels = labels;

            deployment.Spec.Template.Spec            = new PodSpecV1();
            deployment.Spec.Template.Spec.Containers = new List <ContainerV1>();

            deployment.Spec.Template.Spec.Containers.Add(new ContainerV1()
            {
                Name      = name,
                Image     = image,
                Resources = new ResourceRequirementsV1()
                {
                    Requests = new Dictionary <string, string>()
                    {
                        { "cpu", cpu.ToString() },
                        { "memory", $"{memory}Mi" }
                    }
                }
            });

            if (!string.IsNullOrEmpty(port))
            {
                deployment.Spec.Template.Spec.Containers[0].Ports = new List <ContainerPortV1>()
                {
                    new ContainerPortV1()
                    {
                        ContainerPort = int.Parse(port)
                    }
                };
            }

            return(deployment);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Create a <see cref="ResourceEventFilter"/> that matches the specified resource metadata.
        /// </summary>
        /// <param name="metadata">
        ///     The resource metadata.
        /// </param>
        /// <returns>
        ///     The <see cref="ResourceEventFilter"/>.
        /// </returns>
        public static ResourceEventFilter FromMetatadata(ObjectMetaV1 metadata)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            return(new ResourceEventFilter
            {
                Name = metadata.Name,
                LabelSelectors = metadata.Labels != null?metadata.Labels.ToImmutableDictionary() : Empty.LabelSelectors
            });
        }
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // ... Get the ComboBox.
            var          comboBox          = sender as ComboBox;
            ObjectMetaV1 selectedNameSpace = comboBox.SelectedItem as ObjectMetaV1;

            if (selectedNameSpace != null)
            {
                KubernetesViewModel kbModel = (KubernetesViewModel)DataContext;
                kbModel.SelectedNameSpace = selectedNameSpace;
                kbModel.LoadItems(selectedNameSpace.Name);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Determine whether the filter matches the specified resource metadata.
        /// </summary>
        /// <param name="resourceMetadata">
        ///     The resource metadata to match.
        /// </param>
        /// <returns>
        ///     <c>true</c>, if the filter matches the metadata; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsMatch(ObjectMetaV1 resourceMetadata)
        {
            if (resourceMetadata == null)
            {
                throw new ArgumentNullException(nameof(resourceMetadata));
            }

            if (!String.IsNullOrWhiteSpace(Name) && !String.Equals(Name, resourceMetadata.Name))
            {
                return(false);
            }

            return(MatchLabelSelectors(LabelSelectors, resourceMetadata.Labels));
        }
Exemplo n.º 6
0
 /// <summary>
 ///     Determine whether the filter matches the specified metadata.
 /// </summary>
 /// <param name="resourceMetadata">
 ///     The resource metadata to match.
 /// </param>
 /// <returns>
 ///     <c>true</c>, if the filter matches the metadata; otherwise, <c>false</c>.
 /// </returns>
 public abstract bool IsMatch(ObjectMetaV1 resourceMetadata);
 /// <summary>
 ///     Create a filter that exactly matches the specified ReplicationController metadata.
 /// </summary>
 /// <param name="metadata">
 ///     The ReplicationController metadata to match.
 /// </param>
 /// <returns>
 ///     A <see cref="ResourceEventFilter"/> describing the filter.
 /// </returns>
 protected override ResourceEventFilter CreateExactMatchFilter(ObjectMetaV1 metadata) => ResourceEventFilter.FromMetatadata(metadata);
Exemplo n.º 8
0
 /// <summary>
 ///     Create a filter that exactly matches the specified resource metadata.
 /// </summary>
 /// <param name="metadata">
 ///     The resource metadata to match.
 /// </param>
 /// <returns>
 ///     A <typeparamref name="TFilter"/> describing the filter.
 /// </returns>
 protected abstract TFilter CreateExactMatchFilter(ObjectMetaV1 metadata);
Exemplo n.º 9
0
        public void UpdateIngress(string ns, string name, string env, string url, int port, bool acme)
        {
            if (port > 0 && !string.IsNullOrEmpty(url))
            {
                var spec = new IngressSpecV1Beta1()
                {
                    Rules =
                    {
                        new IngressRuleV1Beta1
                        {
                            Host = url,
                            Http = new HTTPIngressRuleValueV1Beta1
                            {
                                Paths =
                                {
                                    new HTTPIngressPathV1Beta1
                                    {
                                        Backend = new IngressBackendV1Beta1
                                        {
                                            ServiceName = $"{name}-{env}",
                                            ServicePort = port
                                        },
                                    }
                                }
                            }
                        }
                    }
                };
                if (acme)
                {
                    spec.Tls.Add(
                        new IngressTLSV1Beta1
                    {
                        Hosts      = { url },
                        SecretName = $"acme-{name}-{env}"
                    }
                        );
                }

                var meta = new ObjectMetaV1
                {
                    Name        = $"{name}-{env}",
                    Namespace   = ns,
                    Annotations =
                    {
                        ["kubernetes.io/tls-acme"] = acme.ToString()
                    }
                };
                var ingress = _kubeApiClient.IngressesV1Beta1().Get($"{name}-{env}", ns).Result;
                if (ingress == null)
                {
                    Log($"Ingress: {name}-{env} -> {url} not found, created");

                    var res = _kubeApiClient.IngressesV1Beta1().Create(new IngressV1Beta1
                    {
                        Metadata = meta,
                        Spec     = spec
                    }).Result;
                }
                else
                {
                    Log($"Ingress: {name}-{env} -> {url} already exists, Updated");
                    var res = _kubeApiClient.IngressesV1Beta1().Update($"{name}-{env}", patch =>
                    {
                        patch.Replace(x => x.Spec, spec);
                        patch.Replace(x => x.Metadata, meta);
                    }, ns).Result;
                }
            }
            else
            {
                var res = _kubeApiClient.IngressesV1Beta1().Delete($"{name}-{env}", ns).Result;
                Log($"Ingress: PLUGIN_PORT or PLUGIN_URL not set,Clean Ingress");
            }
        }