Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

add the AmazonEKS template function to the amazon_eks and kubectl_apply docs #422

Merged
merged 8 commits into from
Aug 20, 2018
5 changes: 5 additions & 0 deletions hack/docs/mutations.json
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@
},
"merge": {
"description": "An `amazon_eks` asset generates a terraform file that will create an Amazon EKS Cluster.",
"extended_description": "It also populates a template function `AmazonEKS` that takes the name of the cluster and returns the path to the generated kubeconfig for the cluster. This template function is only valid after the asset has been generated as part of the `render` lifecycle step, but can be used by later assets within that step. The file itself is created when the generated terraform is applied, whether by the `terraform` lifecycle step or otherwise. This is intended to be used within the [kubectl_apply](/api/ship-lifecycle/lifecycle/kubectl_apply/) lifecycle step.",
"examples": [
{
"cluster_name": "existing-vpc-cluster",
Expand Down Expand Up @@ -825,6 +826,10 @@
{
"path": "k8s/another.yml",
"kubeconfig": "k8s/generated_kubeconfig"
},
{
"path": "k8s/another.yml",
"kubeconfig": "{{repl AmazonEKS \"eks_cluster_name\" }}"
}
]
},
Expand Down
5 changes: 5 additions & 0 deletions hack/docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"properties": {
"amazon_eks": {
"description": "An `amazon_eks` asset generates a terraform file that will create an Amazon EKS Cluster.",
"extended_description": "It also populates a template function `AmazonEKS` that takes the name of the cluster and returns the path to the generated kubeconfig for the cluster. This template function is only valid after the asset has been generated as part of the `render` lifecycle step, but can be used by later assets within that step. The file itself is created when the generated terraform is applied, whether by the `terraform` lifecycle step or otherwise. This is intended to be used within the [kubectl_apply](/api/ship-lifecycle/lifecycle/kubectl_apply/) lifecycle step.",
"examples": [
{
"cluster_name": "existing-vpc-cluster",
Expand Down Expand Up @@ -748,6 +749,10 @@
{
"path": "k8s/another.yml",
"kubeconfig": "k8s/generated_kubeconfig"
},
{
"path": "k8s/another.yml",
"kubeconfig": "{{repl AmazonEKS \"eks_cluster_name\" }}"
}
],
"type": "object",
Expand Down
2 changes: 2 additions & 0 deletions hack/docs/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ gradient: "purpleToPink"

${specTypes[specType].description || ""}

${specTypes[specType].extended_description || ""}

`;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
assets:
v1:
- amazon_eks:
dest: new/new_vpc.tf
cluster_name: new-vpc-cluster
region: "us-west-2"
created_vpc:
vpc_cidr: "10.0.0.0/16"
zones:
- us-west-2a
- us-west-2b
public_subnets:
- "10.0.1.0/24"
- "10.0.2.0/24"
private_subnets:
- "10.0.129.0/24"
- "10.0.130.0/24"
autoscaling_groups:
- name: alpha
group_size: 3
machine_type: m5.2xlarge
- name: bravo
group_size: 1
machine_type: m5.4xlarge
- inline:
dest: install.sh
contents: |
#!/bin/bash
echo "run:"
echo "terraform apply -f new/new_vpc.tf"
echo "kubectl apply -f kube.yaml --kubeconfig {{repl AmazonEKS "new-vpc-cluster" }}"
mode: 0777
- inline:
dest: kube.yaml
contents: |
this is not a valid kubernetes yaml
mode: 0777

config: {}

lifecycle:
v1:
- message:
contents: "hi"
- render: {}
- message:
contents: "bye"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"v1": {
"config": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo "run:"
echo "terraform apply -f new/new_vpc.tf"
echo "kubectl apply -f kube.yaml --kubeconfig new/kubeconfig_new-vpc-cluster"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is not a valid kubernetes yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

variable "vpc_cidr" {
type = "string"
default = "10.0.0.0/16"
}

variable "vpc_public_subnets" {
default = [
"10.0.1.0/24",
"10.0.2.0/24",
]
}

variable "vpc_private_subnets" {
default = [
"10.0.129.0/24",
"10.0.130.0/24",
]
}

variable "vpc_azs" {
default = [
"us-west-2a",
"us-west-2b",
]
}

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "1.37.0"
name = "eks-vpc"
cidr = "${var.vpc_cidr}"
azs = "${var.vpc_azs}"

private_subnets = "${var.vpc_private_subnets}"
public_subnets = "${var.vpc_public_subnets}"

map_public_ip_on_launch = true
enable_nat_gateway = true
single_nat_gateway = true

tags = "${map("kubernetes.io/cluster/${var.eks-cluster-name}", "shared")}"
}

locals {
"eks_vpc" = "${module.vpc.vpc_id}"
"eks_vpc_public_subnets" = "${module.vpc.public_subnets}"
"eks_vpc_private_subnets" = "${module.vpc.private_subnets}"
}

locals {
"worker_group_count" = "2"
}

locals {
"worker_groups" = [
{
name = "alpha"
asg_min_size = "3"
asg_max_size = "3"
asg_desired_capacity = "3"
instance_type = "m5.2xlarge"

subnets = "${join(",", local.eks_vpc_private_subnets)}"
},
{
name = "bravo"
asg_min_size = "1"
asg_max_size = "1"
asg_desired_capacity = "1"
instance_type = "m5.4xlarge"

subnets = "${join(",", local.eks_vpc_private_subnets)}"
},
]
}

provider "aws" {
version = "~> 1.27"
region = "us-west-2"
}

variable "eks-cluster-name" {
default = "new-vpc-cluster"
type = "string"
}

module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "1.4.0"

cluster_name = "${var.eks-cluster-name}"

subnets = ["${local.eks_vpc_private_subnets}", "${local.eks_vpc_public_subnets}"]

vpc_id = "${local.eks_vpc}"

worker_group_count = "${local.worker_group_count}"
worker_groups = "${local.worker_groups}"
}
47 changes: 47 additions & 0 deletions integration/init_app/amazon-eks-template/input/.ship/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
assets:
v1:
- amazon_eks:
dest: new/new_vpc.tf
cluster_name: new-vpc-cluster
region: "us-west-2"
created_vpc:
vpc_cidr: "10.0.0.0/16"
zones:
- us-west-2a
- us-west-2b
public_subnets:
- "10.0.1.0/24"
- "10.0.2.0/24"
private_subnets:
- "10.0.129.0/24"
- "10.0.130.0/24"
autoscaling_groups:
- name: alpha
group_size: 3
machine_type: m5.2xlarge
- name: bravo
group_size: 1
machine_type: m5.4xlarge
- inline:
dest: install.sh
contents: |
#!/bin/bash
echo "run:"
echo "terraform apply -f new/new_vpc.tf"
echo "kubectl apply -f kube.yaml --kubeconfig {{repl AmazonEKS "new-vpc-cluster" }}"
mode: 0777
- inline:
dest: kube.yaml
contents: |
this is not a valid kubernetes yaml
mode: 0777

config: {}

lifecycle:
v1:
- message:
contents: "hi"
- render: {}
- message:
contents: "bye"
5 changes: 5 additions & 0 deletions integration/init_app/amazon-eks-template/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
customer_id: "-Am-_6i5pw0u4AbspOwKN4lZUCn49u_G"
release_version: "1.0.0-amazon-eks-template"

disable_online: false
skip_cleanup: false
5 changes: 3 additions & 2 deletions integration/init_app/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"strings"
"testing"
"time"
Expand All @@ -19,9 +20,9 @@ import (
"github.com/replicatedhq/ship/pkg/cli"
"github.com/replicatedhq/ship/pkg/e2e"
"github.com/replicatedhq/ship/pkg/logger"
"github.com/spf13/afero"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
"github.com/spf13/afero"
)

type TestMetadata struct {
Expand Down Expand Up @@ -88,7 +89,7 @@ var _ = Describe("ship init replicated.app/...", func() {
// if a token is provided, try to ensure the release matches what we have here in the repo

if vendorToken != "" {
channelName := fmt.Sprintf("integration replicated.app %s", file.Name())
channelName := fmt.Sprintf("integration replicated.app %s", filepath.Base(testPath))
installationID = createRelease(vendorEndpoint, vendorToken, testInputPath, testMetadata, channelName)
}
close(done)
Expand Down
3 changes: 3 additions & 0 deletions pkg/lifecycle/message/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (m *CLIMessenger) getBuilder(release *api.Release) templates.Builder {
Meta: release.Metadata,
Viper: m.Viper,
},
templates.ShipContext{
Logger: m.Logger,
},
)
return builder
}
3 changes: 3 additions & 0 deletions pkg/lifecycle/message/messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func (m *DaemonMessenger) getBuilder(meta api.ReleaseMetadata) templates.Builder
Meta: meta,
Viper: m.Viper,
},
templates.ShipContext{
Logger: m.Logger,
},
)
return builder
}
3 changes: 3 additions & 0 deletions pkg/lifecycle/render/docker/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ func (p *DefaultStep) Execute(
Meta: meta,
Viper: p.Viper,
},
templates.ShipContext{
Logger: p.Logger,
},
)
builtDest, err := builder.String(dest)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/lifecycle/render/inline/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func (r *LocalRenderer) Execute(
Meta: meta,
Viper: r.Viper,
},
templates.ShipContext{
Logger: r.Logger,
},
)

built, err := builder.String(asset.Contents)
Expand Down
3 changes: 3 additions & 0 deletions pkg/lifecycle/render/web/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func (p *DefaultStep) buildAsset(
Meta: meta,
Viper: p.Viper,
},
templates.ShipContext{
Logger: p.Logger,
},
)

builtURL, err := builder.String(asset.URL)
Expand Down