Skip to content

Commit

Permalink
Merge pull request #128 from layer5io/kumarabd/feature/labs
Browse files Browse the repository at this point in the history
Kumarabd/feature/labs
  • Loading branch information
leecalcote authored Oct 13, 2020
2 parents 0cd76c1 + 77d2f29 commit 3540faa
Show file tree
Hide file tree
Showing 7 changed files with 443 additions and 70 deletions.
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ 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
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
ENV ISTIO_VERSION=istio-1.7.3
USER appuser
COPY --from=bd //github.com/layer5io/meshery-istio/scripts /app/scripts/.
ENV ISTIO_VERSION=istio-1.5.1
WORKDIR /app
CMD ./meshery-istio
100 changes: 91 additions & 9 deletions istio/install-istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,47 @@ 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"
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"
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")
bookInfoInstallFile = path.Join(basePath, "samples/bookinfo/platform/kube/bookinfo.yaml")
bookInfoGatewayInstallFile = path.Join(basePath, "samples/bookinfo/networking/bookinfo-gateway.yaml")
crdFolder = path.Join(basePath, "install/kubernetes/helm/istio-init/files/")
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")
Expand All @@ -58,6 +65,73 @@ 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 {
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)
Expand Down Expand Up @@ -331,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)
}
Expand Down
Loading

0 comments on commit 3540faa

Please sign in to comment.