Sha256: 08797830650396fca496d3f2b060a58c39a6319b1306f9b301cc7b5cabfc2c99

Contents?: true

Size: 1.94 KB

Versions: 13

Compression:

Stored size: 1.94 KB

Contents

---
title: ERB Comment Syntax PreProcessor
---

Kubes allows you build kubernetes resources by compiling down `.kubes/resources` files with ERB.  This is a powerful ability, but it can get in the way of IDE kubernetes autocompletion tools.

## Pre-Processing Before ERB

To work with IDE kubernetes autocompletion tools, kubes supports a lighter ERB comment-based syntax. It looks like this:

.kubes/resources/web/service.yaml

```yaml
apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    name: web
#ERB if @role_label
    role: #ERB= @role_label
#ERB end
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: <%= dockerfile_port %>
  selector:
    role: web
  type: ClusterIP
```

This allows IDE kubernetes autocompletion plugins and tools to work because the `.kubes/resources/web/service.yaml` source code itself is perfectly valid YAML.

The `#ERB` comments are essentially replaced by `<% ... %>` tags before ERB processing happens. Example:

.kubes/resources/web/service.yaml.erb

```yaml
apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    name: web
<% if @role_label %>
    role: <%= @role_label %>
<% end %>
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: <%= dockerfile_port %>
  selector:
    role: web
  type: ClusterIP
```

If you need to keep around the generated `.erb` file for debugging, use the `KUBES_KEEP_ERB` env var. Example:

    $ KUBES_KEEP_ERB=1 kubes compile
    .kubes/resources/web/service.yaml.erb  # kept around

## Multiple Line ERB Comment Syntax

The ERB Comment syntax works because kubes simply replaces each line with actual ERB. For multiple line ERB syntax:

.kubes/resources/web/service.yaml

```yaml
#ERB if Kubes.env == "dev"
#ERB   env_label = "development"
#ERB end
apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    name: web
    env: #ERB= env_label
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: <%= dockerfile_port %>
  selector:
    role: web
  type: ClusterIP
```

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
kubes-0.9.3 docs/_docs/yaml/erb-comment.md
kubes-0.9.2 docs/_docs/yaml/erb-comment.md
kubes-0.9.1 docs/_docs/yaml/erb-comment.md
kubes-0.9.0 docs/_docs/yaml/erb-comment.md
kubes-0.8.10 docs/_docs/yaml/erb-comment.md
kubes-0.8.9 docs/_docs/yaml/erb-comment.md
kubes-0.8.8 docs/_docs/yaml/erb-comment.md
kubes-0.8.7 docs/_docs/yaml/erb-comment.md
kubes-0.8.6 docs/_docs/yaml/erb-comment.md
kubes-0.8.5 docs/_docs/yaml/erb-comment.md
kubes-0.8.4 docs/_docs/yaml/erb-comment.md
kubes-0.8.3 docs/_docs/yaml/erb-comment.md
kubes-0.8.2 docs/_docs/yaml/erb-comment.md