-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-pods.go
59 lines (51 loc) · 1013 Bytes
/
generate-pods.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"flag"
"fmt"
"html/template"
"os"
"strconv"
)
const podString = `apiVersion: v1
kind: Pod
metadata:
name: {{ .Name }}
namespace: default
labels:
app.kubernetes.io/name: tbyb-fishfood
spec:
containers:
- name: webserver
image: pizza:latest
ports:
- containerPort: 80
- name: webwatcher
image: taco:latest`
var templ *template.Template
func init() {
// template.Must takes the reponse of template.ParseFiles and does error checking
temp, err := template.New("bla").Parse(podString)
if err != nil {
panic(err)
}
templ = temp
}
type data struct {
Name string
}
func main() {
numberOfPods := flag.Int("n", 0, "numberOfPods")
flag.Parse()
for i := 0; i < *numberOfPods; i++ {
// standard output to print merged data
err := templ.Execute(os.Stdout, data{Name: "pod" + strconv.Itoa(i)})
// if there is no error,
// prints the output
if err != nil {
fmt.Println(err)
}
if i < *numberOfPods-1 {
fmt.Println("\n---")
}
}
}