Skip to content

Commit

Permalink
Merge pull request #99 from gr455/mcr
Browse files Browse the repository at this point in the history
Fix Multicontext for incluster
  • Loading branch information
Revolyssup authored Jun 11, 2022
2 parents 6d47854 + e2ac284 commit 8b54747
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
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

0 comments on commit 8b54747

Please sign in to comment.