Skip to content

Commit

Permalink
Merge branch 'master' into latestVersionRegistration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jougan-0 authored Oct 1, 2024
2 parents d216a0a + 38beeb7 commit 3a39262
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 288 deletions.
15 changes: 0 additions & 15 deletions encoding/convert.go

This file was deleted.

8 changes: 0 additions & 8 deletions generators/artifacthub/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ func (pkg AhPackage) GetVersion() string {
return pkg.Version
}

func (pkg AhPackage) GetSourceURL() string {
return pkg.ChartUrl
}

func (pkg AhPackage) GetName() string {
return pkg.Name
}

func (pkg AhPackage) GenerateComponents() ([]_component.ComponentDefinition, error) {
components := make([]_component.ComponentDefinition, 0)
// TODO: Move this to the configuration
Expand Down
59 changes: 19 additions & 40 deletions generators/github/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/component"
"github.com/layer5io/meshkit/utils/kubernetes"
"github.com/layer5io/meshkit/utils/manifests"
"github.com/meshery/schemas/models/v1beta1/category"
_component "github.com/meshery/schemas/models/v1beta1/component"
Expand All @@ -26,14 +25,6 @@ func (gp GitHubPackage) GetVersion() string {
return gp.version
}

func (gp GitHubPackage) GetSourceURL() string {
return gp.SourceURL
}

func (gp GitHubPackage) GetName() string {
return gp.Name
}

func (gp GitHubPackage) GenerateComponents() ([]_component.ComponentDefinition, error) {
components := make([]_component.ComponentDefinition, 0)

Expand All @@ -43,40 +34,28 @@ func (gp GitHubPackage) GenerateComponents() ([]_component.ComponentDefinition,
}

manifestBytes := bytes.Split(data, []byte("\n---\n"))
errs := []error{}

for _, crd := range manifestBytes {
isCrd := kubernetes.IsCRD(string(crd))
if !isCrd {
crds, errs := component.FilterCRDs(manifestBytes)

comps, err := component.GenerateFromOpenAPI(string(crd), gp)
if err != nil {
errs = append(errs, component.ErrGetSchema(err))
continue
}
components = append(components, comps...)
} else {
comp, err := component.Generate(string(crd))
if err != nil {
continue
}
if comp.Model.Metadata == nil {
comp.Model.Metadata = &model.ModelDefinition_Metadata{}
}
if comp.Model.Metadata.AdditionalProperties == nil {
comp.Model.Metadata.AdditionalProperties = make(map[string]interface{})
}

comp.Model.Metadata.AdditionalProperties["source_uri"] = gp.SourceURL
comp.Model.Version = gp.version
comp.Model.Name = gp.Name
comp.Model.Category = category.CategoryDefinition{
Name: "",
}
comp.Model.DisplayName = manifests.FormatToReadableString(comp.Model.Name)
components = append(components, comp)
for _, crd := range crds {
comp, err := component.Generate(crd)
if err != nil {
continue
}
if comp.Model.Metadata == nil {
comp.Model.Metadata = &model.ModelDefinition_Metadata{}
}
if comp.Model.Metadata.AdditionalProperties == nil {
comp.Model.Metadata.AdditionalProperties = make(map[string]interface{})
}

comp.Model.Metadata.AdditionalProperties["source_uri"] = gp.SourceURL
comp.Model.Version = gp.version
comp.Model.Name = gp.Name
comp.Model.Category = category.CategoryDefinition{
Name: "",
}
comp.Model.DisplayName = manifests.FormatToReadableString(comp.Model.Name)
components = append(components, comp)
}

return components, utils.CombineErrors(errs, "\n")
Expand Down
2 changes: 0 additions & 2 deletions generators/models/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ type Validator interface {
type Package interface {
GenerateComponents() ([]component.ComponentDefinition, error)
GetVersion() string
GetSourceURL() string
GetName() string
}

// Supports pulling packages from Artifact Hub and other sources like Docker Hub.
Expand Down
5 changes: 2 additions & 3 deletions schemas/configuration/designImport.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"properties": {
"name": {
"type": "string",
"title": "Design file name",
"title": "Design filename",
"default": "Untitled Design",
"x-rjsf-grid-area": "6",
"description": "Provide a name for your design file. This name will help you identify the file more easily. You can also change the name of your design after importing it."
Expand All @@ -16,7 +16,6 @@
"Docker Compose",
"Meshery Design"
],
"default": "Meshery Design",
"x-rjsf-grid-area": "6",
"description": "Select the type of design you are uploading. The 'Design Type' determines the format, structure, and content of the file you are uploading. Choose the appropriate design type that matches the nature of your file. Checkout https://docs.meshery.io/guides/meshery-design to learn more about designs"
}
Expand Down Expand Up @@ -126,4 +125,4 @@
]
}
]
}
}
15 changes: 2 additions & 13 deletions utils/component/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,17 @@ var DefaultPathConfig2 = CuePathConfig{
SpecPath: "spec.validation.openAPIV3Schema",
}

var OpenAPISpecPathConfig = CuePathConfig{
NamePath: `x-kubernetes-group-version-kind"[0].kind`,
IdentifierPath: "spec.names.kind",
VersionPath: `"x-kubernetes-group-version-kind"[0].version`,
GroupPath: `"x-kubernetes-group-version-kind"[0].group`,
ScopePath: "spec.scope",
SpecPath: "spec.versions[0].schema.openAPIV3Schema",
PropertiesPath: "properties",
}

var Configs = []CuePathConfig{DefaultPathConfig, DefaultPathConfig2}

func Generate(resource string) (component.ComponentDefinition, error) {
func Generate(crd string) (component.ComponentDefinition, error) {
cmp := component.ComponentDefinition{}
cmp.SchemaVersion = v1beta1.ComponentSchemaVersion

cmp.Metadata = component.ComponentDefinition_Metadata{}
crdCue, err := utils.YamlToCue(resource)
crdCue, err := utils.YamlToCue(crd)
if err != nil {
return cmp, err
}

var schema string
for _, cfg := range Configs {
schema, err = getSchema(crdCue, cfg)
Expand Down
172 changes: 0 additions & 172 deletions utils/component/openapi_generator.go

This file was deleted.

16 changes: 13 additions & 3 deletions utils/component/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/kubernetes"
"github.com/layer5io/meshkit/utils/manifests"
"gopkg.in/yaml.v2"
)

// Remove the fields which is either not required by end user (like status) or is prefilled by system (like apiVersion, kind and metadata)
Expand Down Expand Up @@ -80,10 +81,19 @@ func FilterCRDs(manifests [][]byte) ([]string, []error) {
var errs []error
var filteredManifests []string
for _, m := range manifests {
isCrd := kubernetes.IsCRD(string(m))
if isCrd {
filteredManifests = append(filteredManifests, string(m))

var crd map[string]interface{}
err := yaml.Unmarshal(m, &crd)
if err != nil {
errs = append(errs, err)
continue
}

isCrd := kubernetes.IsCRD(crd)
if !isCrd {
continue
}
filteredManifests = append(filteredManifests, string(m))
}
return filteredManifests, errs
}
Loading

0 comments on commit 3a39262

Please sign in to comment.