private static ServiceV1 GetService(string name, string @namespace, DeploymentV1Apps deployment, string serviceType, IDictionary <string, string> annotations = null) { return(new ServiceV1 { ApiVersion = "v1", Kind = "Service", Metadata = new ObjectMetadataV1 { Name = name, Namespace = @namespace, Annotations = annotations }, Spec = new ServiceSpecV1 { Type = serviceType, Ports = new ServicePortV1[] { new ServicePortV1 { Port = 80, Protocol = "TCP", TargetPort = 80 } }, Selector = deployment.Spec.Selector.MatchLabels } }); }
private static ScaledObjectV1Alpha1 GetScaledObject(string name, string @namespace, TriggersPayload triggers, DeploymentV1Apps deployment, int?pollingInterval, int?cooldownPeriod, int?minReplicas, int?maxReplicas) { return(new ScaledObjectV1Alpha1 { ApiVersion = "keda.k8s.io/v1alpha1", Kind = "ScaledObject", Metadata = new ObjectMetadataV1 { Name = name, Namespace = @namespace, Labels = new Dictionary <string, string> { { "deploymentName", deployment.Metadata.Name } } }, Spec = new ScaledObjectSpecV1Alpha1 { ScaleTargetRef = new ScaledObjectScaleTargetRefV1Alpha1 { DeploymentName = deployment.Metadata.Name }, PollingInterval = pollingInterval, CooldownPeriod = cooldownPeriod, MinReplicaCount = minReplicas, MaxReplicaCount = maxReplicas, Triggers = triggers .FunctionsJson .Select(kv => kv.Value) .Where(v => v["bindings"] != null) .Select(b => b["bindings"]) .SelectMany(i => i) .Where(b => b?["type"] != null) .Where(b => b["type"].ToString().IndexOf("Trigger", StringComparison.OrdinalIgnoreCase) != -1) .Where(b => b["type"].ToString().IndexOf("httpTrigger", StringComparison.OrdinalIgnoreCase) == -1) .Select(t => new ScaledObjectTriggerV1Alpha1 { Type = GetKedaTrigger(t["type"]?.ToString()), Metadata = PopulateMetadataDictionary(t) }) } }); }
private static DeploymentV1Apps GetDeployment(string name, string @namespace, string image, string pullSecret, int replicaCount, IDictionary <string, string> additionalEnv = null, IDictionary <string, string> annotations = null, int port = -1) { var deployment = new DeploymentV1Apps { ApiVersion = "apps/v1", Kind = "Deployment", Metadata = new ObjectMetadataV1 { Namespace = @namespace, Name = name, Labels = new Dictionary <string, string> { { "app", name } }, Annotations = annotations }, Spec = new DeploymentSpecV1Apps { Replicas = replicaCount, Selector = new SelectorV1 { MatchLabels = new Dictionary <string, string> { { "app", name } } }, Template = new PodTemplateV1 { Metadata = new ObjectMetadataV1 { Labels = new Dictionary <string, string> { { "app", name } } }, Spec = new PodTemplateSpecV1 { Containers = new ContainerV1[] { new ContainerV1 { Name = name, Image = image, Env = additionalEnv == null ? null : additionalEnv.Select(kv => new ContainerEnvironmentV1 { Name = kv.Key, Value = kv.Value }), Ports = port == -1 ? null : new ContainerPortV1[] { new ContainerPortV1 { ContainerPort = 80 } } } }, ImagePullSecrets = string.IsNullOrEmpty(pullSecret) ? null : new ImagePullSecretV1[] { new ImagePullSecretV1 { Name = pullSecret } } } } } }; return(deployment); }
private DeploymentV1Apps GetDeployment(string name, string image, double cpu, int memory, string port, string nameSpace, int min, string pullSecret) { var deployment = new DeploymentV1Apps { ApiVersion = "apps/v1beta1", Kind = "Deployment", Metadata = new ObjectMetadataV1 { Namespace = nameSpace, Name = name, Labels = new Dictionary <string, string> { { "app", name } } }, Spec = new DeploymentSpecV1Apps { Replicas = min, Selector = new SelectorV1 { MatchLabels = new Dictionary <string, string> { { "app", name } } }, Template = new PodTemplateV1 { Metadata = new ObjectMetadataV1 { Labels = new Dictionary <string, string> { { "app", name } } }, Spec = new PodTemplateSpecV1 { Containers = new ContainerV1[] { new ContainerV1 { Name = name, Image = image, Resources = new ContainerResourcesV1() { Requests = new ContainerResourceRequestsV1() { Cpu = cpu.ToString(), Memory = $"{memory}Mi" } }, Ports = string.IsNullOrEmpty(port) ? Array.Empty <ContainerPortV1>() : new ContainerPortV1[] { new ContainerPortV1 { ContainerPort = int.Parse(port) } }, } }, Tolerations = new PodTolerationV1[] { new PodTolerationV1 { Key = "azure.com/aci", Effect = "NoSchedule" } }, ImagePullSecrets = string.IsNullOrEmpty(pullSecret) ? null : new ImagePullSecretV1[] { new ImagePullSecretV1 { Name = pullSecret } } } } } }; return(deployment); }