Add components copy of Guestbook example in C#
ADD
kubernetes-cs-guestbook/components/Guestbook.csproj
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>netcoreapp3.0</TargetFramework>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Pulumi.Kubernetes" Version="1.3.2-preview" />
+ </ItemGroup>
+
+</Project>

ADD
kubernetes-cs-guestbook/components/Program.cs
+// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Pulumi;
+using Pulumi.Kubernetes.Core.V1;
+using Pulumi.Kubernetes.Types.Inputs.Core.V1;
+using Pulumi.Kubernetes.Types.Inputs.Apps.V1;
+using Pulumi.Kubernetes.Types.Inputs.Meta.V1;
+using Pulumi.Kubernetes.Types.Inputs.ApiExtensions.V1Beta1;
+
+class Program
+{
+ static Task<int> Main(string[] args)
+ {
+ return Deployment.RunAsync(() =>
+ {
+ var config = new Config();
+ var isMiniKube = config.GetBoolean("isMiniKube") ?? false;
+
+ var redisMaster = new ServiceDeployment("redis-master", new ServiceDeploymentArgs
+ {
+ Image = "k8s.gcr.io/redis:e2e",
+ Ports = { 6379 },
+ });
+
+ var redisReplica = new ServiceDeployment("redis-slave", new ServiceDeploymentArgs
+ {
+ Image = "gcr.io/google_samples/gb-redisslave:v1",
+ Ports = { 6379 },
+ });
+
+ var frontend = new ServiceDeployment("frontend", new ServiceDeploymentArgs
+ {
+ Replicas = 3,
+ Image = "gcr.io/google-samples/gb-frontend:v4",
+ Ports = { 80 },
+ AllocateIPAddress = true,
+ ServiceType = isMiniKube ? "ClusterIP" : "LoadBalancer",
+ });
+
+ return new Dictionary<string, object?>{
+ { "frontendIp", frontend.IpAddress },
+ };
+
+ });
+ }
+}

ADD
kubernetes-cs-guestbook/components/Pulumi.yaml
+name: guestbook-csharp-components
+runtime: dotnet
+description: Kubernetes Guestbook example based on https://kubernetes.io/docs/tutorials/stateless-application/guestbook/
+template:
+ config:
+ isMinikube:
+ description: Whether you are deploying to minikube
+ default: true

ADD
kubernetes-cs-guestbook/components/ServiceDeployment.cs
+// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Pulumi;
+using Pulumi.Kubernetes.Core.V1;
+using Pulumi.Kubernetes.Types.Inputs.Core.V1;
+using Pulumi.Kubernetes.Types.Inputs.Apps.V1;
+using Pulumi.Kubernetes.Types.Inputs.Meta.V1;
+using Pulumi.Kubernetes.Types.Inputs.ApiExtensions.V1Beta1;
+
+class ServiceDeploymentArgs
+{
+ public Input<string> Image { get; set; } = null!;
+ public Input<int>? Replicas { get; set; }
+ public Input<ResourceRequirementsArgs>? Resources { get; set; }
+ public InputList<int> Ports { get; set; } = new InputList<int>();
+ public Input<bool>? AllocateIPAddress { get; set; }
+ public Input<string>? ServiceType { get; set; }
+ public InputList<EnvVarArgs> Env { get; set; } = new InputList<EnvVarArgs>();
+}
+
+class ServiceDeployment : Pulumi.ComponentResource
+{
+ public Pulumi.Kubernetes.Apps.V1.Deployment Deployment;
+ public Pulumi.Kubernetes.Core.V1.Service Service;
+ public Output<string>? IpAddress;
+
+ public ServiceDeployment(string name, ServiceDeploymentArgs args, ComponentResourceOptions? opts = null)
+ : base(name, "k8sx:service:ServiceDeployment", opts)
+ {
+ var labels = new InputMap<string>
+ {
+ { "app", name },
+ };
+
+ var deploymentPorts = args.Ports.ToOutput().Apply(ports =>
+ from p in ports select new ContainerPortArgs { ContainerPortValue = 6379 }
+ );
+
+ var container = new ContainerArgs
+ {
+ Name = name,
+ Image = args.Image,
+ Resources = args.Resources ?? new ResourceRequirementsArgs
+ {
+ Requests =
+ {
+ { "cpu", "100m" },
+ { "memory", "100Mi" },
+ },
+ },
+ Env = args.Env,
+ Ports = deploymentPorts,
+ };
+
+ this.Deployment = new Pulumi.Kubernetes.Apps.V1.Deployment(name, new DeploymentArgs
+ {
+ Spec = new DeploymentSpecArgs
+ {
+ Selector = new LabelSelectorArgs
+ {
+ MatchLabels = labels,
+ },
+ Replicas = args.Replicas ?? 1,
+ Template = new PodTemplateSpecArgs
+ {
+ Metadata = new ObjectMetaArgs
+ {
+ Labels = labels,
+ },
+ Spec = new PodSpecArgs
+ {
+ Containers = { container },
+ },
+ },
+ },
+ },
+ new CustomResourceOptions { Parent = this });
+
+ var servicePorts = args.Ports.ToOutput().Apply(ports =>
+ from p in ports select new ServicePortArgs { Port = p, TargetPort = p }
+ );
+
+ this.Service = new Pulumi.Kubernetes.Core.V1.Service(name, new ServiceArgs
+ {
+ Metadata = new ObjectMetaArgs
+ {
+ Name = name,
+ Labels = this.Deployment.Metadata.Apply(metadata => metadata.Labels),
+ },
+ Spec = new ServiceSpecArgs
+ {
+ Type = args.AllocateIPAddress.Apply(hasIp => hasIp ? (args.ServiceType ?? "LoadBalancer") : null),
+ Ports = servicePorts,
+ Selector = this.Deployment.Spec.Apply(spec => spec.Template.Metadata.Labels),
+ },
+ },
+ new CustomResourceOptions { Parent = this });
+
+ this.IpAddress = args.AllocateIPAddress.Apply(hasIp =>
+ {
+ if (hasIp)
+ {
+ return args.ServiceType.Apply(serviceType =>
+ serviceType == "ClusterIP"
+ ? this.Service.Spec.Apply(s => s.ClusterIP)
+ : this.Service.Status.Apply(status =>
+ {
+ var ingress = status.LoadBalancer.Ingress[0];
+ // Return the ip address if populated or else the hostname
+ return ingress.Ip ?? ingress.Hostname;
+ })
+ );
+ }
+ else
+ {
+ return null;
+ }
+ });
+ }
+}

RENAME
kubernetes-cs-guestbook/imgs/guestbook.png
kubernetes-cs-guestbook/components/imgs/guestbook.png
RENAME
kubernetes-cs-guestbook/Guestbook.csproj
kubernetes-cs-guestbook/simple/Guestbook.csproj
RENAME
kubernetes-cs-guestbook/Program.cs
kubernetes-cs-guestbook/simple/Program.cs
@@ -76,6 +76,7 @@ class Program
{
Metadata = new ObjectMetaArgs
{
+ Name = "redis-master",
Labels = redisMasterDeployment.Metadata.Apply(metadata => metadata.Labels),
},
Spec = new ServiceSpecArgs
@@ -155,6 +156,7 @@ class Program
{
Metadata = new ObjectMetaArgs
{
+ Name = "redis-slave",
Labels = redisReplicaDeployment.Metadata.Apply(metadata => metadata.Labels),
},
Spec = new ServiceSpecArgs
@@ -234,6 +236,7 @@ class Program
{
Metadata = new ObjectMetaArgs
{
+ Name = "frontend",
Labels = frontendDeployment.Metadata.Apply(metadata => metadata.Labels),
},
Spec = new ServiceSpecArgs

RENAME
kubernetes-cs-guestbook/Pulumi.yaml
kubernetes-cs-guestbook/simple/Pulumi.yaml
ADD
kubernetes-cs-guestbook/simple/imgs/guestbook.png
kubernetes-cs-guestbook/simple/imgs/guestbook.png
Binary files /dev/null and b/kubernetes-cs-guestbook/simple/imgs/guestbook.png differ

Add components copy of Guestbook example in C# (#492)