mirror of https://github.com/tailscale/tailscale/
cmd/k8s-operator: generate static kube manifests from the Helm chart. (#10436)
* cmd/k8s-operator: generate static manifests from Helm charts This is done to ensure that there is a single source of truth for the operator kube manifests. Also adds linux node selector to the static manifests as this was added as a default to the Helm chart. Static manifests can now be generated by running `go generate tailscale.com/cmd/k8s-operator`. Updates tailscale/tailscale#9222 Signed-off-by: Irbe Krumina <irbe@tailscale.com>pull/10307/head
parent
263e01c47b
commit
49fd0a62c9
@ -0,0 +1,12 @@
|
|||||||
|
# Tailscale Kubernetes operator deployment manifests
|
||||||
|
|
||||||
|
./cmd/k8s-operator/deploy contain various Tailscale Kubernetes operator deployment manifests.
|
||||||
|
|
||||||
|
## Helm chart
|
||||||
|
|
||||||
|
`./cmd/k8s-operator/deploy/chart` contains Tailscale operator Helm chart templates.
|
||||||
|
The chart templates are also used to generate the static manifest, so developers must ensure that any changes applied to the chart have been propagated to the static manifest by running `go generate tailscale.com/cmd/k8s-operator`
|
||||||
|
|
||||||
|
## Static manifests
|
||||||
|
|
||||||
|
`./cmd/k8s-operator/deploy/manifests/operator.yaml` is a static manifest for the operator generated from the Helm chart templates for the operator.
|
@ -0,0 +1,3 @@
|
|||||||
|
# Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
@ -0,0 +1,5 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: tailscale
|
||||||
|
---
|
@ -0,0 +1,9 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: operator-oauth
|
||||||
|
namespace: tailscale
|
||||||
|
stringData:
|
||||||
|
client_id: # SET CLIENT ID HERE
|
||||||
|
client_secret: # SET CLIENT SECRET HERE
|
||||||
|
---
|
@ -0,0 +1,74 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
//go:build !plan9
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
repoRoot := "../../"
|
||||||
|
cmd := exec.Command("./tool/helm", "template", "operator", "./cmd/k8s-operator/deploy/chart",
|
||||||
|
"--namespace=tailscale")
|
||||||
|
cmd.Dir = repoRoot
|
||||||
|
var out bytes.Buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
log.Fatalf("error templating helm manifests: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var final bytes.Buffer
|
||||||
|
|
||||||
|
templatePath := filepath.Join(repoRoot, "cmd/k8s-operator/deploy/manifests/templates")
|
||||||
|
fileInfos, err := os.ReadDir(templatePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error reading templates: %v", err)
|
||||||
|
}
|
||||||
|
for _, fi := range fileInfos {
|
||||||
|
templateBytes, err := os.ReadFile(filepath.Join(templatePath, fi.Name()))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error reading template: %v", err)
|
||||||
|
}
|
||||||
|
final.Write(templateBytes)
|
||||||
|
}
|
||||||
|
decoder := yaml.NewDecoder(&out)
|
||||||
|
for {
|
||||||
|
var document any
|
||||||
|
err := decoder.Decode(&document)
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed read from input data: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes, err := yaml.Marshal(document)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to marshal YAML document: %v", err)
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(string(bytes)) == "null" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err = final.Write(bytes); err != nil {
|
||||||
|
log.Fatalf("error marshaling yaml: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Fprint(&final, "---\n")
|
||||||
|
}
|
||||||
|
finalString, _ := strings.CutSuffix(final.String(), "---\n")
|
||||||
|
if err := os.WriteFile(filepath.Join(repoRoot, "cmd/k8s-operator/deploy/manifests/operator.yaml"), []byte(finalString), 0664); err != nil {
|
||||||
|
log.Fatalf("error writing new file: %v", err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue