chore(fixes): Unwrap yaml before converting and fix volume name variable

2 fixes:

- the first problem to resolve is that some volume names can have "-" in
the name. We now replace them by "_"
- the second problem is that k8s.io library truncates the lines and so
we cannot split the files by lines. We now "unwrap" the result.

TODO: globalize the `yaml.Marshal()` code to our own specific function
This commit is contained in:
2024-11-08 13:11:14 +01:00
parent 817ebe0e53
commit dd63bb6343
11 changed files with 47 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
package generator
import (
"katenary/utils"
"regexp"
"strings"
@@ -9,8 +10,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/yaml"
"katenary/utils"
)
var _ Yaml = (*Service)(nil)
@@ -82,6 +81,11 @@ func (s *Service) Filename() string {
// Yaml returns the yaml representation of the service.
func (s *Service) Yaml() ([]byte, error) {
y, err := yaml.Marshal(s)
if err != nil {
return nil, err
}
y = UnWrapTPL(y)
lines := []string{}
for _, line := range strings.Split(string(y), "\n") {
if regexp.MustCompile(`^\s*loadBalancer:\s*`).MatchString(line) {