Skip to content

Commit

Permalink
Merge pull request #278 from Revolyssup/fixCompGen
Browse files Browse the repository at this point in the history
Fix meshmodel component generation
  • Loading branch information
Revolyssup authored Mar 14, 2023
2 parents edde0bd + 4724183 commit d436c63
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion utils/artifacthub/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
22 changes: 20 additions & 2 deletions utils/manifests/getComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit d436c63

Please sign in to comment.