diff --git a/utils/manifests/generateComponent.go b/utils/manifests/generateComponent.go index 906b2ecc..2aab6374 100644 --- a/utils/manifests/generateComponent.go +++ b/utils/manifests/generateComponent.go @@ -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 diff --git a/utils/manifests/utils.go b/utils/manifests/utils.go index 1a9a5fd0..fa697ea4 100644 --- a/utils/manifests/utils.go +++ b/utils/manifests/utils.go @@ -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" @@ -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 @@ -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, " ", "") @@ -323,3 +340,7 @@ func switchedCasing(a byte, b byte) int { } return samegroup } + +func init() { + templateExpression = regexp.MustCompile(`{{.+}}`) +}