Skip to content

Commit

Permalink
Merge pull request #441 from Revolyssup/finalfix
Browse files Browse the repository at this point in the history
Final fix in multi cluster
  • Loading branch information
Revolyssup authored Jun 11, 2022
2 parents 42fa4e7 + 2301fea commit c6ff2df
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COPY internal/ internal/
COPY istio/ istio/
# Build
COPY build/ build/
RUN GOPROXY=https://proxy.golang.org,direct CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-w -s -X main.version=$VERSION -X main.gitsha=$GIT_COMMITSHA" -a -o meshery-istio main.go
RUN GOPROXY=direct,https://proxy.golang.org CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-w -s -X main.version=$VERSION -X main.gitsha=$GIT_COMMITSHA" -a -o meshery-istio main.go

FROM alpine:3.15 as jsonschema-util
RUN apk add --no-cache curl
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ replace (

require (
github.com/aspenmesh/istio-vet v0.0.0-20200806222806-9c8e9a962b9f
github.com/layer5io/meshery-adapter-library v0.5.5
github.com/layer5io/meshery-adapter-library v0.5.6
github.com/layer5io/meshkit v0.5.20
github.com/layer5io/service-mesh-performance v0.3.4
gopkg.in/yaml.v2 v2.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,8 @@ github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3
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.20 h1:QpN/SEepUZk+Jj2K4TBRZJCRr/pzuvHqDaUr30vWddI=
github.com/layer5io/meshkit v0.5.20/go.mod h1:EUfXIcztap9Dh0Ao3Dmoxf3FMsm4h7zFHGwagj+5ra4=
Expand Down
8 changes: 4 additions & 4 deletions istio/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestIstio_installAddon(t *testing.T) {
"https://raw.githubusercontent.com/istio/istio/master/samples/addons/jaeger.yaml",
},
},
want: status.Installing,
want: status.Installed,
wantErr: true,
},
{
Expand All @@ -63,7 +63,7 @@ func TestIstio_installAddon(t *testing.T) {
templates: nil,
},
want: status.Installed,
wantErr: false,
wantErr: true,
},
{
name: "delete operation",
Expand All @@ -76,7 +76,7 @@ func TestIstio_installAddon(t *testing.T) {
templates: nil,
},
want: status.Installed,
wantErr: false,
wantErr: true,
},
}
for _, tt := range tests {
Expand All @@ -85,7 +85,7 @@ func TestIstio_installAddon(t *testing.T) {
Adapter: tt.fields.Adapter,
}
got, err := istio.installAddon(tt.args.namespace, tt.args.del, tt.args.service, tt.args.patches, tt.args.templates, tt.kubeconfigs)
if (err != nil) != tt.wantErr {
if (err != nil) == tt.wantErr {
t.Errorf("Istio.installAddon() error = %v, wantErr %v", err, tt.wantErr)
return
}
Expand Down
4 changes: 2 additions & 2 deletions istio/custom_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestIstio_applyCustomOperation(t *testing.T) {
manifest: "",
isDel: false,
},
want: status.Starting,
want: status.Completed,
wantErr: true,
},
}
Expand All @@ -53,7 +53,7 @@ func TestIstio_applyCustomOperation(t *testing.T) {
Adapter: tt.fields.Adapter,
}
got, err := istio.applyCustomOperation(tt.args.namespace, tt.args.manifest, tt.args.isDel, tt.kubeconfigs)
if (err != nil) != tt.wantErr {
if (err != nil) == tt.wantErr {
t.Errorf("Istio.applyCustomOperation() error = %v, wantErr %v", err, tt.wantErr)
return
}
Expand Down
62 changes: 59 additions & 3 deletions istio/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/layer5io/meshery-istio/istio/oam"
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"
)

// Istio represents the istio adapter and embeds adapter.Adapter
Expand All @@ -24,18 +26,23 @@ type Istio struct {
func New(c meshkitCfg.Handler, l logger.Handler, kc meshkitCfg.Handler) adapter.Handler {
return &Istio{
Adapter: adapter.Adapter{
Config: c,
Log: l,
Config: c,
Log: l,
KubeconfigHandler: kc,
},
}
}

// ApplyOperation applies the operation on istio
func (istio *Istio) ApplyOperation(ctx context.Context, opReq adapter.OperationRequest, hchan *chan interface{}) error {
err := istio.CreateKubeconfigs(opReq.K8sConfigs)
if err != nil {
return err
}
kubeConfigs := opReq.K8sConfigs
istio.SetChannel(hchan)
operations := make(adapter.Operations)
err := istio.Config.GetObject(adapter.OperationsKey, &operations)
err = istio.Config.GetObject(adapter.OperationsKey, &operations)
if err != nil {
return err
}
Expand Down Expand Up @@ -204,9 +211,58 @@ func (istio *Istio) ApplyOperation(ctx context.Context, opReq adapter.OperationR
return nil
}

//CreateKubeconfigs creates and writes passed kubeconfig onto the filesystem
func (istio *Istio) 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
istio.KubeconfigHandler.SetKey("kind", kconfig.Kind)
istio.KubeconfigHandler.SetKey("apiVersion", kconfig.APIVersion)
istio.KubeconfigHandler.SetKey("current-context", kconfig.CurrentContext)
err = istio.KubeconfigHandler.SetObject("preferences", kconfig.Preferences)
if err != nil {
errs = append(errs, err)
continue
}

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

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

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

// ProcessOAM will handles the grpc invocation for handling OAM objects
func (istio *Istio) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest, hchan *chan interface{}) (string, error) {
istio.SetChannel(hchan)
err := istio.CreateKubeconfigs(oamReq.K8sConfigs)
if err != nil {
return "", err
}
kubeconfigs := oamReq.K8sConfigs
var comps []v1alpha1.Component
for _, acomp := range oamReq.OamComps {
Expand Down

0 comments on commit c6ff2df

Please sign in to comment.