Skip to content

Commit

Permalink
Fixing up Kubernetes Guestbook Examples (pulumi#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
stack72 committed May 4, 2020
1 parent 55ccdf4 commit c318e88
Show file tree
Hide file tree
Showing 18 changed files with 545 additions and 31 deletions.
202 changes: 202 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,205 @@ jobs:
run: make install
- name: Lint typescript files
run: make lint
test-infra-setup:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]
go-version: [1.13.x]
node-version: [10.x]
python-version: [3.7]
dotnet-version: ['3.1.100']
runs-on: ${{ matrix.platform }}
steps:
- name: Install DotNet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Deps
run: |
pip3 install pipenv
- name: Install aws-iam-authenticator
run: |
curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
sudo mv aws-iam-authenticator /usr/local/bin
- name: Install Kubectl
run: |
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv kubectl /usr/local/bin
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '285.0.0'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Install helm
run: |
curl -o- -L https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
- name: Configure helm
run: |
helm init -c
helm repo add bitnami https://charts.bitnami.com/bitnami
- name: Set Azure DNS
run: |
echo "$(getent hosts $ARM_LOCATION.management.azure.com | awk '{ print $1 }') management.azure.com" | sudo tee --append /etc/hosts
- name: Login to Google Cloud Registry
run: |
gcloud --quiet auth configure-docker
- name: Install Pulumi CLI
uses: pulumi/action-install-pulumi-cli@releases/v1
- uses: actions/checkout@v2
- name: Create test infra
run: |
make setup_test_infra StackName="${{ secrets.PULUMI_TEST_OWNER }}/${{ github.sha }}"
test-infra-destroy:
needs: kubernetes
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]
go-version: [1.13.x]
node-version: [10.x]
python-version: [3.7]
dotnet-version: ['3.1.100']
runs-on: ${{ matrix.platform }}
steps:
- name: Install DotNet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Deps
run: |
pip3 install pipenv
- name: Install aws-iam-authenticator
run: |
curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
sudo mv aws-iam-authenticator /usr/local/bin
- name: Install Kubectl
run: |
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv kubectl /usr/local/bin
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '285.0.0'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Install helm
run: |
curl -o- -L https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
- name: Configure helm
run: |
helm init -c
helm repo add bitnami https://charts.bitnami.com/bitnami
- name: Set Azure DNS
run: |
echo "$(getent hosts $ARM_LOCATION.management.azure.com | awk '{ print $1 }') management.azure.com" | sudo tee --append /etc/hosts
- name: Login to Google Cloud Registry
run: |
gcloud --quiet auth configure-docker
- name: Install Pulumi CLI
uses: pulumi/action-install-pulumi-cli@releases/v1
- uses: actions/checkout@v2
- name: Destroy test infra
run: |
make destroy_test_infra StackName="${{ secrets.PULUMI_TEST_OWNER }}/${{ github.sha }}"
kubernetes:
needs: test-infra-setup
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]
go-version: [1.13.x]
node-version: [10.x]
python-version: [3.7]
dotnet-version: ['3.1.100']
runs-on: ${{ matrix.platform }}
steps:
- name: Install DotNet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Deps
run: |
pip3 install pipenv
- name: Install aws-iam-authenticator
run: |
curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
sudo mv aws-iam-authenticator /usr/local/bin
- name: Install Kubectl
run: |
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv kubectl /usr/local/bin
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '285.0.0'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Install helm
run: |
curl -o- -L https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
- name: Configure helm
run: |
helm init -c
helm repo add bitnami https://charts.bitnami.com/bitnami
- name: Set Azure DNS
run: |
echo "$(getent hosts $ARM_LOCATION.management.azure.com | awk '{ print $1 }') management.azure.com" | sudo tee --append /etc/hosts
- name: Login to Google Cloud Registry
run: |
gcloud --quiet auth configure-docker
- name: Install Pulumi CLI
uses: pulumi/action-install-pulumi-cli@releases/v1
- uses: actions/checkout@v2
- name: Install Go dependencies
run: make ensure
- name: Setup Config
run: |
mkdir -p "$HOME/.kube/"
pulumi stack -s "${{ secrets.PULUMI_TEST_OWNER }}/${{ github.sha }}" -C misc/scripts/testinfra/ output kubeconfig >~/.kube/config
- name: Run ${{ matrix.tests-set }} Tests
run: make specific_test_set TestSet=Kubernetes
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ specific_test_set:
echo "running $(TestSet) Acceptance Tests"
cd misc/test && go test . --timeout 4h -v -count=1 -short -parallel 40 --run=TestAcc$(TestSet)

setup_test_infra:
echo "Setting up test infra"
./misc/scripts/create-ci-cluster.sh $(StackName)

destroy_test_infra:
echo "Tearing down test infra"
./misc/scripts/destroy-ci-cluster.sh $(StackName)

# The travis_* targets are entrypoints for CI.
.PHONY: travis_cron travis_push travis_pull_request travis_api
travis_cron: all
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-cs-guestbook/simple/Guestbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public Guestbook()
}
else
{
this.FrontendIp = frontendService.Status.Apply(status => status.LoadBalancer.Ingress[0].Hostname);
this.FrontendIp = frontendService.Status.Apply(status => status.LoadBalancer.Ingress[0].Ip ?? status.LoadBalancer.Ingress[0].Hostname);
}
}

Expand Down
21 changes: 8 additions & 13 deletions kubernetes-go-guestbook/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ func main() {
isMinikube := conf.GetBool("isMinikube")

redisLeaderLabels := pulumi.StringMap{
"app": pulumi.String("redis"),
"tier": pulumi.String("backend"),
"role": pulumi.String("master"),
"app": pulumi.String("redis-master"),
}

// Redis leader Deployment
_, err := appsv1.NewDeployment(ctx, "redis-leader", &appsv1.DeploymentArgs{
_, err := appsv1.NewDeployment(ctx, "redis-master", &appsv1.DeploymentArgs{
Metadata: &metav1.ObjectMetaArgs{
Labels: redisLeaderLabels,
},
Expand Down Expand Up @@ -77,7 +75,7 @@ func main() {
}

// Redis leader Service
_, err = corev1.NewService(ctx, "redis-leader", &corev1.ServiceArgs{
_, err = corev1.NewService(ctx, "redis-master", &corev1.ServiceArgs{
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("redis-master"),
Labels: redisLeaderLabels,
Expand All @@ -97,13 +95,11 @@ func main() {
}

redisFollowerLabels := pulumi.StringMap{
"app": pulumi.String("redis"),
"tier": pulumi.String("backend"),
"role": pulumi.String("slave"),
"app": pulumi.String("redis-slave"),
}

// Redis follower Deployment
_, err = appsv1.NewDeployment(ctx, "redis-follower", &appsv1.DeploymentArgs{
_, err = appsv1.NewDeployment(ctx, "redis-slave", &appsv1.DeploymentArgs{
Metadata: &metav1.ObjectMetaArgs{
Labels: redisFollowerLabels,
},
Expand All @@ -119,7 +115,7 @@ func main() {
Spec: &corev1.PodSpecArgs{
Containers: corev1.ContainerArray{
corev1.ContainerArgs{
Name: pulumi.String("slave"),
Name: pulumi.String("redis-slave"),
Image: pulumi.String("gcr.io/google_samples/gb-redisslave:v3"),
Resources: &corev1.ResourceRequirementsArgs{
Requests: pulumi.StringMap{
Expand Down Expand Up @@ -148,7 +144,7 @@ func main() {
}

// Redis follower Service
_, err = corev1.NewService(ctx, "redis-follower", &corev1.ServiceArgs{
_, err = corev1.NewService(ctx, "redis-slave", &corev1.ServiceArgs{
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("redis-slave"),
Labels: redisFollowerLabels,
Expand All @@ -167,8 +163,7 @@ func main() {
}

frontendLabels := pulumi.StringMap{
"app": pulumi.String("guestbook"),
"tier": pulumi.String("frontend"),
"app": pulumi.String("frontend"),
}

// Frontend Deployment
Expand Down
21 changes: 9 additions & 12 deletions kubernetes-py-guestbook/simple/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
isMinikube = config.get_bool("isMinikube")

redis_leader_labels = {
"app": "redis",
"tier": "backend",
"role": "master"
"app": "redis-master",
}

redis_leader_deployment = Deployment(
"redis-leader",
"redis-master",
spec={
"selector": {
"match_labels": redis_leader_labels,
Expand Down Expand Up @@ -57,8 +55,9 @@
})

redis_leader_service = Service(
"redis-leader",
"redis-master",
metadata={
"name": "redis-master",
"labels": redis_leader_labels
},
spec={
Expand All @@ -70,9 +69,7 @@
})

redis_follower_labels = {
"app": "redis",
"tier": "backend",
"role": "slave"
"app": "redis-slave",
}

redis_follower_deployment = Deployment(
Expand All @@ -88,7 +85,7 @@
},
"spec": {
"containers": [{
"name": "slave",
"name": "redis-slave",
"image": "gcr.io/google_samples/gb-redisslave:v1",
"resources": {
"requests": {
Expand All @@ -113,8 +110,9 @@
})

redis_follower_service = Service(
"redis-follower",
"redis-slave",
metadata={
"name": "redis-slave",
"labels": redis_follower_labels
},
spec={
Expand All @@ -127,8 +125,7 @@

# Frontend
frontend_labels = {
"app": "guestbook",
"tier": "frontend"
"app": "frontend",
}

frontend_deployment = Deployment(
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-ts-guestbook/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const redisMaster = new k8sjs.ServiceDeployment("redis-master", {
ports: [6379],
});

const redisReplica = new k8sjs.ServiceDeployment("redis-replica", {
const redisReplica = new k8sjs.ServiceDeployment("redis-slave", {
image: "gcr.io/google_samples/gb-redisslave:v1",
ports: [6379],
});
Expand Down
1 change: 1 addition & 0 deletions kubernetes-ts-guestbook/components/k8sjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class ServiceDeployment extends pulumi.ComponentResource {

this.service = new k8s.core.v1.Service(name, {
metadata: {
name: name,
labels: this.deployment.metadata.labels,
},
spec: {
Expand Down
Loading

0 comments on commit c318e88

Please sign in to comment.