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

Fix Multicontext for incluster #99

Merged
merged 1 commit into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
58 changes: 57 additions & 1 deletion appmesh/app_mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
internalconfig "github.com/layer5io/meshery-app-mesh/internal/config"
meshkitCfg "github.com/layer5io/meshkit/config"
"github.com/layer5io/meshkit/logger"
"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
"gopkg.in/yaml.v2"
)

// AppMesh is the app-mesh adapter. It embeds adapter.Adapter
Expand All @@ -26,17 +28,22 @@ func New(c meshkitCfg.Handler, l logger.Handler, kc meshkitCfg.Handler) adapter.
Adapter: adapter.Adapter{
Config: c,
Log: l,
KubeconfigHandler: kc,
},
}
}

// ApplyOperation applies the requested operation on app-mesh
func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.OperationRequest, hchan *chan interface{}) error {
err := appMesh.CreateKubeconfigs(opReq.K8sConfigs)
if err != nil {
return err
}
kubeConfigs := opReq.K8sConfigs
appMesh.SetChannel(hchan);

operations := make(adapter.Operations)
err := appMesh.Config.GetObject(adapter.OperationsKey, &operations)
err = appMesh.Config.GetObject(adapter.OperationsKey, &operations)
if err != nil {
return err
}
Expand Down Expand Up @@ -137,9 +144,58 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
return nil
}

//CreateKubeconfigs creates and writes passed kubeconfig onto the filesystem
func (appMesh *AppMesh) CreateKubeconfigs(kubeconfigs []string) error {
var errs = make([]error, 0)
for _, kubeconfig := range kubeconfigs {
kconfig := models.Kubeconfig{}
err := yaml.Unmarshal([]byte(kubeconfig), &kconfig)
if err != nil {
errs = append(errs, err)
continue
}

// To have control over what exactly to take in on kubeconfig
appMesh.KubeconfigHandler.SetKey("kind", kconfig.Kind)
appMesh.KubeconfigHandler.SetKey("apiVersion", kconfig.APIVersion)
appMesh.KubeconfigHandler.SetKey("current-context", kconfig.CurrentContext)
err = appMesh.KubeconfigHandler.SetObject("preferences", kconfig.Preferences)
if err != nil {
errs = append(errs, err)
continue
}

err = appMesh.KubeconfigHandler.SetObject("clusters", kconfig.Clusters)
if err != nil {
errs = append(errs, err)
continue
}

err = appMesh.KubeconfigHandler.SetObject("users", kconfig.Users)
if err != nil {
errs = append(errs, err)
continue
}

err = appMesh.KubeconfigHandler.SetObject("contexts", kconfig.Contexts)
if err != nil {
errs = append(errs, err)
continue
}
}
if len(errs) == 0 {
return nil
}
return mergeErrors(errs)
}

// ProcessOAM handles the grpc invocation for handling OAM objects
func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest, hchan *chan interface{}) (string, error) {
appMesh.SetChannel(hchan)
err := appMesh.CreateKubeconfigs(oamReq.K8sConfigs)
if err != nil {
return "", err
}
kubeConfigs := oamReq.K8sConfigs

var comps []v1alpha1.Component
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ replace (
)

require (
github.com/layer5io/meshery-adapter-library v0.5.5
github.com/layer5io/meshery-adapter-library v0.5.6
github.com/layer5io/meshkit v0.5.17
github.com/layer5io/service-mesh-performance v0.3.4
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,8 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34 h1:QaViadDOBCMDUwYx78kfRvHMkzRVnh/GOhm3s2gxoP4=
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw=
github.com/layer5io/meshery-adapter-library v0.5.5 h1:4dGsHBDCLnkOOA/RaUM5n4bPdEdySREnkd3raU9LSDI=
github.com/layer5io/meshery-adapter-library v0.5.5/go.mod h1:YmLV0w6ucBagrqUB0x9q8ZVXrhN1tJBP5j+Pu6LOY/M=
github.com/layer5io/meshery-adapter-library v0.5.6 h1:pbZTMkWNcGWPk314K7WhO4UGVxSnKvGLmwQXBWZ05GI=
github.com/layer5io/meshery-adapter-library v0.5.6/go.mod h1:YmLV0w6ucBagrqUB0x9q8ZVXrhN1tJBP5j+Pu6LOY/M=
github.com/layer5io/meshkit v0.5.16/go.mod h1:tj5TAjty7T/WJ8YvlDfOZF94t4g3mhWuKBCc6MOUoNU=
github.com/layer5io/meshkit v0.5.17 h1:QnNuIj5CVLfaZyznEAMrwt51QImpVpQ8BTcOZOIOWhI=
github.com/layer5io/meshkit v0.5.17/go.mod h1:tj5TAjty7T/WJ8YvlDfOZF94t4g3mhWuKBCc6MOUoNU=
Expand Down