Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update components & models to v1beta1 schema definitions #158

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions adapter/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package adapter

const (
ComponentDefinition = "component"
)
14 changes: 7 additions & 7 deletions adapter/meshmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"time"

backoff "github.com/cenkalti/backoff/v4"
"github.com/layer5io/meshkit/models/meshmodel/core/types"
"github.com/layer5io/meshkit/models/meshmodel/core/v1alpha1"
"github.com/layer5io/meshkit/models/meshmodel/core/v1beta1"
"github.com/layer5io/meshkit/models/meshmodel/entity"
"github.com/layer5io/meshkit/models/meshmodel/registry"
)

Expand All @@ -19,7 +19,7 @@ type MeshModelRegistrantDefinitionPath struct {
// EntityDefinitionPath holds the path for Entity Definition file
EntityDefintionPath string

Type types.CapabilityType
Type string
// Host is the address of the gRPC host capable of processing the request
Host string
Port int
Expand Down Expand Up @@ -55,15 +55,15 @@ func (or *MeshModelRegistrant) Register(ctxID string) error {
if err != nil {
return ErrOpenOAMDefintionFile(err)
}
mrd.Host = registry.Host{
mrd.Host = v1beta1.Host{
Hostname: dpath.Host,
Port: dpath.Port,
Metadata: ctxID,
}
mrd.EntityType = dpath.Type
mrd.EntityType = entity.EntityType(dpath.Type)
switch dpath.Type {
case types.ComponentDefinition:
var cd v1alpha1.ComponentDefinition
case ComponentDefinition:
var cd v1beta1.ComponentDefinition
if err := json.NewDecoder(definition).Decode(&cd); err != nil {
_ = definition.Close()
return ErrJSONMarshal(err)
Expand Down
24 changes: 11 additions & 13 deletions adapter/oam.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
"time"

meshmodel "github.com/layer5io/meshkit/models/meshmodel/core/v1alpha1"
meshmodel "github.com/layer5io/meshkit/models/meshmodel/core/v1beta1"
"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/manifests"
Expand Down Expand Up @@ -67,11 +67,10 @@ func CreateComponents(scfg StaticCompConfig) error {
return ErrCreatingComponents(errors.New("no components found"))
}

for i, def := range comp.Definitions {
schema := comp.Schemas[i]
for _, def := range comp.Definitions {
name := getNameFromWorkloadDefinition([]byte(def))
meshmodelFileName := name + "_meshmodel.json"
err = createMeshModelComponentsFromLegacyOAMComponents([]byte(def), schema, filepath.Join(meshmodelDir, meshmodelFileName), scfg.MeshModelName, scfg.MeshModelConfig)
err = createMeshModelComponentsFromLegacyOAMComponents([]byte(def), filepath.Join(meshmodelDir, meshmodelFileName), scfg.MeshModelName, scfg.MeshModelConfig)
if err != nil {
return ErrCreatingComponents(err)
}
Expand All @@ -85,7 +84,7 @@ func CreateComponents(scfg StaticCompConfig) error {
}
code-sleuth marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
func convertOAMtoMeshmodel(def []byte, schema string, isCore bool, meshmodelname string, mcfg MeshModelConfig) ([]byte, error) {
func convertOAMtoMeshmodel(def []byte, isCore bool, meshmodelname string, mcfg MeshModelConfig) ([]byte, error) {
var oamdef v1alpha1.WorkloadDefinition
err := json.Unmarshal(def, &oamdef)
if err != nil {
Expand All @@ -107,21 +106,20 @@ func convertOAMtoMeshmodel(def []byte, schema string, isCore bool, meshmodelname
}
c.Metadata = mcfg.Metadata
if isCore {
c.APIVersion = oamdef.APIVersion
c.Kind = oamdef.ObjectMeta.Name
c.Metadata["apiVersion"] = oamdef.APIVersion
c.Metadata["kind"] = oamdef.ObjectMeta.Name
c.Model.Version = oamdef.Spec.Metadata["version"]
c.Model.Name = meshmodelname
} else {
c.APIVersion = oamdef.Spec.Metadata["k8sAPIVersion"]
c.Kind = oamdef.Spec.Metadata["k8sKind"]
c.Metadata["apiVersion"] = oamdef.Spec.Metadata["k8sAPIVersion"]
c.Metadata["kind"] = oamdef.Spec.Metadata["k8sKind"]
c.Model.Version = oamdef.Spec.Metadata["meshVersion"]
c.Model.Name = oamdef.Spec.Metadata["meshName"]
}
c.Model.DisplayName = manifests.FormatToReadableString(c.Model.Name)
c.Model.Name = strings.ToLower(c.Model.Name)
c.Model.Metadata = c.Metadata
c.Format = meshmodel.JSON
c.Schema = schema
byt, err := json.Marshal(c)
if err != nil {
return nil, err
Expand All @@ -130,8 +128,8 @@ func convertOAMtoMeshmodel(def []byte, schema string, isCore bool, meshmodelname
}

// TODO: After OAM is completely removed from meshkit, replace this with fetching native meshmodel components. For now, reuse OAM functions
func createMeshModelComponentsFromLegacyOAMComponents(def []byte, schema string, path string, meshmodel string, mcfg MeshModelConfig) (err error) {
byt, err := convertOAMtoMeshmodel(def, schema, false, meshmodel, mcfg)
func createMeshModelComponentsFromLegacyOAMComponents(def []byte, path string, meshmodel string, mcfg MeshModelConfig) (err error) {
byt, err := convertOAMtoMeshmodel(def, false, meshmodel, mcfg)
if err != nil {
return err
}
Expand Down Expand Up @@ -256,4 +254,4 @@ type DynamicComponentsConfig struct {
GenerationMethod string
Config manifests.Config
Operation string
}
}
4 changes: 1 addition & 3 deletions adapter/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"path/filepath"
"strconv"
"sync"

"github.com/layer5io/meshkit/models/meshmodel/core/types"
)

var (
Expand All @@ -34,7 +32,7 @@ func RegisterMeshModelComponents(uuid, runtime, host, port string) error {
EntityDefintionPath: pathSet.meshmodelDefinitionPath,
Host: host,
Port: portint,
Type: types.ComponentDefinition,
Type: ComponentDefinition,
})
}

Expand Down
69 changes: 39 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34
github.com/layer5io/meshkit v0.6.84
github.com/layer5io/meshkit v0.7.27
github.com/layer5io/service-mesh-performance v0.3.4
github.com/spf13/viper v1.17.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0
golang.org/x/text v0.14.0
google.golang.org/grpc v1.58.3
google.golang.org/protobuf v1.31.0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.33.0
)

require (
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cuelang.org/go v0.6.0 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
Expand All @@ -32,7 +34,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/cockroachdb/apd/v3 v3.2.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/containerd/containerd v1.7.11 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
Expand All @@ -48,7 +50,7 @@ require (
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
Expand All @@ -59,14 +61,18 @@ require (
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
Expand All @@ -78,7 +84,8 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jackc/pgx/v5 v5.5.4 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
Expand All @@ -95,7 +102,7 @@ require (
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -111,46 +118,48 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/image-spec v1.1.0-rc6 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rubenv/sql-migrate v1.5.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.152.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand All @@ -167,13 +176,13 @@ require (
k8s.io/client-go v0.29.0 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect
k8s.io/kubectl v0.29.0 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
oras.land/oras-go v1.2.4 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading