docs: wrap service in service.go with Helm values conditional for katenary.v3/svc-optional label

Co-authored-by: aider (ollama_chat/gpt-oss:120b) <aider@aider.chat>
This commit is contained in:
2025-11-30 17:31:48 -06:00
parent 73be50588a
commit 657b37eb0c

View File

@@ -84,6 +84,7 @@ func (s *Service) Yaml() ([]byte, error) {
return nil, err
}
// Remove any loadBalancer lines that may have been added unintentionally.
lines := []string{}
for line := range strings.SplitSeq(string(y), "\n") {
if regexp.MustCompile(`^\s*loadBalancer:\s*`).MatchString(line) {
@@ -93,5 +94,19 @@ func (s *Service) Yaml() ([]byte, error) {
}
y = []byte(strings.Join(lines, "\n"))
// If the service has the label "katenary.v3/svc-optional", wrap the output
// with a Helm values conditional.
if s.service != nil && s.service.Labels != nil {
if _, ok := s.service.Labels["katenary.v3/svc-optional"]; ok {
// Ensure we have a trailing newline before appending the closing block.
content := string(y)
if !strings.HasSuffix(content, "\n") {
content += "\n"
}
content = "{{- if .Values.service.enabled }}\n" + content + "{{- end }}\n"
y = []byte(content)
}
}
return y, err
}