From 2b75759157028004f50d77bbe65187d44c643f30 Mon Sep 17 00:00:00 2001 From: kumarabd Date: Mon, 21 Dec 2020 16:29:13 +0530 Subject: [PATCH 1/9] v2 nginx adapter Signed-off-by: kumarabd --- Dockerfile | 41 +++++++------ go.mod | 5 +- go.sum | 4 ++ internal/config/config.go | 103 +++++++++++++++++---------------- internal/config/development.go | 45 -------------- internal/config/error.go | 7 ++- internal/config/operations.go | 10 ---- internal/config/production.go | 43 -------------- main.go | 14 ++++- nginx/custom_operation.go | 17 ++++++ nginx/error.go | 36 +++++++----- nginx/install.go | 19 +++--- nginx/nginx.go | 30 +++++++--- nginx/sample_apps.go | 93 ++++++++++++++++++++++++++++- scripts/delete.sh | 7 --- scripts/deploy.sh | 7 --- 16 files changed, 262 insertions(+), 219 deletions(-) delete mode 100644 internal/config/development.go delete mode 100644 internal/config/production.go create mode 100644 nginx/custom_operation.go delete mode 100755 scripts/delete.sh delete mode 100755 scripts/deploy.sh diff --git a/Dockerfile b/Dockerfile index 8ba7e1d..0f8e49a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,24 @@ -FROM golang:1.14-stretch as bd -ARG CONFIG_PROVIDER="viper" -RUN apt update && apt install git libc-dev gcc pkgconf -y -COPY ${PWD} /go/src/github.com/layer5io/meshery-nginx/ -WORKDIR /go/src/github.com/layer5io/meshery-nginx/ -RUN go build -ldflags="-w -s -X main.configProvider=$CONFIG_PROVIDER" -a -o meshery-nginx +FROM golang:1.13 as builder -FROM golang:1.14-stretch -RUN apt update && apt install ca-certificates curl -y -# Install kubectl -RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl" && \ - chmod +x ./kubectl && \ - mv ./kubectl /usr/local/bin/kubectl +WORKDIR /build +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum +# cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer +RUN go mod download +# Copy the go source +COPY main.go main.go +COPY internal/ internal/ +COPY nginx/ nginx/ +# Build +RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o meshery-nginx main.go -RUN mkdir /home/scripts/ && \ - mkdir -p ${HOME}/.kube/ - -COPY --from=bd /go/src/github.com/layer5io/meshery-nginx/meshery-nginx /home/ -COPY ${PWD}/scripts /home/scripts -WORKDIR /home -CMD ./meshery-nginx +# Use distroless as minimal base image to package the manager binary +# Refer to https://github.com/GoogleContainerTools/distroless for more details +FROM gcr.io/distroless/base +ENV DISTRO="debian" +ENV GOARCH="amd64" +WORKDIR / +COPY --from=builder /build/meshery-nginx . +ENTRYPOINT ["/meshery-nginx"] \ No newline at end of file diff --git a/go.mod b/go.mod index c85719f..52fa128 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,9 @@ replace ( ) require ( - github.com/layer5io/meshery-adapter-library v0.1.6 - github.com/layer5io/meshkit v0.1.28 + github.com/layer5io/meshery-adapter-library v0.1.9 + github.com/layer5io/meshkit v0.1.30 google.golang.org/grpc v1.33.1 // indirect helm.sh/helm/v3 v3.3.4 // indirect + k8s.io/apimachinery v0.18.12 ) diff --git a/go.sum b/go.sum index 772e71e..6fca2c5 100644 --- a/go.sum +++ b/go.sum @@ -554,12 +554,16 @@ github.com/layer5io/meshery-adapter-library v0.1.5 h1:ZrYG15THG1D/Mr4sTdMI/ex2hc github.com/layer5io/meshery-adapter-library v0.1.5/go.mod h1:R5K6nE7PAtLj9S/Qg2cFUPYM/8Qs32jeTw/D1MIh4zE= github.com/layer5io/meshery-adapter-library v0.1.6 h1:9U9y4CT7sH3EhAlSqVoWpChdeqDHpHG5XnIzglKNKi4= github.com/layer5io/meshery-adapter-library v0.1.6/go.mod h1:ph6YYsiZn7raWuyvK/c3R4ujWl4FUZBkU0wXiKhZ1Uw= +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.25 h1:+beK1qrqroP1Ce8UW8iRabWqSLVHSaLL2Ks38a/6uME= github.com/layer5io/meshkit v0.1.25/go.mod h1:4x8Azv5a/T7HI8z2amRKxR9rWfeJQlXDOQbohb81GjY= github.com/layer5io/meshkit v0.1.26 h1:yqcjffNeT9yD2PgDfOHB/gzP78biv6DjqqJn2cZ+llw= github.com/layer5io/meshkit v0.1.26/go.mod h1:4x8Azv5a/T7HI8z2amRKxR9rWfeJQlXDOQbohb81GjY= github.com/layer5io/meshkit v0.1.28 h1:F7DWcm3Txqb0QIqoEcBlp/qIO4s6+5Hp/CExMQM7Gjw= github.com/layer5io/meshkit v0.1.28/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= diff --git a/internal/config/config.go b/internal/config/config.go index 76c8418..94c5d64 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -10,69 +10,74 @@ import ( "path" "runtime" + "github.com/layer5io/meshery-adapter-library/common" "github.com/layer5io/meshery-adapter-library/config" configprovider "github.com/layer5io/meshery-adapter-library/config/provider" + "github.com/layer5io/meshery-adapter-library/status" "github.com/layer5io/meshkit/utils" ) const ( NginxOperation = "nginx" - Development = "development" - Production = "production" + LabelNamespace = "label-namespace" ) var ( - configRootPath = path.Join(utils.GetHome(), ".meshery") + configRootPath = path.Join(utils.GetHome(), ".meshery") + NginxExecutable = path.Join(configRootPath, "nginx-meshctl") + + Config = configprovider.Options{ + ServerConfig: ServerConfig, + MeshSpec: MeshSpec, + ProviderConfig: ProviderConfig, + Operations: Operations, + } - kubeconfigFilename = "kubeconfig" - kubeconfigFiletype = "yaml" - KubeconfigPath = path.Join(configRootPath, fmt.Sprintf("%s.%s", kubeconfigFilename, kubeconfigFiletype)) -) + ServerConfig = map[string]string{ + "name": "nginx-adapter", + "port": "10010", + "version": "v1.0.0", + } -// New creates a new config instance -func New(provider string) (config.Handler, error) { + MeshSpec = map[string]string{ + "name": "nginx", + "status": status.None, + "traceurl": status.None, + "version": status.None, + } - // Default config - opts := configprovider.Options{} - environment := os.Getenv("MESHERY_ENV") - if len(environment) < 1 { - environment = Development + ProviderConfig = map[string]string{ + configprovider.FilePath: configRootPath, + configprovider.FileType: "yaml", + configprovider.FileName: "nginx", } - // Config environment - switch environment { - case Production: - opts = ProductionConfig - case Development: - opts = DevelopmentConfig + // KubeConfig - Controlling the kubeconfig lifecycle with viper + KubeConfig = map[string]string{ + configprovider.FilePath: configRootPath, + configprovider.FileType: "yaml", + configprovider.FileName: "kubeconfig", } + Operations = getOperations(common.Operations) +) + +// New creates a new config instance +func New(provider string) (config.Handler, error) { // Config provider switch provider { case configprovider.ViperKey: - return configprovider.NewViper(opts) + return configprovider.NewViper(Config) case configprovider.InMemKey: - return configprovider.NewInMem(opts) + return configprovider.NewInMem(Config) } return nil, ErrEmptyConfig } func NewKubeconfigBuilder(provider string) (config.Handler, error) { - opts := configprovider.Options{} - environment := os.Getenv("MESHERY_ENV") - if len(environment) < 1 { - environment = Development - } - - // Config environment - switch environment { - case Production: - opts.ProviderConfig = productionKubeConfig - case Development: - opts.ProviderConfig = developmentKubeConfig - } + opts.ProviderConfig = KubeConfig // Config provider switch provider { @@ -84,38 +89,38 @@ func NewKubeconfigBuilder(provider string) (config.Handler, error) { return nil, ErrEmptyConfig } +// RootPath returns the config root path for the adapter +func RootPath() string { + return configRootPath +} + // InitialiseNSMCtl looks for the "nginx-meshctl" in the $PATH // if it doesn't finds it then it downloads and installs it in // "configRootPath" and returns the path for the executable -func InitialiseNSMCtl() (string, error) { +func InitialiseNSMCtl() error { // Look for the executable in the path - fmt.Println("Looking for nginx-meshctl in the path...") - executable, err := exec.LookPath("nginx-meshctl") + executable, err := exec.LookPath(NginxExecutable) if err == nil { - return executable, nil + return nil } - fmt.Println("Looking for nginx-meshctl in", configRootPath, "...") executable = path.Join(configRootPath, "nginx-meshctl") if _, err := os.Stat(executable); err == nil { - return executable, nil + return nil } // Proceed to download the binary in the config root path - fmt.Println("nginx-meshctl not found in the path, downloading...") res, err := downloadBinary(runtime.GOOS) if err != nil { - return "", err + return err } // Install the binary - fmt.Println("Installing...") - if err = installBinary(path.Join(configRootPath, "nginx-meshctl"), runtime.GOOS, res); err != nil { - return "", err + if err = installBinary(NginxExecutable, runtime.GOOS, res); err != nil { + return err } - fmt.Println("Done") - return path.Join(configRootPath, "nginx-meshctl"), nil + return nil } func downloadBinary(platform string) (*http.Response, error) { @@ -165,7 +170,7 @@ func installBinary(location, platform string, res *http.Response) error { r.Close() if err = out.Chmod(0755); err != nil { - return fmt.Errorf("Failed to change permission of the binary") + return ErrInstallBinary(err) } case "windows": } diff --git a/internal/config/development.go b/internal/config/development.go deleted file mode 100644 index 3dd1224..0000000 --- a/internal/config/development.go +++ /dev/null @@ -1,45 +0,0 @@ -package config - -import ( - "github.com/layer5io/meshery-adapter-library/common" - configprovider "github.com/layer5io/meshery-adapter-library/config/provider" -) - -var ( - // DevelopmentConfig holds the configuration for development environment - DevelopmentConfig = configprovider.Options{ - ServerConfig: developmentServerConfig, - MeshSpec: developmentMeshSpec, - ProviderConfig: developmentProviderConfig, - Operations: developmentOperations, - } - - developmentServerConfig = map[string]string{ - "name": "nginx-adapter", - "port": "10010", - "version": "v1.0.0", - } - - developmentMeshSpec = map[string]string{ - "name": "nginx", - "status": "none", - "traceurl": "none", - "version": "none", - } - - developmentProviderConfig = map[string]string{ - configprovider.FilePath: configRootPath, - configprovider.FileType: "yaml", - configprovider.FileName: "nginx", - } - - // Controlling the kubeconfig lifecycle with viper - developmentKubeConfig = map[string]string{ - configprovider.FilePath: configRootPath, - configprovider.FileType: "yaml", - configprovider.FileName: "kubeconfig", - } - - // developmentOperations = getDevelopmentOperations(adapter.Operations{}) // Should be used in case of not using common operations - developmentOperations = getOperations(common.Operations) -) diff --git a/internal/config/error.go b/internal/config/error.go index 2dff655..72cd2c5 100644 --- a/internal/config/error.go +++ b/internal/config/error.go @@ -19,9 +19,14 @@ import ( ) const ( - ErrEmptyConfigCode = "11300" + ErrEmptyConfigCode = "test" + ErrInstallBinaryCode = "test" ) var ( ErrEmptyConfig = errors.NewDefault(ErrEmptyConfigCode, "Config is empty") ) + +func ErrInstallBinary(err error) error { + return errors.NewDefault(ErrInstallBinaryCode, "Failed to change permission of the binary", err.Error()) +} diff --git a/internal/config/operations.go b/internal/config/operations.go index bad0876..89400f0 100644 --- a/internal/config/operations.go +++ b/internal/config/operations.go @@ -5,10 +5,6 @@ import ( "github.com/layer5io/meshery-adapter-library/meshes" ) -var ( - ServiceName = "service_name" -) - func getOperations(dev adapter.Operations) adapter.Operations { dev[NginxOperation] = &adapter.Operation{ @@ -17,12 +13,6 @@ func getOperations(dev adapter.Operations) adapter.Operations { Versions: []adapter.Version{ "0.6.0", }, - Templates: []adapter.Template{ - "templates/nginx.yaml", - }, - AdditionalProperties: map[string]string{ - ServiceName: NginxOperation, - }, } return dev diff --git a/internal/config/production.go b/internal/config/production.go deleted file mode 100644 index 5b6c701..0000000 --- a/internal/config/production.go +++ /dev/null @@ -1,43 +0,0 @@ -package config - -import ( - "github.com/layer5io/meshery-adapter-library/common" - configprovider "github.com/layer5io/meshery-adapter-library/config/provider" -) - -var ( - ProductionConfig = configprovider.Options{ - ServerConfig: productionServerConfig, - MeshSpec: productionMeshSpec, - ProviderConfig: productionProviderConfig, - Operations: productionOperations, - } - - productionServerConfig = map[string]string{ - "name": "nginx-adapter", - "port": "10010", - "version": "v1.0.0", - } - - productionMeshSpec = map[string]string{ - "name": "nginx", - "status": "none", - "traceurl": "none", - "version": "none", - } - - productionProviderConfig = map[string]string{ - configprovider.FilePath: configRootPath, - configprovider.FileType: "yaml", - configprovider.FileName: "nginx", - } - - // Controlling the kubeconfig lifecycle with viper - productionKubeConfig = map[string]string{ - configprovider.FilePath: configRootPath, - configprovider.FileType: "", - configprovider.FileName: "kubeconfig", - } - - productionOperations = getOperations(common.Operations) -) diff --git a/main.go b/main.go index 503f3da..02866e3 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "path" "time" "github.com/layer5io/meshery-nginx/nginx" @@ -22,7 +23,7 @@ var ( func init() { var err error - if nginxExecutable, err = config.InitialiseNSMCtl(); err != nil { + if err = config.InitialiseNSMCtl(); err != nil { fmt.Println(err) os.Exit(1) } @@ -40,6 +41,15 @@ func main() { os.Exit(1) } + err = os.Setenv("KUBECONFIG", path.Join( + config.KubeConfig[configprovider.FilePath], + fmt.Sprintf("%s.%s", config.KubeConfig[configprovider.FileName], config.KubeConfig[configprovider.FileType])), + ) + if err != nil { + // Fail silently + log.Warn(err) + } + // Initialize application specific configs and dependencies // App and request config cfg, err := config.New(configprovider.ViperKey) @@ -69,7 +79,7 @@ func main() { // } // Initialize Handler intance - handler := nginx.New(cfg, log, kubeconfigHandler, nginxExecutable) + handler := nginx.New(cfg, log, kubeconfigHandler) handler = adapter.AddLogger(log, handler) service.Handler = handler diff --git a/nginx/custom_operation.go b/nginx/custom_operation.go new file mode 100644 index 0000000..838d017 --- /dev/null +++ b/nginx/custom_operation.go @@ -0,0 +1,17 @@ +// Package nginx - Common operations for the adapter +package nginx + +import ( + "github.com/layer5io/meshery-adapter-library/status" +) + +func (nginx *Nginx) applyCustomOperation(namespace string, manifest string, isDel bool) (string, error) { + st := status.Starting + + err := nginx.applyManifest([]byte(manifest), isDel, namespace) + if err != nil { + return st, ErrCustomOperation(err) + } + + return status.Completed, nil +} diff --git a/nginx/error.go b/nginx/error.go index 52d9ca1..22cb6a4 100644 --- a/nginx/error.go +++ b/nginx/error.go @@ -1,54 +1,58 @@ package nginx import ( - "fmt" - "github.com/layer5io/meshkit/errors" ) var ( - ErrInstallNginxCode = "nginx_test_code" - ErrMeshConfigCode = "nginx_test_code" - ErrClientConfigCode = "nginx_test_code" - ErrStreamEventCode = "nginx_test_code" - ErrExecDeployCode = "nginx_test_code" - ErrExecRemoveCode = "nginx_test_code" - ErrSampleAppCode = "nginx_test_code" + ErrInstallNginxCode = "nginx_test_code" + ErrMeshConfigCode = "nginx_test_code" + ErrClientConfigCode = "nginx_test_code" + ErrStreamEventCode = "nginx_test_code" + ErrExecDeployCode = "nginx_test_code" + ErrExecRemoveCode = "nginx_test_code" + ErrSampleAppCode = "nginx_test_code" + ErrCustomOperationCode = "nginx_test_code" ErrOpInvalid = errors.NewDefault(errors.ErrOpInvalid, "Invalid operation") ) // ErrInstallNginx is the error for install mesh func ErrInstallNginx(err error) error { - return errors.NewDefault(ErrInstallNginxCode, fmt.Sprintf("Error installing nginx: %s", err.Error())) + return errors.NewDefault(ErrInstallNginxCode, "Error installing nginx", err.Error()) } // ErrMeshConfig is the error for mesh config func ErrMeshConfig(err error) error { - return errors.NewDefault(ErrMeshConfigCode, fmt.Sprintf("Error configuration mesh: %s", err.Error())) + return errors.NewDefault(ErrMeshConfigCode, "Error configuration mesh", err.Error()) } // ErrClientConfig is the error for setting client config func ErrClientConfig(err error) error { - return errors.NewDefault(ErrClientConfigCode, fmt.Sprintf("Error setting client config: %s", err.Error())) + return errors.NewDefault(ErrClientConfigCode, "Error setting client config", err.Error()) } // ErrStreamEvent is the error for streaming event func ErrStreamEvent(err error) error { - return errors.NewDefault(ErrStreamEventCode, fmt.Sprintf("Error streaming event: %s", err.Error())) + return errors.NewDefault(ErrStreamEventCode, "Error streaming event", err.Error()) } // ErrExecDeploy is the error for deploying nginx service mesh func ErrExecDeploy(err error, des string) error { - return errors.NewDefault(ErrExecDeployCode, fmt.Sprintf("Error executing deploy command: %s", des)) + return errors.NewDefault(ErrExecDeployCode, "Error executing deploy command", des) } // ErrExecRemove is the error for removing nginx service mesh func ErrExecRemove(err error, des string) error { - return errors.NewDefault(ErrExecRemoveCode, fmt.Sprintf("Error executing remove command: %s", des)) + return errors.NewDefault(ErrExecRemoveCode, "Error executing remove command", des) } // ErrSampleApp is the error for operations on the sample apps func ErrSampleApp(err error) error { - return errors.NewDefault(ErrSampleAppCode, fmt.Sprintf("Error with sample app operation: %s", err.Error())) + return errors.NewDefault(ErrSampleAppCode, "Error with sample app operation", err.Error()) +} + +// ErrCustomOperation is the error for custom operations +func ErrCustomOperation(err error) error { + return errors.NewDefault(ErrCustomOperationCode, "Error with applying custom operation", err.Error()) } diff --git a/nginx/install.go b/nginx/install.go index 5c0be2f..e8eee51 100644 --- a/nginx/install.go +++ b/nginx/install.go @@ -8,6 +8,7 @@ import ( "github.com/layer5io/meshery-adapter-library/adapter" "github.com/layer5io/meshery-adapter-library/status" + internalconfig "github.com/layer5io/meshery-nginx/internal/config" mesherykube "github.com/layer5io/meshkit/utils/kubernetes" ) @@ -42,16 +43,16 @@ func (nginx *Nginx) runInstallCmd(version string) error { var er, out bytes.Buffer cmd := exec.Command( - nginx.Executable, + internalconfig.NginxExecutable, "deploy", "--nginx-mesh-api-image", - fmt.Sprintf("%s/nginx-mesh-api:%s", nginx.DockerRegistry, version), + fmt.Sprintf("nginx/nginx-mesh-api:%s", version), "--nginx-mesh-sidecar-image", - fmt.Sprintf("%s/nginx-mesh-sidecar:%s", nginx.DockerRegistry, version), + fmt.Sprintf("nginx/nginx-mesh-sidecar:%s", version), "--nginx-mesh-init-image", - fmt.Sprintf("%s/nginx-mesh-init:%s", nginx.DockerRegistry, version), + fmt.Sprintf("nginx/nginx-mesh-init:%s", version), "--nginx-mesh-metrics-image", - fmt.Sprintf("%s/nginx-mesh-metrics:%s", nginx.DockerRegistry, version), + fmt.Sprintf("nginx/nginx-mesh-metrics:%s", version), ) cmd.Stderr = &er cmd.Stdout = &out @@ -79,13 +80,17 @@ func (nginx *Nginx) runUninstallCmd() error { return nil } -func (nginx *Nginx) applyManifest(manifest []byte) error { +func (nginx *Nginx) applyManifest(manifest []byte, isDel bool, namespace string) error { kclient, err := mesherykube.New(nginx.KubeClient, nginx.RestConfig) if err != nil { return err } - err = kclient.ApplyManifest(manifest, mesherykube.ApplyOptions{}) + err = kclient.ApplyManifest(manifest, mesherykube.ApplyOptions{ + Namespace: namespace, + Update: true, + Delete: isDel, + }) if err != nil { return err } diff --git a/nginx/nginx.go b/nginx/nginx.go index a882af4..4a7318c 100644 --- a/nginx/nginx.go +++ b/nginx/nginx.go @@ -15,25 +15,19 @@ import ( type Nginx struct { adapter.Adapter // Type Embedded - // DockerRegistry is the registry for - // nginx service mesh related images - DockerRegistry string - // Executable is the path where the // nginx-meshctl is located Executable string } // New initializes nginx handler. -func New(c adapterconfig.Handler, l logger.Handler, kc adapterconfig.Handler, executable string) adapter.Handler { +func New(c adapterconfig.Handler, l logger.Handler, kc adapterconfig.Handler) adapter.Handler { return &Nginx{ Adapter: adapter.Adapter{ Config: c, Log: l, KubeconfigHandler: kc, }, - DockerRegistry: "layer5", - Executable: executable, } } @@ -70,18 +64,25 @@ func (nginx *Nginx) ApplyOperation(ctx context.Context, opReq adapter.OperationR }(nginx, e) case common.SmiConformanceOperation: go func(hh *Nginx, ee *adapter.Event) { + name := operations[opReq.OperationName].Description err := hh.ValidateSMIConformance(&adapter.SmiTestOptions{ Ctx: context.TODO(), OpID: ee.Operationid, }) if err != nil { + e.Summary = fmt.Sprintf("Error while %s %s test", status.Running, name) + e.Details = err.Error() + hh.StreamErr(e, err) return } + ee.Summary = fmt.Sprintf("%s test %s successfully", name, status.Completed) + ee.Details = "" + hh.StreamInfo(e) }(nginx, e) case common.BookInfoOperation, common.HTTPBinOperation, common.ImageHubOperation, common.EmojiVotoOperation: go func(hh *Nginx, ee *adapter.Event) { appName := operations[opReq.OperationName].AdditionalProperties[common.ServiceName] - stat, err := hh.installSampleApp(opReq.IsDeleteOperation, operations[opReq.OperationName].Templates) + stat, err := hh.installSampleApp(opReq.Namespace, opReq.IsDeleteOperation, operations[opReq.OperationName].Templates) if err != nil { e.Summary = fmt.Sprintf("Error while %s %s application", stat, appName) e.Details = err.Error() @@ -92,6 +93,19 @@ func (nginx *Nginx) ApplyOperation(ctx context.Context, opReq adapter.OperationR ee.Details = fmt.Sprintf("The %s application is now %s.", appName, stat) hh.StreamInfo(e) }(nginx, e) + case common.CustomOperation: + go func(hh *Nginx, ee *adapter.Event) { + stat, err := hh.applyCustomOperation(opReq.Namespace, opReq.CustomBody, opReq.IsDeleteOperation) + if err != nil { + e.Summary = fmt.Sprintf("Error while %s custom operation", stat) + e.Details = err.Error() + hh.StreamErr(e, err) + return + } + ee.Summary = fmt.Sprintf("Manifest %s successfully", status.Deployed) + ee.Details = "" + hh.StreamInfo(e) + }(nginx, e) default: nginx.StreamErr(e, ErrOpInvalid) } diff --git a/nginx/sample_apps.go b/nginx/sample_apps.go index d10cf71..511a6b3 100644 --- a/nginx/sample_apps.go +++ b/nginx/sample_apps.go @@ -1,12 +1,18 @@ package nginx import ( + "context" + "fmt" + "io/ioutil" + "strings" + "github.com/layer5io/meshery-adapter-library/adapter" "github.com/layer5io/meshery-adapter-library/status" "github.com/layer5io/meshkit/utils" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func (nginx *Nginx) installSampleApp(del bool, templates []adapter.Template) (string, error) { +func (nginx *Nginx) installSampleApp(namespace string, del bool, templates []adapter.Template) (string, error) { st := status.Installing if del { @@ -14,12 +20,12 @@ func (nginx *Nginx) installSampleApp(del bool, templates []adapter.Template) (st } for _, template := range templates { - contents, err := utils.ReadRemoteFile(string(template)) + contents, err := readFileSource(string(template)) if err != nil { return st, ErrSampleApp(err) } - err = nginx.applyManifest([]byte(contents)) + err = nginx.applyManifest([]byte(contents), del, namespace) if err != nil { return st, ErrSampleApp(err) } @@ -27,3 +33,84 @@ func (nginx *Nginx) installSampleApp(del bool, templates []adapter.Template) (st return status.Installed, nil } + +// readFileSource supports "http", "https" and "file" protocols. +// it takes in the location as a uri and returns the contents of +// file as a string. +// +// TODO: May move this function to meshkit +func readFileSource(uri string) (string, error) { + if strings.HasPrefix(uri, "http") { + return utils.ReadRemoteFile(uri) + } + if strings.HasPrefix(uri, "file") { + return readLocalFile(uri) + } + + return "", fmt.Errorf("invalid protocol: only http, https and file are valid protocols") +} + +// readLocalFile takes in the location of a local file +// in the format `file://location/of/file` and returns +// the content of the file if the path is valid and no +// error occurs +func readLocalFile(location string) (string, error) { + // remove the protocol prefix + location = strings.TrimPrefix(location, "file://") + + // Need to support variable file locations hence + // #nosec + data, err := ioutil.ReadFile(location) + if err != nil { + return "", err + } + + return string(data), nil +} + +// LoadToMesh is used to mark deployment for automatic sidecar injection (or not) +func (nginx *Nginx) LoadToMesh(namespace string, service string, remove bool) error { + deploy, err := nginx.KubeClient.AppsV1().Deployments(namespace).Get(context.TODO(), service, metav1.GetOptions{}) + if err != nil { + return err + } + + if deploy.ObjectMeta.Labels == nil { + deploy.ObjectMeta.Labels = map[string]string{} + } + deploy.ObjectMeta.Labels["injector.nsm.nginx.com/auto-inject"] = "true" + + if remove { + deploy.ObjectMeta.Labels["injector.nsm.nginx.com/auto-inject"] = "false" + } + + _, err = nginx.KubeClient.AppsV1().Deployments(namespace).Update(context.TODO(), deploy, metav1.UpdateOptions{}) + if err != nil { + return err + } + + return nil +} + +// LoadNamespaceToMesh is used to mark namespaces for automatic sidecar injection (or not) +func (nginx *Nginx) LoadNamespaceToMesh(namespace string, remove bool) error { + ns, err := nginx.KubeClient.CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{}) + if err != nil { + return err + } + + if ns.ObjectMeta.Labels == nil { + ns.ObjectMeta.Labels = map[string]string{} + } + ns.ObjectMeta.Labels["injector.nsm.nginx.com/auto-inject"] = "true" + + if remove { + ns.ObjectMeta.Labels["injector.nsm.nginx.com/auto-inject"] = "false" + } + + _, err = nginx.KubeClient.CoreV1().Namespaces().Update(context.TODO(), ns, metav1.UpdateOptions{}) + if err != nil { + return err + } + return nil +} diff --git a/scripts/delete.sh b/scripts/delete.sh deleted file mode 100755 index c691ecf..0000000 --- a/scripts/delete.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -set -e - -if ! ./scripts/nginx-meshctl remove -y; then - exit 1 -fi diff --git a/scripts/deploy.sh b/scripts/deploy.sh deleted file mode 100755 index 3a9342a..0000000 --- a/scripts/deploy.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -set -e - -if ! scripts/nginx-meshctl deploy --nginx-mesh-api-image "${NGINX_DOCKER_REGISTRY}/nginx-mesh-api:${NGINX_MESH_VER}" --nginx-mesh-sidecar-image "${DOCKER_REGISTRY}/nginx-mesh-sidecar:${NGINX_MESH_VER}" --nginx-mesh-init-image "${DOCKER_REGISTRY}/nginx-mesh-init:${NGINX_MESH_VER}" --nginx-mesh-metrics-image "${DOCKER_REGISTRY}/nginx-mesh-metrics:${NGINX_MESH_VER}"; then - exit 1 -fi From 1bb8e3f97ba45be511333cd78c7e608d54c7c35d Mon Sep 17 00:00:00 2001 From: kumarabd Date: Mon, 21 Dec 2020 16:31:22 +0530 Subject: [PATCH 2/9] ci fixes Signed-off-by: kumarabd --- .github/workflows/build-and-release.yml | 16 ++- .github/workflows/ci.yml | 126 +++++++++++++++++------- 2 files changed, 104 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index d0455c3..1d578f6 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -1,4 +1,4 @@ -name: Meshery-NGINX Build and Releaser +name: Meshery-nginx Build and Releaser on: push: branches: @@ -7,6 +7,20 @@ on: - 'v*' jobs: + build: + name: Build check + runs-on: ubuntu-latest + # needs: [lint, error_check, static_check, vet, sec_check, tests] + steps: + - name: Check out code + uses: actions/checkout@master + with: + fetch-depth: 1 + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: ${{ secrets.GO_VERSION }} + - run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go build . docker: name: Docker build and push runs-on: ubuntu-latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30b456e..7b783b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,50 +1,102 @@ -name: Meshery NGINX SM +name: Meshery Nginx SM on: push: branches: - - 'master' + - "*" tags: - - 'v*' + - "v*" pull_request: branches: - - 'master' - + - master jobs: - golangci: - name: golangci-lint + lint: + name: Check & Review code runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v1 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.32 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - - build: - name: Build check + - name: Check out code + uses: actions/checkout@master + with: + fetch-depth: 1 + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: ${{ secrets.GO_VERSION }} + - run: GOPROXY=direct GOSUMDB=off go get -u golang.org/x/lint/golint; go list ./nginx/... | grep -v /vendor/ | xargs -L1 /home/runner/go/bin/golint -set_exit_status + error_check: + name: Error check + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@master + with: + fetch-depth: 1 + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: ${{ secrets.GO_VERSION }} + - run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go get -u github.com/kisielk/errcheck; /home/runner/go/bin/errcheck -tags draft ./... + static_check: + name: Static check + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@master + with: + fetch-depth: 1 + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: ${{ secrets.GO_VERSION }} + - run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go get -u honnef.co/go/tools/cmd/staticcheck; /home/runner/go/bin/staticcheck -tags draft -checks all ./nginx/... # https://staticcheck.io/docs/checks + vet: + name: Vet + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@master + with: + fetch-depth: 1 + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: ${{ secrets.GO_VERSION }} + - run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go vet -tags draft ./... + sec_check: + name: Security check runs-on: ubuntu-latest - # needs: [lint, error_check, static_check, vet, sec_check, tests] + env: + GO111MODULE: on steps: - - name: Check out code - uses: actions/checkout@master - with: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Run Gosec Security Scanner + uses: securego/gosec@master + with: + args: ./... -exclude=G301,G304,G107,G101,G110 + tests: + # needs: [lint, error_check, static_check, vet, sec_check] + name: Tests + runs-on: ubuntu-latest + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + steps: + - name: Check out code + uses: actions/checkout@master + with: fetch-depth: 1 - - name: Setup Go - uses: actions/setup-go@v1 - with: + - name: Setup Go + uses: actions/setup-go@v1 + with: go-version: ${{ secrets.GO_VERSION }} - # TODO(kushthedude): remove the cache clear sub-step once the mod checksum error is solved - - run: | - go clean -modcache - GO111MODULE=on go build . \ No newline at end of file + - name: Create cluster using KinD + uses: engineerd/setup-kind@v0.3.0 + with: + version: "v0.7.0" + - run: | + export CURRENTCONTEXT="$(kubectl config current-context)" + echo "current-context:" ${CURRENTCONTEXT} + export KUBECONFIG="${HOME}/.kube/config" + echo "environment-kubeconfig:" ${KUBECONFIG} + GOPROXY=direct GOSUMDB=off GO111MODULE=on go test ./... \ No newline at end of file From 9642aaa556f552f2e11951815cd22ae196116dcb Mon Sep 17 00:00:00 2001 From: kumarabd Date: Wed, 23 Dec 2020 18:37:55 +0530 Subject: [PATCH 3/9] added binary to the container Signed-off-by: kumarabd --- Dockerfile | 2 ++ nginx/install.go | 2 +- nginx/nginx.go | 4 ---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0f8e49a..8813591 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,8 @@ RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o meshery- FROM gcr.io/distroless/base ENV DISTRO="debian" ENV GOARCH="amd64" +WORKDIR /.meshery +COPY bin/nginx-meshctl . WORKDIR / COPY --from=builder /build/meshery-nginx . ENTRYPOINT ["/meshery-nginx"] \ No newline at end of file diff --git a/nginx/install.go b/nginx/install.go index e8eee51..4a4ccae 100644 --- a/nginx/install.go +++ b/nginx/install.go @@ -69,7 +69,7 @@ func (nginx *Nginx) runUninstallCmd() error { var er bytes.Buffer // Remove the service mesh from kubernetes - cmd := exec.Command(nginx.Executable, "remove", "-y") + cmd := exec.Command(internalconfig.NginxExecutable, "remove", "-y") cmd.Stderr = &er if err := cmd.Run(); err != nil { diff --git a/nginx/nginx.go b/nginx/nginx.go index 4a7318c..1a7a49b 100644 --- a/nginx/nginx.go +++ b/nginx/nginx.go @@ -14,10 +14,6 @@ import ( type Nginx struct { adapter.Adapter // Type Embedded - - // Executable is the path where the - // nginx-meshctl is located - Executable string } // New initializes nginx handler. From e5a0daf71fe00356c1e59a356141a0eac67781ae Mon Sep 17 00:00:00 2001 From: Lee Calcote Date: Thu, 24 Dec 2020 08:51:31 -0600 Subject: [PATCH 4/9] Update internal/config/error.go --- internal/config/error.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/error.go b/internal/config/error.go index 72cd2c5..8860857 100644 --- a/internal/config/error.go +++ b/internal/config/error.go @@ -26,7 +26,7 @@ const ( var ( ErrEmptyConfig = errors.NewDefault(ErrEmptyConfigCode, "Config is empty") ) - +// ErrInstallBinary captures failure to update filesystem permissions func ErrInstallBinary(err error) error { return errors.NewDefault(ErrInstallBinaryCode, "Failed to change permission of the binary", err.Error()) } From 19a5979202253f57dcaa1e844a46daa79b023da4 Mon Sep 17 00:00:00 2001 From: Lee Calcote Date: Thu, 24 Dec 2020 08:51:38 -0600 Subject: [PATCH 5/9] Update nginx/error.go --- nginx/error.go | 1 + 1 file changed, 1 insertion(+) diff --git a/nginx/error.go b/nginx/error.go index 22cb6a4..ebcebab 100644 --- a/nginx/error.go +++ b/nginx/error.go @@ -5,6 +5,7 @@ import ( ) var ( + // ErrInstallNginxCode should really have an error code defined by now. ErrInstallNginxCode = "nginx_test_code" ErrMeshConfigCode = "nginx_test_code" ErrClientConfigCode = "nginx_test_code" From 2ff7d9097ccb4c940139652d5cb47348cd76d5a7 Mon Sep 17 00:00:00 2001 From: Lee Calcote Date: Thu, 24 Dec 2020 08:51:42 -0600 Subject: [PATCH 6/9] Update nginx/nginx.go --- nginx/nginx.go | 1 + 1 file changed, 1 insertion(+) diff --git a/nginx/nginx.go b/nginx/nginx.go index 1a7a49b..c16b5ab 100644 --- a/nginx/nginx.go +++ b/nginx/nginx.go @@ -12,6 +12,7 @@ import ( "github.com/layer5io/meshkit/logger" ) +// Nginx defines a model for this adapter type Nginx struct { adapter.Adapter // Type Embedded } From f8c022c5723b3b7e36344c52e6936ea7fc8ade23 Mon Sep 17 00:00:00 2001 From: kumarabd Date: Mon, 28 Dec 2020 22:37:35 +0530 Subject: [PATCH 7/9] fixes Signed-off-by: kumarabd --- internal/config/config.go | 2 +- internal/config/error.go | 19 ++++++- internal/config/operations.go | 11 ++-- internal/config/releases.go | 97 +++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 internal/config/releases.go diff --git a/internal/config/config.go b/internal/config/config.go index 94c5d64..1d495a9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -24,7 +24,7 @@ const ( var ( configRootPath = path.Join(utils.GetHome(), ".meshery") - NginxExecutable = path.Join(configRootPath, "nginx-meshctl") + NginxExecutable = "nginx-meshctl" Config = configprovider.Options{ ServerConfig: ServerConfig, diff --git a/internal/config/error.go b/internal/config/error.go index 8860857..975fcd0 100644 --- a/internal/config/error.go +++ b/internal/config/error.go @@ -15,18 +15,33 @@ package config import ( + "fmt" + "github.com/layer5io/meshkit/errors" ) const ( - ErrEmptyConfigCode = "test" - ErrInstallBinaryCode = "test" + ErrEmptyConfigCode = "test" + ErrInstallBinaryCode = "test" + ErrGetLatestReleasesCode = "test" + ErrGetLatestReleaseNamesCode = "test" ) var ( ErrEmptyConfig = errors.NewDefault(ErrEmptyConfigCode, "Config is empty") ) + // ErrInstallBinary captures failure to update filesystem permissions func ErrInstallBinary(err error) error { return errors.NewDefault(ErrInstallBinaryCode, "Failed to change permission of the binary", err.Error()) } + +// ErrGetLatestReleases is the error for fetching istio releases +func ErrGetLatestReleases(err error) error { + return errors.NewDefault(ErrGetLatestReleasesCode, fmt.Sprintf("unable to fetch release info: %s", err.Error())) +} + +// ErrGetLatestReleaseNames is the error for fetching istio releases +func ErrGetLatestReleaseNames(err error) error { + return errors.NewDefault(ErrGetLatestReleaseNamesCode, fmt.Sprintf("failed to extract release names: %s", err.Error())) +} diff --git a/internal/config/operations.go b/internal/config/operations.go index 89400f0..9924b9d 100644 --- a/internal/config/operations.go +++ b/internal/config/operations.go @@ -7,12 +7,17 @@ import ( func getOperations(dev adapter.Operations) adapter.Operations { + versions, _ := getLatestReleaseNames(3) + dev[NginxOperation] = &adapter.Operation{ Type: int32(meshes.OpCategory_INSTALL), Description: "Nginx Service Mesh", - Versions: []adapter.Version{ - "0.6.0", - }, + Versions: versions, + } + + dev[LabelNamespace] = &adapter.Operation{ + Type: int32(meshes.OpCategory_CONFIGURE), + Description: "Automatic Sidecar Injection", } return dev diff --git a/internal/config/releases.go b/internal/config/releases.go new file mode 100644 index 0000000..5e88ad2 --- /dev/null +++ b/internal/config/releases.go @@ -0,0 +1,97 @@ +package config + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "regexp" + "sort" + "strings" + + "github.com/layer5io/meshery-adapter-library/adapter" +) + +// Release is used to save the release informations +type Release struct { + ID int `json:"id,omitempty"` + TagName string `json:"tag_name,omitempty"` + Name adapter.Version `json:"name,omitempty"` + Draft bool `json:"draft,omitempty"` + Assets []*Asset `json:"assets,omitempty"` +} + +// Asset describes the github release asset object +type Asset struct { + Name string `json:"name,omitempty"` + State string `json:"state,omitempty"` + DownloadURL string `json:"browser_download_url,omitempty"` +} + +// getLatestReleaseNames returns the names of the latest releases +// limited by the "limit" parameter. It filters out all the alpha +// rc releases and sorts the result lexographically (descending) +func getLatestReleaseNames(limit int) ([]adapter.Version, error) { + releases, err := GetLatestReleases(uint(limit)) + if err != nil { + return []adapter.Version{}, ErrGetLatestReleaseNames(err) + } + + // Filter out the rc and alpha releases + result := make([]adapter.Version, limit) + r, err := regexp.Compile(`Release \d+(\.\d+){2,}$`) + if err != nil { + return []adapter.Version{}, ErrGetLatestReleaseNames(err) + } + + for _, release := range releases { + releaseStr := string(release.Name) + versionStr := strings.Split(releaseStr, " ")[1] + if r.MatchString(releaseStr) { + result = append(result, adapter.Version(versionStr)) + } + } + + // Sort the result + sort.Slice(result, func(i, j int) bool { + return result[i] > result[j] + }) + + if limit > len(result) { + limit = len(result) + } + + return result[:limit], nil +} + +// GetLatestReleases fetches the latest releases from the osm repository +func GetLatestReleases(releases uint) ([]*Release, error) { + releaseAPIURL := "https://api.github.com/repos/openservicemesh/osm/releases?per_page=" + fmt.Sprint(releases) + // We need a variable url here hence using nosec + // #nosec + resp, err := http.Get(releaseAPIURL) + if err != nil { + return []*Release{}, ErrGetLatestReleases(err) + } + + if resp.StatusCode != http.StatusOK { + return []*Release{}, ErrGetLatestReleases(fmt.Errorf("unexpected status code: %d", resp.StatusCode)) + } + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return []*Release{}, ErrGetLatestReleases(err) + } + + var releaseList []*Release + + if err = json.Unmarshal(body, &releaseList); err != nil { + return []*Release{}, ErrGetLatestReleases(err) + } + + if err = resp.Body.Close(); err != nil { + return []*Release{}, ErrGetLatestReleases(err) + } + + return releaseList, nil +} From 38b06d44fe989b206fe3e3bb2ce5db268adc20dc Mon Sep 17 00:00:00 2001 From: kumarabd Date: Mon, 28 Dec 2020 22:44:24 +0530 Subject: [PATCH 8/9] fixes Signed-off-by: kumarabd --- internal/config/config.go | 16 ++++++++++++---- main.go | 3 +-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 1d495a9..ab3e496 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -99,12 +99,12 @@ func RootPath() string { // "configRootPath" and returns the path for the executable func InitialiseNSMCtl() error { // Look for the executable in the path - executable, err := exec.LookPath(NginxExecutable) + _, err := exec.LookPath(NginxExecutable) if err == nil { return nil } - executable = path.Join(configRootPath, "nginx-meshctl") + executable := path.Join(configRootPath, "nginx-meshctl") if _, err := os.Stat(executable); err == nil { return nil } @@ -151,7 +151,6 @@ func installBinary(location, platform string, res *http.Response) error { if err != nil { return err } - defer out.Close() switch platform { case "darwin": @@ -176,6 +175,15 @@ func installBinary(location, platform string, res *http.Response) error { } // Close the response body - res.Body.Close() + err = out.Close() + if err != nil { + return err + } + + err = res.Body.Close() + if err != nil { + return err + } + return nil } diff --git a/main.go b/main.go index 02866e3..c33acf7 100644 --- a/main.go +++ b/main.go @@ -17,8 +17,7 @@ import ( ) var ( - serviceName = "nginx-adaptor" - nginxExecutable = "" + serviceName = "nginx-adaptor" ) func init() { From bf04b6b609b335a8a0103ae5cfa4ea0dad2585b5 Mon Sep 17 00:00:00 2001 From: kumarabd Date: Mon, 28 Dec 2020 22:47:09 +0530 Subject: [PATCH 9/9] fixes Signed-off-by: kumarabd --- internal/config/config.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index ab3e496..49a02ce 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -166,7 +166,10 @@ func installBinary(location, platform string, res *http.Response) error { return err } - r.Close() + err = r.Close() + if err != nil { + return err + } if err = out.Chmod(0755); err != nil { return ErrInstallBinary(err)