From bdfb934be0473998e2f2a06f5836306e8cfcf68e Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Tue, 27 Aug 2024 19:34:02 +0530 Subject: [PATCH 01/13] support generation of model from openapi schemas Signed-off-by: MUzairS15 --- utils/component/generator.go | 34 +++++++++++++++++++++++++++------- utils/component/utils.go | 11 +---------- utils/kubernetes/crd.go | 20 ++++++++++++++++---- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/utils/component/generator.go b/utils/component/generator.go index 417d59cd..a0c76f40 100644 --- a/utils/component/generator.go +++ b/utils/component/generator.go @@ -7,6 +7,7 @@ import ( "cuelang.org/go/cue" "github.com/layer5io/meshkit/utils" + "github.com/layer5io/meshkit/utils/kubernetes" "github.com/layer5io/meshkit/utils/manifests" "github.com/meshery/schemas/models/v1beta1" "github.com/meshery/schemas/models/v1beta1/component" @@ -47,32 +48,43 @@ var DefaultPathConfig2 = CuePathConfig{ var Configs = []CuePathConfig{DefaultPathConfig, DefaultPathConfig2} -func Generate(crd string) (component.ComponentDefinition, error) { +func Generate(resource string) (component.ComponentDefinition, error) { cmp := component.ComponentDefinition{} cmp.SchemaVersion = v1beta1.ComponentSchemaVersion cmp.Metadata = component.ComponentDefinition_Metadata{} - crdCue, err := utils.YamlToCue(crd) + isCRD := kubernetes.IsCRD(resource) + + cueValue, err := cueValueFromResource(resource, isCRD) if err != nil { return cmp, err } + + var specPath string + if isCRD { + specPath = DefaultPathConfig.SpecPath + } else { + specPath = "components.schemas" + } + var schema string for _, cfg := range Configs { - schema, err = getSchema(crdCue, cfg) + cfg.SpecPath = specPath + schema, err = getSchema(cueValue, cfg) if err == nil { break } } cmp.Component.Schema = schema - name, err := extractCueValueFromPath(crdCue, DefaultPathConfig.NamePath) + name, err := extractCueValueFromPath(cueValue, DefaultPathConfig.NamePath) if err != nil { return cmp, err } - version, err := extractCueValueFromPath(crdCue, DefaultPathConfig.VersionPath) + version, err := extractCueValueFromPath(cueValue, DefaultPathConfig.VersionPath) if err != nil { return cmp, err } - group, err := extractCueValueFromPath(crdCue, DefaultPathConfig.GroupPath) + group, err := extractCueValueFromPath(cueValue, DefaultPathConfig.GroupPath) if err != nil { return cmp, err } @@ -80,7 +92,7 @@ func Generate(crd string) (component.ComponentDefinition, error) { if cmp.Metadata.AdditionalProperties == nil { cmp.Metadata.AdditionalProperties = make(map[string]interface{}) } - scope, _ := extractCueValueFromPath(crdCue, DefaultPathConfig.ScopePath) + scope, _ := extractCueValueFromPath(cueValue, DefaultPathConfig.ScopePath) if scope == "Cluster" { cmp.Metadata.AdditionalProperties["isNamespaced"] = false } else if scope == "Namespaced" { @@ -98,6 +110,14 @@ func Generate(crd string) (component.ComponentDefinition, error) { return cmp, nil } +func cueValueFromResource(resource string, isCRD bool) (cue.Value, error) { + if isCRD { + return utils.YamlToCue(resource) + } else { + return utils.JsonToCue([]byte(resource)) + } +} + /* Find and modify specific schema properties. 1. Identify interesting properties by walking entire schema. diff --git a/utils/component/utils.go b/utils/component/utils.go index f63d6068..8df80e59 100644 --- a/utils/component/utils.go +++ b/utils/component/utils.go @@ -7,7 +7,6 @@ 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) @@ -81,15 +80,7 @@ func FilterCRDs(manifests [][]byte) ([]string, []error) { var errs []error var filteredManifests []string for _, m := range manifests { - - var crd map[string]interface{} - err := yaml.Unmarshal(m, &crd) - if err != nil { - errs = append(errs, err) - continue - } - - isCrd := kubernetes.IsCRD(crd) + isCrd := kubernetes.IsCRD(string(m)) if !isCrd { continue } diff --git a/utils/kubernetes/crd.go b/utils/kubernetes/crd.go index b42cfbc9..cac9d97f 100644 --- a/utils/kubernetes/crd.go +++ b/utils/kubernetes/crd.go @@ -53,7 +53,19 @@ func GetGVRForCustomResources(crd *CRDItem) *schema.GroupVersionResource { } } -func IsCRD(manifest map[string]interface{}) bool { - kind, ok := manifest["kind"].(string) - return ok && kind == "CustomResourceDefinition" -} +func IsCRD(manifest string) bool { + cueValue, err := utils.YamlToCue(manifest) + if err!= nil { + return false + } + kind, err := utils.Lookup(cueValue, "kind") + if err!= nil { + return false + } + kindStr, err := kind.String() + if err != nil { + return false + } + + return kindStr == "CustomResourceDefinition" +} \ No newline at end of file From 996d12641ba3ba58f50b48e6e8690fc1006034c3 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Sat, 31 Aug 2024 18:19:07 +0530 Subject: [PATCH 02/13] openapi-gen Signed-off-by: MUzairS15 --- encoding/convert.go | 15 ++++ generators/github/package.go | 45 +++++----- generators/github/package_test.go | 56 +----------- generators/github/url.go | 6 +- utils/component/generator.go | 21 +++-- utils/component/openapi_generator.go | 123 +++++++++++++++++++++++++++ utils/component/utils.go | 11 +-- utils/helm/helm.go | 11 ++- utils/manifests/utils.go | 15 ++-- 9 files changed, 209 insertions(+), 94 deletions(-) create mode 100644 encoding/convert.go create mode 100644 utils/component/openapi_generator.go diff --git a/encoding/convert.go b/encoding/convert.go new file mode 100644 index 00000000..5dc810eb --- /dev/null +++ b/encoding/convert.go @@ -0,0 +1,15 @@ +package encoding + +import ( + "gopkg.in/yaml.v3" +) + +func ToYaml(data []byte) ([]byte, error) { + var out map[string]interface{} + err := Unmarshal(data, &out) + if err != nil { + return nil, err + } + + return yaml.Marshal(out) +} diff --git a/generators/github/package.go b/generators/github/package.go index 0c632ef9..78ac1ba7 100644 --- a/generators/github/package.go +++ b/generators/github/package.go @@ -2,14 +2,12 @@ package github import ( "bytes" + "fmt" "os" "github.com/layer5io/meshkit/utils" "github.com/layer5io/meshkit/utils/component" - "github.com/layer5io/meshkit/utils/manifests" - "github.com/meshery/schemas/models/v1beta1/category" _component "github.com/meshery/schemas/models/v1beta1/component" - "github.com/meshery/schemas/models/v1beta1/model" ) type GitHubPackage struct { @@ -35,28 +33,33 @@ func (gp GitHubPackage) GenerateComponents() ([]_component.ComponentDefinition, manifestBytes := bytes.Split(data, []byte("\n---\n")) crds, errs := component.FilterCRDs(manifestBytes) - for _, crd := range crds { - comp, err := component.Generate(crd) + comps, err := component.GenerateFromOpenAPI(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{}) + fmt.Println("ERR line 42 : ", err) } - - 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) + components = append(components, comps...) } + // 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") } diff --git a/generators/github/package_test.go b/generators/github/package_test.go index 14fad58d..21129e87 100644 --- a/generators/github/package_test.go +++ b/generators/github/package_test.go @@ -15,65 +15,13 @@ func TestGenerateCompFromGitHub(t *testing.T) { ghPackageManager GitHubPackageManager want int }{ - // { // Source pointing to a directory - // ghPackageManager: GitHubPackageManager{ - // PackageName: "k8s-config-connector", - // SourceURL: "git://github.com/GoogleCloudPlatform/k8s-config-connector/master/crds/", - // }, - // want: 337, - // }, - // { // Source pointing to a file in a repo - // ghPackageManager: GitHubPackageManager{ - // PackageName: "k8s-config-connector", - // SourceURL: "git://github.com/GoogleCloudPlatform/k8s-config-connector/master/crds/accesscontextmanager_v1alpha1_accesscontextmanageraccesslevelcondition.yaml", - // }, - // want: 1, - // }, - - // { // Source pointing to a directly downloadable file (not a repo per se) - // ghPackageManager: GitHubPackageManager{ - // PackageName: "k8s-config-connector", - // SourceURL: "git://github.com/GoogleCloudPlatform/k8s-config-connector/master/crds/accesscontextmanager_v1alpha1_accesscontextmanageraccesslevelcondition.yaml", - // }, - // want: 1, - // }, - { // Source pointing to a directly downloadable file (not a repo per se) ghPackageManager: GitHubPackageManager{ - PackageName: "k8s-config-connector", - SourceURL: "https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-config-connector/master/crds/alloydb_v1beta1_alloydbbackup.yaml/1.113.0", + PackageName: "kuberntes", + SourceURL: "https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/v3/apis__autoscaling__v2_openapi.json/v1.29.2", }, want: 1, }, - - // { // Source pointing to a directory containing helm chart - // ghPackageManager: GitHubPackageManager{ - // PackageName: "acm-controller", - // SourceURL: "https://meshery.github.io/meshery.io/charts/meshery-v0.7.12.tgz/v0.7.12", - // }, - // want: 2, - // }, - { // Source pointing to a zip containing manifests but no CRDs - ghPackageManager: GitHubPackageManager{ - PackageName: "acm-controller", - SourceURL: "https://github.com/MUzairS15/WASM-filters/raw/main/test.tar.gz/v0.7.12", - }, - want: 0, - }, - { // Source pointing to a zip containing CRDs - ghPackageManager: GitHubPackageManager{ - PackageName: "acm-controller", - SourceURL: "git://github.com/MUzairS15/WASM-filters/main/chart.tar.gz", - }, - want: 14, - }, - // { // Source pointing to a dir containing CRDs - // ghPackageManager: GitHubPackageManager{ - // PackageName: "acm-controller", - // SourceURL: "git://github.com/meshery/meshery/master/install/kubernetes/helm/meshery-operator", - // }, - // want: 2, - // }, } for _, test := range tests { diff --git a/generators/github/url.go b/generators/github/url.go index 6ca4b94d..22a3f1b1 100644 --- a/generators/github/url.go +++ b/generators/github/url.go @@ -2,6 +2,7 @@ package github import ( "bufio" + "fmt" "io" "net/url" @@ -74,10 +75,13 @@ func ProcessContent(w io.Writer, downloadDirPath, downloadfilePath string) error if err != nil { return err - } + } + + fmt.Println("TEST 80 inside github url.go") err = utils.ProcessContent(downloadDirPath, func(path string) error { err = helm.ConvertToK8sManifest(path, "", w) + fmt.Println("TEST 84 inside github url.go") if err != nil { return err } diff --git a/utils/component/generator.go b/utils/component/generator.go index a0c76f40..5987e5e1 100644 --- a/utils/component/generator.go +++ b/utils/component/generator.go @@ -46,6 +46,16 @@ 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) { @@ -55,11 +65,6 @@ func Generate(resource string) (component.ComponentDefinition, error) { cmp.Metadata = component.ComponentDefinition_Metadata{} isCRD := kubernetes.IsCRD(resource) - cueValue, err := cueValueFromResource(resource, isCRD) - if err != nil { - return cmp, err - } - var specPath string if isCRD { specPath = DefaultPathConfig.SpecPath @@ -67,6 +72,12 @@ func Generate(resource string) (component.ComponentDefinition, error) { specPath = "components.schemas" } + fmt.Println("SPEC PATH ", specPath) + cueValue, err := cueValueFromResource(resource, isCRD) + if err != nil { + return cmp, err + } + var schema string for _, cfg := range Configs { cfg.SpecPath = specPath diff --git a/utils/component/openapi_generator.go b/utils/component/openapi_generator.go new file mode 100644 index 00000000..b340ef65 --- /dev/null +++ b/utils/component/openapi_generator.go @@ -0,0 +1,123 @@ +package component + +import ( + "encoding/json" + "fmt" + "strings" + + "cuelang.org/go/cue" + "cuelang.org/go/cue/cuecontext" + "cuelang.org/go/encoding/yaml" + "github.com/layer5io/meshkit/utils/manifests" + "github.com/meshery/schemas/models/v1beta1" + "github.com/meshery/schemas/models/v1beta1/category" + "github.com/meshery/schemas/models/v1beta1/component" + "github.com/meshery/schemas/models/v1beta1/model" +) + +func GenerateFromOpenAPI(resource string) ([]component.ComponentDefinition, error) { + cuectx := cuecontext.New() + fmt.Println("resource -----------: ", resource) + cueParsedManExpr, err := yaml.Extract("", []byte(resource)) + parsedManifest := cuectx.BuildFile(cueParsedManExpr) + + definitions := parsedManifest.LookupPath(cue.ParsePath("components.schemas")) + if err != nil { + return nil, nil + } + + resol := manifests.ResolveOpenApiRefs{} + cache := make(map[string][]byte) + resolved, err := resol.ResolveReferences([]byte(resource), definitions, cache) + if err != nil { + return nil, err + } + fmt.Println("resource -----------: ", string(resolved)) + cueParsedManExpr, err = yaml.Extract("", []byte(resolved)) + parsedManifest = cuectx.BuildFile(cueParsedManExpr) + definitions = parsedManifest.LookupPath(cue.ParsePath("components.schemas")) + if err != nil { + return nil, nil + } + + fields, err := definitions.Fields() + if err != nil { + fmt.Printf("%v\n", err) + return nil, err + } + components := make([]component.ComponentDefinition, 0) + + for fields.Next() { + fieldVal := fields.Value() + kindCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].kind`)) + if kindCue.Err() != nil { + continue + } + kind, err := kindCue.String() + kind = strings.ToLower(kind) + if err != nil { + fmt.Printf("%v", err) + continue + } + + crd, err := fieldVal.MarshalJSON() + if err != nil { + fmt.Printf("%v", err) + continue + } + versionCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].version`)) + groupCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].group`)) + apiVersion, _ := versionCue.String() + if g, _ := groupCue.String(); g != "" { + apiVersion = g + "/" + apiVersion + } + modified := make(map[string]interface{}) //Remove the given fields which is either not required by End user (like status) or is prefilled by system (like apiVersion, kind and metadata) + err = json.Unmarshal(crd, &modified) + if err != nil { + fmt.Printf("%v", err) + continue + } + + modifiedProps, err := UpdateProperties(fieldVal, cue.ParsePath("properties.spec"), apiVersion) + if err == nil { + modified = modifiedProps + } + + DeleteFields(modified) + crd, err = json.Marshal(modified) + if err != nil { + fmt.Printf("%v", err) + continue + } + + c := component.ComponentDefinition{ + SchemaVersion: v1beta1.ComponentSchemaVersion, + Version: "v1.0.0", + + Format: component.JSON, + Component: component.Component{ + Kind: kind, + Version: apiVersion, + Schema: string(crd), + }, + // Metadata: compMetadata, + DisplayName: manifests.FormatToReadableString(kind), + Model: model.ModelDefinition{ + SchemaVersion: v1beta1.ModelSchemaVersion, + Version: "v1.0.0", + + Model: model.Model{ + Version: "version", + }, + Name: "kubernetes", + DisplayName: "Kubernetes", + Category: category.CategoryDefinition{ + Name: "Orchestration & Management", + }, + }, + } + components = append(components, c) + } + return components, nil + +} diff --git a/utils/component/utils.go b/utils/component/utils.go index 8df80e59..423fbe02 100644 --- a/utils/component/utils.go +++ b/utils/component/utils.go @@ -2,10 +2,10 @@ package component import ( "encoding/json" + "fmt" "cuelang.org/go/cue" "github.com/layer5io/meshkit/utils" - "github.com/layer5io/meshkit/utils/kubernetes" "github.com/layer5io/meshkit/utils/manifests" ) @@ -80,10 +80,11 @@ func FilterCRDs(manifests [][]byte) ([]string, []error) { var errs []error var filteredManifests []string for _, m := range manifests { - isCrd := kubernetes.IsCRD(string(m)) - if !isCrd { - continue - } + fmt.Println("TEST 84 : utils.go: ") + // isCrd := kubernetes.IsCRD(string(m)) + // if !isCrd { + + // } filteredManifests = append(filteredManifests, string(m)) } return filteredManifests, errs diff --git a/utils/helm/helm.go b/utils/helm/helm.go index 4af65eed..400450f9 100644 --- a/utils/helm/helm.go +++ b/utils/helm/helm.go @@ -2,6 +2,7 @@ package helm import ( "bytes" + "fmt" "io" "io/fs" "os" @@ -9,6 +10,7 @@ import ( "regexp" "strings" + "github.com/layer5io/meshkit/encoding" "github.com/layer5io/meshkit/utils" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" @@ -94,6 +96,7 @@ func ConvertToK8sManifest(path, kubeVersion string, w io.Writer) error { } } else { err := writeToFile(w, path) + fmt.Println("line 98: inside helm.go writeToFile") if err != nil { return err } @@ -108,7 +111,13 @@ func writeToFile(w io.Writer, path string) error { if err != nil { return utils.ErrReadFile(err, path) } - _, err = w.Write(data) + + byt, err := encoding.ToYaml(data) + if err != nil { + return utils.ErrWriteFile(err, path) + } + + _, err = w.Write(byt) if err != nil { return utils.ErrWriteFile(err, path) } diff --git a/utils/manifests/utils.go b/utils/manifests/utils.go index fb3990f7..2935f1c0 100644 --- a/utils/manifests/utils.go +++ b/utils/manifests/utils.go @@ -9,6 +9,7 @@ import ( "strings" "cuelang.org/go/cue" + "github.com/layer5io/meshkit/encoding" "github.com/layer5io/meshkit/models/oam/core/v1alpha1" ) @@ -254,7 +255,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue cache = make(map[string][]byte) } var val map[string]interface{} - err := json.Unmarshal(manifest, &val) + err := encoding.Unmarshal(manifest, &val) if err != nil { return nil, err } @@ -266,7 +267,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue if ro.isInsideJsonSchemaProps && (ref == JsonSchemaPropsRef) { // hack so that the UI doesn't crash val["$ref"] = "string" - marVal, errJson := json.Marshal(val) + marVal, errJson := encoding.Marshal(val) if errJson != nil { return manifest, nil } @@ -282,13 +283,13 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue newval = append(newval, v0) continue } - byt, _ := json.Marshal(v0) + byt, _ := encoding.Marshal(v0) byt, err = ro.ResolveReferences(byt, definitions, cache) if err != nil { return nil, err } var newvalmap map[string]interface{} - _ = json.Unmarshal(byt, &newvalmap) + _ = encoding.Unmarshal(byt, &newvalmap) newval = append(newval, newvalmap) } val[k] = newval @@ -333,7 +334,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue if reflect.ValueOf(v).Kind() == reflect.Map { var marVal []byte var def []byte - marVal, err = json.Marshal(v) + marVal, err = encoding.Marshal(v) if err != nil { return nil, err } @@ -349,7 +350,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue } } } - res, err := json.Marshal(val) + res, err := encoding.Marshal(val) if err != nil { return nil, err } @@ -358,7 +359,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue func replaceRefWithVal(def []byte, val map[string]interface{}, k string) error { var defVal map[string]interface{} - err := json.Unmarshal([]byte(def), &defVal) + err := encoding.Unmarshal([]byte(def), &defVal) if err != nil { return err } From 099cdd39516a8e3d2c78f12abb18bb7f78c8fa90 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 9 Sep 2024 18:08:01 +0530 Subject: [PATCH 03/13] update test Signed-off-by: MUzairS15 --- generators/github/package_test.go | 56 +++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/generators/github/package_test.go b/generators/github/package_test.go index 21129e87..14fad58d 100644 --- a/generators/github/package_test.go +++ b/generators/github/package_test.go @@ -15,13 +15,65 @@ func TestGenerateCompFromGitHub(t *testing.T) { ghPackageManager GitHubPackageManager want int }{ + // { // Source pointing to a directory + // ghPackageManager: GitHubPackageManager{ + // PackageName: "k8s-config-connector", + // SourceURL: "git://github.com/GoogleCloudPlatform/k8s-config-connector/master/crds/", + // }, + // want: 337, + // }, + // { // Source pointing to a file in a repo + // ghPackageManager: GitHubPackageManager{ + // PackageName: "k8s-config-connector", + // SourceURL: "git://github.com/GoogleCloudPlatform/k8s-config-connector/master/crds/accesscontextmanager_v1alpha1_accesscontextmanageraccesslevelcondition.yaml", + // }, + // want: 1, + // }, + + // { // Source pointing to a directly downloadable file (not a repo per se) + // ghPackageManager: GitHubPackageManager{ + // PackageName: "k8s-config-connector", + // SourceURL: "git://github.com/GoogleCloudPlatform/k8s-config-connector/master/crds/accesscontextmanager_v1alpha1_accesscontextmanageraccesslevelcondition.yaml", + // }, + // want: 1, + // }, + { // Source pointing to a directly downloadable file (not a repo per se) ghPackageManager: GitHubPackageManager{ - PackageName: "kuberntes", - SourceURL: "https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/v3/apis__autoscaling__v2_openapi.json/v1.29.2", + PackageName: "k8s-config-connector", + SourceURL: "https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-config-connector/master/crds/alloydb_v1beta1_alloydbbackup.yaml/1.113.0", }, want: 1, }, + + // { // Source pointing to a directory containing helm chart + // ghPackageManager: GitHubPackageManager{ + // PackageName: "acm-controller", + // SourceURL: "https://meshery.github.io/meshery.io/charts/meshery-v0.7.12.tgz/v0.7.12", + // }, + // want: 2, + // }, + { // Source pointing to a zip containing manifests but no CRDs + ghPackageManager: GitHubPackageManager{ + PackageName: "acm-controller", + SourceURL: "https://github.com/MUzairS15/WASM-filters/raw/main/test.tar.gz/v0.7.12", + }, + want: 0, + }, + { // Source pointing to a zip containing CRDs + ghPackageManager: GitHubPackageManager{ + PackageName: "acm-controller", + SourceURL: "git://github.com/MUzairS15/WASM-filters/main/chart.tar.gz", + }, + want: 14, + }, + // { // Source pointing to a dir containing CRDs + // ghPackageManager: GitHubPackageManager{ + // PackageName: "acm-controller", + // SourceURL: "git://github.com/meshery/meshery/master/install/kubernetes/helm/meshery-operator", + // }, + // want: 2, + // }, } for _, test := range tests { From 368373ee73fb0d2b95ec219136ece2ca7fd0be77 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 23 Sep 2024 12:18:04 +0530 Subject: [PATCH 04/13] update Signed-off-by: MUzairS15 --- generators/github/package.go | 64 +++++++++++++++----------- generators/github/url.go | 6 +-- utils/component/generator.go | 1 - utils/component/openapi_generator.go | 68 ++++++++++++++++++++-------- utils/component/utils.go | 12 ++--- utils/helm/helm.go | 2 - 6 files changed, 93 insertions(+), 60 deletions(-) diff --git a/generators/github/package.go b/generators/github/package.go index 78ac1ba7..7f083bf3 100644 --- a/generators/github/package.go +++ b/generators/github/package.go @@ -2,12 +2,15 @@ package github import ( "bytes" - "fmt" "os" "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" + "github.com/meshery/schemas/models/v1beta1/model" ) type GitHubPackage struct { @@ -32,34 +35,41 @@ func (gp GitHubPackage) GenerateComponents() ([]_component.ComponentDefinition, } manifestBytes := bytes.Split(data, []byte("\n---\n")) - crds, errs := component.FilterCRDs(manifestBytes) - for _, crd := range crds { - comps, err := component.GenerateFromOpenAPI(crd) - if err != nil { - fmt.Println("ERR line 42 : ", err) + errs := []error{} + + for _, crd := range manifestBytes { + isCrd := kubernetes.IsCRD(string(crd)) + if !isCrd { + + comps, err := component.GenerateFromOpenAPI(string(crd), gp.SourceURL) + if err != nil { + errs = append(errs, 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) } - components = append(components, comps...) - } - // 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") } diff --git a/generators/github/url.go b/generators/github/url.go index 22a3f1b1..6ca4b94d 100644 --- a/generators/github/url.go +++ b/generators/github/url.go @@ -2,7 +2,6 @@ package github import ( "bufio" - "fmt" "io" "net/url" @@ -75,13 +74,10 @@ func ProcessContent(w io.Writer, downloadDirPath, downloadfilePath string) error if err != nil { return err - } - - fmt.Println("TEST 80 inside github url.go") + } err = utils.ProcessContent(downloadDirPath, func(path string) error { err = helm.ConvertToK8sManifest(path, "", w) - fmt.Println("TEST 84 inside github url.go") if err != nil { return err } diff --git a/utils/component/generator.go b/utils/component/generator.go index 8dcabe62..3e5af4c9 100644 --- a/utils/component/generator.go +++ b/utils/component/generator.go @@ -72,7 +72,6 @@ func Generate(resource string) (component.ComponentDefinition, error) { specPath = "components.schemas" } - fmt.Println("SPEC PATH ", specPath) cueValue, err := cueValueFromResource(resource, isCRD) if err != nil { return cmp, err diff --git a/utils/component/openapi_generator.go b/utils/component/openapi_generator.go index b340ef65..25c28de4 100644 --- a/utils/component/openapi_generator.go +++ b/utils/component/openapi_generator.go @@ -7,37 +7,33 @@ import ( "cuelang.org/go/cue" "cuelang.org/go/cue/cuecontext" - "cuelang.org/go/encoding/yaml" + cueJson "cuelang.org/go/encoding/json" + "github.com/layer5io/meshkit/utils" "github.com/layer5io/meshkit/utils/manifests" + + "gopkg.in/yaml.v3" + "github.com/meshery/schemas/models/v1beta1" "github.com/meshery/schemas/models/v1beta1/category" "github.com/meshery/schemas/models/v1beta1/component" "github.com/meshery/schemas/models/v1beta1/model" ) -func GenerateFromOpenAPI(resource string) ([]component.ComponentDefinition, error) { - cuectx := cuecontext.New() - fmt.Println("resource -----------: ", resource) - cueParsedManExpr, err := yaml.Extract("", []byte(resource)) - parsedManifest := cuectx.BuildFile(cueParsedManExpr) - - definitions := parsedManifest.LookupPath(cue.ParsePath("components.schemas")) - if err != nil { +func GenerateFromOpenAPI(resource, sourceURL string) ([]component.ComponentDefinition, error) { + if resource == "" { return nil, nil } - - resol := manifests.ResolveOpenApiRefs{} - cache := make(map[string][]byte) - resolved, err := resol.ResolveReferences([]byte(resource), definitions, cache) + resource, err := getResolvedManifest(resource) if err != nil { return nil, err } - fmt.Println("resource -----------: ", string(resolved)) - cueParsedManExpr, err = yaml.Extract("", []byte(resolved)) - parsedManifest = cuectx.BuildFile(cueParsedManExpr) - definitions = parsedManifest.LookupPath(cue.ParsePath("components.schemas")) + cuectx := cuecontext.New() + cueParsedManExpr, err := cueJson.Extract("", []byte(resource)) + parsedManifest := cuectx.BuildExpr(cueParsedManExpr) + definitions := parsedManifest.LookupPath(cue.ParsePath("components.schemas")) + if err != nil { - return nil, nil + return nil, err } fields, err := definitions.Fields() @@ -114,10 +110,46 @@ func GenerateFromOpenAPI(resource string) ([]component.ComponentDefinition, erro Category: category.CategoryDefinition{ Name: "Orchestration & Management", }, + Metadata: &model.ModelDefinition_Metadata{ + AdditionalProperties: map[string]interface{}{ + "source_uri": sourceURL, + }, + }, }, } + components = append(components, c) } return components, nil } + +func getResolvedManifest(manifest string) (string, error) { + var m map[string]interface{} + + err := yaml.Unmarshal([]byte(manifest), &m) + if err != nil { + return "", utils.ErrDecodeYaml(err) + } + + byt, err := json.Marshal(m) + if err != nil { + return "", utils.ErrMarshal(err) + } + + cuectx := cuecontext.New() + cueParsedManExpr, err := cueJson.Extract("", byt) + parsedManifest := cuectx.BuildExpr(cueParsedManExpr) + definitions := parsedManifest.LookupPath(cue.ParsePath("components.schemas")) + if err != nil { + return "", err + } + resol := manifests.ResolveOpenApiRefs{} + cache := make(map[string][]byte) + resolved, err := resol.ResolveReferences(byt, definitions, cache) + if err != nil { + return "", err + } + manifest = string(resolved) + return manifest, nil +} diff --git a/utils/component/utils.go b/utils/component/utils.go index 423fbe02..f04ded45 100644 --- a/utils/component/utils.go +++ b/utils/component/utils.go @@ -2,10 +2,10 @@ package component import ( "encoding/json" - "fmt" "cuelang.org/go/cue" "github.com/layer5io/meshkit/utils" + "github.com/layer5io/meshkit/utils/kubernetes" "github.com/layer5io/meshkit/utils/manifests" ) @@ -80,12 +80,10 @@ func FilterCRDs(manifests [][]byte) ([]string, []error) { var errs []error var filteredManifests []string for _, m := range manifests { - fmt.Println("TEST 84 : utils.go: ") - // isCrd := kubernetes.IsCRD(string(m)) - // if !isCrd { - - // } - filteredManifests = append(filteredManifests, string(m)) + isCrd := kubernetes.IsCRD(string(m)) + if isCrd { + filteredManifests = append(filteredManifests, string(m)) + } } return filteredManifests, errs } diff --git a/utils/helm/helm.go b/utils/helm/helm.go index 400450f9..091e5902 100644 --- a/utils/helm/helm.go +++ b/utils/helm/helm.go @@ -2,7 +2,6 @@ package helm import ( "bytes" - "fmt" "io" "io/fs" "os" @@ -96,7 +95,6 @@ func ConvertToK8sManifest(path, kubeVersion string, w io.Writer) error { } } else { err := writeToFile(w, path) - fmt.Println("line 98: inside helm.go writeToFile") if err != nil { return err } From 5ba263e6339d365e307096fbc1d18cb4770e3579 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Tue, 27 Aug 2024 19:34:02 +0530 Subject: [PATCH 05/13] support generation of model from openapi schemas Signed-off-by: MUzairS15 --- utils/component/generator.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/component/generator.go b/utils/component/generator.go index 3e5af4c9..0b974245 100644 --- a/utils/component/generator.go +++ b/utils/component/generator.go @@ -65,6 +65,11 @@ func Generate(resource string) (component.ComponentDefinition, error) { cmp.Metadata = component.ComponentDefinition_Metadata{} isCRD := kubernetes.IsCRD(resource) + cueValue, err := cueValueFromResource(resource, isCRD) + if err != nil { + return cmp, err + } + var specPath string if isCRD { specPath = DefaultPathConfig.SpecPath @@ -72,11 +77,6 @@ func Generate(resource string) (component.ComponentDefinition, error) { specPath = "components.schemas" } - cueValue, err := cueValueFromResource(resource, isCRD) - if err != nil { - return cmp, err - } - var schema string for _, cfg := range Configs { cfg.SpecPath = specPath From b8eebd9ed11df5ef542f5d1cd7ae78c315297a21 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 23 Sep 2024 22:28:50 +0530 Subject: [PATCH 06/13] temp Signed-off-by: MUzairS15 --- .../github/kubernetes/apiresourcelist.json | 57 +++++++++++++++++++ .../github/kubernetes/deleteoptions.json | 57 +++++++++++++++++++ .../kubernetes/horizontalpodautoscaler.json | 57 +++++++++++++++++++ .../horizontalpodautoscalerlist.json | 57 +++++++++++++++++++ generators/github/kubernetes/status.json | 57 +++++++++++++++++++ generators/github/kubernetes/watchevent.json | 57 +++++++++++++++++++ 6 files changed, 342 insertions(+) create mode 100644 generators/github/kubernetes/apiresourcelist.json create mode 100644 generators/github/kubernetes/deleteoptions.json create mode 100644 generators/github/kubernetes/horizontalpodautoscaler.json create mode 100644 generators/github/kubernetes/horizontalpodautoscalerlist.json create mode 100644 generators/github/kubernetes/status.json create mode 100644 generators/github/kubernetes/watchevent.json diff --git a/generators/github/kubernetes/apiresourcelist.json b/generators/github/kubernetes/apiresourcelist.json new file mode 100644 index 00000000..8f9d8b74 --- /dev/null +++ b/generators/github/kubernetes/apiresourcelist.json @@ -0,0 +1,57 @@ +{ +"component": { +"kind": "apiresourcelist", +"schema": "{\"description\":\"APIResourceList is a list of APIResource, it is used to expose the name of the resources supported in a specific group and version, and if the resource is namespaced.\",\"properties\":{\"groupVersion\":{\"default\":\"\",\"description\":\"groupVersion is the group and version this APIResourceList is for.\",\"type\":\"string\"},\"resources\":{\"description\":\"resources contains the name of the resources and if they are namespaced.\",\"items\":{\"allOf\":[{\"description\":\"APIResource specifies the name of a resource and whether it is namespaced.\",\"properties\":{\"categories\":{\"description\":\"categories is a list of the grouped resources this resource belongs to (e.g. 'all')\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"group\":{\"description\":\"group is the preferred group of the resource. Empty implies the group of the containing resource list. For subresources, this may have a different value, for example: Scale\\\".\",\"type\":\"string\"},\"kind\":{\"default\":\"\",\"description\":\"kind is the kind for the resource (e.g. 'Foo' is the kind for a resource 'foo')\",\"type\":\"string\"},\"name\":{\"default\":\"\",\"description\":\"name is the plural name of the resource.\",\"type\":\"string\"},\"namespaced\":{\"default\":false,\"description\":\"namespaced indicates if a resource is namespaced or not.\",\"type\":\"boolean\"},\"shortNames\":{\"description\":\"shortNames is a list of suggested short names of the resource.\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"singularName\":{\"default\":\"\",\"description\":\"singularName is the singular name of the resource. This allows clients to handle plural and singular opaquely. The singularName is more correct for reporting status on a single item and both singular and plural are allowed from the kubectl CLI interface.\",\"type\":\"string\"},\"storageVersionHash\":{\"description\":\"The hash value of the storage version, the version this resource is converted to when written to the data store. Value must be treated as opaque by clients. Only equality comparison on the value is valid. This is an alpha feature and may change or be removed in the future. The field is populated by the apiserver only if the StorageVersionHash feature gate is enabled. This field will remain optional even if it graduates.\",\"type\":\"string\"},\"verbs\":{\"description\":\"verbs is a list of supported kube verbs (this includes get, list, watch, create, update, patch, delete, deletecollection, and proxy)\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\"},\"version\":{\"description\":\"version is the preferred version of the resource. Empty implies the version of the containing resource list For subresources, this may have a different value, for example: v1 (while inside a v1beta1 version of the core resource's group)\\\".\",\"type\":\"string\"}},\"required\":[\"name\",\"singularName\",\"namespaced\",\"kind\",\"verbs\"],\"type\":\"object\"}],\"default\":{}},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"}},\"required\":[\"groupVersion\",\"resources\"],\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"\",\"kind\":\"APIResourceList\",\"version\":\"v1\"}]}", +"version": "v1" +}, +"configuration": null, +"description": "", +"displayName": "apiresourcelist", +"format": "JSON", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"genealogy": "", +"isAnnotation": false, +"isNamespaced": false, +"published": false +}, +"model": { +"category": { +"name": "Orchestration \u0026 Management" +}, +"displayName": "Kubernetes", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", +"svgColor": "", +"svgWhite": "" +}, +"model": { +"version": "version" +}, +"name": "kubernetes", +"registrant": { +"created_at": "0001-01-01T00:00:00Z", +"credential_id": "00000000-0000-0000-0000-000000000000", +"deleted_at": "0001-01-01T00:00:00Z", +"id": "00000000-0000-0000-0000-000000000000", +"kind": "", +"name": "", +"status": "", +"sub_type": "", +"type": "", +"updated_at": "0001-01-01T00:00:00Z", +"user_id": "00000000-0000-0000-0000-000000000000" +}, +"connection_id": "00000000-0000-0000-0000-000000000000", +"schemaVersion": "models.meshery.io/v1beta1", +"status": "", +"version": "v1.0.0", +"components": null, +"relationships": null +}, +"schemaVersion": "components.meshery.io/v1beta1", +"status": null, +"styles": null, +"version": "v1.0.0" +} \ No newline at end of file diff --git a/generators/github/kubernetes/deleteoptions.json b/generators/github/kubernetes/deleteoptions.json new file mode 100644 index 00000000..41ebe8d6 --- /dev/null +++ b/generators/github/kubernetes/deleteoptions.json @@ -0,0 +1,57 @@ +{ +"component": { +"kind": "deleteoptions", +"schema": "{\"description\":\"DeleteOptions may be provided when deleting an API object.\",\"properties\":{\"dryRun\":{\"description\":\"When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"gracePeriodSeconds\":{\"description\":\"The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.\",\"format\":\"int64\",\"type\":\"integer\"},\"orphanDependents\":{\"description\":\"Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \\\"orphan\\\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.\",\"type\":\"boolean\"},\"preconditions\":{\"allOf\":[{\"description\":\"Preconditions must be fulfilled before an operation (update, delete, etc.) is carried out.\",\"properties\":{\"resourceVersion\":{\"description\":\"Specifies the target ResourceVersion\",\"type\":\"string\"},\"uid\":{\"description\":\"Specifies the target UID.\",\"type\":\"string\"}},\"type\":\"object\"}],\"description\":\"Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned.\"},\"propagationPolicy\":{\"description\":\"Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.\",\"type\":\"string\"}},\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"admission.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"admission.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"apiextensions.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"apiextensions.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"apiregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"apiregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"apps\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"apps\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"apps\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta2\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"autoscaling\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"autoscaling\",\"kind\":\"DeleteOptions\",\"version\":\"v2\"},{\"group\":\"autoscaling\",\"kind\":\"DeleteOptions\",\"version\":\"v2beta1\"},{\"group\":\"autoscaling\",\"kind\":\"DeleteOptions\",\"version\":\"v2beta2\"},{\"group\":\"batch\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"batch\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"discovery.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"discovery.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"events.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"events.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"extensions\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta2\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta3\"},{\"group\":\"imagepolicy.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"internal.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"node.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"node.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"node.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"policy\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"policy\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"resource.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha3\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"storagemigration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"}]}", +"version": "v1" +}, +"configuration": null, +"description": "", +"displayName": "deleteoptions", +"format": "JSON", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"genealogy": "", +"isAnnotation": false, +"isNamespaced": false, +"published": false +}, +"model": { +"category": { +"name": "Orchestration \u0026 Management" +}, +"displayName": "Kubernetes", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", +"svgColor": "", +"svgWhite": "" +}, +"model": { +"version": "version" +}, +"name": "kubernetes", +"registrant": { +"created_at": "0001-01-01T00:00:00Z", +"credential_id": "00000000-0000-0000-0000-000000000000", +"deleted_at": "0001-01-01T00:00:00Z", +"id": "00000000-0000-0000-0000-000000000000", +"kind": "", +"name": "", +"status": "", +"sub_type": "", +"type": "", +"updated_at": "0001-01-01T00:00:00Z", +"user_id": "00000000-0000-0000-0000-000000000000" +}, +"connection_id": "00000000-0000-0000-0000-000000000000", +"schemaVersion": "models.meshery.io/v1beta1", +"status": "", +"version": "v1.0.0", +"components": null, +"relationships": null +}, +"schemaVersion": "components.meshery.io/v1beta1", +"status": null, +"styles": null, +"version": "v1.0.0" +} \ No newline at end of file diff --git a/generators/github/kubernetes/horizontalpodautoscaler.json b/generators/github/kubernetes/horizontalpodautoscaler.json new file mode 100644 index 00000000..764e2e1d --- /dev/null +++ b/generators/github/kubernetes/horizontalpodautoscaler.json @@ -0,0 +1,57 @@ +{ +"component": { +"kind": "horizontalpodautoscaler", +"schema": "{\"description\":\"configuration of a horizontal pod autoscaler.\",\"properties\":{\"spec\":{\"allOf\":[{\"description\":\"specification of a horizontal pod autoscaler.\",\"properties\":{\"maxReplicas\":{\"default\":0,\"description\":\"maxReplicas is the upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.\",\"format\":\"int32\",\"type\":\"integer\"},\"minReplicas\":{\"description\":\"minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down. It defaults to 1 pod. minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured. Scaling is active as long as at least one metric value is available.\",\"format\":\"int32\",\"type\":\"integer\"},\"scaleTargetRef\":{\"allOf\":[{\"description\":\"CrossVersionObjectReference contains enough information to let you identify the referred resource.\",\"properties\":{\"apiVersion\":{\"description\":\"apiVersion is the API version of the referent\",\"type\":\"string\"},\"kind\":{\"default\":\"\",\"description\":\"kind is the kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"name\":{\"default\":\"\",\"description\":\"name is the name of the referent; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names\",\"type\":\"string\"}},\"required\":[\"kind\",\"name\"],\"type\":\"object\",\"x-kubernetes-map-type\":\"atomic\"}],\"default\":{},\"description\":\"reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption and will set the desired number of pods by using its Scale subresource.\"},\"targetCPUUtilizationPercentage\":{\"description\":\"targetCPUUtilizationPercentage is the target average CPU utilization (represented as a percentage of requested CPU) over all the pods; if not specified the default autoscaling policy will be used.\",\"format\":\"int32\",\"type\":\"integer\"}},\"required\":[\"scaleTargetRef\",\"maxReplicas\"],\"type\":\"object\"}],\"default\":{},\"description\":\"spec defines the behaviour of autoscaler. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.\"}},\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"autoscaling\",\"kind\":\"HorizontalPodAutoscaler\",\"version\":\"v1\"}]}", +"version": "autoscaling/v1" +}, +"configuration": null, +"description": "", +"displayName": "horizontalpodautoscaler", +"format": "JSON", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"genealogy": "", +"isAnnotation": false, +"isNamespaced": false, +"published": false +}, +"model": { +"category": { +"name": "Orchestration \u0026 Management" +}, +"displayName": "Kubernetes", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", +"svgColor": "", +"svgWhite": "" +}, +"model": { +"version": "version" +}, +"name": "kubernetes", +"registrant": { +"created_at": "0001-01-01T00:00:00Z", +"credential_id": "00000000-0000-0000-0000-000000000000", +"deleted_at": "0001-01-01T00:00:00Z", +"id": "00000000-0000-0000-0000-000000000000", +"kind": "", +"name": "", +"status": "", +"sub_type": "", +"type": "", +"updated_at": "0001-01-01T00:00:00Z", +"user_id": "00000000-0000-0000-0000-000000000000" +}, +"connection_id": "00000000-0000-0000-0000-000000000000", +"schemaVersion": "models.meshery.io/v1beta1", +"status": "", +"version": "v1.0.0", +"components": null, +"relationships": null +}, +"schemaVersion": "components.meshery.io/v1beta1", +"status": null, +"styles": null, +"version": "v1.0.0" +} \ No newline at end of file diff --git a/generators/github/kubernetes/horizontalpodautoscalerlist.json b/generators/github/kubernetes/horizontalpodautoscalerlist.json new file mode 100644 index 00000000..175ce10b --- /dev/null +++ b/generators/github/kubernetes/horizontalpodautoscalerlist.json @@ -0,0 +1,57 @@ +{ +"component": { +"kind": "horizontalpodautoscalerlist", +"schema": "{\"description\":\"list of horizontal pod autoscaler objects.\",\"properties\":{\"items\":{\"description\":\"items is the list of horizontal pod autoscaler objects.\",\"items\":{\"allOf\":[{\"description\":\"configuration of a horizontal pod autoscaler.\",\"properties\":{\"apiVersion\":{\"description\":\"APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources\",\"type\":\"string\"},\"kind\":{\"description\":\"Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"metadata\":{\"allOf\":[{\"description\":\"ObjectMeta is metadata that all persisted resources must have, which includes all objects users must create.\",\"properties\":{\"annotations\":{\"additionalProperties\":{\"default\":\"\",\"type\":\"string\"},\"description\":\"Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations\",\"type\":\"object\"},\"creationTimestamp\":{\"allOf\":[{\"description\":\"Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.\",\"format\":\"date-time\",\"type\":\"string\"}],\"description\":\"CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.\\n\\nPopulated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata\"},\"deletionGracePeriodSeconds\":{\"description\":\"Number of seconds allowed for this object to gracefully terminate before it will be removed from the system. Only set when deletionTimestamp is also set. May only be shortened. Read-only.\",\"format\":\"int64\",\"type\":\"integer\"},\"deletionTimestamp\":{\"allOf\":[{\"description\":\"Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.\",\"format\":\"date-time\",\"type\":\"string\"}],\"description\":\"DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted. This field is set by the server when a graceful deletion is requested by the user, and is not directly settable by a client. The resource is expected to be deleted (no longer visible from resource lists, and not reachable by name) after the time in this field, once the finalizers list is empty. As long as the finalizers list contains items, deletion is blocked. Once the deletionTimestamp is set, this value may not be unset or be set further into the future, although it may be shortened or the resource may be deleted prior to this time. For example, a user may request that a pod is deleted in 30 seconds. The Kubelet will react by sending a graceful termination signal to the containers in the pod. After that 30 seconds, the Kubelet will send a hard termination signal (SIGKILL) to the container and after cleanup, remove the pod from the API. In the presence of network partitions, this object may still exist after this timestamp, until an administrator or automated process can determine the resource is fully terminated. If not set, graceful deletion of the object has not been requested.\\n\\nPopulated by the system when a graceful deletion is requested. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata\"},\"finalizers\":{\"description\":\"Must be empty before the object is deleted from the registry. Each entry is an identifier for the responsible component that will remove the entry from the list. If the deletionTimestamp of the object is non-nil, entries in this list can only be removed. Finalizers may be processed and removed in any order. Order is NOT enforced because it introduces significant risk of stuck finalizers. finalizers is a shared field, any actor with permission can reorder it. If the finalizer list is processed in order, then this can lead to a situation in which the component responsible for the first finalizer in the list is waiting for a signal (field value, external system, or other) produced by a component responsible for a finalizer later in the list, resulting in a deadlock. Without enforced ordering finalizers are free to order amongst themselves and are not vulnerable to ordering changes in the list.\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\",\"x-kubernetes-list-type\":\"set\",\"x-kubernetes-patch-strategy\":\"merge\"},\"generateName\":{\"description\":\"GenerateName is an optional prefix, used by the server, to generate a unique name ONLY IF the Name field has not been provided. If this field is used, the name returned to the client will be different than the name passed. This value will also be combined with a unique suffix. The provided value has the same validation rules as the Name field, and may be truncated by the length of the suffix required to make the value unique on the server.\\n\\nIf this field is specified and the generated name exists, the server will return a 409.\\n\\nApplied only if Name is not specified. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency\",\"type\":\"string\"},\"generation\":{\"description\":\"A sequence number representing a specific generation of the desired state. Populated by the system. Read-only.\",\"format\":\"int64\",\"type\":\"integer\"},\"labels\":{\"additionalProperties\":{\"default\":\"\",\"type\":\"string\"},\"description\":\"Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels\",\"type\":\"object\"},\"managedFields\":{\"description\":\"ManagedFields maps workflow-id and version to the set of fields that are managed by that workflow. This is mostly for internal housekeeping, and users typically shouldn't need to set or understand this field. A workflow can be the user's name, a controller's name, or the name of a specific apply path like \\\"ci-cd\\\". The set of fields is always in the version that the workflow used when modifying the object.\",\"items\":{\"allOf\":[{\"description\":\"ManagedFieldsEntry is a workflow-id, a FieldSet and the group version of the resource that the fieldset applies to.\",\"properties\":{\"apiVersion\":{\"description\":\"APIVersion defines the version of this resource that this field set applies to. The format is \\\"group/version\\\" just like the top-level APIVersion field. It is necessary to track the version of a field set because it cannot be automatically converted.\",\"type\":\"string\"},\"fieldsType\":{\"description\":\"FieldsType is the discriminator for the different fields format and version. There is currently only one possible value: \\\"FieldsV1\\\"\",\"type\":\"string\"},\"fieldsV1\":{\"allOf\":[{\"description\":\"FieldsV1 stores a set of fields in a data structure like a Trie, in JSON format.\\n\\nEach key is either a '.' representing the field itself, and will always map to an empty set, or a string representing a sub-field or item. The string will follow one of these four formats: 'f:\\u003cname\\u003e', where \\u003cname\\u003e is the name of a field in a struct, or key in a map 'v:\\u003cvalue\\u003e', where \\u003cvalue\\u003e is the exact json formatted value of a list item 'i:\\u003cindex\\u003e', where \\u003cindex\\u003e is position of a item in a list 'k:\\u003ckeys\\u003e', where \\u003ckeys\\u003e is a map of a list item's key fields to their unique values If a key maps to an empty Fields value, the field that key represents is part of the set.\\n\\nThe exact format is defined in sigs.k8s.io/structured-merge-diff\",\"type\":\"object\"}],\"description\":\"FieldsV1 holds the first JSON version format as described in the \\\"FieldsV1\\\" type.\"},\"manager\":{\"description\":\"Manager is an identifier of the workflow managing these fields.\",\"type\":\"string\"},\"operation\":{\"description\":\"Operation is the type of operation which lead to this ManagedFieldsEntry being created. The only valid values for this field are 'Apply' and 'Update'.\",\"type\":\"string\"},\"subresource\":{\"description\":\"Subresource is the name of the subresource used to update that object, or empty string if the object was updated through the main resource. The value of this field is used to distinguish between managers, even if they share the same name. For example, a status update will be distinct from a regular update using the same manager name. Note that the APIVersion field is not related to the Subresource field and it always corresponds to the version of the main resource.\",\"type\":\"string\"},\"time\":{\"allOf\":[{\"description\":\"Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.\",\"format\":\"date-time\",\"type\":\"string\"}],\"description\":\"Time is the timestamp of when the ManagedFields entry was added. The timestamp will also be updated if a field is added, the manager changes any of the owned fields value or removes a field. The timestamp does not update when a field is removed from the entry because another manager took it over.\"}},\"type\":\"object\"}],\"default\":{}},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"name\":{\"description\":\"Name must be unique within a namespace. Is required when creating resources, although some resources may allow a client to request the generation of an appropriate name automatically. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names\",\"type\":\"string\"},\"namespace\":{\"description\":\"Namespace defines the space within which each name must be unique. An empty namespace is equivalent to the \\\"default\\\" namespace, but \\\"default\\\" is the canonical representation. Not all objects are required to be scoped to a namespace - the value of this field for those objects will be empty.\\n\\nMust be a DNS_LABEL. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces\",\"type\":\"string\"},\"ownerReferences\":{\"description\":\"List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.\",\"items\":{\"allOf\":[{\"description\":\"OwnerReference contains enough information to let you identify an owning object. An owning object must be in the same namespace as the dependent, or be cluster-scoped, so there is no namespace field.\",\"properties\":{\"apiVersion\":{\"default\":\"\",\"description\":\"API version of the referent.\",\"type\":\"string\"},\"blockOwnerDeletion\":{\"description\":\"If true, AND if the owner has the \\\"foregroundDeletion\\\" finalizer, then the owner cannot be deleted from the key-value store until this reference is removed. See https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion for how the garbage collector interacts with this field and enforces the foreground deletion. Defaults to false. To set this field, a user needs \\\"delete\\\" permission of the owner, otherwise 422 (Unprocessable Entity) will be returned.\",\"type\":\"boolean\"},\"controller\":{\"description\":\"If true, this reference points to the managing controller.\",\"type\":\"boolean\"},\"kind\":{\"default\":\"\",\"description\":\"Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"name\":{\"default\":\"\",\"description\":\"Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names\",\"type\":\"string\"},\"uid\":{\"default\":\"\",\"description\":\"UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids\",\"type\":\"string\"}},\"required\":[\"apiVersion\",\"kind\",\"name\",\"uid\"],\"type\":\"object\",\"x-kubernetes-map-type\":\"atomic\"}],\"default\":{}},\"type\":\"array\",\"x-kubernetes-list-map-keys\":[\"uid\"],\"x-kubernetes-list-type\":\"map\",\"x-kubernetes-patch-merge-key\":\"uid\",\"x-kubernetes-patch-strategy\":\"merge\"},\"resourceVersion\":{\"description\":\"An opaque value that represents the internal version of this object that can be used by clients to determine when objects have changed. May be used for optimistic concurrency, change detection, and the watch operation on a resource or set of resources. Clients must treat these values as opaque and passed unmodified back to the server. They may only be valid for a particular resource or set of resources.\\n\\nPopulated by the system. Read-only. Value must be treated as opaque by clients and . More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency\",\"type\":\"string\"},\"selfLink\":{\"description\":\"Deprecated: selfLink is a legacy read-only field that is no longer populated by the system.\",\"type\":\"string\"},\"uid\":{\"description\":\"UID is the unique in time and space value for this object. It is typically generated by the server on successful creation of a resource and is not allowed to change on PUT operations.\\n\\nPopulated by the system. Read-only. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids\",\"type\":\"string\"}},\"type\":\"object\"}],\"default\":{},\"description\":\"Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata\"},\"spec\":{\"allOf\":[{\"description\":\"specification of a horizontal pod autoscaler.\",\"properties\":{\"maxReplicas\":{\"default\":0,\"description\":\"maxReplicas is the upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.\",\"format\":\"int32\",\"type\":\"integer\"},\"minReplicas\":{\"description\":\"minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down. It defaults to 1 pod. minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured. Scaling is active as long as at least one metric value is available.\",\"format\":\"int32\",\"type\":\"integer\"},\"scaleTargetRef\":{\"allOf\":[{\"description\":\"CrossVersionObjectReference contains enough information to let you identify the referred resource.\",\"properties\":{\"apiVersion\":{\"description\":\"apiVersion is the API version of the referent\",\"type\":\"string\"},\"kind\":{\"default\":\"\",\"description\":\"kind is the kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"name\":{\"default\":\"\",\"description\":\"name is the name of the referent; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names\",\"type\":\"string\"}},\"required\":[\"kind\",\"name\"],\"type\":\"object\",\"x-kubernetes-map-type\":\"atomic\"}],\"default\":{},\"description\":\"reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption and will set the desired number of pods by using its Scale subresource.\"},\"targetCPUUtilizationPercentage\":{\"description\":\"targetCPUUtilizationPercentage is the target average CPU utilization (represented as a percentage of requested CPU) over all the pods; if not specified the default autoscaling policy will be used.\",\"format\":\"int32\",\"type\":\"integer\"}},\"required\":[\"scaleTargetRef\",\"maxReplicas\"],\"type\":\"object\"}],\"default\":{},\"description\":\"spec defines the behaviour of autoscaler. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.\"},\"status\":{\"allOf\":[{\"description\":\"current status of a horizontal pod autoscaler\",\"properties\":{\"currentCPUUtilizationPercentage\":{\"description\":\"currentCPUUtilizationPercentage is the current average CPU utilization over all pods, represented as a percentage of requested CPU, e.g. 70 means that an average pod is using now 70% of its requested CPU.\",\"format\":\"int32\",\"type\":\"integer\"},\"currentReplicas\":{\"default\":0,\"description\":\"currentReplicas is the current number of replicas of pods managed by this autoscaler.\",\"format\":\"int32\",\"type\":\"integer\"},\"desiredReplicas\":{\"default\":0,\"description\":\"desiredReplicas is the desired number of replicas of pods managed by this autoscaler.\",\"format\":\"int32\",\"type\":\"integer\"},\"lastScaleTime\":{\"allOf\":[{\"description\":\"Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.\",\"format\":\"date-time\",\"type\":\"string\"}],\"description\":\"lastScaleTime is the last time the HorizontalPodAutoscaler scaled the number of pods; used by the autoscaler to control how often the number of pods is changed.\"},\"observedGeneration\":{\"description\":\"observedGeneration is the most recent generation observed by this autoscaler.\",\"format\":\"int64\",\"type\":\"integer\"}},\"required\":[\"currentReplicas\",\"desiredReplicas\"],\"type\":\"object\"}],\"default\":{},\"description\":\"status is the current information about the autoscaler.\"}},\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"autoscaling\",\"kind\":\"HorizontalPodAutoscaler\",\"version\":\"v1\"}]}],\"default\":{}},\"type\":\"array\"}},\"required\":[\"items\"],\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"autoscaling\",\"kind\":\"HorizontalPodAutoscalerList\",\"version\":\"v1\"}]}", +"version": "autoscaling/v1" +}, +"configuration": null, +"description": "", +"displayName": "horizontalpodautoscalerlist", +"format": "JSON", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"genealogy": "", +"isAnnotation": false, +"isNamespaced": false, +"published": false +}, +"model": { +"category": { +"name": "Orchestration \u0026 Management" +}, +"displayName": "Kubernetes", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", +"svgColor": "", +"svgWhite": "" +}, +"model": { +"version": "version" +}, +"name": "kubernetes", +"registrant": { +"created_at": "0001-01-01T00:00:00Z", +"credential_id": "00000000-0000-0000-0000-000000000000", +"deleted_at": "0001-01-01T00:00:00Z", +"id": "00000000-0000-0000-0000-000000000000", +"kind": "", +"name": "", +"status": "", +"sub_type": "", +"type": "", +"updated_at": "0001-01-01T00:00:00Z", +"user_id": "00000000-0000-0000-0000-000000000000" +}, +"connection_id": "00000000-0000-0000-0000-000000000000", +"schemaVersion": "models.meshery.io/v1beta1", +"status": "", +"version": "v1.0.0", +"components": null, +"relationships": null +}, +"schemaVersion": "components.meshery.io/v1beta1", +"status": null, +"styles": null, +"version": "v1.0.0" +} \ No newline at end of file diff --git a/generators/github/kubernetes/status.json b/generators/github/kubernetes/status.json new file mode 100644 index 00000000..2eef9691 --- /dev/null +++ b/generators/github/kubernetes/status.json @@ -0,0 +1,57 @@ +{ +"component": { +"kind": "status", +"schema": "{\"description\":\"Status is a return value for calls that don't return other objects.\",\"properties\":{\"code\":{\"description\":\"Suggested HTTP return code for this status, 0 if not set.\",\"format\":\"int32\",\"type\":\"integer\"},\"details\":{\"allOf\":[{\"description\":\"StatusDetails is a set of additional properties that MAY be set by the server to provide additional information about a response. The Reason field of a Status object defines what attributes will be set. Clients must ignore fields that do not match the defined type of each attribute, and should assume that any attribute may be empty, invalid, or under defined.\",\"properties\":{\"causes\":{\"description\":\"The Causes array includes more details associated with the StatusReason failure. Not all StatusReasons may provide detailed causes.\",\"items\":{\"allOf\":[{\"description\":\"StatusCause provides more information about an api.Status failure, including cases when multiple errors are encountered.\",\"properties\":{\"field\":{\"description\":\"The field of the resource that has caused this error, as named by its JSON serialization. May include dot and postfix notation for nested attributes. Arrays are zero-indexed. Fields may appear more than once in an array of causes due to fields having multiple errors. Optional.\\n\\nExamples:\\n \\\"name\\\" - the field \\\"name\\\" on the current resource\\n \\\"items[0].name\\\" - the field \\\"name\\\" on the first array entry in \\\"items\\\"\",\"type\":\"string\"},\"message\":{\"description\":\"A human-readable description of the cause of the error. This field may be presented as-is to a reader.\",\"type\":\"string\"},\"reason\":{\"description\":\"A machine-readable description of the cause of the error. If this value is empty there is no information available.\",\"type\":\"string\"}},\"type\":\"object\"}],\"default\":{}},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"group\":{\"description\":\"The group attribute of the resource associated with the status StatusReason.\",\"type\":\"string\"},\"kind\":{\"description\":\"The kind attribute of the resource associated with the status StatusReason. On some operations may differ from the requested resource Kind. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"name\":{\"description\":\"The name attribute of the resource associated with the status StatusReason (when there is a single name which can be described).\",\"type\":\"string\"},\"retryAfterSeconds\":{\"description\":\"If specified, the time in seconds before the operation should be retried. Some errors may indicate the client must take an alternate action - for those errors this field may indicate how long to wait before taking the alternate action.\",\"format\":\"int32\",\"type\":\"integer\"},\"uid\":{\"description\":\"UID of the resource. (when there is a single resource which can be described). More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids\",\"type\":\"string\"}},\"type\":\"object\"}],\"description\":\"Extended data associated with the reason. Each reason may define its own extended details. This field is optional and the data returned is not guaranteed to conform to any schema except that defined by the reason type.\",\"x-kubernetes-list-type\":\"atomic\"},\"message\":{\"description\":\"A human-readable description of the status of this operation.\",\"type\":\"string\"},\"reason\":{\"description\":\"A machine-readable description of why this operation is in the \\\"Failure\\\" status. If this value is empty there is no information available. A Reason clarifies an HTTP status code but does not override it.\",\"type\":\"string\"}},\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"\",\"kind\":\"Status\",\"version\":\"v1\"}]}", +"version": "v1" +}, +"configuration": null, +"description": "", +"displayName": "status", +"format": "JSON", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"genealogy": "", +"isAnnotation": false, +"isNamespaced": false, +"published": false +}, +"model": { +"category": { +"name": "Orchestration \u0026 Management" +}, +"displayName": "Kubernetes", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", +"svgColor": "", +"svgWhite": "" +}, +"model": { +"version": "version" +}, +"name": "kubernetes", +"registrant": { +"created_at": "0001-01-01T00:00:00Z", +"credential_id": "00000000-0000-0000-0000-000000000000", +"deleted_at": "0001-01-01T00:00:00Z", +"id": "00000000-0000-0000-0000-000000000000", +"kind": "", +"name": "", +"status": "", +"sub_type": "", +"type": "", +"updated_at": "0001-01-01T00:00:00Z", +"user_id": "00000000-0000-0000-0000-000000000000" +}, +"connection_id": "00000000-0000-0000-0000-000000000000", +"schemaVersion": "models.meshery.io/v1beta1", +"status": "", +"version": "v1.0.0", +"components": null, +"relationships": null +}, +"schemaVersion": "components.meshery.io/v1beta1", +"status": null, +"styles": null, +"version": "v1.0.0" +} \ No newline at end of file diff --git a/generators/github/kubernetes/watchevent.json b/generators/github/kubernetes/watchevent.json new file mode 100644 index 00000000..342c16f8 --- /dev/null +++ b/generators/github/kubernetes/watchevent.json @@ -0,0 +1,57 @@ +{ +"component": { +"kind": "watchevent", +"schema": "{\"description\":\"Event represents a single event to a watched resource.\",\"properties\":{\"object\":{\"allOf\":[{\"description\":\"RawExtension is used to hold extensions in external versions.\\n\\nTo use this, make a field which has RawExtension as its type in your external, versioned struct, and Object in your internal struct. You also need to register your various plugin types.\\n\\n// Internal package:\\n\\n\\ttype MyAPIObject struct {\\n\\t\\truntime.TypeMeta `json:\\\",inline\\\"`\\n\\t\\tMyPlugin runtime.Object `json:\\\"myPlugin\\\"`\\n\\t}\\n\\n\\ttype PluginA struct {\\n\\t\\tAOption string `json:\\\"aOption\\\"`\\n\\t}\\n\\n// External package:\\n\\n\\ttype MyAPIObject struct {\\n\\t\\truntime.TypeMeta `json:\\\",inline\\\"`\\n\\t\\tMyPlugin runtime.RawExtension `json:\\\"myPlugin\\\"`\\n\\t}\\n\\n\\ttype PluginA struct {\\n\\t\\tAOption string `json:\\\"aOption\\\"`\\n\\t}\\n\\n// On the wire, the JSON will look something like this:\\n\\n\\t{\\n\\t\\t\\\"kind\\\":\\\"MyAPIObject\\\",\\n\\t\\t\\\"apiVersion\\\":\\\"v1\\\",\\n\\t\\t\\\"myPlugin\\\": {\\n\\t\\t\\t\\\"kind\\\":\\\"PluginA\\\",\\n\\t\\t\\t\\\"aOption\\\":\\\"foo\\\",\\n\\t\\t},\\n\\t}\\n\\nSo what happens? Decode first uses json or yaml to unmarshal the serialized data into your external MyAPIObject. That causes the raw JSON to be stored, but not unpacked. The next step is to copy (using pkg/conversion) into the internal struct. The runtime package's DefaultScheme has conversion functions installed which will unpack the JSON stored in RawExtension, turning it into the correct object type, and storing it in the Object. (TODO: In the case where the object is of an unknown type, a runtime.Unknown object will be created and stored.)\",\"type\":\"object\"}],\"description\":\"Object is:\\n * If Type is Added or Modified: the new state of the object.\\n * If Type is Deleted: the state of the object immediately before deletion.\\n * If Type is Error: *Status is recommended; other types may make sense\\n depending on context.\"},\"type\":{\"default\":\"\",\"type\":\"string\"}},\"required\":[\"type\",\"object\"],\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"admission.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"admission.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"apiextensions.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"apiextensions.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"apiregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"apiregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"apps\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"apps\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"apps\",\"kind\":\"WatchEvent\",\"version\":\"v1beta2\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"autoscaling\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"autoscaling\",\"kind\":\"WatchEvent\",\"version\":\"v2\"},{\"group\":\"autoscaling\",\"kind\":\"WatchEvent\",\"version\":\"v2beta1\"},{\"group\":\"autoscaling\",\"kind\":\"WatchEvent\",\"version\":\"v2beta2\"},{\"group\":\"batch\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"batch\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"discovery.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"discovery.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"events.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"events.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"extensions\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta2\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta3\"},{\"group\":\"imagepolicy.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"internal.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"node.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"node.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"node.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"policy\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"policy\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"resource.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha3\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"storagemigration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"}]}", +"version": "v1" +}, +"configuration": null, +"description": "", +"displayName": "watchevent", +"format": "JSON", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"genealogy": "", +"isAnnotation": false, +"isNamespaced": false, +"published": false +}, +"model": { +"category": { +"name": "Orchestration \u0026 Management" +}, +"displayName": "Kubernetes", +"id": "00000000-0000-0000-0000-000000000000", +"metadata": { +"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", +"svgColor": "", +"svgWhite": "" +}, +"model": { +"version": "version" +}, +"name": "kubernetes", +"registrant": { +"created_at": "0001-01-01T00:00:00Z", +"credential_id": "00000000-0000-0000-0000-000000000000", +"deleted_at": "0001-01-01T00:00:00Z", +"id": "00000000-0000-0000-0000-000000000000", +"kind": "", +"name": "", +"status": "", +"sub_type": "", +"type": "", +"updated_at": "0001-01-01T00:00:00Z", +"user_id": "00000000-0000-0000-0000-000000000000" +}, +"connection_id": "00000000-0000-0000-0000-000000000000", +"schemaVersion": "models.meshery.io/v1beta1", +"status": "", +"version": "v1.0.0", +"components": null, +"relationships": null +}, +"schemaVersion": "components.meshery.io/v1beta1", +"status": null, +"styles": null, +"version": "v1.0.0" +} \ No newline at end of file From e75742849f19b96f4344d27cdedfaf49197cd635 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Wed, 25 Sep 2024 14:07:59 +0530 Subject: [PATCH 07/13] fix import Signed-off-by: MUzairS15 --- utils/kubernetes/crd.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/utils/kubernetes/crd.go b/utils/kubernetes/crd.go index de813120..9bf8d991 100644 --- a/utils/kubernetes/crd.go +++ b/utils/kubernetes/crd.go @@ -4,6 +4,7 @@ import ( "context" "github.com/layer5io/meshkit/encoding" + "github.com/layer5io/meshkit/utils" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/rest" ) @@ -54,18 +55,18 @@ func GetGVRForCustomResources(crd *CRDItem) *schema.GroupVersionResource { } func IsCRD(manifest string) bool { - cueValue, err := utils.YamlToCue(manifest) - if err!= nil { - return false - } - kind, err := utils.Lookup(cueValue, "kind") - if err!= nil { - return false - } - kindStr, err := kind.String() + cueValue, err := utils.YamlToCue(manifest) if err != nil { - return false - } + return false + } + kind, err := utils.Lookup(cueValue, "kind") + if err != nil { + return false + } + kindStr, err := kind.String() + if err != nil { + return false + } - return kindStr == "CustomResourceDefinition" -} \ No newline at end of file + return kindStr == "CustomResourceDefinition" +} From 112a538180174fea091f744dfae28f7ee29e8f69 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Wed, 25 Sep 2024 15:26:16 +0530 Subject: [PATCH 08/13] define new methods on package interface Signed-off-by: MUzairS15 --- generators/artifacthub/package.go | 8 ++++++++ generators/github/package.go | 10 +++++++++- generators/models/interfaces.go | 2 ++ utils/component/openapi_generator.go | 11 ++++++----- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/generators/artifacthub/package.go b/generators/artifacthub/package.go index 61b3d8be..e40509d8 100644 --- a/generators/artifacthub/package.go +++ b/generators/artifacthub/package.go @@ -38,6 +38,14 @@ 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 diff --git a/generators/github/package.go b/generators/github/package.go index 7f083bf3..aff3be4b 100644 --- a/generators/github/package.go +++ b/generators/github/package.go @@ -26,6 +26,14 @@ 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) @@ -41,7 +49,7 @@ func (gp GitHubPackage) GenerateComponents() ([]_component.ComponentDefinition, isCrd := kubernetes.IsCRD(string(crd)) if !isCrd { - comps, err := component.GenerateFromOpenAPI(string(crd), gp.SourceURL) + comps, err := component.GenerateFromOpenAPI(string(crd), gp) if err != nil { errs = append(errs, err) continue diff --git a/generators/models/interfaces.go b/generators/models/interfaces.go index 19f61177..c6dcd3eb 100644 --- a/generators/models/interfaces.go +++ b/generators/models/interfaces.go @@ -13,6 +13,8 @@ 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. diff --git a/utils/component/openapi_generator.go b/utils/component/openapi_generator.go index 25c28de4..12d37a59 100644 --- a/utils/component/openapi_generator.go +++ b/utils/component/openapi_generator.go @@ -8,6 +8,7 @@ import ( "cuelang.org/go/cue" "cuelang.org/go/cue/cuecontext" cueJson "cuelang.org/go/encoding/json" + "github.com/layer5io/meshkit/generators/models" "github.com/layer5io/meshkit/utils" "github.com/layer5io/meshkit/utils/manifests" @@ -19,7 +20,7 @@ import ( "github.com/meshery/schemas/models/v1beta1/model" ) -func GenerateFromOpenAPI(resource, sourceURL string) ([]component.ComponentDefinition, error) { +func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.ComponentDefinition, error) { if resource == "" { return nil, nil } @@ -103,16 +104,16 @@ func GenerateFromOpenAPI(resource, sourceURL string) ([]component.ComponentDefin Version: "v1.0.0", Model: model.Model{ - Version: "version", + Version: pkg.GetVersion(), }, - Name: "kubernetes", - DisplayName: "Kubernetes", + Name: pkg.GetName(), + DisplayName: manifests.FormatToReadableString(pkg.GetName()), Category: category.CategoryDefinition{ Name: "Orchestration & Management", }, Metadata: &model.ModelDefinition_Metadata{ AdditionalProperties: map[string]interface{}{ - "source_uri": sourceURL, + "source_uri": pkg.GetSourceURL(), }, }, }, From 12ec8f66b1b1a3b47628a56b181112b0b648d5d1 Mon Sep 17 00:00:00 2001 From: aabidsofi19 Date: Sun, 29 Sep 2024 22:23:41 +0530 Subject: [PATCH 09/13] Update import design schema Signed-off-by: aabidsofi19 --- schemas/configuration/designImport.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/schemas/configuration/designImport.json b/schemas/configuration/designImport.json index 4c5752af..f59b205b 100644 --- a/schemas/configuration/designImport.json +++ b/schemas/configuration/designImport.json @@ -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." @@ -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" } @@ -126,4 +125,4 @@ ] } ] -} \ No newline at end of file +} From ad5c26539f105a8fff3dc2ef78bdd5ea08c6a2af Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 30 Sep 2024 15:31:27 +0530 Subject: [PATCH 10/13] remove unneeded files Signed-off-by: MUzairS15 --- .../github/kubernetes/apiresourcelist.json | 57 ------------------- .../github/kubernetes/deleteoptions.json | 57 ------------------- .../kubernetes/horizontalpodautoscaler.json | 57 ------------------- .../horizontalpodautoscalerlist.json | 57 ------------------- generators/github/kubernetes/status.json | 57 ------------------- generators/github/kubernetes/watchevent.json | 57 ------------------- 6 files changed, 342 deletions(-) delete mode 100644 generators/github/kubernetes/apiresourcelist.json delete mode 100644 generators/github/kubernetes/deleteoptions.json delete mode 100644 generators/github/kubernetes/horizontalpodautoscaler.json delete mode 100644 generators/github/kubernetes/horizontalpodautoscalerlist.json delete mode 100644 generators/github/kubernetes/status.json delete mode 100644 generators/github/kubernetes/watchevent.json diff --git a/generators/github/kubernetes/apiresourcelist.json b/generators/github/kubernetes/apiresourcelist.json deleted file mode 100644 index 8f9d8b74..00000000 --- a/generators/github/kubernetes/apiresourcelist.json +++ /dev/null @@ -1,57 +0,0 @@ -{ -"component": { -"kind": "apiresourcelist", -"schema": "{\"description\":\"APIResourceList is a list of APIResource, it is used to expose the name of the resources supported in a specific group and version, and if the resource is namespaced.\",\"properties\":{\"groupVersion\":{\"default\":\"\",\"description\":\"groupVersion is the group and version this APIResourceList is for.\",\"type\":\"string\"},\"resources\":{\"description\":\"resources contains the name of the resources and if they are namespaced.\",\"items\":{\"allOf\":[{\"description\":\"APIResource specifies the name of a resource and whether it is namespaced.\",\"properties\":{\"categories\":{\"description\":\"categories is a list of the grouped resources this resource belongs to (e.g. 'all')\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"group\":{\"description\":\"group is the preferred group of the resource. Empty implies the group of the containing resource list. For subresources, this may have a different value, for example: Scale\\\".\",\"type\":\"string\"},\"kind\":{\"default\":\"\",\"description\":\"kind is the kind for the resource (e.g. 'Foo' is the kind for a resource 'foo')\",\"type\":\"string\"},\"name\":{\"default\":\"\",\"description\":\"name is the plural name of the resource.\",\"type\":\"string\"},\"namespaced\":{\"default\":false,\"description\":\"namespaced indicates if a resource is namespaced or not.\",\"type\":\"boolean\"},\"shortNames\":{\"description\":\"shortNames is a list of suggested short names of the resource.\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"singularName\":{\"default\":\"\",\"description\":\"singularName is the singular name of the resource. This allows clients to handle plural and singular opaquely. The singularName is more correct for reporting status on a single item and both singular and plural are allowed from the kubectl CLI interface.\",\"type\":\"string\"},\"storageVersionHash\":{\"description\":\"The hash value of the storage version, the version this resource is converted to when written to the data store. Value must be treated as opaque by clients. Only equality comparison on the value is valid. This is an alpha feature and may change or be removed in the future. The field is populated by the apiserver only if the StorageVersionHash feature gate is enabled. This field will remain optional even if it graduates.\",\"type\":\"string\"},\"verbs\":{\"description\":\"verbs is a list of supported kube verbs (this includes get, list, watch, create, update, patch, delete, deletecollection, and proxy)\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\"},\"version\":{\"description\":\"version is the preferred version of the resource. Empty implies the version of the containing resource list For subresources, this may have a different value, for example: v1 (while inside a v1beta1 version of the core resource's group)\\\".\",\"type\":\"string\"}},\"required\":[\"name\",\"singularName\",\"namespaced\",\"kind\",\"verbs\"],\"type\":\"object\"}],\"default\":{}},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"}},\"required\":[\"groupVersion\",\"resources\"],\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"\",\"kind\":\"APIResourceList\",\"version\":\"v1\"}]}", -"version": "v1" -}, -"configuration": null, -"description": "", -"displayName": "apiresourcelist", -"format": "JSON", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"genealogy": "", -"isAnnotation": false, -"isNamespaced": false, -"published": false -}, -"model": { -"category": { -"name": "Orchestration \u0026 Management" -}, -"displayName": "Kubernetes", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", -"svgColor": "", -"svgWhite": "" -}, -"model": { -"version": "version" -}, -"name": "kubernetes", -"registrant": { -"created_at": "0001-01-01T00:00:00Z", -"credential_id": "00000000-0000-0000-0000-000000000000", -"deleted_at": "0001-01-01T00:00:00Z", -"id": "00000000-0000-0000-0000-000000000000", -"kind": "", -"name": "", -"status": "", -"sub_type": "", -"type": "", -"updated_at": "0001-01-01T00:00:00Z", -"user_id": "00000000-0000-0000-0000-000000000000" -}, -"connection_id": "00000000-0000-0000-0000-000000000000", -"schemaVersion": "models.meshery.io/v1beta1", -"status": "", -"version": "v1.0.0", -"components": null, -"relationships": null -}, -"schemaVersion": "components.meshery.io/v1beta1", -"status": null, -"styles": null, -"version": "v1.0.0" -} \ No newline at end of file diff --git a/generators/github/kubernetes/deleteoptions.json b/generators/github/kubernetes/deleteoptions.json deleted file mode 100644 index 41ebe8d6..00000000 --- a/generators/github/kubernetes/deleteoptions.json +++ /dev/null @@ -1,57 +0,0 @@ -{ -"component": { -"kind": "deleteoptions", -"schema": "{\"description\":\"DeleteOptions may be provided when deleting an API object.\",\"properties\":{\"dryRun\":{\"description\":\"When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"gracePeriodSeconds\":{\"description\":\"The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.\",\"format\":\"int64\",\"type\":\"integer\"},\"orphanDependents\":{\"description\":\"Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \\\"orphan\\\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.\",\"type\":\"boolean\"},\"preconditions\":{\"allOf\":[{\"description\":\"Preconditions must be fulfilled before an operation (update, delete, etc.) is carried out.\",\"properties\":{\"resourceVersion\":{\"description\":\"Specifies the target ResourceVersion\",\"type\":\"string\"},\"uid\":{\"description\":\"Specifies the target UID.\",\"type\":\"string\"}},\"type\":\"object\"}],\"description\":\"Must be fulfilled before a deletion is carried out. If not possible, a 409 Conflict status will be returned.\"},\"propagationPolicy\":{\"description\":\"Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.\",\"type\":\"string\"}},\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"admission.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"admission.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"apiextensions.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"apiextensions.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"apiregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"apiregistration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"apps\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"apps\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"apps\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta2\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"autoscaling\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"autoscaling\",\"kind\":\"DeleteOptions\",\"version\":\"v2\"},{\"group\":\"autoscaling\",\"kind\":\"DeleteOptions\",\"version\":\"v2beta1\"},{\"group\":\"autoscaling\",\"kind\":\"DeleteOptions\",\"version\":\"v2beta2\"},{\"group\":\"batch\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"batch\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"discovery.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"discovery.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"events.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"events.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"extensions\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta2\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta3\"},{\"group\":\"imagepolicy.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"internal.apiserver.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"node.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"node.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"node.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"policy\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"policy\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"resource.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha3\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1beta1\"},{\"group\":\"storagemigration.k8s.io\",\"kind\":\"DeleteOptions\",\"version\":\"v1alpha1\"}]}", -"version": "v1" -}, -"configuration": null, -"description": "", -"displayName": "deleteoptions", -"format": "JSON", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"genealogy": "", -"isAnnotation": false, -"isNamespaced": false, -"published": false -}, -"model": { -"category": { -"name": "Orchestration \u0026 Management" -}, -"displayName": "Kubernetes", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", -"svgColor": "", -"svgWhite": "" -}, -"model": { -"version": "version" -}, -"name": "kubernetes", -"registrant": { -"created_at": "0001-01-01T00:00:00Z", -"credential_id": "00000000-0000-0000-0000-000000000000", -"deleted_at": "0001-01-01T00:00:00Z", -"id": "00000000-0000-0000-0000-000000000000", -"kind": "", -"name": "", -"status": "", -"sub_type": "", -"type": "", -"updated_at": "0001-01-01T00:00:00Z", -"user_id": "00000000-0000-0000-0000-000000000000" -}, -"connection_id": "00000000-0000-0000-0000-000000000000", -"schemaVersion": "models.meshery.io/v1beta1", -"status": "", -"version": "v1.0.0", -"components": null, -"relationships": null -}, -"schemaVersion": "components.meshery.io/v1beta1", -"status": null, -"styles": null, -"version": "v1.0.0" -} \ No newline at end of file diff --git a/generators/github/kubernetes/horizontalpodautoscaler.json b/generators/github/kubernetes/horizontalpodautoscaler.json deleted file mode 100644 index 764e2e1d..00000000 --- a/generators/github/kubernetes/horizontalpodautoscaler.json +++ /dev/null @@ -1,57 +0,0 @@ -{ -"component": { -"kind": "horizontalpodautoscaler", -"schema": "{\"description\":\"configuration of a horizontal pod autoscaler.\",\"properties\":{\"spec\":{\"allOf\":[{\"description\":\"specification of a horizontal pod autoscaler.\",\"properties\":{\"maxReplicas\":{\"default\":0,\"description\":\"maxReplicas is the upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.\",\"format\":\"int32\",\"type\":\"integer\"},\"minReplicas\":{\"description\":\"minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down. It defaults to 1 pod. minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured. Scaling is active as long as at least one metric value is available.\",\"format\":\"int32\",\"type\":\"integer\"},\"scaleTargetRef\":{\"allOf\":[{\"description\":\"CrossVersionObjectReference contains enough information to let you identify the referred resource.\",\"properties\":{\"apiVersion\":{\"description\":\"apiVersion is the API version of the referent\",\"type\":\"string\"},\"kind\":{\"default\":\"\",\"description\":\"kind is the kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"name\":{\"default\":\"\",\"description\":\"name is the name of the referent; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names\",\"type\":\"string\"}},\"required\":[\"kind\",\"name\"],\"type\":\"object\",\"x-kubernetes-map-type\":\"atomic\"}],\"default\":{},\"description\":\"reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption and will set the desired number of pods by using its Scale subresource.\"},\"targetCPUUtilizationPercentage\":{\"description\":\"targetCPUUtilizationPercentage is the target average CPU utilization (represented as a percentage of requested CPU) over all the pods; if not specified the default autoscaling policy will be used.\",\"format\":\"int32\",\"type\":\"integer\"}},\"required\":[\"scaleTargetRef\",\"maxReplicas\"],\"type\":\"object\"}],\"default\":{},\"description\":\"spec defines the behaviour of autoscaler. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.\"}},\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"autoscaling\",\"kind\":\"HorizontalPodAutoscaler\",\"version\":\"v1\"}]}", -"version": "autoscaling/v1" -}, -"configuration": null, -"description": "", -"displayName": "horizontalpodautoscaler", -"format": "JSON", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"genealogy": "", -"isAnnotation": false, -"isNamespaced": false, -"published": false -}, -"model": { -"category": { -"name": "Orchestration \u0026 Management" -}, -"displayName": "Kubernetes", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", -"svgColor": "", -"svgWhite": "" -}, -"model": { -"version": "version" -}, -"name": "kubernetes", -"registrant": { -"created_at": "0001-01-01T00:00:00Z", -"credential_id": "00000000-0000-0000-0000-000000000000", -"deleted_at": "0001-01-01T00:00:00Z", -"id": "00000000-0000-0000-0000-000000000000", -"kind": "", -"name": "", -"status": "", -"sub_type": "", -"type": "", -"updated_at": "0001-01-01T00:00:00Z", -"user_id": "00000000-0000-0000-0000-000000000000" -}, -"connection_id": "00000000-0000-0000-0000-000000000000", -"schemaVersion": "models.meshery.io/v1beta1", -"status": "", -"version": "v1.0.0", -"components": null, -"relationships": null -}, -"schemaVersion": "components.meshery.io/v1beta1", -"status": null, -"styles": null, -"version": "v1.0.0" -} \ No newline at end of file diff --git a/generators/github/kubernetes/horizontalpodautoscalerlist.json b/generators/github/kubernetes/horizontalpodautoscalerlist.json deleted file mode 100644 index 175ce10b..00000000 --- a/generators/github/kubernetes/horizontalpodautoscalerlist.json +++ /dev/null @@ -1,57 +0,0 @@ -{ -"component": { -"kind": "horizontalpodautoscalerlist", -"schema": "{\"description\":\"list of horizontal pod autoscaler objects.\",\"properties\":{\"items\":{\"description\":\"items is the list of horizontal pod autoscaler objects.\",\"items\":{\"allOf\":[{\"description\":\"configuration of a horizontal pod autoscaler.\",\"properties\":{\"apiVersion\":{\"description\":\"APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources\",\"type\":\"string\"},\"kind\":{\"description\":\"Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"metadata\":{\"allOf\":[{\"description\":\"ObjectMeta is metadata that all persisted resources must have, which includes all objects users must create.\",\"properties\":{\"annotations\":{\"additionalProperties\":{\"default\":\"\",\"type\":\"string\"},\"description\":\"Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations\",\"type\":\"object\"},\"creationTimestamp\":{\"allOf\":[{\"description\":\"Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.\",\"format\":\"date-time\",\"type\":\"string\"}],\"description\":\"CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.\\n\\nPopulated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata\"},\"deletionGracePeriodSeconds\":{\"description\":\"Number of seconds allowed for this object to gracefully terminate before it will be removed from the system. Only set when deletionTimestamp is also set. May only be shortened. Read-only.\",\"format\":\"int64\",\"type\":\"integer\"},\"deletionTimestamp\":{\"allOf\":[{\"description\":\"Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.\",\"format\":\"date-time\",\"type\":\"string\"}],\"description\":\"DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted. This field is set by the server when a graceful deletion is requested by the user, and is not directly settable by a client. The resource is expected to be deleted (no longer visible from resource lists, and not reachable by name) after the time in this field, once the finalizers list is empty. As long as the finalizers list contains items, deletion is blocked. Once the deletionTimestamp is set, this value may not be unset or be set further into the future, although it may be shortened or the resource may be deleted prior to this time. For example, a user may request that a pod is deleted in 30 seconds. The Kubelet will react by sending a graceful termination signal to the containers in the pod. After that 30 seconds, the Kubelet will send a hard termination signal (SIGKILL) to the container and after cleanup, remove the pod from the API. In the presence of network partitions, this object may still exist after this timestamp, until an administrator or automated process can determine the resource is fully terminated. If not set, graceful deletion of the object has not been requested.\\n\\nPopulated by the system when a graceful deletion is requested. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata\"},\"finalizers\":{\"description\":\"Must be empty before the object is deleted from the registry. Each entry is an identifier for the responsible component that will remove the entry from the list. If the deletionTimestamp of the object is non-nil, entries in this list can only be removed. Finalizers may be processed and removed in any order. Order is NOT enforced because it introduces significant risk of stuck finalizers. finalizers is a shared field, any actor with permission can reorder it. If the finalizer list is processed in order, then this can lead to a situation in which the component responsible for the first finalizer in the list is waiting for a signal (field value, external system, or other) produced by a component responsible for a finalizer later in the list, resulting in a deadlock. Without enforced ordering finalizers are free to order amongst themselves and are not vulnerable to ordering changes in the list.\",\"items\":{\"default\":\"\",\"type\":\"string\"},\"type\":\"array\",\"x-kubernetes-list-type\":\"set\",\"x-kubernetes-patch-strategy\":\"merge\"},\"generateName\":{\"description\":\"GenerateName is an optional prefix, used by the server, to generate a unique name ONLY IF the Name field has not been provided. If this field is used, the name returned to the client will be different than the name passed. This value will also be combined with a unique suffix. The provided value has the same validation rules as the Name field, and may be truncated by the length of the suffix required to make the value unique on the server.\\n\\nIf this field is specified and the generated name exists, the server will return a 409.\\n\\nApplied only if Name is not specified. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency\",\"type\":\"string\"},\"generation\":{\"description\":\"A sequence number representing a specific generation of the desired state. Populated by the system. Read-only.\",\"format\":\"int64\",\"type\":\"integer\"},\"labels\":{\"additionalProperties\":{\"default\":\"\",\"type\":\"string\"},\"description\":\"Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels\",\"type\":\"object\"},\"managedFields\":{\"description\":\"ManagedFields maps workflow-id and version to the set of fields that are managed by that workflow. This is mostly for internal housekeeping, and users typically shouldn't need to set or understand this field. A workflow can be the user's name, a controller's name, or the name of a specific apply path like \\\"ci-cd\\\". The set of fields is always in the version that the workflow used when modifying the object.\",\"items\":{\"allOf\":[{\"description\":\"ManagedFieldsEntry is a workflow-id, a FieldSet and the group version of the resource that the fieldset applies to.\",\"properties\":{\"apiVersion\":{\"description\":\"APIVersion defines the version of this resource that this field set applies to. The format is \\\"group/version\\\" just like the top-level APIVersion field. It is necessary to track the version of a field set because it cannot be automatically converted.\",\"type\":\"string\"},\"fieldsType\":{\"description\":\"FieldsType is the discriminator for the different fields format and version. There is currently only one possible value: \\\"FieldsV1\\\"\",\"type\":\"string\"},\"fieldsV1\":{\"allOf\":[{\"description\":\"FieldsV1 stores a set of fields in a data structure like a Trie, in JSON format.\\n\\nEach key is either a '.' representing the field itself, and will always map to an empty set, or a string representing a sub-field or item. The string will follow one of these four formats: 'f:\\u003cname\\u003e', where \\u003cname\\u003e is the name of a field in a struct, or key in a map 'v:\\u003cvalue\\u003e', where \\u003cvalue\\u003e is the exact json formatted value of a list item 'i:\\u003cindex\\u003e', where \\u003cindex\\u003e is position of a item in a list 'k:\\u003ckeys\\u003e', where \\u003ckeys\\u003e is a map of a list item's key fields to their unique values If a key maps to an empty Fields value, the field that key represents is part of the set.\\n\\nThe exact format is defined in sigs.k8s.io/structured-merge-diff\",\"type\":\"object\"}],\"description\":\"FieldsV1 holds the first JSON version format as described in the \\\"FieldsV1\\\" type.\"},\"manager\":{\"description\":\"Manager is an identifier of the workflow managing these fields.\",\"type\":\"string\"},\"operation\":{\"description\":\"Operation is the type of operation which lead to this ManagedFieldsEntry being created. The only valid values for this field are 'Apply' and 'Update'.\",\"type\":\"string\"},\"subresource\":{\"description\":\"Subresource is the name of the subresource used to update that object, or empty string if the object was updated through the main resource. The value of this field is used to distinguish between managers, even if they share the same name. For example, a status update will be distinct from a regular update using the same manager name. Note that the APIVersion field is not related to the Subresource field and it always corresponds to the version of the main resource.\",\"type\":\"string\"},\"time\":{\"allOf\":[{\"description\":\"Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.\",\"format\":\"date-time\",\"type\":\"string\"}],\"description\":\"Time is the timestamp of when the ManagedFields entry was added. The timestamp will also be updated if a field is added, the manager changes any of the owned fields value or removes a field. The timestamp does not update when a field is removed from the entry because another manager took it over.\"}},\"type\":\"object\"}],\"default\":{}},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"name\":{\"description\":\"Name must be unique within a namespace. Is required when creating resources, although some resources may allow a client to request the generation of an appropriate name automatically. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names\",\"type\":\"string\"},\"namespace\":{\"description\":\"Namespace defines the space within which each name must be unique. An empty namespace is equivalent to the \\\"default\\\" namespace, but \\\"default\\\" is the canonical representation. Not all objects are required to be scoped to a namespace - the value of this field for those objects will be empty.\\n\\nMust be a DNS_LABEL. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces\",\"type\":\"string\"},\"ownerReferences\":{\"description\":\"List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller.\",\"items\":{\"allOf\":[{\"description\":\"OwnerReference contains enough information to let you identify an owning object. An owning object must be in the same namespace as the dependent, or be cluster-scoped, so there is no namespace field.\",\"properties\":{\"apiVersion\":{\"default\":\"\",\"description\":\"API version of the referent.\",\"type\":\"string\"},\"blockOwnerDeletion\":{\"description\":\"If true, AND if the owner has the \\\"foregroundDeletion\\\" finalizer, then the owner cannot be deleted from the key-value store until this reference is removed. See https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion for how the garbage collector interacts with this field and enforces the foreground deletion. Defaults to false. To set this field, a user needs \\\"delete\\\" permission of the owner, otherwise 422 (Unprocessable Entity) will be returned.\",\"type\":\"boolean\"},\"controller\":{\"description\":\"If true, this reference points to the managing controller.\",\"type\":\"boolean\"},\"kind\":{\"default\":\"\",\"description\":\"Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"name\":{\"default\":\"\",\"description\":\"Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names\",\"type\":\"string\"},\"uid\":{\"default\":\"\",\"description\":\"UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids\",\"type\":\"string\"}},\"required\":[\"apiVersion\",\"kind\",\"name\",\"uid\"],\"type\":\"object\",\"x-kubernetes-map-type\":\"atomic\"}],\"default\":{}},\"type\":\"array\",\"x-kubernetes-list-map-keys\":[\"uid\"],\"x-kubernetes-list-type\":\"map\",\"x-kubernetes-patch-merge-key\":\"uid\",\"x-kubernetes-patch-strategy\":\"merge\"},\"resourceVersion\":{\"description\":\"An opaque value that represents the internal version of this object that can be used by clients to determine when objects have changed. May be used for optimistic concurrency, change detection, and the watch operation on a resource or set of resources. Clients must treat these values as opaque and passed unmodified back to the server. They may only be valid for a particular resource or set of resources.\\n\\nPopulated by the system. Read-only. Value must be treated as opaque by clients and . More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency\",\"type\":\"string\"},\"selfLink\":{\"description\":\"Deprecated: selfLink is a legacy read-only field that is no longer populated by the system.\",\"type\":\"string\"},\"uid\":{\"description\":\"UID is the unique in time and space value for this object. It is typically generated by the server on successful creation of a resource and is not allowed to change on PUT operations.\\n\\nPopulated by the system. Read-only. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids\",\"type\":\"string\"}},\"type\":\"object\"}],\"default\":{},\"description\":\"Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata\"},\"spec\":{\"allOf\":[{\"description\":\"specification of a horizontal pod autoscaler.\",\"properties\":{\"maxReplicas\":{\"default\":0,\"description\":\"maxReplicas is the upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.\",\"format\":\"int32\",\"type\":\"integer\"},\"minReplicas\":{\"description\":\"minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down. It defaults to 1 pod. minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured. Scaling is active as long as at least one metric value is available.\",\"format\":\"int32\",\"type\":\"integer\"},\"scaleTargetRef\":{\"allOf\":[{\"description\":\"CrossVersionObjectReference contains enough information to let you identify the referred resource.\",\"properties\":{\"apiVersion\":{\"description\":\"apiVersion is the API version of the referent\",\"type\":\"string\"},\"kind\":{\"default\":\"\",\"description\":\"kind is the kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"name\":{\"default\":\"\",\"description\":\"name is the name of the referent; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names\",\"type\":\"string\"}},\"required\":[\"kind\",\"name\"],\"type\":\"object\",\"x-kubernetes-map-type\":\"atomic\"}],\"default\":{},\"description\":\"reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption and will set the desired number of pods by using its Scale subresource.\"},\"targetCPUUtilizationPercentage\":{\"description\":\"targetCPUUtilizationPercentage is the target average CPU utilization (represented as a percentage of requested CPU) over all the pods; if not specified the default autoscaling policy will be used.\",\"format\":\"int32\",\"type\":\"integer\"}},\"required\":[\"scaleTargetRef\",\"maxReplicas\"],\"type\":\"object\"}],\"default\":{},\"description\":\"spec defines the behaviour of autoscaler. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status.\"},\"status\":{\"allOf\":[{\"description\":\"current status of a horizontal pod autoscaler\",\"properties\":{\"currentCPUUtilizationPercentage\":{\"description\":\"currentCPUUtilizationPercentage is the current average CPU utilization over all pods, represented as a percentage of requested CPU, e.g. 70 means that an average pod is using now 70% of its requested CPU.\",\"format\":\"int32\",\"type\":\"integer\"},\"currentReplicas\":{\"default\":0,\"description\":\"currentReplicas is the current number of replicas of pods managed by this autoscaler.\",\"format\":\"int32\",\"type\":\"integer\"},\"desiredReplicas\":{\"default\":0,\"description\":\"desiredReplicas is the desired number of replicas of pods managed by this autoscaler.\",\"format\":\"int32\",\"type\":\"integer\"},\"lastScaleTime\":{\"allOf\":[{\"description\":\"Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON. Wrappers are provided for many of the factory methods that the time package offers.\",\"format\":\"date-time\",\"type\":\"string\"}],\"description\":\"lastScaleTime is the last time the HorizontalPodAutoscaler scaled the number of pods; used by the autoscaler to control how often the number of pods is changed.\"},\"observedGeneration\":{\"description\":\"observedGeneration is the most recent generation observed by this autoscaler.\",\"format\":\"int64\",\"type\":\"integer\"}},\"required\":[\"currentReplicas\",\"desiredReplicas\"],\"type\":\"object\"}],\"default\":{},\"description\":\"status is the current information about the autoscaler.\"}},\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"autoscaling\",\"kind\":\"HorizontalPodAutoscaler\",\"version\":\"v1\"}]}],\"default\":{}},\"type\":\"array\"}},\"required\":[\"items\"],\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"autoscaling\",\"kind\":\"HorizontalPodAutoscalerList\",\"version\":\"v1\"}]}", -"version": "autoscaling/v1" -}, -"configuration": null, -"description": "", -"displayName": "horizontalpodautoscalerlist", -"format": "JSON", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"genealogy": "", -"isAnnotation": false, -"isNamespaced": false, -"published": false -}, -"model": { -"category": { -"name": "Orchestration \u0026 Management" -}, -"displayName": "Kubernetes", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", -"svgColor": "", -"svgWhite": "" -}, -"model": { -"version": "version" -}, -"name": "kubernetes", -"registrant": { -"created_at": "0001-01-01T00:00:00Z", -"credential_id": "00000000-0000-0000-0000-000000000000", -"deleted_at": "0001-01-01T00:00:00Z", -"id": "00000000-0000-0000-0000-000000000000", -"kind": "", -"name": "", -"status": "", -"sub_type": "", -"type": "", -"updated_at": "0001-01-01T00:00:00Z", -"user_id": "00000000-0000-0000-0000-000000000000" -}, -"connection_id": "00000000-0000-0000-0000-000000000000", -"schemaVersion": "models.meshery.io/v1beta1", -"status": "", -"version": "v1.0.0", -"components": null, -"relationships": null -}, -"schemaVersion": "components.meshery.io/v1beta1", -"status": null, -"styles": null, -"version": "v1.0.0" -} \ No newline at end of file diff --git a/generators/github/kubernetes/status.json b/generators/github/kubernetes/status.json deleted file mode 100644 index 2eef9691..00000000 --- a/generators/github/kubernetes/status.json +++ /dev/null @@ -1,57 +0,0 @@ -{ -"component": { -"kind": "status", -"schema": "{\"description\":\"Status is a return value for calls that don't return other objects.\",\"properties\":{\"code\":{\"description\":\"Suggested HTTP return code for this status, 0 if not set.\",\"format\":\"int32\",\"type\":\"integer\"},\"details\":{\"allOf\":[{\"description\":\"StatusDetails is a set of additional properties that MAY be set by the server to provide additional information about a response. The Reason field of a Status object defines what attributes will be set. Clients must ignore fields that do not match the defined type of each attribute, and should assume that any attribute may be empty, invalid, or under defined.\",\"properties\":{\"causes\":{\"description\":\"The Causes array includes more details associated with the StatusReason failure. Not all StatusReasons may provide detailed causes.\",\"items\":{\"allOf\":[{\"description\":\"StatusCause provides more information about an api.Status failure, including cases when multiple errors are encountered.\",\"properties\":{\"field\":{\"description\":\"The field of the resource that has caused this error, as named by its JSON serialization. May include dot and postfix notation for nested attributes. Arrays are zero-indexed. Fields may appear more than once in an array of causes due to fields having multiple errors. Optional.\\n\\nExamples:\\n \\\"name\\\" - the field \\\"name\\\" on the current resource\\n \\\"items[0].name\\\" - the field \\\"name\\\" on the first array entry in \\\"items\\\"\",\"type\":\"string\"},\"message\":{\"description\":\"A human-readable description of the cause of the error. This field may be presented as-is to a reader.\",\"type\":\"string\"},\"reason\":{\"description\":\"A machine-readable description of the cause of the error. If this value is empty there is no information available.\",\"type\":\"string\"}},\"type\":\"object\"}],\"default\":{}},\"type\":\"array\",\"x-kubernetes-list-type\":\"atomic\"},\"group\":{\"description\":\"The group attribute of the resource associated with the status StatusReason.\",\"type\":\"string\"},\"kind\":{\"description\":\"The kind attribute of the resource associated with the status StatusReason. On some operations may differ from the requested resource Kind. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds\",\"type\":\"string\"},\"name\":{\"description\":\"The name attribute of the resource associated with the status StatusReason (when there is a single name which can be described).\",\"type\":\"string\"},\"retryAfterSeconds\":{\"description\":\"If specified, the time in seconds before the operation should be retried. Some errors may indicate the client must take an alternate action - for those errors this field may indicate how long to wait before taking the alternate action.\",\"format\":\"int32\",\"type\":\"integer\"},\"uid\":{\"description\":\"UID of the resource. (when there is a single resource which can be described). More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#uids\",\"type\":\"string\"}},\"type\":\"object\"}],\"description\":\"Extended data associated with the reason. Each reason may define its own extended details. This field is optional and the data returned is not guaranteed to conform to any schema except that defined by the reason type.\",\"x-kubernetes-list-type\":\"atomic\"},\"message\":{\"description\":\"A human-readable description of the status of this operation.\",\"type\":\"string\"},\"reason\":{\"description\":\"A machine-readable description of why this operation is in the \\\"Failure\\\" status. If this value is empty there is no information available. A Reason clarifies an HTTP status code but does not override it.\",\"type\":\"string\"}},\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"\",\"kind\":\"Status\",\"version\":\"v1\"}]}", -"version": "v1" -}, -"configuration": null, -"description": "", -"displayName": "status", -"format": "JSON", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"genealogy": "", -"isAnnotation": false, -"isNamespaced": false, -"published": false -}, -"model": { -"category": { -"name": "Orchestration \u0026 Management" -}, -"displayName": "Kubernetes", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", -"svgColor": "", -"svgWhite": "" -}, -"model": { -"version": "version" -}, -"name": "kubernetes", -"registrant": { -"created_at": "0001-01-01T00:00:00Z", -"credential_id": "00000000-0000-0000-0000-000000000000", -"deleted_at": "0001-01-01T00:00:00Z", -"id": "00000000-0000-0000-0000-000000000000", -"kind": "", -"name": "", -"status": "", -"sub_type": "", -"type": "", -"updated_at": "0001-01-01T00:00:00Z", -"user_id": "00000000-0000-0000-0000-000000000000" -}, -"connection_id": "00000000-0000-0000-0000-000000000000", -"schemaVersion": "models.meshery.io/v1beta1", -"status": "", -"version": "v1.0.0", -"components": null, -"relationships": null -}, -"schemaVersion": "components.meshery.io/v1beta1", -"status": null, -"styles": null, -"version": "v1.0.0" -} \ No newline at end of file diff --git a/generators/github/kubernetes/watchevent.json b/generators/github/kubernetes/watchevent.json deleted file mode 100644 index 342c16f8..00000000 --- a/generators/github/kubernetes/watchevent.json +++ /dev/null @@ -1,57 +0,0 @@ -{ -"component": { -"kind": "watchevent", -"schema": "{\"description\":\"Event represents a single event to a watched resource.\",\"properties\":{\"object\":{\"allOf\":[{\"description\":\"RawExtension is used to hold extensions in external versions.\\n\\nTo use this, make a field which has RawExtension as its type in your external, versioned struct, and Object in your internal struct. You also need to register your various plugin types.\\n\\n// Internal package:\\n\\n\\ttype MyAPIObject struct {\\n\\t\\truntime.TypeMeta `json:\\\",inline\\\"`\\n\\t\\tMyPlugin runtime.Object `json:\\\"myPlugin\\\"`\\n\\t}\\n\\n\\ttype PluginA struct {\\n\\t\\tAOption string `json:\\\"aOption\\\"`\\n\\t}\\n\\n// External package:\\n\\n\\ttype MyAPIObject struct {\\n\\t\\truntime.TypeMeta `json:\\\",inline\\\"`\\n\\t\\tMyPlugin runtime.RawExtension `json:\\\"myPlugin\\\"`\\n\\t}\\n\\n\\ttype PluginA struct {\\n\\t\\tAOption string `json:\\\"aOption\\\"`\\n\\t}\\n\\n// On the wire, the JSON will look something like this:\\n\\n\\t{\\n\\t\\t\\\"kind\\\":\\\"MyAPIObject\\\",\\n\\t\\t\\\"apiVersion\\\":\\\"v1\\\",\\n\\t\\t\\\"myPlugin\\\": {\\n\\t\\t\\t\\\"kind\\\":\\\"PluginA\\\",\\n\\t\\t\\t\\\"aOption\\\":\\\"foo\\\",\\n\\t\\t},\\n\\t}\\n\\nSo what happens? Decode first uses json or yaml to unmarshal the serialized data into your external MyAPIObject. That causes the raw JSON to be stored, but not unpacked. The next step is to copy (using pkg/conversion) into the internal struct. The runtime package's DefaultScheme has conversion functions installed which will unpack the JSON stored in RawExtension, turning it into the correct object type, and storing it in the Object. (TODO: In the case where the object is of an unknown type, a runtime.Unknown object will be created and stored.)\",\"type\":\"object\"}],\"description\":\"Object is:\\n * If Type is Added or Modified: the new state of the object.\\n * If Type is Deleted: the state of the object immediately before deletion.\\n * If Type is Error: *Status is recommended; other types may make sense\\n depending on context.\"},\"type\":{\"default\":\"\",\"type\":\"string\"}},\"required\":[\"type\",\"object\"],\"type\":\"object\",\"x-kubernetes-group-version-kind\":[{\"group\":\"\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"admission.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"admission.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"admissionregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"apiextensions.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"apiextensions.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"apiregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"apiregistration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"apps\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"apps\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"apps\",\"kind\":\"WatchEvent\",\"version\":\"v1beta2\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"authentication.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"autoscaling\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"autoscaling\",\"kind\":\"WatchEvent\",\"version\":\"v2\"},{\"group\":\"autoscaling\",\"kind\":\"WatchEvent\",\"version\":\"v2beta1\"},{\"group\":\"autoscaling\",\"kind\":\"WatchEvent\",\"version\":\"v2beta2\"},{\"group\":\"batch\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"batch\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"certificates.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"coordination.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"discovery.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"discovery.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"events.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"events.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"extensions\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta2\"},{\"group\":\"flowcontrol.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta3\"},{\"group\":\"imagepolicy.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"internal.apiserver.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"networking.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"node.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"node.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"node.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"policy\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"policy\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"rbac.authorization.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"resource.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha3\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"scheduling.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"},{\"group\":\"storage.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1beta1\"},{\"group\":\"storagemigration.k8s.io\",\"kind\":\"WatchEvent\",\"version\":\"v1alpha1\"}]}", -"version": "v1" -}, -"configuration": null, -"description": "", -"displayName": "watchevent", -"format": "JSON", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"genealogy": "", -"isAnnotation": false, -"isNamespaced": false, -"published": false -}, -"model": { -"category": { -"name": "Orchestration \u0026 Management" -}, -"displayName": "Kubernetes", -"id": "00000000-0000-0000-0000-000000000000", -"metadata": { -"source_uri": "https://raw.githubusercontent.com/kubernetes/kubernetes/refs/heads/master/api/openapi-spec/v3/apis__autoscaling__v1_openapi.json/v1.31.3", -"svgColor": "", -"svgWhite": "" -}, -"model": { -"version": "version" -}, -"name": "kubernetes", -"registrant": { -"created_at": "0001-01-01T00:00:00Z", -"credential_id": "00000000-0000-0000-0000-000000000000", -"deleted_at": "0001-01-01T00:00:00Z", -"id": "00000000-0000-0000-0000-000000000000", -"kind": "", -"name": "", -"status": "", -"sub_type": "", -"type": "", -"updated_at": "0001-01-01T00:00:00Z", -"user_id": "00000000-0000-0000-0000-000000000000" -}, -"connection_id": "00000000-0000-0000-0000-000000000000", -"schemaVersion": "models.meshery.io/v1beta1", -"status": "", -"version": "v1.0.0", -"components": null, -"relationships": null -}, -"schemaVersion": "components.meshery.io/v1beta1", -"status": null, -"styles": null, -"version": "v1.0.0" -} \ No newline at end of file From 45521cd6e072dba4e2bd0e989e1724a7a860e842 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 30 Sep 2024 15:41:41 +0530 Subject: [PATCH 11/13] finalize changes Signed-off-by: MUzairS15 --- utils/component/generator.go | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/utils/component/generator.go b/utils/component/generator.go index 0b974245..b228b363 100644 --- a/utils/component/generator.go +++ b/utils/component/generator.go @@ -7,7 +7,6 @@ import ( "cuelang.org/go/cue" "github.com/layer5io/meshkit/utils" - "github.com/layer5io/meshkit/utils/kubernetes" "github.com/layer5io/meshkit/utils/manifests" "github.com/meshery/schemas/models/v1beta1" "github.com/meshery/schemas/models/v1beta1/component" @@ -63,38 +62,28 @@ func Generate(resource string) (component.ComponentDefinition, error) { cmp.SchemaVersion = v1beta1.ComponentSchemaVersion cmp.Metadata = component.ComponentDefinition_Metadata{} - isCRD := kubernetes.IsCRD(resource) - - cueValue, err := cueValueFromResource(resource, isCRD) + crdCue, err := utils.YamlToCue(resource) if err != nil { return cmp, err } - var specPath string - if isCRD { - specPath = DefaultPathConfig.SpecPath - } else { - specPath = "components.schemas" - } - var schema string for _, cfg := range Configs { - cfg.SpecPath = specPath - schema, err = getSchema(cueValue, cfg) + schema, err = getSchema(crdCue, cfg) if err == nil { break } } cmp.Component.Schema = schema - name, err := extractCueValueFromPath(cueValue, DefaultPathConfig.NamePath) + name, err := extractCueValueFromPath(crdCue, DefaultPathConfig.NamePath) if err != nil { return cmp, err } - version, err := extractCueValueFromPath(cueValue, DefaultPathConfig.VersionPath) + version, err := extractCueValueFromPath(crdCue, DefaultPathConfig.VersionPath) if err != nil { return cmp, err } - group, err := extractCueValueFromPath(cueValue, DefaultPathConfig.GroupPath) + group, err := extractCueValueFromPath(crdCue, DefaultPathConfig.GroupPath) if err != nil { return cmp, err } @@ -102,7 +91,7 @@ func Generate(resource string) (component.ComponentDefinition, error) { if cmp.Metadata.AdditionalProperties == nil { cmp.Metadata.AdditionalProperties = make(map[string]interface{}) } - scope, _ := extractCueValueFromPath(cueValue, DefaultPathConfig.ScopePath) + scope, _ := extractCueValueFromPath(crdCue, DefaultPathConfig.ScopePath) if scope == "Cluster" { cmp.Metadata.IsNamespaced = false } else if scope == "Namespaced" { @@ -120,14 +109,6 @@ func Generate(resource string) (component.ComponentDefinition, error) { return cmp, nil } -func cueValueFromResource(resource string, isCRD bool) (cue.Value, error) { - if isCRD { - return utils.YamlToCue(resource) - } else { - return utils.JsonToCue([]byte(resource)) - } -} - /* Find and modify specific schema properties. 1. Identify interesting properties by walking entire schema. From 98a1e99e5fc1bf7874de9a9557b8558a2ab8e61b Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 30 Sep 2024 15:53:31 +0530 Subject: [PATCH 12/13] finalize changes Signed-off-by: MUzairS15 --- generators/github/package.go | 2 +- utils/component/openapi_generator.go | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/generators/github/package.go b/generators/github/package.go index aff3be4b..e7efea6c 100644 --- a/generators/github/package.go +++ b/generators/github/package.go @@ -51,7 +51,7 @@ func (gp GitHubPackage) GenerateComponents() ([]_component.ComponentDefinition, comps, err := component.GenerateFromOpenAPI(string(crd), gp) if err != nil { - errs = append(errs, err) + errs = append(errs, component.ErrGetSchema(err)) continue } components = append(components, comps...) diff --git a/utils/component/openapi_generator.go b/utils/component/openapi_generator.go index 12d37a59..f1acf67d 100644 --- a/utils/component/openapi_generator.go +++ b/utils/component/openapi_generator.go @@ -30,8 +30,12 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo } cuectx := cuecontext.New() cueParsedManExpr, err := cueJson.Extract("", []byte(resource)) + if err != nil { + return nil, err + } + parsedManifest := cuectx.BuildExpr(cueParsedManExpr) - definitions := parsedManifest.LookupPath(cue.ParsePath("components.schemas")) + definitions, err := utils.Lookup(parsedManifest, "components.schemas") if err != nil { return nil, err @@ -46,8 +50,8 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo for fields.Next() { fieldVal := fields.Value() - kindCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].kind`)) - if kindCue.Err() != nil { + kindCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].kind`) + if err != nil { continue } kind, err := kindCue.String() @@ -62,8 +66,16 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo fmt.Printf("%v", err) continue } - versionCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].version`)) - groupCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].group`)) + versionCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].version`) + if err != nil { + continue + } + + groupCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].group`) + if err != nil { + continue + } + apiVersion, _ := versionCue.String() if g, _ := groupCue.String(); g != "" { apiVersion = g + "/" + apiVersion @@ -140,8 +152,12 @@ func getResolvedManifest(manifest string) (string, error) { cuectx := cuecontext.New() cueParsedManExpr, err := cueJson.Extract("", byt) + if err != nil { + return "", ErrGetSchema(err) + } + parsedManifest := cuectx.BuildExpr(cueParsedManExpr) - definitions := parsedManifest.LookupPath(cue.ParsePath("components.schemas")) + definitions, err := utils.Lookup(parsedManifest, "components.schemas") if err != nil { return "", err } From d889a68359a1f9de0462a53e06ca21c9aca62cc1 Mon Sep 17 00:00:00 2001 From: Lee Calcote Date: Mon, 30 Sep 2024 16:24:54 -0500 Subject: [PATCH 13/13] Revert "support generation of model from openapi schemas" --- encoding/convert.go | 15 --- generators/artifacthub/package.go | 8 -- generators/github/package.go | 59 +++------ generators/models/interfaces.go | 2 - utils/component/generator.go | 15 +-- utils/component/openapi_generator.go | 172 --------------------------- utils/component/utils.go | 16 ++- utils/helm/helm.go | 9 +- utils/kubernetes/crd.go | 19 +-- utils/manifests/utils.go | 15 ++- 10 files changed, 45 insertions(+), 285 deletions(-) delete mode 100644 encoding/convert.go delete mode 100644 utils/component/openapi_generator.go diff --git a/encoding/convert.go b/encoding/convert.go deleted file mode 100644 index 5dc810eb..00000000 --- a/encoding/convert.go +++ /dev/null @@ -1,15 +0,0 @@ -package encoding - -import ( - "gopkg.in/yaml.v3" -) - -func ToYaml(data []byte) ([]byte, error) { - var out map[string]interface{} - err := Unmarshal(data, &out) - if err != nil { - return nil, err - } - - return yaml.Marshal(out) -} diff --git a/generators/artifacthub/package.go b/generators/artifacthub/package.go index e40509d8..61b3d8be 100644 --- a/generators/artifacthub/package.go +++ b/generators/artifacthub/package.go @@ -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 diff --git a/generators/github/package.go b/generators/github/package.go index e7efea6c..0c632ef9 100644 --- a/generators/github/package.go +++ b/generators/github/package.go @@ -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" @@ -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) @@ -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") diff --git a/generators/models/interfaces.go b/generators/models/interfaces.go index c6dcd3eb..19f61177 100644 --- a/generators/models/interfaces.go +++ b/generators/models/interfaces.go @@ -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. diff --git a/utils/component/generator.go b/utils/component/generator.go index b228b363..288f2780 100644 --- a/utils/component/generator.go +++ b/utils/component/generator.go @@ -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) diff --git a/utils/component/openapi_generator.go b/utils/component/openapi_generator.go deleted file mode 100644 index f1acf67d..00000000 --- a/utils/component/openapi_generator.go +++ /dev/null @@ -1,172 +0,0 @@ -package component - -import ( - "encoding/json" - "fmt" - "strings" - - "cuelang.org/go/cue" - "cuelang.org/go/cue/cuecontext" - cueJson "cuelang.org/go/encoding/json" - "github.com/layer5io/meshkit/generators/models" - "github.com/layer5io/meshkit/utils" - "github.com/layer5io/meshkit/utils/manifests" - - "gopkg.in/yaml.v3" - - "github.com/meshery/schemas/models/v1beta1" - "github.com/meshery/schemas/models/v1beta1/category" - "github.com/meshery/schemas/models/v1beta1/component" - "github.com/meshery/schemas/models/v1beta1/model" -) - -func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.ComponentDefinition, error) { - if resource == "" { - return nil, nil - } - resource, err := getResolvedManifest(resource) - if err != nil { - return nil, err - } - cuectx := cuecontext.New() - cueParsedManExpr, err := cueJson.Extract("", []byte(resource)) - if err != nil { - return nil, err - } - - parsedManifest := cuectx.BuildExpr(cueParsedManExpr) - definitions, err := utils.Lookup(parsedManifest, "components.schemas") - - if err != nil { - return nil, err - } - - fields, err := definitions.Fields() - if err != nil { - fmt.Printf("%v\n", err) - return nil, err - } - components := make([]component.ComponentDefinition, 0) - - for fields.Next() { - fieldVal := fields.Value() - kindCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].kind`) - if err != nil { - continue - } - kind, err := kindCue.String() - kind = strings.ToLower(kind) - if err != nil { - fmt.Printf("%v", err) - continue - } - - crd, err := fieldVal.MarshalJSON() - if err != nil { - fmt.Printf("%v", err) - continue - } - versionCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].version`) - if err != nil { - continue - } - - groupCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].group`) - if err != nil { - continue - } - - apiVersion, _ := versionCue.String() - if g, _ := groupCue.String(); g != "" { - apiVersion = g + "/" + apiVersion - } - modified := make(map[string]interface{}) //Remove the given fields which is either not required by End user (like status) or is prefilled by system (like apiVersion, kind and metadata) - err = json.Unmarshal(crd, &modified) - if err != nil { - fmt.Printf("%v", err) - continue - } - - modifiedProps, err := UpdateProperties(fieldVal, cue.ParsePath("properties.spec"), apiVersion) - if err == nil { - modified = modifiedProps - } - - DeleteFields(modified) - crd, err = json.Marshal(modified) - if err != nil { - fmt.Printf("%v", err) - continue - } - - c := component.ComponentDefinition{ - SchemaVersion: v1beta1.ComponentSchemaVersion, - Version: "v1.0.0", - - Format: component.JSON, - Component: component.Component{ - Kind: kind, - Version: apiVersion, - Schema: string(crd), - }, - // Metadata: compMetadata, - DisplayName: manifests.FormatToReadableString(kind), - Model: model.ModelDefinition{ - SchemaVersion: v1beta1.ModelSchemaVersion, - Version: "v1.0.0", - - Model: model.Model{ - Version: pkg.GetVersion(), - }, - Name: pkg.GetName(), - DisplayName: manifests.FormatToReadableString(pkg.GetName()), - Category: category.CategoryDefinition{ - Name: "Orchestration & Management", - }, - Metadata: &model.ModelDefinition_Metadata{ - AdditionalProperties: map[string]interface{}{ - "source_uri": pkg.GetSourceURL(), - }, - }, - }, - } - - components = append(components, c) - } - return components, nil - -} - -func getResolvedManifest(manifest string) (string, error) { - var m map[string]interface{} - - err := yaml.Unmarshal([]byte(manifest), &m) - if err != nil { - return "", utils.ErrDecodeYaml(err) - } - - byt, err := json.Marshal(m) - if err != nil { - return "", utils.ErrMarshal(err) - } - - cuectx := cuecontext.New() - cueParsedManExpr, err := cueJson.Extract("", byt) - if err != nil { - return "", ErrGetSchema(err) - } - - parsedManifest := cuectx.BuildExpr(cueParsedManExpr) - definitions, err := utils.Lookup(parsedManifest, "components.schemas") - if err != nil { - return "", err - } - resol := manifests.ResolveOpenApiRefs{} - cache := make(map[string][]byte) - resolved, err := resol.ResolveReferences(byt, definitions, cache) - if err != nil { - return "", err - } - manifest = string(resolved) - return manifest, nil -} diff --git a/utils/component/utils.go b/utils/component/utils.go index f04ded45..f63d6068 100644 --- a/utils/component/utils.go +++ b/utils/component/utils.go @@ -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) @@ -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 } diff --git a/utils/helm/helm.go b/utils/helm/helm.go index 091e5902..4af65eed 100644 --- a/utils/helm/helm.go +++ b/utils/helm/helm.go @@ -9,7 +9,6 @@ import ( "regexp" "strings" - "github.com/layer5io/meshkit/encoding" "github.com/layer5io/meshkit/utils" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" @@ -109,13 +108,7 @@ func writeToFile(w io.Writer, path string) error { if err != nil { return utils.ErrReadFile(err, path) } - - byt, err := encoding.ToYaml(data) - if err != nil { - return utils.ErrWriteFile(err, path) - } - - _, err = w.Write(byt) + _, err = w.Write(data) if err != nil { return utils.ErrWriteFile(err, path) } diff --git a/utils/kubernetes/crd.go b/utils/kubernetes/crd.go index 9bf8d991..0525a624 100644 --- a/utils/kubernetes/crd.go +++ b/utils/kubernetes/crd.go @@ -4,7 +4,6 @@ import ( "context" "github.com/layer5io/meshkit/encoding" - "github.com/layer5io/meshkit/utils" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/rest" ) @@ -54,19 +53,7 @@ func GetGVRForCustomResources(crd *CRDItem) *schema.GroupVersionResource { } } -func IsCRD(manifest string) bool { - cueValue, err := utils.YamlToCue(manifest) - if err != nil { - return false - } - kind, err := utils.Lookup(cueValue, "kind") - if err != nil { - return false - } - kindStr, err := kind.String() - if err != nil { - return false - } - - return kindStr == "CustomResourceDefinition" +func IsCRD(manifest map[string]interface{}) bool { + kind, ok := manifest["kind"].(string) + return ok && kind == "CustomResourceDefinition" } diff --git a/utils/manifests/utils.go b/utils/manifests/utils.go index 2935f1c0..fb3990f7 100644 --- a/utils/manifests/utils.go +++ b/utils/manifests/utils.go @@ -9,7 +9,6 @@ import ( "strings" "cuelang.org/go/cue" - "github.com/layer5io/meshkit/encoding" "github.com/layer5io/meshkit/models/oam/core/v1alpha1" ) @@ -255,7 +254,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue cache = make(map[string][]byte) } var val map[string]interface{} - err := encoding.Unmarshal(manifest, &val) + err := json.Unmarshal(manifest, &val) if err != nil { return nil, err } @@ -267,7 +266,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue if ro.isInsideJsonSchemaProps && (ref == JsonSchemaPropsRef) { // hack so that the UI doesn't crash val["$ref"] = "string" - marVal, errJson := encoding.Marshal(val) + marVal, errJson := json.Marshal(val) if errJson != nil { return manifest, nil } @@ -283,13 +282,13 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue newval = append(newval, v0) continue } - byt, _ := encoding.Marshal(v0) + byt, _ := json.Marshal(v0) byt, err = ro.ResolveReferences(byt, definitions, cache) if err != nil { return nil, err } var newvalmap map[string]interface{} - _ = encoding.Unmarshal(byt, &newvalmap) + _ = json.Unmarshal(byt, &newvalmap) newval = append(newval, newvalmap) } val[k] = newval @@ -334,7 +333,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue if reflect.ValueOf(v).Kind() == reflect.Map { var marVal []byte var def []byte - marVal, err = encoding.Marshal(v) + marVal, err = json.Marshal(v) if err != nil { return nil, err } @@ -350,7 +349,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue } } } - res, err := encoding.Marshal(val) + res, err := json.Marshal(val) if err != nil { return nil, err } @@ -359,7 +358,7 @@ func (ro *ResolveOpenApiRefs) ResolveReferences(manifest []byte, definitions cue func replaceRefWithVal(def []byte, val map[string]interface{}, k string) error { var defVal map[string]interface{} - err := encoding.Unmarshal([]byte(def), &defVal) + err := json.Unmarshal([]byte(def), &defVal) if err != nil { return err }