Skip to content

Commit

Permalink
Update linkerd version
Browse files Browse the repository at this point in the history
* Renames CLI binary to linkerd2 to match the release URL
* Updates to stable-2.8.1
* Removes instruction to install CLI given it is already
available

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Aug 6, 2020
1 parent 3160414 commit 8de0eff
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 182 deletions.
78 changes: 33 additions & 45 deletions cmd/apps/linkerd_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ package apps

import (
"bufio"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"path"
"strings"

"github.com/alexellis/arkade/pkg/get"
"github.com/alexellis/arkade/pkg/k8s"

"github.com/alexellis/arkade/pkg"
Expand All @@ -25,7 +23,7 @@ import (
"github.com/spf13/cobra"
)

var linkerdVersion = "stable-2.6.1"
var linkerdVersion = "stable-2.8.1"

func MakeInstallLinkerd() *cobra.Command {
var linkerd = &cobra.Command{
Expand Down Expand Up @@ -55,17 +53,17 @@ func MakeInstallLinkerd() *cobra.Command {
return err
}

_, clientOS := env.GetClientArch()
arch, clientOS := env.GetClientArch()

fmt.Printf("Client: %q\n", clientOS)

log.Printf("User dir established as: %s\n", userPath)

err = downloadLinkerd(userPath, clientOS)
err = downloadLinkerd(userPath, arch, clientOS)
if err != nil {
return err
}
fmt.Println("Running linkerd check, this may take a few moments.")
fmt.Println("Running linkerd2 check, this may take a few moments.")

_, err = linkerdCli("check", "--pre")
if err != nil {
Expand Down Expand Up @@ -104,16 +102,13 @@ func MakeInstallLinkerd() *cobra.Command {
= Linkerd has been installed. =
=======================================================================
# Get the linkerd-cli
curl -sL https://run.linkerd.io/install | sh
# Find out more at:
# https://linkerd.io
# To use the Linkerd CLI set this path:
# To use the linkerd2 CLI set this path:
export PATH=$PATH:` + path.Join(userPath, "bin/") + `
linkerd --help
linkerd2 --help
` + pkg.ThanksForUsing)
return nil
Expand All @@ -122,47 +117,43 @@ linkerd --help
return linkerd
}

func getLinkerdURL(os, version string) string {
osSuffix := strings.ToLower(os)
return fmt.Sprintf("https://github.com/linkerd/linkerd2/releases/download/%s/linkerd2-cli-%s-%s", version, version, osSuffix)
}
// func getLinkerdURL(os, version string) string {
// osSuffix := strings.ToLower(os)
// return fmt.Sprintf("https://github.com/linkerd/linkerd2/releases/download/%s/linkerd2-cli-%s-%s", version, version, osSuffix)
// }

func downloadLinkerd(userPath, clientOS string) error {
filePath := path.Join(path.Join(userPath, "bin"), "linkerd")
if _, statErr := os.Stat(filePath); statErr != nil {
linkerdURL := getLinkerdURL(clientOS, linkerdVersion)
fmt.Println(linkerdURL)
parsedURL, _ := url.Parse(linkerdURL)
func downloadLinkerd(userPath, arch, clientOS string) error {

res, err := http.DefaultClient.Get(parsedURL.String())
if err != nil {
return err
tools := get.MakeTools()
var tool *get.Tool
for _, t := range tools {
if t.Name == "linkerd2" {
tool = &t
break
}
}
if tool == nil {
return fmt.Errorf("unable to find tool definition")
}

defer res.Body.Close()
out, err := os.Create(filePath)
if err != nil {
return err
}
defer out.Close()
if _, err := os.Stat(fmt.Sprintf("%s", env.LocalBinary(tool.Name, ""))); errors.Is(err, os.ErrNotExist) {

// Write the body to file
_, err = io.Copy(out, res.Body)
outPath, finalName, err := get.Download(tool, arch, clientOS, tool.Version, get.DownloadArkadeDir)
if err != nil {
return err
}

err = os.Chmod(filePath, 0755)
if err != nil {
return err
}
fmt.Println("Downloaded to: ", outPath, finalName)
} else {
fmt.Printf("%s already exists, skipping download.\n", tool.Name)
}

return nil
}

func linkerdCli(parts ...string) (execute.ExecResult, error) {
task := execute.ExecTask{
Command: fmt.Sprintf("%s", env.LocalBinary("linkerd", "")),
Command: fmt.Sprintf("%s", env.LocalBinary("linkerd2", "")),
Args: parts,
Env: os.Environ(),
StreamStdio: true,
Expand Down Expand Up @@ -191,16 +182,13 @@ func getExportPath() string {
return path.Join(userPath, "bin/")
}

var LinkerdInfoMsg = `# Get the linkerd-cli
curl -sL https://run.linkerd.io/install | sh
# Find out more at:
var LinkerdInfoMsg = `# Find out more at:
# https://linkerd.io
# To use the Linkerd CLI set this path:
# To use the linkerd2 CLI set this path:
export PATH=$PATH:` + getExportPath() + `
linkerd --help`
linkerd2 --help`

var linkerdInstallMsg = `=======================================================================
= Linkerd has been installed. =
Expand Down
91 changes: 44 additions & 47 deletions cmd/apps/osm_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
package apps

import (
"errors"
"fmt"
"log"
"os"
"path"

"github.com/alexellis/arkade/pkg/get"
"github.com/alexellis/arkade/pkg/k8s"
Expand All @@ -22,13 +22,17 @@ import (

func MakeInstallOSM() *cobra.Command {
var osm = &cobra.Command{
Use: "osm",
Short: "Install osm",
Long: `Install Open Service Mesh (OSM) - a lightweight, extensible, cloud native service mesh`,
Use: "osm",
Short: "Install osm",
Long: `Install Open Service Mesh (OSM) - a lightweight, extensible, cloud native
service mesh created by Microsoft Azure.`,
Example: ` arkade install osm`,
SilenceUsage: true,
}

osm.Flags().String("mesh", "osm", "Give a specific mesh name override")
osm.Flags().StringP("namespace", "n", "osm-system", "Give a specific mesh namespace override")

osm.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := config.GetDefaultKubeconfig()

Expand Down Expand Up @@ -59,72 +63,58 @@ func MakeInstallOSM() *cobra.Command {
return err
}
fmt.Println("Running osm check, this may take a few moments.")
ns, _ := osm.Flags().GetString("namespace")
meshName, _ := osm.Flags().GetString("mesh")

_, err = osmCli("check", "--pre-flight")
_, err = osmCli("check", "--pre-install", "--namespace="+ns)
if err != nil {
return err
}

res, err := osmCli("install")
res, err := osmCli("install", "--mesh-name="+meshName)
if err != nil {
return err
}
if res.ExitCode != 0 {
return fmt.Errorf("exit code %d, error: %s", res.ExitCode, res.Stderr)
}

_, err = osmCli("check")
if err != nil {
return err
}

fmt.Println(`=======================================================================
= OSM has been installed. =
= OSM has been installed. =
=======================================================================
# Get the osm-cli
curl -sL https://run.osm.io/install | sh
# Find out more at:
# https://osm.io
# To use the OSM CLI set this path:
export PATH=$PATH:` + path.Join(userPath, "bin/") + `
osm --help
` + pkg.ThanksForUsing)
` +
OSMInfoMsg + pkg.ThanksForUsing)
return nil
}

return osm
}

func downloadOSM(userPath, arch, clientOS string) error {
t := &get.Tool{
Name: "osm",
Repo: "osm",
Owner: "openservicemesh",
Version: "v0.1.0",
URLTemplate: `
{{$osStr := ""}}
{{ if HasPrefix .OS "ming" -}}
{{$osStr = "windows"}}
{{- else if eq .OS "Linux" -}}
{{$osStr = "linux"}}
{{- else if eq .OS "Darwin" -}}
{{$osStr = "darwin"}}
{{- end -}}
https://github.com/openservicemesh/osm/releases/download/{{.Version}}/osm-{{.Version}}-{{$osStr}}-amd64.tar.gz`,
}

u, err := get.GetDownloadURL(t, clientOS, arch, t.Version)
if err != nil {
return err
tools := get.MakeTools()
var tool *get.Tool
for _, t := range tools {
if t.Name == "osm" {
tool = &t
break
}
}
if tool == nil {
return fmt.Errorf("unable to find tool definition")
}

if _, err := os.Stat(fmt.Sprintf("%s", env.LocalBinary(tool.Name, ""))); errors.Is(err, os.ErrNotExist) {

fmt.Printf("Download URL: %s\n", u)
outPath, finalName, err := get.Download(tool, arch, clientOS, tool.Version, get.DownloadArkadeDir)
if err != nil {
return err
}

fmt.Println("Downloaded to: ", outPath, finalName)
} else {
fmt.Printf("%s already exists, skipping download.\n", tool.Name)
}
return nil
}

Expand All @@ -150,15 +140,22 @@ func osmCli(parts ...string) (execute.ExecResult, error) {
}

var OSMInfoMsg = `# The osm CLI is installed at:
# $HOME/.bin/arkade
# $HOME/.bin/arkade/osm
# Find out more at:
# https://github.com/openservicemesh/osm
# Docs are live at:
# https://openservicemesh.io
# Walk-through a demo at:
# https://github.com/openservicemesh/osm/blob/main/docs/example/README.md
# To use the OSM CLI set this path:
export PATH=$PATH:` + getExportPath() + `
osm --help`
osm --help
`

var osmInstallMsg = `=======================================================================
= Open Service Mesh (OSM) has been installed. =
Expand Down

0 comments on commit 8de0eff

Please sign in to comment.