Skip to content

Commit

Permalink
Merge pull request #170 from layer5io/kumarabd/feature/fix
Browse files Browse the repository at this point in the history
fixes for bugs
  • Loading branch information
kumarabd authored Dec 10, 2020
2 parents c88c96b + d423a77 commit 91bafdf
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 43 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
check:
golangci-lint run

protoc-setup:
cd meshes
wget https://raw.githubusercontent.com/layer5io/meshery/master/meshes/meshops.proto
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ replace (

require (
github.com/aspenmesh/istio-vet v0.0.0-20200806222806-9c8e9a962b9f
github.com/layer5io/meshery-adapter-library v0.1.8
github.com/layer5io/meshkit v0.1.29
github.com/layer5io/meshery-adapter-library v0.1.9
github.com/layer5io/meshkit v0.1.30
github.com/onsi/ginkgo v1.13.0 // indirect
golang.org/x/net v0.0.0-20200927032502-5d4f70055728 // indirect
google.golang.org/grpc v1.32.0 // indirect
gopkg.in/yaml.v2 v2.3.0
istio.io/client-go v1.8.0
k8s.io/apimachinery v0.18.12
k8s.io/client-go v0.18.12
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,12 @@ github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f/go.mod h1:LpewBZnN0QDRcC2fDiBVK+iByfFyf2HJM1B2h0rTMZo=
github.com/layer5io/meshery-adapter-library v0.1.8 h1:w0Q0sotVRtz3BQYJb2IhSmyfpLn9JeVWdj6JMreXlmc=
github.com/layer5io/meshery-adapter-library v0.1.8/go.mod h1:V3JWQ6xmtdLF5VYVL+7U9N3MA9CO8uiccE4t0OfjPfk=
github.com/layer5io/meshery-adapter-library v0.1.9 h1:1faPSuaUDIRNMyECElWm/C5fedQDDXRHPAfi1M58T4Y=
github.com/layer5io/meshery-adapter-library v0.1.9/go.mod h1:dxrUzS10o5qDwfJE5qvAAH/s8PzLcRHFu3L4afgSBNc=
github.com/layer5io/meshkit v0.1.29 h1:wfemsp3R7JukX63Q+jejttAAYgF0/O5dA4hcEdwvuMw=
github.com/layer5io/meshkit v0.1.29/go.mod h1:AznOL6xqpUZGyExSZJ3Bdx6EZ22UnAT9V620pm7R484=
github.com/layer5io/meshkit v0.1.30 h1:d9emBQAf+YnURkA5wZ6VbbqDfnx9G8G3xqOv6dG4n/k=
github.com/layer5io/meshkit v0.1.30/go.mod h1:AznOL6xqpUZGyExSZJ3Bdx6EZ22UnAT9V620pm7R484=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY=
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const (
// Constants to use in log statements
IstioOperation = "istio"
LabelNamespace = "label-namespace"
PatchFile = "patch-file"

// Istio vet operation
IstioVetOperation = "istio-vet"

// Configure Envoy filter operation
EnvoyFilterOperation = "envoy-filter-operation"
EnvoyPatchFile = "envoy-patch-file"

// Addons that the adapter supports
PrometheusAddon = "prometheus-addon"
Expand Down
51 changes: 43 additions & 8 deletions internal/config/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ var (
func getOperations(dev adapter.Operations) adapter.Operations {
versions, _ := getLatestReleaseNames(3)

// Add Istio networking resources to sample applications
dev[common.BookInfoOperation].Templates = append(dev[common.BookInfoOperation].Templates, "file://templates/bookinfo-gateway.yaml")
dev[common.HTTPBinOperation].Templates = append(dev[common.HTTPBinOperation].Templates, "file://templates/httpbin-gateway.yaml")
dev[common.ImageHubOperation].Templates = append(dev[common.ImageHubOperation].Templates, "file://templates/imagehub-gateway.yaml")
dev[common.EmojiVotoOperation].Templates = append(dev[common.EmojiVotoOperation].Templates, "file://templates/emojivoto-gateway.yaml")

dev[IstioOperation] = &adapter.Operation{
Type: int32(meshes.OpCategory_INSTALL),
Description: "Istio Service Mesh",
Versions: versions,
AdditionalProperties: map[string]string{},
}

// Add Istio networking resources to sample applications
dev[common.BookInfoOperation].Templates = append(dev[common.BookInfoOperation].Templates, "file://templates/bookinfo-gateway.yaml")
dev[common.HTTPBinOperation].Templates = append(dev[common.HTTPBinOperation].Templates, "file://templates/httpbin-gateway.yaml")
dev[common.ImageHubOperation].Templates = append(dev[common.ImageHubOperation].Templates, "file://templates/imagehub-gateway.yaml")
dev[common.EmojiVotoOperation].Templates = append(dev[common.EmojiVotoOperation].Templates, "file://templates/emojivoto-gateway.yaml")

dev[LabelNamespace] = &adapter.Operation{
Type: int32(meshes.OpCategory_CONFIGURE),
Description: "Automatic Sidecar Injection",
Expand All @@ -34,26 +34,61 @@ func getOperations(dev adapter.Operations) adapter.Operations {
dev[PrometheusAddon] = &adapter.Operation{
Type: int32(meshes.OpCategory_CONFIGURE),
Description: "Add-on: Prometheus",
Templates: []adapter.Template{
"https://raw.githubusercontent.com/istio/istio/master/samples/addons/prometheus.yaml",
},
AdditionalProperties: map[string]string{
ServiceName: "prometheus",
PatchFile: "file://templates/service-patch.json",
},
}

dev[GrafanaAddon] = &adapter.Operation{
Type: int32(meshes.OpCategory_CONFIGURE),
Description: "Add-on: Grafana",
Templates: []adapter.Template{
"https://raw.githubusercontent.com/istio/istio/master/samples/addons/grafana.yaml",
},
AdditionalProperties: map[string]string{
ServiceName: "grafana",
PatchFile: "file://templates/service-patch.json",
},
}

dev[KialiAddon] = &adapter.Operation{
Type: int32(meshes.OpCategory_CONFIGURE),
Description: "Add-on: Kiali",
Templates: []adapter.Template{
"https://raw.githubusercontent.com/istio/istio/master/samples/addons/kiali.yaml",
},
AdditionalProperties: map[string]string{
ServiceName: "kiali",
PatchFile: "file://templates/service-patch.json",
},
}

dev[JaegerAddon] = &adapter.Operation{
Type: int32(meshes.OpCategory_CONFIGURE),
Description: "Add-on: Jaeger",
Templates: []adapter.Template{
"https://raw.githubusercontent.com/istio/istio/master/samples/addons/jaeger.yaml",
},
AdditionalProperties: map[string]string{
ServiceName: "jaeger",
PatchFile: "file://templates/service-patch.json",
},
}

dev[ZipkinAddon] = &adapter.Operation{
Type: int32(meshes.OpCategory_CONFIGURE),
Description: "Add-on: Zipkin",
Templates: []adapter.Template{
"https://raw.githubusercontent.com/istio/istio/master/samples/addons/extras/zipkin.yaml",
},
AdditionalProperties: map[string]string{
ServiceName: "zipkin",
PatchFile: "file://templates/service-patch.json",
},
}

dev[IstioVetOperation] = &adapter.Operation{
Expand All @@ -69,8 +104,8 @@ func getOperations(dev adapter.Operations) adapter.Operations {
"file://templates/imagehub-filter.yaml",
},
AdditionalProperties: map[string]string{
ServiceName: "api-v1",
EnvoyPatchFile: "file://templates/imagehub-patch.json",
ServiceName: "api-v1",
PatchFile: "file://templates/imagehub-patch.json",
},
}

Expand Down
56 changes: 26 additions & 30 deletions istio/addons.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
package istio

import (
"context"
"fmt"
"strings"

"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshery-adapter-library/status"
"github.com/layer5io/meshery-istio/internal/config"
)

// AddonTemplate is as a container for addon templates
var AddonTemplate = map[string]adapter.Template{
config.PrometheusAddon: "https://raw.githubusercontent.com/istio/istio/master/samples/addons/prometheus.yaml",
config.GrafanaAddon: "https://raw.githubusercontent.com/istio/istio/master/samples/addons/grafana.yaml",
config.KialiAddon: "https://raw.githubusercontent.com/istio/istio/master/samples/addons/kiali.yaml",
config.JaegerAddon: "https://raw.githubusercontent.com/istio/istio/master/samples/addons/jaeger.yaml",
config.ZipkinAddon: "https://raw.githubusercontent.com/istio/istio/master/samples/addons/extras/zipkin.yaml",
}

// InstallAddon installs the specified addon in the given namespace
func (istio *Istio) InstallAddon(namespace string, del bool, addon string) (string, error) {
// Some of addons will have a different install process
// than these template based addons
switch addon {
case config.PrometheusAddon, config.GrafanaAddon, config.KialiAddon, config.JaegerAddon, config.ZipkinAddon:
return istio.installAddonFromTemplate(namespace, del, AddonTemplate[addon])
}

return "", ErrAddonInvalidConfig(fmt.Errorf("%s is invalid addon", addon))
}
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

// installAddonFromTemplate installs/uninstalls an addon in the given namespace
// installAddon installs/uninstalls an addon in the given namespace
//
// the template defines the manifest's link/location which needs to be used to
// install the addon
func (istio *Istio) installAddonFromTemplate(namespace string, del bool, template adapter.Template) (string, error) {
istio.Log.Info(fmt.Sprintf("Requested action is delete: %v", del))
func (istio *Istio) installAddon(namespace string, del bool, service string, patch string, templates []adapter.Template) (string, error) {
st := status.Installing

if del {
st = status.Removing
}

contents, err := readFileSource(string(template))
istio.Log.Debug(fmt.Sprintf("Overidden namespace: %s", namespace))
namespace = ""

for _, template := range templates {
contents, err := readFileSource(string(template))
if err != nil {
return st, ErrAddonFromTemplate(err)
}

err = istio.applyManifest([]byte(contents), del, namespace)
// Specifically choosing to ignore kiali dashboard's error.
// Referring to: https://github.com/kiali/kiali/issues/3112
if err != nil && !strings.Contains(err.Error(), "no matches for kind \"MonitoringDashboard\" in version \"monitoring.kiali.io/v1alpha1\"") {
return st, ErrAddonFromTemplate(err)
}
}

jsonContents, err := readFileSource(patch)
if err != nil {
return st, ErrAddonFromTemplate(err)
}

err = istio.applyManifest([]byte(contents), del, namespace)
// Specifically choosing to ignore kiali dashboard's error.
// Referring to: https://github.com/kiali/kiali/issues/3112
if err != nil && !strings.Contains(err.Error(), "no matches for kind \"MonitoringDashboard\" in version \"monitoring.kiali.io/v1alpha1\"") {
_, err = istio.KubeClient.CoreV1().Services("istio-system").Patch(context.TODO(), service, types.MergePatchType, []byte(jsonContents), metav1.PatchOptions{})
if err != nil {
return st, ErrAddonFromTemplate(err)
}

Expand Down
6 changes: 4 additions & 2 deletions istio/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ func (istio *Istio) ApplyOperation(ctx context.Context, opReq adapter.OperationR
}(istio, e)
case internalconfig.PrometheusAddon, internalconfig.GrafanaAddon, internalconfig.KialiAddon, internalconfig.JaegerAddon, internalconfig.ZipkinAddon:
go func(hh *Istio, ee *adapter.Event) {
_, err := hh.InstallAddon(opReq.Namespace, opReq.IsDeleteOperation, opReq.OperationName)
svcname := operations[opReq.OperationName].AdditionalProperties[common.ServiceName]
patch := operations[opReq.OperationName].AdditionalProperties[internalconfig.PatchFile]
_, err := hh.installAddon(opReq.Namespace, opReq.IsDeleteOperation, svcname, patch, operations[opReq.OperationName].Templates)
operation := "install"
if opReq.IsDeleteOperation {
operation = "uninstall"
Expand Down Expand Up @@ -172,7 +174,7 @@ func (istio *Istio) ApplyOperation(ctx context.Context, opReq adapter.OperationR
case internalconfig.EnvoyFilterOperation:
go func(hh *Istio, ee *adapter.Event) {
appName := operations[opReq.OperationName].AdditionalProperties[common.ServiceName]
patchFile := operations[opReq.OperationName].AdditionalProperties[internalconfig.EnvoyPatchFile]
patchFile := operations[opReq.OperationName].AdditionalProperties[internalconfig.PatchFile]
stat, err := hh.patchWithEnvoyFilter(opReq.Namespace, opReq.IsDeleteOperation, appName, operations[opReq.OperationName].Templates, patchFile)
if err != nil {
e.Summary = fmt.Sprintf("Error while %s %s application", stat, appName)
Expand Down
5 changes: 5 additions & 0 deletions templates/service-patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"spec": {
"type": "LoadBalancer"
}
}

0 comments on commit 91bafdf

Please sign in to comment.