From f33f344d0703974816fe347972483a38c2cab5dd Mon Sep 17 00:00:00 2001 From: kumarabd Date: Sat, 10 Oct 2020 12:31:46 +0530 Subject: [PATCH 1/5] fixes for the labs Signed-off-by: kumarabd --- Dockerfile | 5 +- istio/install-istio.go | 48 ++++++++++++++++ istio/istio.go | 118 +++++++++++++++++++++++++++++++++----- istio/supported_ops.go | 16 +++++- scripts/delete.sh | 7 +++ scripts/deleteHttpbin.sh | 7 +++ scripts/install.sh | 52 +++++++++++++++++ scripts/installHttpbin.sh | 7 +++ 8 files changed, 241 insertions(+), 19 deletions(-) create mode 100755 scripts/delete.sh create mode 100644 scripts/deleteHttpbin.sh create mode 100755 scripts/install.sh create mode 100644 scripts/installHttpbin.sh diff --git a/Dockerfile b/Dockerfile index 799589dc3..75e7bf54d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /github.com/layer5io/meshery-istio ADD . . RUN GOPROXY=direct GOSUMDB=off go build -ldflags="-w -s" -a -o /meshery-istio . RUN find . -name "*.go" -type f -delete; mv istio / -RUN wget -O /istio.tar.gz https://github.com/istio/istio/releases/download/1.7.3/istio-1.7.3-linux-amd64.tar.gz +RUN wget -O /istio.tar.gz https://github.com/istio/istio/releases/download/1.5.1/istio-1.5.1-linux.tar.gz FROM alpine RUN apk --update add ca-certificates @@ -13,7 +13,8 @@ COPY --from=bd /meshery-istio /app/ COPY --from=bd /istio /app/istio COPY --from=bd /istio.tar.gz /app/ COPY --from=bd /etc/passwd /etc/passwd -ENV ISTIO_VERSION=istio-1.7.3 +COPY --from=bd //github.com/layer5io/meshery-istio/scripts /app/scripts/. +ENV ISTIO_VERSION=istio-1.5.1 USER appuser WORKDIR /app CMD ./meshery-istio diff --git a/istio/install-istio.go b/istio/install-istio.go index faf6e7768..701ec6595 100644 --- a/istio/install-istio.go +++ b/istio/install-istio.go @@ -3,18 +3,21 @@ package istio import ( "archive/tar" "compress/gzip" + "context" "encoding/json" "fmt" "io" "io/ioutil" "net/http" "os" + "os/exec" "path" "path/filepath" "regexp" "strings" "time" + "github.com/layer5io/meshery-istio/meshes" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -35,6 +38,8 @@ var ( installWithmTLSFile = path.Join(basePath, "install/kubernetes/istio-demo.yaml") bookInfoInstallFile = path.Join(basePath, "samples/bookinfo/platform/kube/bookinfo.yaml") bookInfoGatewayInstallFile = path.Join(basePath, "samples/bookinfo/networking/bookinfo-gateway.yaml") + httpbinInstallFile = path.Join(basePath, "samples/httpbin/httpbin.yaml") + httpbinGatewayInstallFile = path.Join(basePath, "samples/httpbin/httpbin-gateway.yaml") crdFolder = path.Join(basePath, "install/kubernetes/helm/istio-init/files/") defaultBookInfoDestRulesFile = path.Join(basePath, "samples/bookinfo/networking/destination-rule-all-mtls.yaml") @@ -58,6 +63,49 @@ type asset struct { DownloadURL string `json:"browser_download_url,omitempty"` } +func (iClient *Client) executev173Install(ctx context.Context, arReq *meshes.ApplyRuleRequest) error { + Executable, err := exec.LookPath("./scripts/install.sh") + if err != nil { + return err + } + + if arReq.DeleteOp { + Executable, err = exec.LookPath("./scripts/delete.sh") + if err != nil { + return err + } + } + + cmd := &exec.Cmd{ + Path: Executable, + Args: []string{Executable}, + Stdout: os.Stdout, + Stderr: os.Stdout, + } + + mode := "istioctl" + if arReq.OpName == installOperatorIstioCommand { + mode = "operator" + } + + cmd.Env = append(os.Environ(), + "ISTIO_VERSION=1.7.3", + fmt.Sprintf("ISTIO_MODE=%s", mode), + "ISTIO_PROFILE=demo", + ) + + err = cmd.Start() + if err != nil { + return err + } + err = cmd.Wait() + if err != nil { + return err + } + + return nil +} + func (iClient *Client) getLatestReleaseURL() error { if iClient.istioReleaseDownloadURL == "" || time.Since(iClient.istioReleaseUpdatedAt) > cachePeriod { logrus.Debugf("API info url: %s", repoURL) diff --git a/istio/istio.go b/istio/istio.go index 49d381f54..ed3e17769 100644 --- a/istio/istio.go +++ b/istio/istio.go @@ -31,6 +31,7 @@ import ( "github.com/layer5io/meshery-istio/meshes" "github.com/pkg/errors" "github.com/sirupsen/logrus" + kubeerror "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -69,16 +70,16 @@ func (iClient *Client) CreateMeshInstance(_ context.Context, k8sReq *meshes.Crea func (iClient *Client) createResource(ctx context.Context, res schema.GroupVersionResource, data *unstructured.Unstructured) error { _, err := iClient.k8sDynamicClient.Resource(res).Namespace(data.GetNamespace()).Create(context.TODO(), data, metav1.CreateOptions{}) if err != nil { - if strings.Contains(err.Error(), "already exists") { + if kubeerror.IsAlreadyExists(err) { // if err1 := iClient.deleteResource(ctx, res, data); err1 != nil { // } - return errors.Wrap(err, "resource already exists") + logrus.Warn(errors.Wrap(err, "resource already exists")) } err = errors.Wrapf(err, "unable to create the requested resource, attempting operation without namespace") logrus.Warn(err) if _, err = iClient.k8sDynamicClient.Resource(res).Create(context.TODO(), data, metav1.CreateOptions{}); err != nil { - if strings.Contains(err.Error(), "already exists") { + if kubeerror.IsAlreadyExists(err) { return errors.Wrap(err, "resource already exists") } err = errors.Wrapf(err, "unable to create the requested resource, attempting to update") @@ -228,7 +229,7 @@ func (iClient *Client) executeRule(ctx context.Context, data *unstructured.Unstr case "logentry": kind = "logentries" case "kubernetes": - kind = "kuberneteses" + kind = "kubernetes" case "podsecuritypolicy": kind = "podsecuritypolicies" case "serviceentry": @@ -403,6 +404,37 @@ func (iClient *Client) executeInstall(ctx context.Context, arReq *meshes.ApplyRu return nil } +func (iClient *Client) executeHttpbinInstall(ctx context.Context, arReq *meshes.ApplyRuleRequest) error { + Executable, err := exec.LookPath("./scripts/installHttpbin.sh") + if err != nil { + return err + } + + if arReq.DeleteOp { + Executable, err = exec.LookPath("./scripts/deleteHttpbin.sh") + if err != nil { + return err + } + } + + cmd := &exec.Cmd{ + Path: Executable, + Args: []string{Executable}, + Stdout: os.Stdout, + Stderr: os.Stdout, + } + + err = cmd.Start() + if err != nil { + return err + } + err = cmd.Wait() + if err != nil { + return err + } + return nil +} + func (iClient *Client) executeBookInfoInstall(ctx context.Context, arReq *meshes.ApplyRuleRequest) error { if !arReq.DeleteOp { if err := iClient.labelNamespaceForAutoInjection(ctx, arReq.Namespace); err != nil { @@ -496,6 +528,35 @@ func (iClient *Client) ApplyOperation(ctx context.Context, arReq *meshes.ApplyRu isCustomOp := false switch arReq.OpName { + case installv173IstioCommand, installOperatorIstioCommand: + go func() { + opName1 := "deploying" + if arReq.DeleteOp { + opName1 = "removing" + } + if err := iClient.executev173Install(ctx, arReq); err != nil { + iClient.eventChan <- &meshes.EventsResponse{ + OperationId: arReq.OperationId, + EventType: meshes.EventType_ERROR, + Summary: fmt.Sprintf("Error while %s Istio", opName1), + Details: err.Error(), + } + return + } + opName := "deployed" + if arReq.DeleteOp { + opName = "removed" + } + iClient.eventChan <- &meshes.EventsResponse{ + OperationId: arReq.OperationId, + EventType: meshes.EventType_INFO, + Summary: fmt.Sprintf("Istio %s successfully", opName), + Details: fmt.Sprintf("The latest version of Istio is now %s.", opName), + } + }() + return &meshes.ApplyRuleResponse{ + OperationId: arReq.OperationId, + }, nil case installmTLSIstioCommand: go func() { opName1 := "deploying" @@ -557,6 +618,35 @@ func (iClient *Client) ApplyOperation(ctx context.Context, arReq *meshes.ApplyRu OperationId: arReq.OperationId, }, nil + case installHttpbinCommand: + go func() { + opName1 := "deploying" + if arReq.DeleteOp { + opName1 = "removing" + } + if err := iClient.executeHttpbinInstall(ctx, arReq); err != nil { + iClient.eventChan <- &meshes.EventsResponse{ + OperationId: arReq.OperationId, + EventType: meshes.EventType_ERROR, + Summary: fmt.Sprintf("Error while %s the canonical Httpbin App", opName1), + Details: err.Error(), + } + return + } + opName := "deployed" + if arReq.DeleteOp { + opName = "removed" + } + iClient.eventChan <- &meshes.EventsResponse{ + OperationId: arReq.OperationId, + EventType: meshes.EventType_INFO, + Summary: fmt.Sprintf("Httpbin app %s successfully", opName), + Details: fmt.Sprintf("The Istio canonical Httpbin app is now %s.", opName), + } + }() + return &meshes.ApplyRuleResponse{ + OperationId: arReq.OperationId, + }, nil case installBookInfoCommand: go func() { opName1 := "deploying" @@ -673,16 +763,16 @@ func (iClient *Client) ApplyOperation(ctx context.Context, arReq *meshes.ApplyRu } return } - opName := "deployed" - if arReq.DeleteOp { - opName = "removed" - } - iClient.eventChan <- &meshes.EventsResponse{ - OperationId: arReq.OperationId, - EventType: meshes.EventType_INFO, - Summary: fmt.Sprintf("\"%s\" %s successfully", op.name, opName), - Details: fmt.Sprintf("\"%s\" %s successfully", op.name, opName), - } + // opName := "deployed" + // if arReq.DeleteOp { + // opName = "removed" + // } + // iClient.eventChan <- &meshes.EventsResponse{ + // OperationId: arReq.OperationId, + // EventType: meshes.EventType_INFO, + // Summary: fmt.Sprintf("\"%s\" %s successfully", op.name, opName), + // Details: fmt.Sprintf("\"%s\" %s successfully", op.name, opName), + // } }() return &meshes.ApplyRuleResponse{ diff --git a/istio/supported_ops.go b/istio/supported_ops.go index 13d7b47c1..038d76b0e 100644 --- a/istio/supported_ops.go +++ b/istio/supported_ops.go @@ -27,11 +27,13 @@ type supportedOperation struct { const ( customOpCommand = "custom" runVet = "istio_vet" + installv173IstioCommand = "istio_install_v173" + installOperatorIstioCommand = "istio_install_operator" installmTLSIstioCommand = "istio_mtls_install" installBookInfoCommand = "install_book_info" cbCommand = "cb1" installSMI = "install_smi" - installHTTPBin = "install_http_bin" + installHttpbinCommand = "install_http_bin" googleMSSampleApplication = "google_microservices_demo_application" bookInfoDefaultDestinationRules = "bookInfoDefaultDestinationRules" bookInfoRouteToV1AllServices = "bookInfoRouteToV1AllServices" @@ -45,8 +47,16 @@ const ( ) var supportedOps = map[string]supportedOperation{ + installv173IstioCommand: { + name: "Istio 1.7.3 with mTLS", + opType: meshes.OpCategory_INSTALL, + }, + installOperatorIstioCommand: { + name: "Istio with Operator", + opType: meshes.OpCategory_INSTALL, + }, installmTLSIstioCommand: { - name: "Latest Istio with mTLS", + name: "Istio 1.5.1 with mTLS", opType: meshes.OpCategory_INSTALL, }, installBookInfoCommand: { @@ -103,7 +113,7 @@ var supportedOps = map[string]supportedOperation{ name: "Service Mesh Interface (SMI) Istio Adapter", opType: meshes.OpCategory_INSTALL, }, - installHTTPBin: { + installHttpbinCommand: { name: "httpbin Application", templateName: "httpbin.yaml", opType: meshes.OpCategory_SAMPLE_APPLICATION, diff --git a/scripts/delete.sh b/scripts/delete.sh new file mode 100755 index 000000000..d7885094a --- /dev/null +++ b/scripts/delete.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +if ! /tmp/istio/bin/istioctl x uninstall --purge -y; then + exit 1 +fi diff --git a/scripts/deleteHttpbin.sh b/scripts/deleteHttpbin.sh new file mode 100644 index 000000000..c5ac1e3a3 --- /dev/null +++ b/scripts/deleteHttpbin.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +if ! kubectl delete -f /tmp/istio/samples/httpbin/httpbin.yaml; then + exit 1 +fi diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 000000000..b1c765fd3 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +set -e + +: "${ISTIO_VERSION:=}" +: "${ARCH:=amd64}" +: "${DISTRO:=linux}" + +OS=`uname -s` +if [ "$OS" = "Linux" ]; then + DISTRO="linux" + URL="https://github.com/istio/istio/releases/download/$ISTIO_VERSION/istio-$ISTIO_VERSION-$DISTRO-$ARCH.tar.gz" +elif [ "$OS" = "Darwin" ]; then + DISTRO="osx" + URL="https://github.com/istio/istio/releases/download/$ISTIO_VERSION/istio-$ISTIO_VERSION-$DISTRO.tar.gz" +else + exit 1 +fi + +if [ -z "$DISTRO" ]; then + exit 2 +fi + + +if ! type "grep" > /dev/null 2>&1; then + exit 3; +fi +if ! type "curl" > /dev/null 2>&1; then + exit 4; +fi +if ! type "tar" > /dev/null 2>&1; then + exit 5; +fi +if ! type "gzip" > /dev/null 2>&1; then + exit 6; +fi + +if ! curl -s --head $URL | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null; then + exit 7 +fi + +if ! curl -L "$URL" | tar xz; then + exit 8 +fi + +if ! ./istio-$ISTIO_VERSION/bin/istioctl install --set profile=$ISTIO_PROFILE; then + exit 9 +fi + +mv istio-$ISTIO_VERSION /tmp/istio + + diff --git a/scripts/installHttpbin.sh b/scripts/installHttpbin.sh new file mode 100644 index 000000000..d09e475ee --- /dev/null +++ b/scripts/installHttpbin.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -e + +if ! kubectl apply -f /tmp/istio/samples/httpbin/httpbin.yaml; then + exit 1 +fi From 39b8606db59f57053342b93b404e53f3b0c92284 Mon Sep 17 00:00:00 2001 From: kumarabd Date: Sun, 11 Oct 2020 18:19:17 +0530 Subject: [PATCH 2/5] fixes for sample applications Signed-off-by: kumarabd --- Dockerfile | 6 +-- istio/install-istio.go | 58 ++++++++++++++++++----- istio/istio.go | 99 ++++++++++++++++++++++----------------- istio/supported_ops.go | 44 ++++++++++++----- scripts/install.sh | 2 +- scripts/installHttpbin.sh | 7 --- 6 files changed, 137 insertions(+), 79 deletions(-) delete mode 100644 scripts/installHttpbin.sh diff --git a/Dockerfile b/Dockerfile index 75e7bf54d..c4bf9c365 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,14 +7,12 @@ RUN find . -name "*.go" -type f -delete; mv istio / RUN wget -O /istio.tar.gz https://github.com/istio/istio/releases/download/1.5.1/istio-1.5.1-linux.tar.gz FROM alpine -RUN apk --update add ca-certificates -RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 +RUN apk --update add ca-certificates curl +# RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 COPY --from=bd /meshery-istio /app/ COPY --from=bd /istio /app/istio COPY --from=bd /istio.tar.gz /app/ -COPY --from=bd /etc/passwd /etc/passwd COPY --from=bd //github.com/layer5io/meshery-istio/scripts /app/scripts/. ENV ISTIO_VERSION=istio-1.5.1 -USER appuser WORKDIR /app CMD ./meshery-istio diff --git a/istio/install-istio.go b/istio/install-istio.go index 701ec6595..5458b139b 100644 --- a/istio/install-istio.go +++ b/istio/install-istio.go @@ -20,28 +20,30 @@ import ( "github.com/layer5io/meshery-istio/meshes" "github.com/pkg/errors" "github.com/sirupsen/logrus" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( repoURL = "https://api.github.com/repos/istio/istio/releases/latest" - urlSuffix = "-linux.tar.gz" + urlSuffix = "-osx.tar.gz" crdPattern = "crd(.*)yaml" cachePeriod = 6 * time.Hour ) var ( - localByPassFile = "/app/istio.tar.gz" - - localFile = path.Join(os.TempDir(), "istio.tar.gz") - destinationFolder = path.Join(os.TempDir(), "istio") - basePath = path.Join(destinationFolder, "%s") - installWithmTLSFile = path.Join(basePath, "install/kubernetes/istio-demo.yaml") - bookInfoInstallFile = path.Join(basePath, "samples/bookinfo/platform/kube/bookinfo.yaml") - bookInfoGatewayInstallFile = path.Join(basePath, "samples/bookinfo/networking/bookinfo-gateway.yaml") - httpbinInstallFile = path.Join(basePath, "samples/httpbin/httpbin.yaml") - httpbinGatewayInstallFile = path.Join(basePath, "samples/httpbin/httpbin-gateway.yaml") - crdFolder = path.Join(basePath, "install/kubernetes/helm/istio-init/files/") + localByPassFile = "/tmp/istio.tar.gz" + localFile = path.Join(os.TempDir(), "istio.tar.gz") + destinationFolder = path.Join(os.TempDir(), "istio") + basePath = path.Join(destinationFolder, "%s") + installWithmTLSFile = path.Join(basePath, "install/kubernetes/istio-demo.yaml") + crdFolder = path.Join(basePath, "install/kubernetes/helm/istio-init/files/") + + httpbinInstallFile = path.Join(basePath, "samples/httpbin/httpbin.yaml") + httpbinGatewayInstallFile = path.Join(basePath, "samples/httpbin/httpbin-gateway.yaml") + + bookInfoGatewayInstallFile = path.Join(basePath, "samples/bookinfo/networking/bookinfo-gateway.yaml") + bookInfoInstallFile = path.Join(basePath, "samples/bookinfo/platform/kube/bookinfo.yaml") defaultBookInfoDestRulesFile = path.Join(basePath, "samples/bookinfo/networking/destination-rule-all-mtls.yaml") bookInfoRouteToV1AllServicesFile = path.Join(basePath, "samples/bookinfo/networking/virtual-service-all-v1.yaml") bookInfoRouteToReviewsV2ForJasonFile = path.Join(basePath, "samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml") @@ -63,6 +65,30 @@ type asset struct { DownloadURL string `json:"browser_download_url,omitempty"` } +func (iClient *Client) AddLabel(namespace string, remove bool) error { + ns, err := iClient.k8sClientset.CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{}) + if err != nil { + err = errors.Wrapf(err, "Unable to get namespace") + return err + } + + if ns.ObjectMeta.Labels == nil { + ns.ObjectMeta.Labels = map[string]string{} + } + ns.ObjectMeta.Labels["istio-injection"] = "enabled" + + if remove { + delete(ns.ObjectMeta.Labels, "istio-injection") + } + + _, err = iClient.k8sClientset.CoreV1().Namespaces().Update(context.TODO(), ns, metav1.UpdateOptions{}) + if err != nil { + err = errors.Wrapf(err, "Unable to update namespace with Label") + return err + } + return nil +} + func (iClient *Client) executev173Install(ctx context.Context, arReq *meshes.ApplyRuleRequest) error { Executable, err := exec.LookPath("./scripts/install.sh") if err != nil { @@ -379,6 +405,14 @@ func (iClient *Client) getBookInfoGatewayYAML() (string, error) { return iClient.getIstioComponentYAML(bookInfoGatewayInstallFile) } +func (iClient *Client) getHttpbinAppYAML() (string, error) { + return iClient.getIstioComponentYAML(httpbinInstallFile) +} + +func (iClient *Client) getHttpbinGatewayYAML() (string, error) { + return iClient.getIstioComponentYAML(httpbinGatewayInstallFile) +} + func (iClient *Client) getBookInfoDefaultDesinationRulesYAML() (string, error) { return iClient.getIstioComponentYAML(defaultBookInfoDestRulesFile) } diff --git a/istio/istio.go b/istio/istio.go index ed3e17769..afa76af36 100644 --- a/istio/istio.go +++ b/istio/istio.go @@ -39,6 +39,7 @@ import ( ) const ( + httpbinv2name = "httpbinv2" hipsterShopIstioManifestsURL = "https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/master/release/istio-manifests.yaml" hipsterShopKubernetesManifestsURL = "https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/master/release/kubernetes-manifests.yaml" ) @@ -69,19 +70,10 @@ func (iClient *Client) CreateMeshInstance(_ context.Context, k8sReq *meshes.Crea func (iClient *Client) createResource(ctx context.Context, res schema.GroupVersionResource, data *unstructured.Unstructured) error { _, err := iClient.k8sDynamicClient.Resource(res).Namespace(data.GetNamespace()).Create(context.TODO(), data, metav1.CreateOptions{}) - if err != nil { - if kubeerror.IsAlreadyExists(err) { - // if err1 := iClient.deleteResource(ctx, res, data); err1 != nil { - - // } - logrus.Warn(errors.Wrap(err, "resource already exists")) - } + if err != nil && !kubeerror.IsAlreadyExists(err) { err = errors.Wrapf(err, "unable to create the requested resource, attempting operation without namespace") logrus.Warn(err) - if _, err = iClient.k8sDynamicClient.Resource(res).Create(context.TODO(), data, metav1.CreateOptions{}); err != nil { - if kubeerror.IsAlreadyExists(err) { - return errors.Wrap(err, "resource already exists") - } + if _, err = iClient.k8sDynamicClient.Resource(res).Create(context.TODO(), data, metav1.CreateOptions{}); err != nil && !kubeerror.IsAlreadyExists(err) { err = errors.Wrapf(err, "unable to create the requested resource, attempting to update") logrus.Error(err) return err @@ -118,8 +110,7 @@ func (iClient *Client) deleteResource(ctx context.Context, res schema.GroupVersi err := iClient.k8sDynamicClient.Resource(res).Namespace(data.GetNamespace()).Delete(context.TODO(), data.GetName(), metav1.DeleteOptions{}) if err != nil { err = errors.Wrapf(err, "unable to delete the requested resource, attempting operation without namespace") - logrus.Warn(err) - + logrus.Error(err) err := iClient.k8sDynamicClient.Resource(res).Delete(context.TODO(), data.GetName(), metav1.DeleteOptions{}) if err != nil { err = errors.Wrapf(err, "unable to delete the requested resource") @@ -404,34 +395,59 @@ func (iClient *Client) executeInstall(ctx context.Context, arReq *meshes.ApplyRu return nil } -func (iClient *Client) executeHttpbinInstall(ctx context.Context, arReq *meshes.ApplyRuleRequest) error { - Executable, err := exec.LookPath("./scripts/installHttpbin.sh") - if err != nil { - return err - } +func (iClient *Client) executeHttpbinInstall(ctx context.Context, arReq *meshes.ApplyRuleRequest, version string) error { + if version == "v2" { + if arReq.DeleteOp { + err := iClient.k8sClientset.AppsV1().Deployments(arReq.Namespace).Delete(context.TODO(), httpbinv2name, metav1.DeleteOptions{}) + if err != nil { + err = errors.Wrapf(err, "Unable to delete deployment httpbin v2") + logrus.Error(err) + return err + } + } - if arReq.DeleteOp { - Executable, err = exec.LookPath("./scripts/deleteHttpbin.sh") + deploy, err := iClient.k8sClientset.AppsV1().Deployments(arReq.Namespace).Get(context.TODO(), "httpbin", metav1.GetOptions{}) if err != nil { + err = errors.Wrapf(err, "Unable to get deployment httpbin") + logrus.Error(err) return err } - } - cmd := &exec.Cmd{ - Path: Executable, - Args: []string{Executable}, - Stdout: os.Stdout, - Stderr: os.Stdout, + if deploy.ObjectMeta.Labels == nil { + deploy.ObjectMeta.Labels = map[string]string{} + } + deploy.ObjectMeta.Labels["version"] = "v2" + deploy.ObjectMeta.Name = httpbinv2name + deploy.ObjectMeta.ResourceVersion = "" + + _, err = iClient.k8sClientset.AppsV1().Deployments(arReq.Namespace).Create(context.TODO(), deploy, metav1.CreateOptions{}) + if err != nil && !kubeerror.IsAlreadyExists(err) { + err = errors.Wrapf(err, "Unable to create deployment httpbin version 2") + logrus.Error(err) + return err + } + return nil } - err = cmd.Start() + if !arReq.DeleteOp { + if err := iClient.labelNamespaceForAutoInjection(ctx, arReq.Namespace); err != nil { + return err + } + } + yamlFileContents, err := iClient.getHttpbinAppYAML() if err != nil { return err } - err = cmd.Wait() + if err := iClient.applyConfigChange(ctx, yamlFileContents, arReq.Namespace, arReq.DeleteOp, false); err != nil { + return err + } + yamlFileContents, err = iClient.getHttpbinGatewayYAML() if err != nil { return err } + if err := iClient.applyConfigChange(ctx, yamlFileContents, arReq.Namespace, arReq.DeleteOp, false); err != nil { + return err + } return nil } @@ -618,13 +634,13 @@ func (iClient *Client) ApplyOperation(ctx context.Context, arReq *meshes.ApplyRu OperationId: arReq.OperationId, }, nil - case installHttpbinCommand: + case installHttpbinCommandV1, installHttpbinCommandV2: go func() { opName1 := "deploying" if arReq.DeleteOp { opName1 = "removing" } - if err := iClient.executeHttpbinInstall(ctx, arReq); err != nil { + if err := iClient.executeHttpbinInstall(ctx, arReq, op.templateName); err != nil { iClient.eventChan <- &meshes.EventsResponse{ OperationId: arReq.OperationId, EventType: meshes.EventType_ERROR, @@ -790,20 +806,15 @@ func (iClient *Client) applyConfigChange(ctx context.Context, yamlFileContents, } for _, yml := range yamls { if strings.TrimSpace(yml) != "" { - if err := iClient.applyRulePayload(ctx, namespace, []byte(yml), delete, isCustomOp); err != nil { - errStr := strings.TrimSpace(err.Error()) - if delete { - if strings.HasSuffix(errStr, "not found") || - strings.HasSuffix(errStr, "the server could not find the requested resource") { - // logrus.Debugf("skipping error. . .") - continue - } - } else { - if strings.HasSuffix(errStr, "already exists") { - continue - } - } - // logrus.Debugf("returning error: %v", err) + err := iClient.applyRulePayload(ctx, namespace, []byte(yml), delete, isCustomOp) + if err != nil && !kubeerror.IsAlreadyExists(err) { + err = errors.Wrap(err, "error while applying rule payload yaml") + logrus.Error(err) + return err + } + if delete && !kubeerror.IsNotFound(err) && !kubeerror.IsInvalid(err) && !kubeerror.IsGone(err) && !kubeerror.IsResourceExpired(err) { + err = errors.Wrap(err, "error while deleting rule payload yaml") + logrus.Error(err) return err } } diff --git a/istio/supported_ops.go b/istio/supported_ops.go index 038d76b0e..cf512cba0 100644 --- a/istio/supported_ops.go +++ b/istio/supported_ops.go @@ -25,15 +25,21 @@ type supportedOperation struct { } const ( - customOpCommand = "custom" - runVet = "istio_vet" - installv173IstioCommand = "istio_install_v173" - installOperatorIstioCommand = "istio_install_operator" - installmTLSIstioCommand = "istio_mtls_install" + customOpCommand = "custom" + runVet = "istio_vet" + + // Install istio + installv173IstioCommand = "istio_install_v173" + installv173IstioCommandTls = "istio_install_v173_tls" + installOperatorIstioCommand = "istio_install_operator" + installmTLSIstioCommand = "istio_mtls_install" + verifyInstallation = "verify_installation" // requires + installAddons = "install_addons" + injectLabels = "inject_labels" + + // Bookinfo installBookInfoCommand = "install_book_info" cbCommand = "cb1" - installSMI = "install_smi" - installHttpbinCommand = "install_http_bin" googleMSSampleApplication = "google_microservices_demo_application" bookInfoDefaultDestinationRules = "bookInfoDefaultDestinationRules" bookInfoRouteToV1AllServices = "bookInfoRouteToV1AllServices" @@ -43,11 +49,22 @@ const ( bookInfoInjectDelayForRatingsForJason = "bookInfoInjectDelayForRatingsForJason" bookInfoInjectHTTPAbortToRatingsForJason = "bookInfoInjectHTTPAbortToRatingsForJason" bookInfoProductPageCircuitBreaking = "bookInfoProductPageCircuitBreaking" - smiConformanceCommand = "smiConformanceTest" + + // HTTPbin + installHttpbinCommandV1 = "install_http_binv1" + installHttpbinCommandV2 = "install_http_binv2" + + // SMI conformance test + smiConformanceCommand = "smiConformanceTest" + installSMI = "install_smi" ) var supportedOps = map[string]supportedOperation{ installv173IstioCommand: { + name: "Istio 1.7.3", + opType: meshes.OpCategory_INSTALL, + }, + installv173IstioCommandTls: { name: "Istio 1.7.3 with mTLS", opType: meshes.OpCategory_INSTALL, }, @@ -113,9 +130,14 @@ var supportedOps = map[string]supportedOperation{ name: "Service Mesh Interface (SMI) Istio Adapter", opType: meshes.OpCategory_INSTALL, }, - installHttpbinCommand: { - name: "httpbin Application", - templateName: "httpbin.yaml", + installHttpbinCommandV1: { + name: "httpbin Application V1", + templateName: "v1", + opType: meshes.OpCategory_SAMPLE_APPLICATION, + }, + installHttpbinCommandV2: { + name: "httpbin Application V2 (Needs V1 installed)", + templateName: "v2", opType: meshes.OpCategory_SAMPLE_APPLICATION, }, customOpCommand: { diff --git a/scripts/install.sh b/scripts/install.sh index b1c765fd3..3de2a864b 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -43,7 +43,7 @@ if ! curl -L "$URL" | tar xz; then exit 8 fi -if ! ./istio-$ISTIO_VERSION/bin/istioctl install --set profile=$ISTIO_PROFILE; then +if ! ./istio-$ISTIO_VERSION/bin/istioctl install --set profile=$ISTIO_PROFILE --set meshConfig.accessLogFile=/dev/stdout; then exit 9 fi diff --git a/scripts/installHttpbin.sh b/scripts/installHttpbin.sh deleted file mode 100644 index d09e475ee..000000000 --- a/scripts/installHttpbin.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -set -e - -if ! kubectl apply -f /tmp/istio/samples/httpbin/httpbin.yaml; then - exit 1 -fi From f5bf3d9bd585d23fdba03b82985886e7d3f9858c Mon Sep 17 00:00:00 2001 From: kumarabd Date: Sun, 11 Oct 2020 19:09:06 +0530 Subject: [PATCH 3/5] added more operations Signed-off-by: kumarabd --- istio/supported_ops.go | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/istio/supported_ops.go b/istio/supported_ops.go index cf512cba0..1d6f3e487 100644 --- a/istio/supported_ops.go +++ b/istio/supported_ops.go @@ -54,6 +54,27 @@ const ( installHttpbinCommandV1 = "install_http_binv1" installHttpbinCommandV2 = "install_http_binv2" + // Labs + enablePrometheus = "enable_prometheus" + enableGrafana = "enable_grafana" + enableKiali = "enable_kiali" + denyAllPolicy = "deny_all_policy" + strictMtls = "strict_mtls" + mutualMtls = "mutual_mtls" + disableMtls = "disable_mtls" + + bookInfoRouteV1ForUser = "bookinfo_route_v1_for_user" + bookInfoMirrorTrafficToV2 = "bookinfo_mirror_traffic_to_v2" + bookInfoRetrySpecForReviews = "bookinfo_retry_spec_for_reviews" + bookInfoCanaryDeploy20V3 = "bookinfo_canary_deploy_20_v3" + bookInfoCanaryDeploy80V3 = "bookinfo_canary_deploy_80_v3" + bookInfoCanaryDeploy100V3 = "bookinfo_canary_deploy_100_v3" + bookInfoInjectDelayFaultRatings = "bookinfo_inject_delay_fault_ratings" + bookInfoInjectDelayFaultReviews = "bookinfo_inject_delay_fault_reviews" + bookInfoConfigureConnectionPoolOutlier = "bookinfo_configure_connection_pool_outlier" + bookInfoAllowGet = "bookinfo_allow_get" + bookInfoAllowReviewsForUser = "bookinfo_allow_reviews_for_user" + // SMI conformance test smiConformanceCommand = "smiConformanceTest" installSMI = "install_smi" @@ -152,4 +173,76 @@ var supportedOps = map[string]supportedOperation{ name: "Run SMI conformance test", opType: meshes.OpCategory_VALIDATE, }, + enablePrometheus: { + name: "Enable Prometheus monitoring", + opType: meshes.OpCatergory_INSTALL, + }, + enableGrafana: { + name: "Enable Grafana dashboard", + opType: meshes.OpCatergory_INSTALL, + }, + enableKiali: { + name: "Enable Prometheus dashboard", + opType: meshes.OpCatergory_INSTALL, + }, + denyAllPolicy: { + name: "Deny-All policy on the namespace", + opType: meshes.OpCatergory_CONFIGURE, + }, + strictMtls: { + name: "Strict Mtls policy", + opType: meshes.OpCatergory_CONFIGURE, + }, + mutualMtls: { + name: "Mutual Mtls policy", + opType: meshes.OpCatergory_CONFIGURE, + }, + disableMtls: { + name: "Disable Mtls policy", + opType: meshes.OpCatergory_CONFIGURE, + }, + bookInfoRouteV1ForUser: { + name: "Configure bookinfo page to version v1", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoMirrorTrafficToV2: { + name: "Configure bookinfo page mirror traffic from v1 to v2", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoRetrySpecForReviews: { + name: "Configure bookinfo page to retry for reviews application", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoCanaryDeploy20V3: { + name: "Configure bookinfo to forward 20 percent traffic to v2", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoCanaryDeploy80V3: { + name: "Configure bookinfo to forward 80 percent traffic to v2", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoCanaryDeploy100V3: { + name: "Configure bookinfo to forward 100 percent traffic to v2", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoInjectDelayFaultRatings: { + name: "Configure bookinfo to add delay to ratings application", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoInjectDelayFaultReviews: { + name: "Configure bookinfo to add delay to ratings application", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoConfigureConnectionPoolOutlier: { + name: "Configure bookinfo for connection pool limits and outlier detection", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoAllowGet: { + name: "Configure bookinfo to allow only GET requests", + opType: meshes.OpCategory_CONFIGURE, + }, + bookInfoAllowReviewsForUser: { + name: "Configure bookinfo to allow reviews only for user", + opType: meshes.OpCategory_CONFIGURE, + }, } From b276b9312d686d2414cfe51f0b122b7e0e79a1d7 Mon Sep 17 00:00:00 2001 From: leecalcote Date: Sun, 11 Oct 2020 11:15:15 -0500 Subject: [PATCH 4/5] OpCategory misspelling Signed-off-by: leecalcote --- istio/supported_ops.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/istio/supported_ops.go b/istio/supported_ops.go index 1d6f3e487..1b1e14641 100644 --- a/istio/supported_ops.go +++ b/istio/supported_ops.go @@ -175,31 +175,31 @@ var supportedOps = map[string]supportedOperation{ }, enablePrometheus: { name: "Enable Prometheus monitoring", - opType: meshes.OpCatergory_INSTALL, + opType: meshes.OpCategory_INSTALL, }, enableGrafana: { name: "Enable Grafana dashboard", - opType: meshes.OpCatergory_INSTALL, + opType: meshes.OpCategory_INSTALL, }, enableKiali: { name: "Enable Prometheus dashboard", - opType: meshes.OpCatergory_INSTALL, + opType: meshes.OpCategory_INSTALL, }, denyAllPolicy: { name: "Deny-All policy on the namespace", - opType: meshes.OpCatergory_CONFIGURE, + opType: meshes.OpCategory_CONFIGURE, }, strictMtls: { name: "Strict Mtls policy", - opType: meshes.OpCatergory_CONFIGURE, + opType: meshes.OpCategory_CONFIGURE, }, mutualMtls: { name: "Mutual Mtls policy", - opType: meshes.OpCatergory_CONFIGURE, + opType: meshes.OpCategory_CONFIGURE, }, disableMtls: { name: "Disable Mtls policy", - opType: meshes.OpCatergory_CONFIGURE, + opType: meshes.OpCategory_CONFIGURE, }, bookInfoRouteV1ForUser: { name: "Configure bookinfo page to version v1", From 77d2f291c1140529ade8b13230f1c987cbbf7f05 Mon Sep 17 00:00:00 2001 From: leecalcote Date: Sun, 11 Oct 2020 12:17:33 -0500 Subject: [PATCH 5/5] operation names Signed-off-by: leecalcote --- istio/supported_ops.go | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/istio/supported_ops.go b/istio/supported_ops.go index 1b1e14641..76d3bcd17 100644 --- a/istio/supported_ops.go +++ b/istio/supported_ops.go @@ -119,31 +119,31 @@ var supportedOps = map[string]supportedOperation{ opType: meshes.OpCategory_CONFIGURE, }, bookInfoRouteToV1AllServices: { - name: "BookInfo: Route traffic to V1 of all BookInfo services", + name: "BookInfo: Route traffic to v1 of all BookInfo services", opType: meshes.OpCategory_CONFIGURE, }, bookInfoRouteToReviewsV2ForJason: { - name: "BookInfo: Route traffic to V2 of BookInfo reviews service for user Jason", + name: "BookInfo: Route traffic to Reviews v2 for user Jason", opType: meshes.OpCategory_CONFIGURE, }, bookInfoCanary50pcReviewsV3: { - name: "BookInfo: Route 50% of the traffic to BookInfo reviews V3", + name: "BookInfo: Route 50% of the traffic to Reviews v3", opType: meshes.OpCategory_CONFIGURE, }, bookInfoCanary100pcReviewsV3: { - name: "BookInfo: Route 100% of the traffic to BookInfo reviews V3", + name: "BookInfo: Route 100% of the traffic to Reviews v3", opType: meshes.OpCategory_CONFIGURE, }, bookInfoInjectDelayForRatingsForJason: { - name: "BookInfo: Inject a 7s delay in the traffic to BookInfo ratings service for user Jason", + name: "BookInfo: Inject a 7s delay in the traffic to Ratings for user Jason", opType: meshes.OpCategory_CONFIGURE, }, bookInfoInjectHTTPAbortToRatingsForJason: { - name: "BookInfo: Inject HTTP abort to BookInfo ratings service for user Jason", + name: "BookInfo: Inject HTTP abort to Ratings for user Jason", opType: meshes.OpCategory_CONFIGURE, }, bookInfoProductPageCircuitBreaking: { - name: "BookInfo: Configure circuit breaking with max 1 request per connection and max 1 pending request to BookInfo productpage service", + name: "BookInfo: Configure circuit breaking with max 1 request per connection and max 1 pending request to Productpage service", opType: meshes.OpCategory_CONFIGURE, templateName: "book_info_product_page_circuit_breaking.tmpl", }, @@ -174,75 +174,75 @@ var supportedOps = map[string]supportedOperation{ opType: meshes.OpCategory_VALIDATE, }, enablePrometheus: { - name: "Enable Prometheus monitoring", + name: "Enable Prometheus add-on", opType: meshes.OpCategory_INSTALL, }, enableGrafana: { - name: "Enable Grafana dashboard", + name: "Enable Grafana add-on", opType: meshes.OpCategory_INSTALL, }, enableKiali: { - name: "Enable Prometheus dashboard", + name: "Enable Kiali add-on", opType: meshes.OpCategory_INSTALL, }, denyAllPolicy: { - name: "Deny-All policy on the namespace", + name: "Deny-all policy on the namespace", opType: meshes.OpCategory_CONFIGURE, }, strictMtls: { - name: "Strict Mtls policy", + name: "Strict mTLS policy", opType: meshes.OpCategory_CONFIGURE, }, mutualMtls: { - name: "Mutual Mtls policy", + name: "Mutual mTLS policy", opType: meshes.OpCategory_CONFIGURE, }, disableMtls: { - name: "Disable Mtls policy", + name: "Disable mTLS policy", opType: meshes.OpCategory_CONFIGURE, }, bookInfoRouteV1ForUser: { - name: "Configure bookinfo page to version v1", + name: "BookInfo: Productpage to version v1", opType: meshes.OpCategory_CONFIGURE, }, bookInfoMirrorTrafficToV2: { - name: "Configure bookinfo page mirror traffic from v1 to v2", + name: "BookInfo: Productpage mirror traffic from v1 to v2", opType: meshes.OpCategory_CONFIGURE, }, bookInfoRetrySpecForReviews: { - name: "Configure bookinfo page to retry for reviews application", + name: "BookInfo: Productpage to retry for Reviews application", opType: meshes.OpCategory_CONFIGURE, }, bookInfoCanaryDeploy20V3: { - name: "Configure bookinfo to forward 20 percent traffic to v2", + name: "BookInfo: Forward 20 percent traffic to Reviews v2", opType: meshes.OpCategory_CONFIGURE, }, bookInfoCanaryDeploy80V3: { - name: "Configure bookinfo to forward 80 percent traffic to v2", + name: "BookInfo: Forward 80 percent traffic to Reviews v2", opType: meshes.OpCategory_CONFIGURE, }, bookInfoCanaryDeploy100V3: { - name: "Configure bookinfo to forward 100 percent traffic to v2", + name: "BookInfo: Forward 100 percent traffic to Reviews v2", opType: meshes.OpCategory_CONFIGURE, }, bookInfoInjectDelayFaultRatings: { - name: "Configure bookinfo to add delay to ratings application", + name: "BookInfo: Add delay to Ratings", opType: meshes.OpCategory_CONFIGURE, }, bookInfoInjectDelayFaultReviews: { - name: "Configure bookinfo to add delay to ratings application", + name: "BookInfo: Add delay in Ratings", opType: meshes.OpCategory_CONFIGURE, }, bookInfoConfigureConnectionPoolOutlier: { - name: "Configure bookinfo for connection pool limits and outlier detection", + name: "BookInfo: Connection pool limits and outlier detection", opType: meshes.OpCategory_CONFIGURE, }, bookInfoAllowGet: { - name: "Configure bookinfo to allow only GET requests", + name: "BookInfo: Allow only GET requests", opType: meshes.OpCategory_CONFIGURE, }, bookInfoAllowReviewsForUser: { - name: "Configure bookinfo to allow reviews only for user", + name: "BookInfo: Allow Reviews only for user", opType: meshes.OpCategory_CONFIGURE, }, }