Skip to content

Commit f1f8326

Browse files
authored
Merge pull request #165 from layer5io/kumarabd/feature/fix
added policies, gateway resources and envoy filter
2 parents b0612e6 + 968fe53 commit f1f8326

19 files changed

+426
-22
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-w -
1919
# Use distroless as minimal base image to package the manager binary
2020
# Refer to https://github.com/GoogleContainerTools/distroless for more details
2121
FROM gcr.io/distroless/base
22-
WORKDIR /
2322
ENV DISTRO="debian"
2423
ENV GOARCH="amd64"
24+
WORKDIR /templates
25+
COPY templates/* .
26+
WORKDIR /
2527
COPY --from=builder /build/meshery-istio .
2628
ENTRYPOINT ["/meshery-istio"]

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ replace (
99

1010
require (
1111
github.com/aspenmesh/istio-vet v0.0.0-20200806222806-9c8e9a962b9f
12-
github.com/layer5io/meshery-adapter-library v0.1.7
13-
github.com/layer5io/meshkit v0.1.28
12+
github.com/layer5io/meshery-adapter-library v0.1.8
13+
github.com/layer5io/meshkit v0.1.29
1414
github.com/onsi/ginkgo v1.13.0 // indirect
1515
golang.org/x/net v0.0.0-20200927032502-5d4f70055728 // indirect
1616
google.golang.org/grpc v1.32.0 // indirect

go.sum

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,10 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
573573
github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
574574
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f h1:ZwVdDIb9RRXCRfRNUGOgwcyn5WrjfJi7NV64SwQ0Gvo=
575575
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20201022191033-40468652a54f/go.mod h1:LpewBZnN0QDRcC2fDiBVK+iByfFyf2HJM1B2h0rTMZo=
576-
github.com/layer5io/meshery-adapter-library v0.1.7 h1:RSDBbVvjM3HgXEaGp3qd0QW8JuORkXOxe9KE3ll0rMg=
577-
github.com/layer5io/meshery-adapter-library v0.1.7/go.mod h1:IZefiA/D02QB1wUbG8mStUnYA9Pukf+NEQdMYeWQo/o=
578-
github.com/layer5io/meshkit v0.1.27/go.mod h1:AznOL6xqpUZGyExSZJ3Bdx6EZ22UnAT9V620pm7R484=
579-
github.com/layer5io/meshkit v0.1.28 h1:F7DWcm3Txqb0QIqoEcBlp/qIO4s6+5Hp/CExMQM7Gjw=
580-
github.com/layer5io/meshkit v0.1.28/go.mod h1:AznOL6xqpUZGyExSZJ3Bdx6EZ22UnAT9V620pm7R484=
576+
github.com/layer5io/meshery-adapter-library v0.1.8 h1:w0Q0sotVRtz3BQYJb2IhSmyfpLn9JeVWdj6JMreXlmc=
577+
github.com/layer5io/meshery-adapter-library v0.1.8/go.mod h1:V3JWQ6xmtdLF5VYVL+7U9N3MA9CO8uiccE4t0OfjPfk=
578+
github.com/layer5io/meshkit v0.1.29 h1:wfemsp3R7JukX63Q+jejttAAYgF0/O5dA4hcEdwvuMw=
579+
github.com/layer5io/meshkit v0.1.29/go.mod h1:AznOL6xqpUZGyExSZJ3Bdx6EZ22UnAT9V620pm7R484=
581580
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
582581
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
583582
github.com/lib/pq v1.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY=

internal/config/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,24 @@ const (
1616
LabelNamespace = "label-namespace"
1717

1818
// Istio vet operation
19-
IstioVetOpertation = "istio-vet"
19+
IstioVetOperation = "istio-vet"
20+
21+
// Configure Envoy filter operation
22+
EnvoyFilterOperation = "envoy-filter-operation"
23+
EnvoyPatchFile = "envoy-patch-file"
2024

2125
// Addons that the adapter supports
2226
PrometheusAddon = "prometheus-addon"
2327
GrafanaAddon = "grafana-addon"
2428
KialiAddon = "kiali-addon"
2529
JaegerAddon = "jaeger-addon"
2630
ZipkinAddon = "zipkin-addon"
31+
32+
// Policies
33+
DenyAllPolicyOperation = "deny-all-policy-operation"
34+
StrictMTLSPolicyOperation = "strict-mtls-policy-operation"
35+
MutualMTLSPolicyOperation = "mutual-mtls-policy-operation"
36+
DisableMTLSPolicyOperation = "disable-mtls-policy-operation"
2737
)
2838

2939
var (

internal/config/operations.go

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"github.com/layer5io/meshery-adapter-library/adapter"
5+
"github.com/layer5io/meshery-adapter-library/common"
56
"github.com/layer5io/meshery-adapter-library/meshes"
67
)
78

@@ -13,15 +14,18 @@ func getOperations(dev adapter.Operations) adapter.Operations {
1314
versions, _ := getLatestReleaseNames(3)
1415

1516
dev[IstioOperation] = &adapter.Operation{
16-
Type: int32(meshes.OpCategory_INSTALL),
17-
Description: "Istio Service Mesh",
18-
Versions: versions,
19-
Templates: []adapter.Template{
20-
"templates/istio.yaml",
21-
},
17+
Type: int32(meshes.OpCategory_INSTALL),
18+
Description: "Istio Service Mesh",
19+
Versions: versions,
2220
AdditionalProperties: map[string]string{},
2321
}
2422

23+
// Add Istio networking resources to sample applications
24+
dev[common.BookInfoOperation].Templates = append(dev[common.BookInfoOperation].Templates, "file://templates/bookinfo-gateway.yaml")
25+
dev[common.HTTPBinOperation].Templates = append(dev[common.HTTPBinOperation].Templates, "file://templates/httpbin-gateway.yaml")
26+
dev[common.ImageHubOperation].Templates = append(dev[common.ImageHubOperation].Templates, "file://templates/imagehub-gateway.yaml")
27+
dev[common.EmojiVotoOperation].Templates = append(dev[common.EmojiVotoOperation].Templates, "file://templates/emojivoto-gateway.yaml")
28+
2529
dev[LabelNamespace] = &adapter.Operation{
2630
Type: int32(meshes.OpCategory_CONFIGURE),
2731
Description: "Label Namespace for Automatic Sidecar Injection",
@@ -52,10 +56,55 @@ func getOperations(dev adapter.Operations) adapter.Operations {
5256
Description: "Zipkin Dashboard",
5357
}
5458

55-
dev[IstioVetOpertation] = &adapter.Operation{
59+
dev[IstioVetOperation] = &adapter.Operation{
5660
Type: int32(meshes.OpCategory_VALIDATE),
5761
Description: "Analyze Running Configuration",
5862
}
5963

64+
dev[EnvoyFilterOperation] = &adapter.Operation{
65+
Type: int32(meshes.OpCategory_CONFIGURE),
66+
Description: "Envoy Filter for Imagehub",
67+
Versions: adapter.NoneVersion,
68+
Templates: []adapter.Template{
69+
"file://templates/imagehub-filter.yaml",
70+
},
71+
AdditionalProperties: map[string]string{
72+
ServiceName: "api-v1",
73+
EnvoyPatchFile: "file://templates/imagehub-patch.json",
74+
},
75+
}
76+
77+
dev[DenyAllPolicyOperation] = &adapter.Operation{
78+
Type: int32(meshes.OpCategory_CONFIGURE),
79+
Description: "Deny-All Policy",
80+
Templates: []adapter.Template{
81+
"file://templates/policy-denyall.yaml",
82+
},
83+
}
84+
85+
dev[StrictMTLSPolicyOperation] = &adapter.Operation{
86+
Type: int32(meshes.OpCategory_CONFIGURE),
87+
Description: "Strict MTLS Policy",
88+
Templates: []adapter.Template{
89+
"file://templates/policy-strict.yaml",
90+
},
91+
}
92+
93+
dev[MutualMTLSPolicyOperation] = &adapter.Operation{
94+
Type: int32(meshes.OpCategory_CONFIGURE),
95+
Description: "Mutual MTLS Policy",
96+
Templates: []adapter.Template{
97+
"file://templates/policy-mutual.yaml",
98+
},
99+
}
100+
101+
dev[DisableMTLSPolicyOperation] = &adapter.Operation{
102+
Type: int32(meshes.OpCategory_CONFIGURE),
103+
Description: "Disable MTLS Policy",
104+
Templates: []adapter.Template{
105+
"file://templates/policy-disable.yaml",
106+
},
107+
}
108+
60109
return dev
61110
}

istio/error.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ var (
4242
// duing sample app installation
4343
ErrSampleAppCode = "istio_test_code"
4444

45+
// ErrEnvoyFilterCode represents the errors which are generated
46+
// duing envoy filter patching
47+
ErrEnvoyFilterCode = "istio_test_code"
48+
49+
// ErrApplyPolicyCode represents the errors which are generated
50+
// duing policy apply operation
51+
ErrApplyPolicyCode = "istio_test_code"
52+
4553
// ErrCustomOperationCode represents the errors which are generated
4654
// when an invalid addon operation is requested
4755
ErrCustomOperationCode = "istio_test_code"
@@ -111,6 +119,16 @@ func ErrSampleApp(err error) error {
111119
return errors.NewDefault(ErrSampleAppCode, fmt.Sprintf("Error with sample app operation: %s", err.Error()))
112120
}
113121

122+
// ErrEnvoyFilter is the error for streaming event
123+
func ErrEnvoyFilter(err error) error {
124+
return errors.NewDefault(ErrEnvoyFilterCode, fmt.Sprintf("Error with envoy filter operation: %s", err.Error()))
125+
}
126+
127+
// ErrApplyPolicy is the error for streaming event
128+
func ErrApplyPolicy(err error) error {
129+
return errors.NewDefault(ErrApplyPolicyCode, fmt.Sprintf("Error with apply policy operation: %s", err.Error()))
130+
}
131+
114132
// ErrAddonFromTemplate is the error for streaming event
115133
func ErrAddonFromTemplate(err error) error {
116134
return errors.NewDefault(ErrAddonFromTemplateCode, fmt.Sprintf("Error with addon install operation: %s", err.Error()))

istio/install.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
)
2323

2424
func (istio *Istio) installIstio(del bool, version, namespace string) (string, error) {
25-
istio.Log.Info(fmt.Sprintf("Requested install of version: %s", version))
26-
istio.Log.Info(fmt.Sprintf("Requested action is delete: %v", del))
27-
istio.Log.Info(fmt.Sprintf("Requested action is in namespace: %s", namespace))
25+
istio.Log.Debug(fmt.Sprintf("Requested install of version: %s", version))
26+
istio.Log.Debug(fmt.Sprintf("Requested action is delete: %v", del))
27+
istio.Log.Debug(fmt.Sprintf("Requested action is in namespace: %s", namespace))
2828

2929
// Overiding the namespace to be empty
3030
// This is intentional as deploying istio on custom namespace
@@ -95,7 +95,11 @@ func (istio *Istio) applyManifest(contents []byte, isDel bool, namespace string)
9595
return err
9696
}
9797

98-
err = kclient.ApplyManifest(contents, mesherykube.ApplyOptions{Namespace: namespace, Delete: isDel})
98+
err = kclient.ApplyManifest(contents, mesherykube.ApplyOptions{
99+
Namespace: namespace,
100+
Update: true,
101+
Delete: isDel,
102+
})
99103
if err != nil {
100104
return err
101105
}

istio/istio.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ func (istio *Istio) ApplyOperation(ctx context.Context, opReq adapter.OperationR
8989
ee.Details = ""
9090
hh.StreamInfo(e)
9191
}(istio, e)
92+
case internalconfig.DenyAllPolicyOperation, internalconfig.StrictMTLSPolicyOperation, internalconfig.MutualMTLSPolicyOperation, internalconfig.DisableMTLSPolicyOperation:
93+
go func(hh *Istio, ee *adapter.Event) {
94+
stat, err := hh.applyPolicy(opReq.Namespace, opReq.IsDeleteOperation, operations[opReq.OperationName].Templates)
95+
if err != nil {
96+
e.Summary = fmt.Sprintf("Error while %s policy", stat)
97+
e.Details = err.Error()
98+
hh.StreamErr(e, err)
99+
return
100+
}
101+
ee.Summary = fmt.Sprintf("Policy %s successfully", status.Deployed)
102+
ee.Details = ""
103+
hh.StreamInfo(e)
104+
}(istio, e)
92105
case common.CustomOperation:
93106
go func(hh *Istio, ee *adapter.Event) {
94107
stat, err := hh.applyCustomOperation(opReq.Namespace, opReq.CustomBody, opReq.IsDeleteOperation)
@@ -133,7 +146,7 @@ func (istio *Istio) ApplyOperation(ctx context.Context, opReq adapter.OperationR
133146
ee.Details = fmt.Sprintf("Succesfully %sed %s from the %s namespace", operation, opReq.OperationName, opReq.Namespace)
134147
hh.StreamInfo(e)
135148
}(istio, e)
136-
case internalconfig.IstioVetOpertation:
149+
case internalconfig.IstioVetOperation:
137150
go func(hh *Istio, ee *adapter.Event) {
138151
responseChan := make(chan *adapter.Event, 1)
139152

@@ -152,6 +165,21 @@ func (istio *Istio) ApplyOperation(ctx context.Context, opReq adapter.OperationR
152165

153166
istio.Log.Info("Done")
154167
}(istio, e)
168+
case internalconfig.EnvoyFilterOperation:
169+
go func(hh *Istio, ee *adapter.Event) {
170+
appName := operations[opReq.OperationName].AdditionalProperties[common.ServiceName]
171+
patchFile := operations[opReq.OperationName].AdditionalProperties[internalconfig.EnvoyPatchFile]
172+
stat, err := hh.patchWithEnvoyFilter(opReq.Namespace, opReq.IsDeleteOperation, appName, operations[opReq.OperationName].Templates, patchFile)
173+
if err != nil {
174+
e.Summary = fmt.Sprintf("Error while %s %s application", stat, appName)
175+
e.Details = err.Error()
176+
hh.StreamErr(e, err)
177+
return
178+
}
179+
ee.Summary = fmt.Sprintf("%s application %s successfully", appName, stat)
180+
ee.Details = fmt.Sprintf("The %s application is now %s.", appName, stat)
181+
hh.StreamInfo(e)
182+
}(istio, e)
155183
default:
156184
istio.StreamErr(e, ErrOpInvalid)
157185
}

istio/sample_apps.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"github.com/layer5io/meshkit/utils"
1212

1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
types "k8s.io/apimachinery/pkg/types"
1415
)
1516

1617
func (istio *Istio) installSampleApp(namespace string, del bool, templates []adapter.Template) (string, error) {
17-
istio.Log.Info(fmt.Sprintf("Requested action is delete: %v", del))
1818
st := status.Installing
1919

2020
if del {
@@ -36,6 +36,58 @@ func (istio *Istio) installSampleApp(namespace string, del bool, templates []ada
3636
return status.Installed, nil
3737
}
3838

39+
func (istio *Istio) patchWithEnvoyFilter(namespace string, del bool, app string, templates []adapter.Template, patchObject string) (string, error) {
40+
st := status.Deploying
41+
42+
if del {
43+
st = status.Removing
44+
}
45+
46+
jsonContents, err := readFileSource(patchObject)
47+
if err != nil {
48+
return st, ErrEnvoyFilter(err)
49+
}
50+
51+
_, err = istio.KubeClient.AppsV1().Deployments(namespace).Patch(context.TODO(), app, types.MergePatchType, []byte(jsonContents), metav1.PatchOptions{})
52+
if err != nil {
53+
return st, ErrEnvoyFilter(err)
54+
}
55+
56+
for _, template := range templates {
57+
contents, err := readFileSource(string(template))
58+
if err != nil {
59+
return st, ErrEnvoyFilter(err)
60+
}
61+
62+
err = istio.applyManifest([]byte(contents), del, namespace)
63+
if err != nil {
64+
return st, ErrEnvoyFilter(err)
65+
}
66+
}
67+
68+
return status.Deployed, nil
69+
}
70+
func (istio *Istio) applyPolicy(namespace string, del bool, templates []adapter.Template) (string, error) {
71+
st := status.Deploying
72+
73+
if del {
74+
st = status.Removing
75+
}
76+
77+
for _, template := range templates {
78+
contents, err := readFileSource(string(template))
79+
if err != nil {
80+
return st, ErrApplyPolicy(err)
81+
}
82+
83+
err = istio.applyManifest([]byte(contents), del, namespace)
84+
if err != nil {
85+
return st, ErrApplyPolicy(err)
86+
}
87+
}
88+
return status.Deployed, nil
89+
}
90+
3991
// LoadToMesh is used to mark deployment for automatic sidecar injection (or not)
4092
func (istio *Istio) LoadToMesh(namespace string, service string, remove bool) error {
4193
deploy, err := istio.KubeClient.AppsV1().Deployments(namespace).Get(context.TODO(), service, metav1.GetOptions{})

templates/bookinfo-gateway.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: networking.istio.io/v1alpha3
2+
kind: Gateway
3+
metadata:
4+
name: sample-app-gateway
5+
spec:
6+
selector:
7+
istio: ingressgateway # use istio default controller
8+
servers:
9+
- port:
10+
number: 80
11+
name: http
12+
protocol: HTTP
13+
hosts:
14+
- "*"
15+
---
16+
apiVersion: networking.istio.io/v1alpha3
17+
kind: VirtualService
18+
metadata:
19+
name: bookinfo
20+
spec:
21+
hosts:
22+
- "bookinfo.meshery.io"
23+
gateways:
24+
- sample-app-gateway
25+
http:
26+
- match:
27+
- uri:
28+
exact: /productpage
29+
- uri:
30+
prefix: /static
31+
- uri:
32+
exact: /login
33+
- uri:
34+
exact: /logout
35+
- uri:
36+
prefix: /api/v1/products
37+
route:
38+
- destination:
39+
host: productpage
40+
port:
41+
number: 9080

0 commit comments

Comments
 (0)