Skip to content

Commit f7b3b17

Browse files
authored
Merge pull request #19 from stakater/SA-7871_gotemplate-support-added
Sa 7871 gotemplate support added
2 parents 5315859 + 9093ab1 commit f7b3b17

16 files changed

Lines changed: 307 additions & 3290 deletions

File tree

.github/workflows/pull_request.yaml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
doc_qa:
11-
uses: stakater/.github/.github/workflows/pull_request_doc_qa.yaml@v0.0.131
11+
uses: stakater/.github/.github/workflows/pull_request_doc_qa.yaml@v0.0.137
1212
with:
1313
MD_CONFIG: .github/md_config.json
1414
DOC_SRC: content README.md
@@ -23,7 +23,7 @@ jobs:
2323
build_container:
2424
needs: deploy_doc
2525
if: ${{ github.base_ref == 'main' }}
26-
uses: stakater/.github/.github/workflows/pull_request_container_build.yaml@v0.0.131
26+
uses: stakater/.github/.github/workflows/pull_request_container_build.yaml@v0.0.137
2727
with:
2828
DOCKER_BUILD_CONTEXTS: content=https://github.com/stakater/template-operator-docs.git#pull-request-deployments
2929
DOCKER_FILE_PATH: Dockerfile
@@ -35,29 +35,43 @@ jobs:
3535
DOCKER_SECRETS: GIT_AUTH_TOKEN=${{ secrets.PUBLISH_TOKEN }}
3636
test:
3737
runs-on: ubuntu-latest
38-
needs: [
39-
build_container,
40-
deploy_doc
41-
]
38+
needs: [ build_container, deploy_doc ]
4239
env:
4340
CURRENT_BRANCH: ${{ needs.deploy_doc.outputs.CURRENT_BRANCH }}
4441
IMAGE_PATH: ${{ needs.build_container.outputs.IMAGE_PATH }}
4542
steps:
4643
- name: Checkout repository
4744
uses: actions/checkout@v4
45+
4846
- name: Login to Docker Registry
4947
uses: docker/login-action@v3
5048
with:
5149
registry: ghcr.io/stakater
5250
username: ${{ github.actor }}
5351
password: ${{ secrets.GHCR_TOKEN }}
52+
5453
- name: Run Docker container for the docs
5554
run: |
56-
docker run -d --name template-operator-docs -p 8080:8080 ${{ env.IMAGE_PATH }} || exit 1
57-
- name: Build testcafe tests
58-
working-directory: ./testcafe
55+
docker run -d --name template-operator-docs -p 8080:8080 $IMAGE_PATH
56+
57+
- name: Wait for docs site to be ready
58+
run: |
59+
echo "Waiting for docs site to be ready..."
60+
timeout 60 bash -c 'until curl -f http://127.0.0.1:8080/${{ env.CURRENT_BRANCH }}/ > /dev/null 2>&1; do sleep 2; done'
61+
echo "Docs site is ready!"
62+
63+
- name: Setup Node
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: 20
67+
68+
- name: Install dependencies
69+
working-directory: ./e2e
5970
run: |
60-
docker build -t testcafe-tests --build-arg CURRENT_BRANCH=${{ env.CURRENT_BRANCH }} .
61-
- name: Run Docker container to run tests
71+
yarn install
72+
npx playwright install --with-deps
73+
74+
- name: Run Playwright tests
75+
working-directory: ./e2e
6276
run: |
63-
docker run --rm --network="host" --name myapp-testcafe-container testcafe-tests:latest
77+
yarn test --reporter=line

.vale.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
StylesPath = styles
22
MinAlertLevel = warning
33

4-
Packages = https://github.com/stakater/vale-package/releases/download/v0.0.60/Stakater.zip
4+
Packages = https://github.com/stakater/vale-package/releases/download/v0.0.89/Stakater.zip
55
Vocab = Stakater
66

77
# Only check MarkDown files

content/architecture/concepts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Here are the key concepts of Template Operator:
44

55
## Template
66

7-
A **Template** is a reusable blueprint in Template Operator that defines configurations for Kubernetes resources. It supports raw manifests, Helm charts, or resource mappings, enabling standardization and automation across multiple tenants.
7+
A **Template** is a reusable blueprint in Template Operator that defines configurations for Kubernetes resources. It supports raw manifests, gotemplate based dynamic manifests, Helm charts, or resource mappings, enabling standardization and automation across multiple tenants.
88

99
## Template Instance (TI)
1010

content/kubernetes-resources/cluster-template-instance.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ spec:
1717
values:
1818
- alpha
1919
- beta
20-
parameters:
21-
- name: CIDR_IP
22-
value: "172.17.0.0/16"
20+
parameters:
21+
- name: CIDR_IP
22+
value: "172.17.0.0/16"
2323
```
2424
2525
ClusterTemplateInstance distributes a template across multiple namespaces which are selected by labelSelector.

content/kubernetes-resources/how-to-guides/deploying-templates.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ metadata:
186186
spec:
187187
template: namespace-parameterized-restrictions
188188
sync: true
189-
parameters:
190-
- name: DEFAULT_CPU_LIMIT
191-
value: "1.5"
192-
- name: DEFAULT_CPU_REQUESTS
193-
value: "1"
189+
parameters:
190+
- name: DEFAULT_CPU_LIMIT
191+
value: "1.5"
192+
- name: DEFAULT_CPU_REQUESTS
193+
value: "1"
194194
```
195195

196196
If she wants to distribute the same Template over multiple namespaces, she can use `ClusterTemplateInstance`.
@@ -210,9 +210,9 @@ spec:
210210
values:
211211
- alpha
212212
- beta
213-
parameters:
214-
- name: DEFAULT_CPU_LIMIT
215-
value: "1.5"
216-
- name: DEFAULT_CPU_REQUESTS
217-
value: "1"
213+
parameters:
214+
- name: DEFAULT_CPU_LIMIT
215+
value: "1.5"
216+
- name: DEFAULT_CPU_REQUESTS
217+
value: "1"
218218
```

content/kubernetes-resources/template-instance.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ metadata:
1111
spec:
1212
template: networkpolicy
1313
sync: true
14-
parameters:
15-
- name: CIDR_IP
16-
value: "172.17.0.0/16"
14+
parameters:
15+
- name: CIDR_IP
16+
value: "172.17.0.0/16"
1717
```
1818
1919
TemplateInstance are used to keep track of resources created from Templates, which are being instantiated inside a Namespace.

content/kubernetes-resources/template.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Also, you can define custom variables in `Template`, `TemplateInstance` and `Clu
88

99
## Specification
1010

11-
`Template` Custom Resource (CR) supports three key methods for defining and managing resources: `manifests`, `helm`, and `resource mapping`. Let’s dive into each method, their differences, and their use cases:
11+
`Template` Custom Resource (CR) supports three key methods for defining and managing resources: `manifests`, `helm`, `gotemplate`, and `resource mapping`. Let’s dive into each method, their differences, and their use cases:
1212

1313
### 1. Manifests
1414

@@ -140,7 +140,49 @@ A brief explanation of the fields in the Helm section:
140140
* `forceString`: Whether to use `--set` or `--set-string` when setting the value. Default is `false` (use `--set`).
141141
* `values`: The values file for the Helm chart.
142142

143-
### 3. Resource Mapping
143+
### 3. GoTemplate
144+
145+
This method uses inline Go templates to dynamically generate Kubernetes manifests. It leverages Go’s `text/template` syntax along with Sprig functions for string operations, date formatting, conditionals, arithmetic, and more.
146+
147+
#### How It Works
148+
149+
* The `gotemplate` section contains YAML written with Go template expressions such as `{{ .Name }}` or `{{ now | date "2006-01-02" }}`.
150+
* Template `parameters` are injected at runtime, and Sprig functions can be used to transform or compute values.
151+
* The rendered output must be valid Kubernetes YAML, which the operator then applies to the target namespaces.
152+
153+
#### Use Cases
154+
155+
* Ideal for dynamic resource generation without maintaining a full Helm chart.
156+
* Useful when you need lightweight templating with conditional or computed fields.
157+
* Suitable for resources that change based on tenant, namespace, or environment attributes.
158+
159+
#### Example
160+
161+
```yaml
162+
apiVersion: templates.stakater.com/v1alpha1
163+
kind: Template
164+
metadata:
165+
name: inline-gotemplate
166+
parameters:
167+
- name: Name
168+
value: "sample-App"
169+
- name: LogLevel
170+
value: "INFO"
171+
resources:
172+
gotemplate: |
173+
apiVersion: v1
174+
kind: ConfigMap
175+
metadata:
176+
name: "{{ .Name | lower }}-config"
177+
labels:
178+
app: "{{ .Name | lower }}"
179+
data:
180+
appName: "{{ .Name }}"
181+
logLevel: "{{ .LogLevel }}"
182+
configVersion: "{{ now | date "2006-01-02" }}"
183+
```
184+
185+
### 4. Resource Mapping
144186

145187
This approach maps secrets and ConfigMaps from one tenant's namespace to another tenant's namespace, or within a tenant's namespace.
146188

e2e/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Stage 1: Install Playwright and Chromium
2+
FROM node:22-bookworm AS playwright-setup
3+
4+
WORKDIR /e2e
5+
6+
# Copy package files
7+
COPY package.json yarn.lock* ./
8+
9+
# Install dependencies
10+
RUN yarn install --frozen-lockfile || yarn install
11+
12+
# Install only Chromium browser
13+
RUN npx playwright install --with-deps chromium
14+
15+
# Copy tests
16+
COPY src ./src
17+
COPY playwright.config.ts ./
18+
19+
# Set CI env for Playwright
20+
ENV CI=true
21+
22+
# Run Playwright tests
23+
CMD ["yarn", "start"]

e2e/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "e2e",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@types/node": "^24.10.1",
8+
"dotenv": "^17.2.3"
9+
},
10+
"devDependencies": {
11+
"@playwright/test": "^1.57.0"
12+
},
13+
"scripts": {
14+
"local": "playwright test --headed",
15+
"start": "playwright test",
16+
"test": "playwright test",
17+
"test:ui": "playwright test --ui",
18+
"test:debug": "playwright test --debug"
19+
}
20+
}

e2e/playwright.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
export default defineConfig({
4+
testDir: './src',
5+
fullyParallel: true,
6+
forbidOnly: !!process.env.CI,
7+
retries: process.env.CI ? 2 : 0,
8+
workers: process.env.CI ? 1 : undefined,
9+
reporter: process.env.CI ? 'github' : 'html',
10+
use: {
11+
baseURL: process.env.BASE_URL || 'http://127.0.0.1:8080',
12+
trace: 'on-first-retry',
13+
},
14+
projects: [
15+
{
16+
name: 'chromium',
17+
use: {
18+
...devices['Desktop Chrome'],
19+
headless: true,
20+
},
21+
},
22+
],
23+
});

0 commit comments

Comments
 (0)