Skip to content

Commit

Permalink
Merge pull request #149 from Revolyssup/abc
Browse files Browse the repository at this point in the history
Preprocess Manifests and remove helm templating
  • Loading branch information
leecalcote authored Jan 24, 2022
2 parents 6478c0d + 2da4a6c commit 42abdc0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions utils/manifests/generateComponent.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func GenerateComponents(manifest string, resource int, cfg Config) (*Component,
return nil, err
}
path := filepath.Join(wd, "test.yaml")
removeHelmTemplatingFromCRD(&manifest)
err := populateTempyaml(manifest, path)
if err != nil {
return nil, err
Expand Down
23 changes: 22 additions & 1 deletion utils/manifests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
)

var templateExpression *regexp.Regexp

func getDefinitions(crd string, resource int, cfg Config, filepath string, binPath string) (string, error) {
//the default input format is "yaml"
inputFormat := "yaml"
Expand Down Expand Up @@ -144,7 +147,6 @@ func populateTempyaml(yaml string, path string) error {
return err
}
defer file.Close()

_, err = file.WriteString(yaml)
if err != nil {
return err
Expand All @@ -157,6 +159,21 @@ func populateTempyaml(yaml string, path string) error {
return nil
}

//removeMetadataFromCRD is used because in few cases (like linkerd), helm templating might be used there which makes the yaml invalid.
//As those templates are useless for component creatin, we can replace them with "meshery" to make the YAML valid
func removeHelmTemplatingFromCRD(crdyaml *string) {
y := strings.Split(*crdyaml, "\n---\n")
var yamlArr []string
for _, y0 := range y {
if y0 == "" {
continue
}
y0 = templateExpression.ReplaceAllString(y0, "meshery")
yamlArr = append(yamlArr, string(y0))
}
*crdyaml = strings.Join(yamlArr, "\n---\n")
}

func getCrdnames(s string) []string {
s = strings.ReplaceAll(s, "\"", "")
s = strings.ReplaceAll(s, " ", "")
Expand Down Expand Up @@ -323,3 +340,7 @@ func switchedCasing(a byte, b byte) int {
}
return samegroup
}

func init() {
templateExpression = regexp.MustCompile(`{{.+}}`)
}

0 comments on commit 42abdc0

Please sign in to comment.