diff --git a/go.mod b/go.mod index 70f23a27..a0cdf57b 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/spf13/cobra v1.6.1 github.com/spf13/viper v1.15.0 gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 gorm.io/driver/postgres v1.3.10 gorm.io/driver/sqlite v1.3.1 gorm.io/gorm v1.23.7 @@ -187,7 +188,6 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.26.0 // indirect k8s.io/apiserver v0.26.0 // indirect k8s.io/component-base v0.26.0 // indirect diff --git a/utils/artifacthub/package.go b/utils/artifacthub/package.go index 2863d09e..394fc599 100644 --- a/utils/artifacthub/package.go +++ b/utils/artifacthub/package.go @@ -46,7 +46,7 @@ func (pkg AhPackage) GenerateComponents() ([]v1alpha1.ComponentDefinition, error comp.Metadata = make(map[string]interface{}) } comp.Model.Version = pkg.Version - comp.Model.Name = pkg.Repository + comp.Model.Name = pkg.Name comp.Model.DisplayName = manifests.FormatToReadableString(comp.Model.Name) components = append(components, comp) } @@ -87,6 +87,12 @@ func (pkg *AhPackage) UpdatePackageData() error { if !ok || chartUrl == "" { return ErrGetChartUrl(fmt.Errorf("Cannot extract chartUrl from repository helm index")) } + if !strings.HasPrefix(chartUrl, "http") { + if !strings.HasSuffix(pkg.RepoUrl, "/") { + pkg.RepoUrl = pkg.RepoUrl + "/" + } + chartUrl = fmt.Sprintf("%s%s", pkg.RepoUrl, chartUrl) + } pkg.ChartUrl = chartUrl return nil } diff --git a/utils/manifests/getComponents.go b/utils/manifests/getComponents.go index 854036bc..b164beda 100644 --- a/utils/manifests/getComponents.go +++ b/utils/manifests/getComponents.go @@ -2,8 +2,13 @@ package manifests import ( "context" + "encoding/json" + "fmt" + "io" "strings" + "gopkg.in/yaml.v3" + "github.com/layer5io/meshkit/utils" k8s "github.com/layer5io/meshkit/utils/kubernetes" ) @@ -37,14 +42,27 @@ func GetCrdsFromHelm(url string) ([]string, error) { if err != nil { return nil, err } - mans := strings.Split(manifest, "---") + dec := yaml.NewDecoder(strings.NewReader(manifest)) + var mans []string + for { + var parsedYaml map[string]interface{} + if err := dec.Decode(&parsedYaml); err != nil { + if err == io.EOF { + break + } + fmt.Println(err) + } + b, _ := json.Marshal(parsedYaml) + mans = append(mans, string(b)) + } + return removeNonCrdValues(mans), nil } func removeNonCrdValues(crds []string) []string { out := make([]string, 0) for _, crd := range crds { - if crd != "" && crd != " " { + if crd != "" && crd != " " && crd != "null" { out = append(out, crd) } }