Skip to content

Commit

Permalink
feat(microblog): ✨ cool way to use kubectl with go-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldonhull committed Mar 10, 2022
1 parent 022662e commit 645dd14
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Expand Up @@ -64,6 +64,10 @@ repos:
# https://pre-commit.com/#supported-languages
- repo: local
hooks:
- id: shellcheck
name: shellcheck
entry: zsh -c docker run --rm -v "${PWD}:/mnt" koalaman/shellcheck:stable --format=json
language: system
# FIRST TIME SETUP: GO111MODULE=on go get github.com/zricethezav/gitleaks/v4@latest
# - id: local-run
# name: Scan for secrets
Expand All @@ -76,19 +80,16 @@ repos:
# - id: markdownlint
# name: markdownlint-autofix
# entry: zsh -c docker run -i --rm -v ${PWD}:/work tmknom/markdownlint:latest --fix --config ./settings/.markdownlint.yaml content/docs
language: system
- id: shellcheck
name: shellcheck
entry: zsh -c docker run --rm -v "${PWD}:/mnt" koalaman/shellcheck:stable --format=json
language: system
# language: system

- repo: https://github.com/tchoedak/pre-commit-sql-format
rev: v0.0.3
hooks:
- id: format-sql


- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.3.2
rev: v0.4.0
hooks:
- id: markdownlint-cli2
- repo: local
Expand Down
16 changes: 16 additions & 0 deletions .yamllint.yaml
@@ -0,0 +1,16 @@
---
extends: default
rules:
line-length: disable
comments:
require-starting-space: false
ignore-shebangs: true
min-spaces-from-content: 1
comments-indentation: disable

# For all rules
ignore: |-
.markdownlint-cli2.yaml
.licenses/
docs/godocs/
.pre-commit-config.yaml
37 changes: 37 additions & 0 deletions content/posts/2022/2022-03-10-go-templates-with-kubectl.md
@@ -0,0 +1,37 @@
---

date: 2022-03-10T19:13:52+0000
title: Go Templates With Kubectl
slug: go-templates-with-kubectl
tags:

- tech
- development
- microblog
- go
- kubernetes

# images: [/images/]

typora-root-url: ../../../static
typora-copy-images-to: ../../../static/images
---

An alternative to using jsonpath with kubectl is go templates!

Try switching this:

````shell
kubectl get serviceaccount myserviceaccount --context supercoolcontext --namespace themagicalcloud -o jsonpath='{.secrets[0].name}'
```
To this and it should work just the same.
Since I know go templates pretty well, this is a good alternative for jsonpath syntax.
````shell
kubectl get serviceaccount myserviceaccount --context supercoolcontext --namespace themagicalcloud -o go-template='{{range .secrets }}{{.name}}{{end}}'
```

Further reading:

- [List Container images using a go-template instead of jsonpath](https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/#list-container-images-using-a-go-template-instead-of-jsonpath)

0 comments on commit 645dd14

Please sign in to comment.