LoginSignup
3
2

More than 5 years have passed since last update.

kustomizeでsecretGenerator内でcatを使うときに改行コードを気にしたくない

Last updated at Posted at 2018-09-04

セキュリティ上の懸念からsecretGenerator.commandsは廃止されました

これらの情報はもう使えません。


secretGenerator は便利な機能だけど
環境変数で使う場合、相変わらず末尾の改行コードを意識しなくてはならなくて
k8sのsecretを知らない人がハマりやすい

今まではこんな感じに準備してた

$ echo -n "sensitive_text" > secret_file

末尾の改行コードがあってもなくても動かす

xargs echo -n にpipeで繋ぐことによって末尾の改行コードがあってもなくても動く。
またkustomizeが実行するdefault commandは["sh", "-c"] のため、
pipeの途中で失敗しても最終コマンドが成功すると、成功とみなされてしまうためpipefailを指定したbashで実行する。

kustomization.yaml

generatorOptions:
  shell: ["bash","-o", "pipefail", "-c"] 
secretGenerator:
- name: your-secret
  type: Opaque
  commands:
    SECRET_TOKEN: "cat ./secret_file | xargs echo -n"
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2