Skip to content

Commit

Permalink
Merge branch 'master' into chore/get-release-tag-commit-sha
Browse files Browse the repository at this point in the history
  • Loading branch information
jerensl authored Oct 28, 2024
2 parents 2f9a323 + 868cbfb commit a8f16fb
Show file tree
Hide file tree
Showing 77 changed files with 2,654 additions and 1,068 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/slack.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
name: Slack Notify on Star
on: watch
name: Slack Notify
on:
watch:
types: [started]
jobs:
star-notify:
if: github.event_name == 'watch'
name: Notify Slack on star
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Get current star count
run: |
echo "STARS=$(curl --silent 'https://api.github.com/repos/layer5io/meshkit' -H 'Accept: application/vnd.github.preview' | jq '.watchers_count')" >> $GITHUB_ENV
echo "STARS=$(curl --silent 'https://api.github.com/repos/${{github.repository}}' -H 'Accept: application/vnd.github.preview' | jq '.stargazers_count')" >> $GITHUB_ENV
- name: Notify slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: pullreminders/slack-action@master
with:
args: '{\"channel\":\"CSK7N9TGX\",\"text\":\"${{ github.actor }} just starred Meshkit! (https://github.com/layer5io/meshkit/stargazers) Total ⭐️: ${{env.STARS}}\"}'
args: '{\"channel\":\"CSK7N9TGX\",\"text\":\"${{ github.actor }} just starred ${{github.repository}}! (https://github.com/${{github.repository}}/stargazers) Total ⭐️: ${{env.STARS}}\"}'
good-first-issue-notify:
if: github.event_name == 'issues' && github.event.label.name == 'good first issue' || github.event.label.name == 'first-timers-only'
name: Notify Slack for new good-first-issue
runs-on: ubuntu-22.04
steps:
- name: Notify slack
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
uses: pullreminders/slack-action@master
with:
args: '{\"channel\":\"C019426UBNY\",\"text\":\"A good first issue label was just added to ${{github.event.issue.html_url}}.\"}'
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
2 changes: 1 addition & 1 deletion cmd/syncmodutil/internal/modsync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func getRequiredVersionsFromString(s string) (p []Package) {
if pkg == "" {
continue
}

pkgName, pkgVersion := getPackageAndVersionFromPackageVersion(pkg)
if strings.HasPrefix(pkgName, "//") { //Has been commented out
continue
Expand Down
3 changes: 2 additions & 1 deletion config/provider/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"sync"

"github.com/layer5io/meshkit/config"
"github.com/layer5io/meshkit/encoding"
"github.com/layer5io/meshkit/utils"
)

Expand Down Expand Up @@ -54,7 +55,7 @@ func (l *InMem) GetKey(key string) string {
func (l *InMem) GetObject(key string, result interface{}) error {
l.mutex.Lock()
defer l.mutex.Unlock()
return utils.Unmarshal(l.store[key], result)
return encoding.Unmarshal([]byte(l.store[key]), result)
}

// SetObject sets an object value for the key
Expand Down
85 changes: 85 additions & 0 deletions converter/k8s.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package converter

import (
"bytes"

"github.com/layer5io/meshkit/models/patterns"
"github.com/layer5io/meshkit/utils"
"github.com/meshery/schemas/models/v1beta1/component"
"github.com/meshery/schemas/models/v1beta1/pattern"
"gopkg.in/yaml.v3"
)

type K8sConverter struct{}

func (k *K8sConverter) Convert(patternFile string) (string, error) {
pattern, err := patterns.GetPatternFormat(patternFile)
if err != nil {
return "", err
}

patterns.ProcessAnnotations(pattern)
return NewK8sManifestsFromPatternfile(pattern)
}

func NewK8sManifestsFromPatternfile(patternFile *pattern.PatternFile) (string, error) {

buf := bytes.NewBufferString("")

enc := yaml.NewEncoder(buf)
for _, comp := range patternFile.Components {
err := enc.Encode(CreateK8sResourceStructure(comp))
if err != nil {
return "", err
}
}
return buf.String(), nil
}

func CreateK8sResourceStructure(comp *component.ComponentDefinition) map[string]interface{} {
annotations := map[string]interface{}{}
labels := map[string]interface{}{}
namespace := "default"

_confMetadata, ok := comp.Configuration["metadata"]
if ok {
confMetadata, err := utils.Cast[map[string]interface{}](_confMetadata)
if err == nil {

_annotations, ok := confMetadata["annotations"]
if ok {
annotations, _ = utils.Cast[map[string]interface{}](_annotations)
}

_label, ok := confMetadata["labels"]
if ok {
labels, _ = utils.Cast[map[string]interface{}](_label)
}

_ns, ok := confMetadata["namespace"]
if ok {
namespace, _ = utils.Cast[string](_ns)
}
}
}

component := map[string]interface{}{
"apiVersion": comp.Component.Version,
"kind": comp.Component.Kind,
"metadata": map[string]interface{}{
"name": comp.DisplayName,
"annotations": annotations,
"labels": labels,
"namespace": namespace,
},
}

for k, v := range comp.Configuration {
if k == "apiVersion" || k == "kind" || k == "metadata" || k == "namespace" {
continue
}

component[k] = v
}
return component
}
15 changes: 15 additions & 0 deletions encoding/convert.go
Original file line number Diff line number Diff line change
@@ -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)
}
64 changes: 64 additions & 0 deletions encoding/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package encoding

import (
"encoding/json"

"github.com/layer5io/meshkit/utils"
"gopkg.in/yaml.v2"
)

// Unmarshal parses the JSON/YAML data and stores the result in the value pointed to by out
func Unmarshal(data []byte, out interface{}) error {
err := unmarshalJSON(data, out)
if err != nil {
err = unmarshalYAML(data, out)
if err != nil {
return err
}
}
return nil
}

func unmarshalYAML(data []byte, result interface{}) error {
err := yaml.Unmarshal(data, result)
if err != nil {
return ErrDecodeYaml(err)
}
return nil
}

func unmarshalJSON(data []byte, result interface{}) error {

err := json.Unmarshal(data, result)
if err != nil {
if e, ok := err.(*json.SyntaxError); ok {
return ErrUnmarshalSyntax(err, e.Offset)
}
if e, ok := err.(*json.UnmarshalTypeError); ok {
return ErrUnmarshalType(err, e.Value)
}
if e, ok := err.(*json.UnsupportedTypeError); ok {
return ErrUnmarshalUnsupportedType(err, e.Type)
}
if e, ok := err.(*json.UnsupportedValueError); ok {
return ErrUnmarshalUnsupportedValue(err, e.Value)
}
if e, ok := err.(*json.InvalidUnmarshalError); ok {
return ErrUnmarshalInvalid(err, e.Type)
}
return ErrUnmarshal(err)
}
return nil
}

func Marshal(in interface{}) ([]byte, error) {
result, err := json.Marshal(in)
if err != nil {
result, err = yaml.Marshal(in)
if err != nil {
return nil, utils.ErrMarshal(err)
}
}

return result, nil
}
47 changes: 47 additions & 0 deletions encoding/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package encoding

import (
"reflect"
"strconv"

"github.com/layer5io/meshkit/errors"
)

const (
ErrDecodeYamlCode = ""
ErrUnmarshalCode = ""
ErrUnmarshalInvalidCode = ""
ErrUnmarshalSyntaxCode = ""
ErrUnmarshalTypeCode = ""
ErrUnmarshalUnsupportedTypeCode = ""
ErrUnmarshalUnsupportedValueCode = ""
)

// ErrDecodeYaml is the error when the yaml unmarshal fails
func ErrDecodeYaml(err error) error {
return errors.New(ErrDecodeYamlCode, errors.Alert, []string{"Error occurred while decoding YAML"}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid YAML object"})
}

func ErrUnmarshal(err error) error {
return errors.New(ErrUnmarshalCode, errors.Alert, []string{"Unmarshal unknown error: "}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}

func ErrUnmarshalInvalid(err error, typ reflect.Type) error {
return errors.New(ErrUnmarshalInvalidCode, errors.Alert, []string{"Unmarshal invalid error for type: ", typ.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}

func ErrUnmarshalSyntax(err error, offset int64) error {
return errors.New(ErrUnmarshalSyntaxCode, errors.Alert, []string{"Unmarshal syntax error at offest: ", strconv.Itoa(int(offset))}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}

func ErrUnmarshalType(err error, value string) error {
return errors.New(ErrUnmarshalTypeCode, errors.Alert, []string{"Unmarshal type error at key: %s. Error: %s", value}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}

func ErrUnmarshalUnsupportedType(err error, typ reflect.Type) error {
return errors.New(ErrUnmarshalUnsupportedTypeCode, errors.Alert, []string{"Unmarshal unsupported type error at key: ", typ.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}

func ErrUnmarshalUnsupportedValue(err error, value reflect.Value) error {
return errors.New(ErrUnmarshalUnsupportedValueCode, errors.Alert, []string{"Unmarshal unsupported value error at key: ", value.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"})
}
5 changes: 5 additions & 0 deletions generators/artifacthub/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package artifacthub

const (
ArtifactHub = "artifacthub"
)
29 changes: 20 additions & 9 deletions generators/artifacthub/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"strings"
"time"

"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"
"github.com/meshery/schemas/models/v1beta1/category"
_component "github.com/meshery/schemas/models/v1beta1/component"
"github.com/meshery/schemas/models/v1beta1/model"
"gopkg.in/yaml.v2"
)

Expand All @@ -36,8 +38,16 @@ func (pkg AhPackage) GetVersion() string {
return pkg.Version
}

func (pkg AhPackage) GenerateComponents() ([]v1beta1.ComponentDefinition, error) {
components := make([]v1beta1.ComponentDefinition, 0)
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

if pkg.ChartUrl == "" {
Expand All @@ -52,16 +62,17 @@ func (pkg AhPackage) GenerateComponents() ([]v1beta1.ComponentDefinition, error)
if err != nil {
continue
}
if comp.Metadata == nil {
comp.Metadata = make(map[string]interface{})
}
if comp.Model.Metadata == nil {
comp.Model.Metadata = make(map[string]interface{})
comp.Model.Metadata = &model.ModelDefinition_Metadata{}
}

if comp.Model.Metadata.AdditionalProperties == nil {
comp.Model.Metadata.AdditionalProperties = make(map[string]interface{})
}
comp.Model.Metadata["source_uri"] = pkg.ChartUrl
comp.Model.Metadata.AdditionalProperties["source_uri"] = pkg.ChartUrl
comp.Model.Version = pkg.Version
comp.Model.Name = pkg.Name
comp.Model.Category = v1beta1.Category{
comp.Model.Category = category.CategoryDefinition{
Name: "",
}
comp.Model.DisplayName = manifests.FormatToReadableString(comp.Model.Name)
Expand Down
5 changes: 5 additions & 0 deletions generators/github/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package github

const (
GitHub = "github"
)
2 changes: 1 addition & 1 deletion generators/github/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func fileInterceptor(br *bufio.Writer) walker.FileInterceptor {
// Add more calrifying commment and entry inside docs.
func dirInterceptor(br *bufio.Writer) walker.DirInterceptor {
return func(d walker.Directory) error {
err := helm.ConvertToK8sManifest(d.Path, br)
err := helm.ConvertToK8sManifest(d.Path, "", br)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit a8f16fb

Please sign in to comment.