Skip to content

Commit

Permalink
- add kubectl_context & gcloud_project built-in assertions
Browse files Browse the repository at this point in the history
- update all examples
- clean up code a bit
  • Loading branch information
aaabramov committed Nov 9, 2021
1 parent 6e23067 commit 8b66a14
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 161 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ $ goal tf-apply --on stage
- [X] Validate empty goal cmd
- [X] Validate empty assertion ref
- [X] Add `goal init` which simply generated example `goal.yaml`
- [X] Add predefined assertions:
- [X] `k8s_cluster`
- [X] `terraform_workspace`
- [X] `gcloud_project`
- [ ] Simpler `brew tap aaabramov/goal`
- [ ] Manual approvals for proceeding like `assert.approval`
- [ ] Add "depends on" other task like switch to dev?
Expand All @@ -152,9 +156,6 @@ $ goal tf-apply --on stage
- [ ] Self-autocompletion via [https://github.com/posener/complete](complete) library
- [ ] Support both goal.yaml & goal.yml
- [ ] Generate simple markdown file from `goal.yaml` (ops-doc)
- [ ] Add predefined assertions:
- [ ] `k8s_cluster`
- [ ] `terraform_workspace`
- [ ] `goal add GOAL_NAME` -- check if already exists
- [ ] rework `Fatal` with `err`
- [ ] suggest `fix?` when precondition failed with `yes/no` prompt
74 changes: 0 additions & 74 deletions examples/envs/goal.yaml

This file was deleted.

101 changes: 64 additions & 37 deletions examples/helm/goal.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,66 @@
current-context:
desc: Current kubectl context
cmd: kubectl
args:
- config
- current-context
# This example combines two `goal` features:
# 1. Environmental executions: `goal run helm-upgrade --on dev`
# 2. Built-in `kubectl_context` assertions upon execution
# to prevent accidental runs on wrong environment.
#
# NOTE: Your can list available `kubectl` contexts with `kubectl config get-contexts`

helm-upgrade-dev-dry-run:
desc: Dry run upgrade on dev
assert:
desc: Check if on dev cluster
ref: current-context
expect: dev-cluster
cmd: helm
args:
- upgrade
- release-name
- -f
- values.yaml
- -f
- values/dev.yaml
- .
- --dry-run
helm-dry-run:
envs:
dev:
desc: Dry run upgrade on dev
assert:
- kubectl_context: dev-cluster
cmd: helm
args:
- upgrade
- release-name
- -f
- values.yaml
- -f
- values/dev.yaml
- .
- --dry-run
stage:
desc: Dry run upgrade on stage
assert:
- kubectl_context: stage-cluster
cmd: helm
args:
- upgrade
- release-name
- -f
- values.yaml
- -f
- values/stage.yaml
- .
- --dry-run

helm-upgrade-dev:
desc: Upgrade on dev
assert:
desc: Check if on dev cluster
ref: current-context
expect: dev-cluster
cmd: helm
args:
- upgrade
- release-name
- -f
- values.yaml
- -f
- values/dev.yaml
- .
helm-upgrade:
envs:
dev:
desc: Run upgrade on dev
assert:
- kubectl_context: dev-cluster
cmd: helm
args:
- upgrade
- release-name
- -f
- values.yaml
- -f
- values/dev.yaml
- .
stage:
desc: Run upgrade on stage
assert:
- kubectl_context: stage-cluster
cmd: helm
args:
- upgrade
- release-name
- -f
- values.yaml
- -f
- values/stage.yaml
- .
28 changes: 10 additions & 18 deletions examples/terraform/goal.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
workspace:
desc: Current terraform workspace
cmd: terraform
args:
- workspace
- show
# This example combines two `goal` features:
# 1. Environmental executions: `goal run tf-plan --on dev`
# 2. Built-in `terraform_workspace` assertions upon execution
# to prevent accidental runs on wrong environment.
#
# NOTE: Your can list available `terraform` workspaces with `terraform workspace list`

tf-plan:
envs:
dev:
desc: Terraform plan on dev
assert:
desc: Check if on dev workspace
ref: workspace # References goal above
expect: dev # Checks whether trimmed output from 'ref' goal is equal to "dev"
- terraform_workspace: dev # Checks whether selected terraform workspace is "dev"
cmd: terraform
args:
- plan
Expand All @@ -21,9 +19,7 @@ tf-plan:
stage:
desc: Terraform plan on stage
assert:
desc: Check if on stage workspace
ref: workspace # References goal above
expect: stage # Checks whether trimmed output from 'ref' goal is equal to "stage"
- terraform_workspace: stage # Checks whether selected terraform workspace is "stage"
cmd: terraform
args:
- plan
Expand All @@ -35,9 +31,7 @@ tf-apply:
dev:
desc: Terraform apply on dev
assert:
desc: Check if on dev workspace
ref: workspace # References goal above
expect: dev # Checks whether trimmed output from 'ref' goal is equal to "dev"
- terraform_workspace: dev # Checks whether selected terraform workspace is "dev"
cmd: terraform
args:
- apply
Expand All @@ -46,9 +40,7 @@ tf-apply:
stage:
desc: Terraform apply on stage
assert:
desc: Check if on stage workspace
ref: workspace # References goal above
expect: stage # Checks whether trimmed output from 'ref' goal is equal to "stage"
- terraform_workspace: stage # Checks whether selected terraform workspace is "stage"
cmd: terraform
args:
- apply
Expand Down
79 changes: 62 additions & 17 deletions goal.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,77 @@
tf-apply:
# simple alias: `goal run pods`
pods:
desc: Get nginx pods
cmd: kubectl
args:
- get
- pods
- -l
- app=nginx

# list your workspaces with `terraform workspace list`
terraform:
envs:
dev:
desc: Terraform apply on dev
cmd: terraform
args:
- apply
- -var-file
- vars/dev.tfvars
assert:
- desc: Check if on dev workspace
ref: workspace
expect: dev
fix: terraform workspace select dev
desc: Terraform apply on dev
- terraform_workspace: dev
stage:
desc: Terraform apply on stage
cmd: terraform
args:
- apply
- -var-file
- vars/stage.tfvars
assert:
- desc: Check if on stage workspace
ref: workspace
expect: stage
fix: terraform workspace select stage
desc: Terraform apply on stage
workspace:
cmd: terraform
args:
- apply
- -var-file
- vars/dev.tfvars
- terraform_workspace: stage

# list your contexts with `kubectl config get-contexts`
k8s:
envs:
dev:
desc: Kubectl apply on dev
cmd: kubectl
args:
- apply
- -f
- deployment.yaml
assert:
- kubectl_context: gke_project_region_dev
stage:
desc: Kubectl apply on stage
cmd: kubectl
args:
- apply
- -f
- deployment.yaml
assert:
- kubectl_context: gke_project_region_stage

# list your projects with `gcloud projects list`
gcloud:
envs:
dev:
desc: SSH to dev
cmd: gcloud
args:
- compute
- ssh
- dev-vm
- --zone=us-central1-c
assert:
- gcloud_project: dev-project
stage:
desc: SSH to stage
cmd: gcloud
args:
- compute
- ssh
- stage-vm
- --zone=us-central1-c
assert:
- gcloud_project: stage-project

0 comments on commit 8b66a14

Please sign in to comment.