-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add "service mesh" as category in meshmodel #100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,16 +167,23 @@ func (or *OAMRegistrant) Register() error { | |
return nil | ||
} | ||
|
||
type MeshModelConfig struct { | ||
Category string | ||
SubCategory string | ||
Metadata map[string]interface{} | ||
} | ||
|
||
// StaticCompConfig is used to configure CreateComponents | ||
type StaticCompConfig struct { | ||
MeshModelName string //Used in Adding ModelName onto Core Meshmodel components. Pass it the same as meshName in OAM components | ||
URL string //URL | ||
Method string //Use the constants exported by package. Manifests or Helm | ||
OAMPath string //Where to store the directory.(Each directory will have an array of definitions and schemas) | ||
MeshModelPath string | ||
DirName string //The directory's name. By convention, it should be the version name | ||
Config manifests.Config //Filters required to create definition and schema | ||
Force bool //When set to true, if the file with same name already exists, they will be overridden | ||
MeshModelName string //Used in Adding ModelName onto Core Meshmodel components. Pass it the same as meshName in OAM components | ||
URL string //URL | ||
Method string //Use the constants exported by package. Manifests or Helm | ||
OAMPath string //Where to store the directory.(Each directory will have an array of definitions and schemas) | ||
MeshModelPath string | ||
MeshModelConfig MeshModelConfig | ||
DirName string //The directory's name. By convention, it should be the version name | ||
Config manifests.Config //Filters required to create definition and schema | ||
Force bool //When set to true, if the file with same name already exists, they will be overridden | ||
} | ||
|
||
// CreateComponents generates components for a given configuration and stores them. | ||
|
@@ -235,7 +242,7 @@ func CreateComponents(scfg StaticCompConfig) error { | |
defFileName := name + "_definition.json" | ||
schemaFileName := name + ".meshery.layer5io.schema.json" | ||
meshmodelFileName := name + "_meshmodel.json" | ||
err = createMeshModelComponentsFromLegacyOAMComponents([]byte(def), schema, filepath.Join(meshmodelDir, meshmodelFileName), scfg.MeshModelName) | ||
err = createMeshModelComponentsFromLegacyOAMComponents([]byte(def), schema, filepath.Join(meshmodelDir, meshmodelFileName), scfg.MeshModelName, scfg.MeshModelConfig) | ||
if err != nil { | ||
return ErrCreatingComponents(err) | ||
} | ||
|
@@ -261,27 +268,35 @@ func CreateComponents(scfg StaticCompConfig) error { | |
} | ||
return nil | ||
} | ||
func convertOAMtoMeshmodel(def []byte, schema string, isCore bool, meshmodelname string) ([]byte, error) { | ||
func convertOAMtoMeshmodel(def []byte, schema string, isCore bool, meshmodelname string, mcfg MeshModelConfig) ([]byte, error) { | ||
var oamdef v1alpha1.WorkloadDefinition | ||
err := json.Unmarshal(def, &oamdef) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var c meshmodel.ComponentDefinition | ||
c.Metadata = make(map[string]interface{}) | ||
metaname := strings.Split(manifests.FormatToReadableString(oamdef.ObjectMeta.Name), ".") | ||
var displayname string | ||
if len(metaname) > 0 { | ||
displayname = metaname[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would love for this not to be a numeric index reference, but one that is named instead in order to avoid fragility (slightly). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The length of array is checked above so if code reaches at this line then it is guaranteed to have 0th element. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Readability is also improved when named keys are used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually here I am just doing some string manipulation to extract Readable name from name with suffix like ".Istio". Nothing much to move into a map or struct. |
||
} | ||
c.DisplayName = displayname | ||
c.Model.Category = mcfg.Category | ||
c.Model.SubCategory = mcfg.SubCategory | ||
c.Metadata = mcfg.Metadata | ||
if isCore { | ||
c.APIVersion = oamdef.APIVersion | ||
c.Kind = oamdef.ObjectMeta.Name | ||
c.Model.Version = oamdef.Spec.Metadata["version"] | ||
c.Model.Name = meshmodelname | ||
c.DisplayName = manifests.FormatToReadableString(oamdef.ObjectMeta.Name) | ||
} else { | ||
c.APIVersion = oamdef.Spec.Metadata["k8sAPIVersion"] | ||
c.Kind = oamdef.Spec.Metadata["k8sKind"] | ||
c.Model.Version = oamdef.Spec.Metadata["meshVersion"] | ||
c.Model.Name = oamdef.Spec.Metadata["meshName"] | ||
c.DisplayName = manifests.FormatToReadableString(oamdef.ObjectMeta.Name) | ||
} | ||
c.Model.DisplayName = manifests.FormatToReadableString(c.Model.Name) | ||
c.Format = meshmodel.JSON | ||
c.Schema = schema | ||
byt, err := json.Marshal(c) | ||
|
@@ -292,8 +307,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) (err error) { | ||
byt, err := convertOAMtoMeshmodel(def, schema, false, meshmodel) | ||
func createMeshModelComponentsFromLegacyOAMComponents(def []byte, schema string, path string, meshmodel string, mcfg MeshModelConfig) (err error) { | ||
byt, err := convertOAMtoMeshmodel(def, schema, false, meshmodel, mcfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps there's a more forward-looking descriptor and a more generic one than "OAMPath".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OAMPath is to be removed anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will you open an issue to follow up on removal of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not just this, this along with a lot of other things will be stripped off. That is a part of last phase of MeshModel migration. So this will come under that legend.