package main
import (
"bytes"
"embed"
"text/template"
)
//go:embed templates/*.tmpl
var templateFS embed.FS
var tmpl = template.Must(template.ParseFS(templateFS, "templates/*.tmpl"))
type instanceConfig struct {
Domain string
Contact string
}
func render(name string, cfg instanceConfig) (string, error) {
var buf bytes.Buffer
if err := tmpl.ExecuteTemplate(&buf, name, cfg); err != nil {
return "", err
}
return buf.String(), nil
}
func renderConfigMap(cfg instanceConfig) (string, error) { return render("configmap.yaml.tmpl", cfg) }
func renderIngress(cfg instanceConfig) (string, error) { return render("ingress.yaml.tmpl", cfg) }
func renderClusterIssuer(cfg instanceConfig) (string, error) {
return render("clusterissuer.yaml.tmpl", cfg)
}
// manifestFiles are applied straight from the cloned source checkout, in
// this order — none of them need templating: deployment.yaml's image tag
// already matches VERSION in that same checkout (see INSTALL.md's fix for
// why that pairing matters), and the rest have no per-instance values.
// configmap.yaml and ingress.yaml are NOT in this list — those two are
// generated (see above) instead of applied from the checkout, since
// they're the only files with a domain/contact to fill in.
var manifestFiles = []string{
"deploy/k8s/namespace.yaml",
"deploy/k8s/pvc.yaml",
"deploy/k8s/deployment.yaml",
"deploy/k8s/service.yaml",
}