LoginSignup
0
0

More than 3 years have passed since last update.

kubernetesマニフェストを含むYeoman generatorを作るときのメモ

Posted at

構成を考えるのを諦めた、ただのメモです。

generatorのひな型の作成方法

  1. Node.js をインストールする。
  2. yeoman をインストールする。
   npm install -g yo
  1. yeoman の generator-generator をインストールする。
   npm install -g generator-generator
  1. yeoman の generator-generator を使って、generator のひな型を作成する。
   yo generator

generator の名前を聞かれるので、適当に generator-test-123456 などと答える。

開発中のテスト方法

generator のディレクトリで、 npm link と実行すると、
yo test-123456 (入力した generator の名前) で実行できるようになる。

YAMLのテンプレート

テンプレートの例

test-ns.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: test
  <%_ if (ownerLabelEnabled) { -%>
  labels:
    owner: <%= ownerLabel %>
  <%_ } -%>
  • <%_ : 前の空白を消す。これがないと、変な空白行ができる。
  • -%> : 改行を消す。これがないと、変な空白行ができる。

テンプレートを書き込む例

generators/app/index.js
  writing() {
    this.fs.copyTpl(
      this.templatePath('test'),
      this.destinationPath('test'),
      this.props
    );
  }

テンプレートパスはディレクトリを指定可能。
ただし、オプションによってファイル自体含めたくない場合は、
下記のようにファイル1個1個を指定していかないといけなそう。

generators/app/index.js
  writing() {
    this.fs.copyTpl(
      this.templatePath('test/test-ns.yaml'),
      this.destinationPath('test/test-ns.yaml'),
      this.props
    );
    if (this.props.generateDefaultServiceAccount) {
      this.fs.copyTpl(
        this.templatePath('test/test-default-sa.yaml'),
        this.destinationPath('test/test-default-sa.yaml'),
        this.props
      );
    }
  }
0
0
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
0
0