generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into chore/get-release-tag-commit-sha
- Loading branch information
Showing
77 changed files
with
2,654 additions
and
1,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}.\"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package artifacthub | ||
|
||
const ( | ||
ArtifactHub = "artifacthub" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package github | ||
|
||
const ( | ||
GitHub = "github" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.