From 1c6579df9a1bf41cd3c5fb5b690f0ec0da949fb1 Mon Sep 17 00:00:00 2001 From: Benoit Plessis Date: Thu, 28 Sep 2023 11:17:55 +0200 Subject: [PATCH 1/5] PLTFRS-18353: Filter out non healthy on non in services instances from ASG --- .github/workflows/release.yml | 81 ++++++++-------------------------- .github/workflows/validate.yml | 16 ++++--- go.mod | 8 ++-- pkg/lookable/asg.go | 12 ++--- 4 files changed, 40 insertions(+), 77 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9ccf7c9..c715499 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,69 +1,39 @@ # This workflow will build a golang project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go -name: Create Release +name: Build Release on: workflow_dispatch: - inputs: - snapshot: - description: 'is snapshot version?' - type: boolean - default: true - required: true - push: - branches: - - master + release: + types: [created] + +permissions: read-all jobs: release: + permissions: + contents: write # To upload release assets. + actions: read # To read workflow path. - strategy: - matrix: - os: ['ubuntu-latest'] - go-version: [1.18.x] - - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - - - - name: Set up Go 1.x - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go-version }} - id: go - - - - name: Compute release version - uses: AirVantage/github-actions/version-action@v37 - id: get-version - with: - is-snapshot: ${{ github.event.inputs.snapshot == 'true' && '1' || '0' }} - - - - name: GitHub Tag & Release - uses: AirVantage/github-actions/github-release-action@v37 - id: create-release - with: - version: ${{ steps.get-version.outputs.version }} - token: ${{ secrets.GITHUB_TOKEN }} - draft: ${{ github.event.inputs.snapshot == 'true' && '1' || '0' }} - - name: Check out code into the Go module directory - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: # Fetch whole repository to get release tags # See https://github.com/actions/checkout/issues/701 fetch-depth: 0 - # Option B: split checkout + local tags ? - #- - # name: Tag local copy - # run: git tag ${{ steps.get-version.outputs.version }} - + - + name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version-file: go.mod + - name: Run GoReleaser uses: goreleaser/goreleaser-action@v3 @@ -72,19 +42,6 @@ jobs: distribution: goreleaser version: latest args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution - # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} - - - - name: Release on JIRA - if: github.event.inputs.snapshot == 'false' - continue-on-error: true # Useful if JIRA is down - uses: AirVantage/github-actions/tag-jira-action@v37 - with: - version: ${{ steps.get-version.outputs.version }} - jira-url: ${{ secrets.JIRA_URL }} - jira-username: ${{ secrets.JIRA_USERNAME }} - jira-password: ${{ secrets.JIRA_PASSWORD }} - repo-name: ${{ github.event.repository.name }} + #env: + # # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index e57e6c5..34ce07e 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -12,28 +12,30 @@ jobs: strategy: matrix: os: ['ubuntu-latest'] - - go-version: [1.18.x] - go-arch: [ amd64 ] + go-arch: [ amd64, arm64 ] go-os: [ linux ] runs-on: ${{ matrix.os }} steps: - name: Check out code into the Go module directory - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Go 1.x uses: actions/setup-go@v3 with: - go-version: ${{ matrix.go-version }} - id: go + go-version-file: go.mod + + - id: govulncheck + uses: golang/govulncheck-action@v1 + with: + go-version-file: go.mod - name: Build run: go build -o build/${{ github.event.repository.name }}-${{ matrix.go-os }}-${{ matrix.go-arch }} -v env: GOARCH: ${{ matrix.go-arch }} GOOS: ${{ matrix.go-os }} - + - name: Test run: go test -v -cover -race -timeout 120s ./... diff --git a/go.mod b/go.mod index acd3dd9..b8b4c1d 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,10 @@ module github.com/AirVantage/overlord -go 1.13 +go 1.21 require ( - github.com/BurntSushi/toml v0.3.1 - github.com/aws/aws-sdk-go v1.31.9 + github.com/BurntSushi/toml v1.3.2 + github.com/aws/aws-sdk-go v1.45.18 ) + +require github.com/jmespath/go-jmespath v0.4.0 // indirect diff --git a/pkg/lookable/asg.go b/pkg/lookable/asg.go index 9d0ef35..6cc4bf3 100644 --- a/pkg/lookable/asg.go +++ b/pkg/lookable/asg.go @@ -56,11 +56,13 @@ func (asg AutoScalingGroup) LookupIPs(ipv6 bool) ([]string, error) { return output, nil } - // Make a list of instance ID - instances := make([]*string, numInstances) - for i, inst := range resp2.AutoScalingGroups[0].Instances { - instances[i] = inst.InstanceId - } + // Make a list of healthy instance ID in the ASG + instances := make([]*string, numInstances) + for i, inst := range resp2.AutoScalingGroups[0].Instances { + if (*inst.HealthStatus == "Healthy" && *inst.LifecycleState == "InService") { + instances[i] = inst.InstanceId + } + } // Find running instances IP params3 := &ec2.DescribeInstancesInput{ From f669f5d7c78adf9c106b2bf27ac68bb1741189c5 Mon Sep 17 00:00:00 2001 From: Benoit Plessis Date: Thu, 28 Sep 2023 11:20:44 +0200 Subject: [PATCH 2/5] add the missing go.sum updates --- go.sum | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/go.sum b/go.sum index cd9d165..0f82a3f 100644 --- a/go.sum +++ b/go.sum @@ -1,25 +1,44 @@ -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/aws/aws-sdk-go v1.31.9 h1:n+b34ydVfgC30j0Qm69yaapmjejQPW2BoDBX7Uy/tLI= -github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/aws/aws-sdk-go v1.45.18 h1:uSOGg4LFtpQH/bq9FsumMKfZHNl7BdH7WURHOqKXHNU= +github.com/aws/aws-sdk-go v1.45.18/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= 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/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= -github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 823dee9edcdc8214fae459b6bead1f8b00490658 Mon Sep 17 00:00:00 2001 From: Benoit Plessis Date: Thu, 28 Sep 2023 11:27:04 +0200 Subject: [PATCH 3/5] bump setup-go --- .github/workflows/release.yml | 2 +- .github/workflows/validate.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c715499..d39ec7d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: - name: Set up Go 1.x - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: go-version-file: go.mod diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 34ce07e..73a5ca4 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Go 1.x - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: go-version-file: go.mod @@ -30,6 +30,7 @@ jobs: uses: golang/govulncheck-action@v1 with: go-version-file: go.mod + repo-checkout: false - name: Build run: go build -o build/${{ github.event.repository.name }}-${{ matrix.go-os }}-${{ matrix.go-arch }} -v From 5c95411ecb9083354a5bbed8d93f13bed04d9fde Mon Sep 17 00:00:00 2001 From: Benoit Plessis Date: Thu, 28 Sep 2023 11:29:59 +0200 Subject: [PATCH 4/5] bump govulncheck --- .github/workflows/validate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 73a5ca4..aaf9c3c 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -27,7 +27,7 @@ jobs: go-version-file: go.mod - id: govulncheck - uses: golang/govulncheck-action@v1 + uses: golang/govulncheck-action@v1.0.1 with: go-version-file: go.mod repo-checkout: false From a3bd936a03e7ed5f0c9a75938f1dcd2bb1e21a68 Mon Sep 17 00:00:00 2001 From: Benoit Plessis Date: Tue, 3 Oct 2023 18:11:45 +0200 Subject: [PATCH 5/5] Avoid allocating a fixed slice, and filling it with 'holes', instead use append() --- pkg/lookable/asg.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/lookable/asg.go b/pkg/lookable/asg.go index 6cc4bf3..5947a75 100644 --- a/pkg/lookable/asg.go +++ b/pkg/lookable/asg.go @@ -57,13 +57,19 @@ func (asg AutoScalingGroup) LookupIPs(ipv6 bool) ([]string, error) { } // Make a list of healthy instance ID in the ASG - instances := make([]*string, numInstances) - for i, inst := range resp2.AutoScalingGroups[0].Instances { + instances := make([]*string, 0, numInstances) + for _, inst := range resp2.AutoScalingGroups[0].Instances { if (*inst.HealthStatus == "Healthy" && *inst.LifecycleState == "InService") { - instances[i] = inst.InstanceId + instances = append(instances, inst.InstanceId) } } + // No healthy instances + if len(instances) == 0 { + return nil, nil + } + + // Find running instances IP params3 := &ec2.DescribeInstancesInput{ InstanceIds: instances,