Skip to content

Commit 8b54747

Browse files
authored
Merge pull request #99 from gr455/mcr
Fix Multicontext for incluster
2 parents 6d47854 + e2ac284 commit 8b54747

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

appmesh/app_mesh.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
internalconfig "github.com/layer5io/meshery-app-mesh/internal/config"
1313
meshkitCfg "github.com/layer5io/meshkit/config"
1414
"github.com/layer5io/meshkit/logger"
15+
"github.com/layer5io/meshkit/models"
1516
"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
17+
"gopkg.in/yaml.v2"
1618
)
1719

1820
// AppMesh is the app-mesh adapter. It embeds adapter.Adapter
@@ -26,17 +28,22 @@ func New(c meshkitCfg.Handler, l logger.Handler, kc meshkitCfg.Handler) adapter.
2628
Adapter: adapter.Adapter{
2729
Config: c,
2830
Log: l,
31+
KubeconfigHandler: kc,
2932
},
3033
}
3134
}
3235

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

3845
operations := make(adapter.Operations)
39-
err := appMesh.Config.GetObject(adapter.OperationsKey, &operations)
46+
err = appMesh.Config.GetObject(adapter.OperationsKey, &operations)
4047
if err != nil {
4148
return err
4249
}
@@ -137,9 +144,58 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
137144
return nil
138145
}
139146

147+
//CreateKubeconfigs creates and writes passed kubeconfig onto the filesystem
148+
func (appMesh *AppMesh) CreateKubeconfigs(kubeconfigs []string) error {
149+
var errs = make([]error, 0)
150+
for _, kubeconfig := range kubeconfigs {
151+
kconfig := models.Kubeconfig{}
152+
err := yaml.Unmarshal([]byte(kubeconfig), &kconfig)
153+
if err != nil {
154+
errs = append(errs, err)
155+
continue
156+
}
157+
158+
// To have control over what exactly to take in on kubeconfig
159+
appMesh.KubeconfigHandler.SetKey("kind", kconfig.Kind)
160+
appMesh.KubeconfigHandler.SetKey("apiVersion", kconfig.APIVersion)
161+
appMesh.KubeconfigHandler.SetKey("current-context", kconfig.CurrentContext)
162+
err = appMesh.KubeconfigHandler.SetObject("preferences", kconfig.Preferences)
163+
if err != nil {
164+
errs = append(errs, err)
165+
continue
166+
}
167+
168+
err = appMesh.KubeconfigHandler.SetObject("clusters", kconfig.Clusters)
169+
if err != nil {
170+
errs = append(errs, err)
171+
continue
172+
}
173+
174+
err = appMesh.KubeconfigHandler.SetObject("users", kconfig.Users)
175+
if err != nil {
176+
errs = append(errs, err)
177+
continue
178+
}
179+
180+
err = appMesh.KubeconfigHandler.SetObject("contexts", kconfig.Contexts)
181+
if err != nil {
182+
errs = append(errs, err)
183+
continue
184+
}
185+
}
186+
if len(errs) == 0 {
187+
return nil
188+
}
189+
return mergeErrors(errs)
190+
}
191+
140192
// ProcessOAM handles the grpc invocation for handling OAM objects
141193
func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest, hchan *chan interface{}) (string, error) {
142194
appMesh.SetChannel(hchan)
195+
err := appMesh.CreateKubeconfigs(oamReq.K8sConfigs)
196+
if err != nil {
197+
return "", err
198+
}
143199
kubeConfigs := oamReq.K8sConfigs
144200

145201
var comps []v1alpha1.Component

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ replace (
1010
)
1111

1212
require (
13-
github.com/layer5io/meshery-adapter-library v0.5.5
13+
github.com/layer5io/meshery-adapter-library v0.5.6
1414
github.com/layer5io/meshkit v0.5.17
1515
github.com/layer5io/service-mesh-performance v0.3.4
1616
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,8 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
878878
github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
879879
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34 h1:QaViadDOBCMDUwYx78kfRvHMkzRVnh/GOhm3s2gxoP4=
880880
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw=
881-
github.com/layer5io/meshery-adapter-library v0.5.5 h1:4dGsHBDCLnkOOA/RaUM5n4bPdEdySREnkd3raU9LSDI=
882-
github.com/layer5io/meshery-adapter-library v0.5.5/go.mod h1:YmLV0w6ucBagrqUB0x9q8ZVXrhN1tJBP5j+Pu6LOY/M=
881+
github.com/layer5io/meshery-adapter-library v0.5.6 h1:pbZTMkWNcGWPk314K7WhO4UGVxSnKvGLmwQXBWZ05GI=
882+
github.com/layer5io/meshery-adapter-library v0.5.6/go.mod h1:YmLV0w6ucBagrqUB0x9q8ZVXrhN1tJBP5j+Pu6LOY/M=
883883
github.com/layer5io/meshkit v0.5.16/go.mod h1:tj5TAjty7T/WJ8YvlDfOZF94t4g3mhWuKBCc6MOUoNU=
884884
github.com/layer5io/meshkit v0.5.17 h1:QnNuIj5CVLfaZyznEAMrwt51QImpVpQ8BTcOZOIOWhI=
885885
github.com/layer5io/meshkit v0.5.17/go.mod h1:tj5TAjty7T/WJ8YvlDfOZF94t4g3mhWuKBCc6MOUoNU=

0 commit comments

Comments
 (0)