Skip to content

Commit

Permalink
Merge branch 'master' into missingNameSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
Jougan-0 authored Oct 14, 2024
2 parents 21e7b72 + 62137a0 commit 4224be0
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 19 deletions.
18 changes: 1 addition & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ Or you may configure your IDE, for example, Visual Studio Code to automatically

<a href="https://user-images.githubusercontent.com/7570704/64490167-98906400-d25a-11e9-8b8a-5f465b854d49.png" ><img src="https://user-images.githubusercontent.com/7570704/64490167-98906400-d25a-11e9-8b8a-5f465b854d49.png" width="50%"><a>

## <a name="contributing-docs">Documentation Contribution Flow</a>
Please contribute! Layer5 documentation uses Jekyll and GitHub Pages to host docs sites. Learn more about [Layer5's documentation framework](https://docs.google.com/document/d/17guuaxb0xsfutBCzyj2CT6OZiFnMu9w4PzoILXhRXSo/edit?usp=sharing). The process of contributing follows this flow:

1. Create a fork, if you have not already, by following the steps described [here](./CONTRIBUTING-gitflow.md)
1. In the local copy of your fork, navigate to the docs folder.
`cd docs`
1. Create and checkout a new branch to make changes within
`git checkout -b <my-changes>`
1. Edit/add documentation.
`vi <specific page>.md`
1. Run site locally to preview changes.
`make site`
1. Commit, [sign-off](#commit-signing), and push changes to your remote branch.
`git push origin <my-changes>`
1. Open a pull request (in your web browser) against the repo.


#### Tests
Users can now test their code on their local machine against the CI checks implemented using `make run-tests`.
Expand All @@ -92,7 +76,7 @@ All contributors are invited to review pull requests. See this short video on [h
Resources: https://lab.github.com and https://try.github.com/


# FQA
# FAQs

### Instructions for making custom dictionary entries

Expand Down
3 changes: 3 additions & 0 deletions models/meshmodel/registry/v1alpha3/relationship_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func (relationshipFilter *RelationshipFilter) Get(db *database.Handler) ([]entit
if relationshipFilter.SubType != "" {
finder = finder.Where("relationship_definition_dbs.sub_type = ?", relationshipFilter.SubType)
}
if relationshipFilter.Id != "" {
finder = finder.Where("relationship_definition_dbs.id = ?", relationshipFilter.Id)
}
if relationshipFilter.ModelName != "" {
finder = finder.Where("model_dbs.name = ?", relationshipFilter.ModelName)
}
Expand Down
3 changes: 3 additions & 0 deletions models/meshmodel/registry/v1beta1/category_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (cf *CategoryFilter) Get(db *database.Handler) ([]entity.Entity, int64, int
finder = finder.Where("name = ?", cf.Name)
}
}
if cf.Id != "" {
finder = finder.Where("id = ?", cf.Id)
}
if cf.OrderOn != "" {
if cf.Sort == "desc" {
finder = finder.Order(clause.OrderByColumn{Column: clause.Column{Name: cf.OrderOn}, Desc: true})
Expand Down
4 changes: 3 additions & 1 deletion models/meshmodel/registry/v1beta1/component_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ func (componentFilter *ComponentFilter) Get(db *database.Handler) ([]entity.Enti
if componentFilter.Version != "" {
finder = finder.Where("model_dbs.model->>'version' = ?", componentFilter.Version)
}

if componentFilter.Id != "" {
finder = finder.Where("component_definition_dbs.id = ?", componentFilter.Id)
}
if componentFilter.OrderOn != "" {
if componentFilter.Sort == "desc" {
finder = finder.Order(clause.OrderByColumn{Column: clause.Column{Name: componentFilter.OrderOn}, Desc: true})
Expand Down
3 changes: 3 additions & 0 deletions models/meshmodel/registry/v1beta1/model_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func (mf *ModelFilter) Get(db *database.Handler) ([]entity.Entity, int64, int, e
} else if mf.Annotations == "false" {
finder = finder.Where("model_dbs.metadata->>'isAnnotation' = false")
}
if mf.Id != "" {
finder = finder.Where("model_dbs.id = ?", mf.Id)
}
if mf.OrderOn != "" {
if mf.Sort == "desc" {
finder = finder.Order(clause.OrderByColumn{Column: clause.Column{Name: mf.OrderOn}, Desc: true})
Expand Down
4 changes: 3 additions & 1 deletion models/meshmodel/registry/v1beta1/policy_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func (pf *PolicyFilter) Get(db *database.Handler) ([]entity.Entity, int64, int,
if pf.ModelName != "" {
finder = finder.Where("model_dbs.name = ?", pf.ModelName)
}

if pf.Id != "" {
finder = finder.Where("policy_definition_dbs.id = ?", pf.Id)
}
var count int64
finder.Count(&count)

Expand Down
44 changes: 44 additions & 0 deletions utils/component/openapi_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"

"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
Expand Down Expand Up @@ -100,6 +101,26 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo
continue
}

// Determine if the resource is namespaced
var isNamespaced bool

scopeCue, err := utils.Lookup(fieldVal, `"x-kubernetes-resource".scope`)
if err == nil {
scope, err := scopeCue.String()
if err == nil {
if scope == "Namespaced" {
isNamespaced = true
} else if scope == "Cluster" {
isNamespaced = false
}
}
} else {
isNamespaced, err = getResourceScope(resource, kind)
if err != nil {
isNamespaced = false
}
}

c := component.ComponentDefinition{
SchemaVersion: v1beta1.ComponentSchemaVersion,
Format: component.JSON,
Expand All @@ -109,6 +130,9 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo
Schema: string(crd),
},
DisplayName: manifests.FormatToReadableString(kind),
Metadata: component.ComponentDefinition_Metadata{
IsNamespaced: isNamespaced,
},
Model: model.ModelDefinition{
SchemaVersion: v1beta1.ModelSchemaVersion,
Model: model.Model{
Expand All @@ -127,7 +151,27 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo
components = append(components, c)
}
return components, nil
}
func getResourceScope(manifest string, kind string) (bool, error) {
var m map[string]interface{}

err := yaml.Unmarshal([]byte(manifest), &m)
if err != nil {
return false, utils.ErrDecodeYaml(err)
}

paths, ok := m["paths"].(map[string]interface{})
if !ok {
return false, fmt.Errorf("paths not found in manifest")
}

for path := range paths {
if strings.Contains(path, "/namespaces/{namespace}/") && strings.Contains(path, strings.ToLower(kind)) {
return true, nil // Resource is namespaced
}
}

return false, nil // Resource is cluster-scoped
}

func getResolvedManifest(manifest string) (string, error) {
Expand Down

0 comments on commit 4224be0

Please sign in to comment.