Skip to content

Commit

Permalink
Merge pull request #28 from datarootsio/issue_19_number_of_replicas
Browse files Browse the repository at this point in the history
Adding a setting for replicas
  • Loading branch information
sam-dumont authored Aug 6, 2020
2 parents 93d8918 + 12cf9ec commit 9c854a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ However, you have to be consistent across variables, you cannot mix styles.
| node\_selector | Map of labels and values for node selection | `map(string)` | `{}` | no |
| ports | Map of ports to expose, and associated settings. | `any` | `{}` | no |
| readiness\_probes | Map of readiness probes per container. Pass the regular terraform object as is : https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#readiness_probe-1 | `any` | n/a | yes |
| replicas | Amount of replicas | `number` | `1` | no |
| resources\_limits | Map of resources limits to assign to the container | `map` | <pre>{<br> "cpu": "0.2",<br> "memory": "256Mi"<br>}</pre> | no |
| resources\_requests | Map of resources requests to assign to the container | `map` | <pre>{<br> "cpu": "0.1",<br> "memory": "128Mi"<br>}</pre> | no |
| volume\_mounts | Map of volumes to mount. | `any` | `{}` | no |
Expand Down
2 changes: 2 additions & 0 deletions deployment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ resource "kubernetes_deployment" "container" {
}
}

replicas = var.replicas

template {
metadata {
labels = {
Expand Down
11 changes: 9 additions & 2 deletions test/terraform_apply_destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestApplyAndDestroyWithDefaultValues(t *testing.T) {
k8s.KubectlApply(t, k8sOptions, kubeResourcePath)

options.Vars["image"] = map[string]interface{}{"test-container": "training/webapp:latest"}
options.Vars["replicas"] = 2
options.Vars["annotations"] = map[string]interface{}{"foo": "bar"}

options.Vars["ports"] = map[string]interface{}{
Expand Down Expand Up @@ -83,9 +84,12 @@ func TestApplyAndDestroyWithDefaultValues(t *testing.T) {
_, err = terraform.InitAndApplyE(t, options)
assert.NoError(t, err)

pod := k8s.ListPods(t, k8sOptions, metav1.ListOptions{LabelSelector: "app=test-name"})[0]
pods := k8s.ListPods(t, k8sOptions, metav1.ListOptions{LabelSelector: "app=test-name"})

pod := pods[0]
container := pod.Spec.Containers[0]

assert.Equal(t,len(pods),2)
assert.Equal(t, "training/webapp:latest", container.Image)
assert.NotContains(t, pod.ObjectMeta.Annotations, "linkerd.io/inject")
assert.Contains(t, pod.ObjectMeta.Annotations, "foo")
Expand Down Expand Up @@ -167,9 +171,12 @@ func TestApplyAndDestroyWithSingleContainer(t *testing.T) {
_, err = terraform.InitAndApplyE(t, options)
assert.NoError(t, err)

pod := k8s.ListPods(t, k8sOptions, metav1.ListOptions{LabelSelector: "app=test-name"})[0]
pods := k8s.ListPods(t, k8sOptions, metav1.ListOptions{LabelSelector: "app=test-name"})

pod := pods[0]
container := pod.Spec.Containers[0]

assert.Equal(t,len(pods),1)
assert.Equal(t, "training/webapp:latest", container.Image)
assert.Contains(t, pod.ObjectMeta.Annotations, "linkerd.io/inject")
assert.Contains(t, pod.ObjectMeta.Annotations, "foo")
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ variable "image" {
description = "The image to deploy."
}

variable "replicas" {
type = number
default = 1
description = "The number of replicas."
}

variable "inject_linkerd" {
type = bool
default = false
Expand Down

0 comments on commit 9c854a9

Please sign in to comment.