Adding svc-optional
Some checks failed
Go-Tests / tests (pull_request) Successful in 5m21s
Go-Tests / sonar (pull_request) Failing after 37s

This commit is contained in:
2025-12-02 20:40:57 -06:00
parent 7230081401
commit 3a1c170140
6 changed files with 33 additions and 1 deletions

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
}