Skip to content

Commit

Permalink
Merge pull request #484 from MUzairS15/MUzairS15/feat/v1beta1
Browse files Browse the repository at this point in the history
[Server] Upgrade to `v1beta1` schema.
  • Loading branch information
leecalcote authored May 5, 2024
2 parents 2a1ef52 + ab974c8 commit 3da3150
Show file tree
Hide file tree
Showing 40 changed files with 1,202 additions and 1,267 deletions.
8 changes: 4 additions & 4 deletions generators/artifacthub/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/layer5io/meshkit/models/meshmodel/core/v1alpha1"
"github.com/layer5io/meshkit/models/meshmodel/core/v1beta1"
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/component"
"github.com/layer5io/meshkit/utils/manifests"
Expand Down Expand Up @@ -36,8 +36,8 @@ func (pkg AhPackage) GetVersion() string {
return pkg.Version
}

func (pkg AhPackage) GenerateComponents() ([]v1alpha1.ComponentDefinition, error) {
components := make([]v1alpha1.ComponentDefinition, 0)
func (pkg AhPackage) GenerateComponents() ([]v1beta1.ComponentDefinition, error) {
components := make([]v1beta1.ComponentDefinition, 0)
// TODO: Move this to the configuration
crds, err := manifests.GetCrdsFromHelm(pkg.ChartUrl)
if err != nil {
Expand All @@ -57,7 +57,7 @@ func (pkg AhPackage) GenerateComponents() ([]v1alpha1.ComponentDefinition, error
comp.Model.Metadata["source_uri"] = pkg.ChartUrl
comp.Model.Version = pkg.Version
comp.Model.Name = pkg.Name
comp.Model.Category = v1alpha1.Category{
comp.Model.Category = v1beta1.Category{
Name: "",
}
comp.Model.DisplayName = manifests.FormatToReadableString(comp.Model.Name)
Expand Down
2 changes: 1 addition & 1 deletion generators/artifacthub/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package artifacthub
import (
"fmt"

"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/generators/models"
)

type ArtifactHubPackageManager struct {
Expand Down
2 changes: 1 addition & 1 deletion generators/artifacthub/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestGetChartUrl(t *testing.T) {
}
byt, _ := json.MarshalIndent(comp, "", "")

f, err := os.Create(dirName + "/" + comp.Kind + ".json")
f, err := os.Create(dirName + "/" + comp.Component.Kind + ".json")
if err != nil {
t.Errorf("error create file : %v", err)
continue
Expand Down
2 changes: 1 addition & 1 deletion generators/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/layer5io/meshkit/generators/artifacthub"
"github.com/layer5io/meshkit/generators/github"
"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/generators/models"
"github.com/layer5io/meshkit/utils"
)

Expand Down
9 changes: 4 additions & 5 deletions generators/github/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package github
import (
"bufio"
"fmt"
"github.com/layer5io/meshkit/generators/models"
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/helm"
"github.com/layer5io/meshkit/utils/walker"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/helm"
"github.com/layer5io/meshkit/utils/walker"
)

type GitRepo struct {
Expand Down
8 changes: 4 additions & 4 deletions generators/github/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"os"

"github.com/layer5io/meshkit/models/meshmodel/core/v1alpha1"
"github.com/layer5io/meshkit/models/meshmodel/core/v1beta1"
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/component"
"github.com/layer5io/meshkit/utils/manifests"
Expand All @@ -23,8 +23,8 @@ func (gp GitHubPackage) GetVersion() string {
return gp.version
}

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

data, err := os.ReadFile(gp.filePath)
if err != nil {
Expand All @@ -49,7 +49,7 @@ func (gp GitHubPackage) GenerateComponents() ([]v1alpha1.ComponentDefinition, er
comp.Model.Metadata["source_uri"] = gp.SourceURL
comp.Model.Version = gp.version
comp.Model.Name = gp.Name
comp.Model.Category = v1alpha1.Category{
comp.Model.Category = v1beta1.Category{
Name: "",
}
comp.Model.DisplayName = manifests.FormatToReadableString(comp.Model.Name)
Expand Down
2 changes: 1 addition & 1 deletion generators/github/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package github
import (
"net/url"

"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/generators/models"
"github.com/layer5io/meshkit/utils/walker"
)

Expand Down
4 changes: 2 additions & 2 deletions generators/github/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ func TestGenerateCompFromGitHub(t *testing.T) {
}
byt, _ := json.MarshalIndent(comp, "", "")

f, err := os.Create(fmt.Sprintf("%s/%s%s", dirName, comp.Kind, ".json"))
f, err := os.Create(fmt.Sprintf("%s/%s%s", dirName, comp.Component.Kind, ".json"))
if err != nil {
t.Errorf("error creating file for %s: %v", comp.Kind, err)
t.Errorf("error creating file for %s: %v", comp.Component.Kind, err)
continue
}
_, _ = f.Write(byt)
Expand Down
2 changes: 1 addition & 1 deletion generators/github/scheme_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package github
import (
"net/url"

"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/generators/models"
)

type DownloaderScheme interface {
Expand Down
2 changes: 1 addition & 1 deletion generators/github/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"

"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/generators/models"
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/helm"
)
Expand Down
4 changes: 2 additions & 2 deletions models/interfaces.go → generators/models/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package models

import "github.com/layer5io/meshkit/models/meshmodel/core/v1alpha1"
import "github.com/layer5io/meshkit/models/meshmodel/core/v1beta1"

// anything that can be validated is a Validator
type Validator interface {
Expand All @@ -11,7 +11,7 @@ type Validator interface {
// system's capabilities in Meshery
// A Package should have all the information that we need to generate the components
type Package interface {
GenerateComponents() ([]v1alpha1.ComponentDefinition, error)
GenerateComponents() ([]v1beta1.ComponentDefinition, error)
GetVersion() string
}

Expand Down
18 changes: 1 addition & 17 deletions models/meshmodel/core/policies/data_models.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
package policies

// Define a simple policy struct
type RegoPolicy struct {
Rules string `json:"rules"`
}

type RelationObject struct {
DestinationID string `json:"destination_id,omitempty"`
DestinationName string `json:"destination_name,omitempty"`
SourceId string `json:"source_id,omitempty"`
SourceName string `json:"source_name,omitempty"`
Port map[string]interface{} `json:"port,omitempty"`
}

type NetworkPolicyRegoResponse struct {
ServicePodRelationships []RelationObject `json:"service_pod_relationships,omitempty"`
ServiceDeploymentRelationships []RelationObject `json:"service_deployment_relationships,omitempty"`
}
// Add response struct based on schema for all relationships evaluations. binding, network, hierarchical
8 changes: 5 additions & 3 deletions models/meshmodel/core/policies/rego_policy_relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"github.com/layer5io/meshkit/models/meshmodel/core/v1alpha1"
"github.com/layer5io/meshkit/models/meshmodel/registry"
"github.com/layer5io/meshkit/models/meshmodel/registry/v1alpha2"
"github.com/layer5io/meshkit/utils"
"github.com/open-policy-agent/opa/rego"
"github.com/open-policy-agent/opa/storage"
Expand All @@ -26,7 +26,10 @@ func NewRegoInstance(policyDir string, regManager *registry.RegistryManager) (*R
var store storage.Store

ctx := context.Background()
registeredRelationships, _, _ := regManager.GetEntities(&v1alpha1.RelationshipFilter{})
registeredRelationships, _, _, err := regManager.GetEntities(&v1alpha2.RelationshipFilter{})
if err != nil {
return nil, err
}

if len(registeredRelationships) > 0 {
data := map[string]interface{}{
Expand Down Expand Up @@ -70,7 +73,6 @@ func (r *Rego) RegoPolicyHandler(regoQueryString string, designFile []byte) (int
if err != nil {
return nil, ErrEval(err)
}

if !eval_result.Allowed() {
if len(eval_result) > 0 {
if len(eval_result[0].Expressions) > 0 {
Expand Down
15 changes: 0 additions & 15 deletions models/meshmodel/core/types/types.go

This file was deleted.

83 changes: 0 additions & 83 deletions models/meshmodel/core/v1alpha1/category.go

This file was deleted.

Loading

0 comments on commit 3da3150

Please sign in to comment.