Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump golang to 1.21 #62

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
FROM golang:1.17.9-buster AS build
FROM golang:1.21.3 AS build
ARG VERSION="local"
COPY . /app

WORKDIR /app
RUN go get -d

# Download dependencies
COPY go.mod .
COPY go.sum .
RUN go mod download

# Copy actual go files
COPY *.go .

# Test and build
RUN go test -test.timeout 30s
RUN CGO_ENABLED=0 go build -o scuttle -ldflags="-X 'main.Version=${VERSION}'"

FROM alpine as test
# This image is used for local testing scuttle in a container with shell tooling
COPY --from=build /app/scuttle /scuttle

FROM scratch
COPY --from=build /app/scuttle /scuttle
14 changes: 2 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
module github.com/redboxllc/scuttle

go 1.14
go 1.21

require (
github.com/cenk/backoff v2.1.1+incompatible
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/monzo/slog v0.0.0-20200629180744-4e22e890d327 // indirect
github.com/monzo/terrors v0.0.0-20191030112059-325b9ec5dcdf // indirect
github.com/monzo/typhon v0.0.0-20190413083455-45c89a830a76
github.com/stretchr/testify v1.6.1 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
)
require github.com/cenk/backoff v2.2.1+incompatible
59 changes: 2 additions & 57 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,57 +1,2 @@
github.com/cenk/backoff v2.1.1+incompatible h1:gaShhlJc32b7ht9cwld/ti0z7tJOf69oUEA8jJNYV48=
github.com/cenk/backoff v2.1.1+incompatible/go.mod h1:7FtoeaSnHoZnmZzz47cM35Y9nSW7tNyaidugnHTaFDE=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/monzo/slog v0.0.0-20200629180744-4e22e890d327 h1:81B3hRUnClvhrui1IjSkaAesTWyqwu4xFm2UeUagA+U=
github.com/monzo/slog v0.0.0-20200629180744-4e22e890d327/go.mod h1:WLNpEHhXIwQynoqjGY9HxPbseatrTIBTbG1Rij/oCXY=
github.com/monzo/terrors v0.0.0-20191030112059-325b9ec5dcdf h1:bc56AoaESXUcGSkXQwIN5FZwNl+lYr5RWawqzyjCank=
github.com/monzo/terrors v0.0.0-20191030112059-325b9ec5dcdf/go.mod h1:gfOuNDWYOyNdgpG0gUVODIjwDBQRXe+mPjnTybHGb5k=
github.com/monzo/typhon v0.0.0-20190413083455-45c89a830a76 h1:nsEO/Xl50HrEHIIw8k/pIrXVdGCxVgqmdZPUo8Da+S4=
github.com/monzo/typhon v0.0.0-20190413083455-45c89a830a76/go.mod h1:PwlvLMpr2GwvL6TJsROBExc1KTxZz2BHu4wSX7c+dyQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/cenk/backoff v2.2.1+incompatible h1:djdFT7f4gF2ttuzRKPbMOWgZajgesItGLwG5FTQKmmE=
github.com/cenk/backoff v2.2.1+incompatible/go.mod h1:7FtoeaSnHoZnmZzz47cM35Y9nSW7tNyaidugnHTaFDE=
57 changes: 42 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"os/exec"
"os/signal"
"strings"
"time"
"syscall"
"time"

"github.com/cenk/backoff"
"github.com/monzo/typhon"
)

// ServerInfo ... represents the response from Envoy's server info endpoint
Expand All @@ -25,7 +26,10 @@ type ServerInfo struct {
var Version = "vlocal"

var (
config ScuttleConfig
config ScuttleConfig
httpClient = &http.Client{
Timeout: 30 * time.Second,
}
)

func main() {
Expand Down Expand Up @@ -70,11 +74,11 @@ func main() {
var proc *os.Process
stop := make(chan os.Signal, 2)
signal.Notify(stop, syscall.SIGINT) // Only listen to SIGINT until after child proc starts

// Pass signals to the child process
// This takes an OS signal and passes to the child process scuttle starts (proc)
go func() {

for sig := range stop {
if sig == syscall.SIGURG {
// SIGURG is used by Golang for it's own purposes, ignore it as these signals
Expand All @@ -87,7 +91,7 @@ func main() {
} else {
// Proc is not null, so the child process is running and should also receive this signal
log(fmt.Sprintf("Received signal '%v', passing to child", sig))
proc.Signal(sig)
_ = proc.Signal(sig)
}
}
}()
Expand Down Expand Up @@ -115,6 +119,19 @@ func main() {
os.Exit(exitCode)
}

func executeHttpRequest(ctx context.Context, method, url string) (*http.Response, error) {
req, err := http.NewRequestWithContext(ctx, method, url, nil)
if err != nil {
return nil, err
}

resp, err := httpClient.Do(req)
if err != nil {
return nil, err
}
return resp, nil
}

func kill(exitCode int) {
var logLineUnformatted = "Kill received: (Action: %s, Reason: %s, Exit Code: %d)"
switch {
Expand Down Expand Up @@ -145,13 +162,16 @@ func killGenericEndpoints() {
return
}

ctx := context.Background()

for _, genericEndpoint := range config.GenericQuitEndpoints {
genericEndpoint = strings.Trim(genericEndpoint, " ")
resp := typhon.NewRequest(context.Background(), "POST", genericEndpoint, nil).Send().Response()
if resp.Error != nil {
log(fmt.Sprintf("Sent POST to '%s', error: %s", genericEndpoint, resp.Error))
resp, err := executeHttpRequest(ctx, "POST", genericEndpoint)
if err != nil {
log(fmt.Sprintf("Sent POST to '%s', error: %s", genericEndpoint, err))
continue
}
_ = resp.Body.Close()
log(fmt.Sprintf("Sent POST to '%s', status code: %d", genericEndpoint, resp.StatusCode))
}
}
Expand All @@ -160,11 +180,11 @@ func killIstioWithAPI() {
log(fmt.Sprintf("Stopping Istio using Istio API '%s' (intended for Istio >v1.2)", config.IstioQuitAPI))

url := fmt.Sprintf("%s/quitquitquit", config.IstioQuitAPI)
resp := typhon.NewRequest(context.Background(), "POST", url, nil).Send().Response()
responseSuccess := false

if resp.Error != nil {
log(fmt.Sprintf("Sent quitquitquit to Istio, error: %d", resp.Error))
responseSuccess := false
resp, err := executeHttpRequest(context.Background(), "POST", url)
if err != nil {
log(fmt.Sprintf("Sent quitquitquit to Istio, error: %d", err))
} else {
log(fmt.Sprintf("Sent quitquitquit to Istio, status code: %d", resp.StatusCode))
responseSuccess = resp.StatusCode == 200
Expand Down Expand Up @@ -221,11 +241,18 @@ func pollEnvoy(ctx context.Context, cancel context.CancelFunc) {

_ = backoff.Retry(func() error {
pollCount++
rsp := typhon.NewRequest(ctx, "GET", url, nil).Send().Response()
rsp, err := executeHttpRequest(ctx, "GET", url)
if err != nil {
log(fmt.Sprintf("Polling Envoy (%d), error: %s", pollCount, err))
return err
}
defer func() {
_ = rsp.Body.Close()
}()

info := &ServerInfo{}

err := rsp.Decode(info)
err = json.NewDecoder(rsp.Body).Decode(info)
if err != nil {
log(fmt.Sprintf("Polling Envoy (%d), error: %s", pollCount, err))
return err
Expand Down
22 changes: 0 additions & 22 deletions vendor/github.com/cenk/backoff/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions vendor/github.com/cenk/backoff/.travis.yml

This file was deleted.

20 changes: 0 additions & 20 deletions vendor/github.com/cenk/backoff/LICENSE

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/github.com/cenk/backoff/README.md

This file was deleted.

66 changes: 0 additions & 66 deletions vendor/github.com/cenk/backoff/backoff.go

This file was deleted.

Loading