Skip to content

Commit

Permalink
Merge branch 'main' into apply-changes-force-latest-variables-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneadams authored Apr 11, 2024
2 parents 7a378b1 + 284d75c commit fa73b79
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.22.0
go-version-file: './om/go.mod'

- name: Test
run: |
go install github.com/onsi/ginkgo/ginkgo
Expand Down
63 changes: 62 additions & 1 deletion .github/workflows/upgrade-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ concurrency: Upgrade Golang 2

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 1'

jobs:
upgrade-golang:
Expand All @@ -17,8 +19,67 @@ jobs:
shell: bash

steps:
- name: Checkout Om
- id: checkout-om
name: Checkout Om
uses: actions/checkout@v2
with:
fetch-depth: 0
path: om

- id: setup-go
name: Set Go to latest
uses: actions/setup-go@v5
with:
check-latest: true

- id: upgrade-golang
name: Upgrade Golang
working-directory: om
run: |
version=$(go version | awk '{print $3}' | sed 's/go//')
echo "Current go version: $version"
go mod edit -go=$version
go get -u -t ./...
go mod tidy
- id: install-gh-cli
name: Install GH CLI
uses: dev-hanz-ops/[email protected]
with:
gh-cli-version: 2.43.1

- id: commit-changes-and-create-pr
name: Commit changes and create PR
working-directory: om
run: |
set -x
branch_suffix=$(echo "${GITHUB_SHA}" | cut -c1-7)
branch_name="tmp/upgrade-golang-${branch_suffix}"
if git show-ref --verify --quiet "refs/remotes/origin/${branch_name}"; then
echo "Branch ${branch_name} already exists. Exiting..."
exit 0
fi
if gh pr list --search "Upgrade Golang in:title" | grep -q "Upgrade Golang"; then
echo "PR with title 'Upgrade Golang' already exists. Exiting..."
exit 0
fi
files_changed=$(git status --porcelain)
if [[ -z ${files_changed} ]]; then
echo "No changes to detected. Exiting..."
exit 0
fi
git config --global url.https://${GITHUB_TOKEN}@github.com/.insteadOf https://github.com/
git config --global user.email "[email protected]"
git config --global user.name "tas-operability-bot"
git checkout -b ${branch_name}
git add .
git commit -m "Upgrade Golang"
git push --set-upstream origin ${branch_name}
gh pr create --title "Upgrade Golang" --body "Upgrade Golang" --base main --head ${branch_name}
gh pr merge ${branch_name} --auto --rebase --delete-branch
env:
GITHUB_TOKEN: ${{ secrets.TAS_OPERABILITY_BOT_OM_REPO_PAT }}
22 changes: 10 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,20 @@ git clone https://github.com/pivotal-cf/om

### Run the tests

We recommend running using a minimum of [Go 1.12](https://golang.org/dl).
The tests may run fine, but you may experience issues when using `go run` or `go build`
We recommend running tests through our docker image to ensure that the tests run in a consistent environment.

`om` uses the [ginkgo](https://onsi.github.io/ginkgo/) test framework.
If you have used ginkgo before, make sure it is rebuilt so as to have proper `go mod` support.

No special `bin` or `scripts` dir here, we run the tests with this one-liner:
Here's a one-liner to run the tests:

```bash
ginkgo -r -race -p .
docker run \
-it \
-v $(pwd):/workspace \
-w /workspace internalpcfplatformautomation/ci:testing \
/bin/bash \
-c "go install github.com/onsi/ginkgo/ginkgo && CGO_ENABLED=1 ginkgo -r -race -succinct -randomizeAllSpecs -randomizeSuites -keepGoing -skipPackage acceptance,vmlifecyclecommands,vmmanagers"
```

Several integration tests require [`minio`](https://minio.io/)) to be installed for s3 testing.
For OSX, `brew install minio/stable/minio minio/stable/mc`. These tests will be skipped if minio
is not installed, but to ensure that we will be able to pull in your PR, and that all tests will
pass, it is recommended to install it for local development.
This follows the setup that we use in our CI pipeline.

## Vendoring dependencies

Expand Down Expand Up @@ -140,7 +138,7 @@ on code that is a work in progress.
# Becoming a committer

At this time, there is no official process for becoming a comitter to `om`. The
project is currently maintained by the Platform Provider Experience team. But we're open to new ideas here!
project is currently maintained by the TAS Operability team. But we're open to new ideas here!

# Prior Art

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ To build from source, after you've cloned the repo,
run these commands from the top level of the repo:

```bash
GO112MODULE=on go mod download
GO112MODULE=on go build
GO111MODULE=on go mod download
GO111MODULE=on go build
```

Go 1.11 uses some heuristics to determine if Go Modules should be used.
Expand Down
18 changes: 16 additions & 2 deletions commands/apply_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,24 @@ func (ac ApplyChanges) Execute(args []string) error {
}

func (ac ApplyChanges) waitForApplyChangesCompletion(installation api.InstallationsServiceOutput) error {
const maxRetries = 3

for {
current, err := ac.service.GetInstallation(installation.ID)
var current api.InstallationsServiceOutput
var err error

for i := 0; i < maxRetries; i++ {
current, err = ac.service.GetInstallation(installation.ID)
if err == nil {
break
}
if i < maxRetries-1 {
time.Sleep(ac.waitDuration)
}
}

if err != nil {
return fmt.Errorf("installation failed to get status: %s", err)
return fmt.Errorf("installation failed to get status after %d attempts: %s", maxRetries, err)
}

install, err := ac.service.GetInstallationLogs(installation.ID)
Expand Down
35 changes: 33 additions & 2 deletions commands/apply_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ var _ = Describe("ApplyChanges", func() {
Expect(writer.FlushArgsForCall(2)).To(Equal("some other logs"))
})

It("retries apply changes to the Ops Manager", func() {
service.GetInstallationReturnsOnCall(0, api.InstallationsServiceOutput{}, errors.New("some error"))
service.GetInstallationReturnsOnCall(1, api.InstallationsServiceOutput{Status: "running"}, nil)
service.GetInstallationReturnsOnCall(2, api.InstallationsServiceOutput{Status: "succeeded"}, nil)

command := commands.NewApplyChanges(service, pendingService, writer, logger, 1)

err := executeCommand(command, []string{})
Expect(err).ToNot(HaveOccurred())

Expect(service.CreateInstallationCallCount()).To(Equal(1))

ignoreWarnings, deployProducts, _, _ := service.CreateInstallationArgsForCall(0)
Expect(ignoreWarnings).To(Equal(false))
Expect(deployProducts).To(Equal(true))

Expect(stderr).To(gbytes.Say("attempting to apply changes to the targeted Ops Manager"))

Expect(service.GetInstallationArgsForCall(0)).To(Equal(311))
Expect(service.GetInstallationCallCount()).To(Equal(3))

Expect(service.GetInstallationLogsArgsForCall(0)).To(Equal(311))
Expect(service.GetInstallationLogsCallCount()).To(Equal(2))

Expect(writer.FlushCallCount()).To(Equal(2))
Expect(writer.FlushArgsForCall(0)).To(Equal("start of logs"))
Expect(writer.FlushArgsForCall(1)).To(Equal("these logs"))
})

When("passed the ignore-warnings flag", func() {
It("applies changes while ignoring warnings", func() {
service.InfoReturns(api.Info{Version: "2.3-build43"}, nil)
Expand Down Expand Up @@ -490,12 +519,14 @@ errands: lolololol
When("getting the installation status has an error", func() {
It("returns an error", func() {
service.CreateInstallationReturns(api.InstallationsServiceOutput{ID: 311}, nil)
service.GetInstallationReturnsOnCall(0, api.InstallationsServiceOutput{}, errors.New("another error"))
service.GetInstallationReturnsOnCall(0, api.InstallationsServiceOutput{}, errors.New("first error"))
service.GetInstallationReturnsOnCall(1, api.InstallationsServiceOutput{}, errors.New("second error"))
service.GetInstallationReturnsOnCall(2, api.InstallationsServiceOutput{}, errors.New("third error"))

command := commands.NewApplyChanges(service, pendingService, writer, logger, 1)

err := executeCommand(command, []string{})
Expect(err).To(MatchError("installation failed to get status: another error"))
Expect(err).To(MatchError("installation failed to get status after 3 attempts: third error"))
})
})

Expand Down
1 change: 0 additions & 1 deletion depstability/records/depnames-7.11.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ github.com/cloudfoundry/config-server
github.com/cloudfoundry/go-socks5
github.com/cloudfoundry/socks5-proxy
github.com/cncf/udpa/go
github.com/cncf/xds/go
github.com/cppforlife/go-patch
github.com/cppforlife/go-semi-semantic
github.com/creack/pty
Expand Down
60 changes: 30 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/pivotal-cf/om

go 1.22.0
go 1.22.1

require (
cloud.google.com/go/storage v1.37.0
cloud.google.com/go/storage v1.39.1
code.cloudfoundry.org/credhub-cli v0.0.0-20201102140135-1a6b82ad1f99
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.29
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12
github.com/aws/aws-sdk-go v1.50.12
github.com/aws/aws-sdk-go v1.50.37
github.com/blang/semver v3.5.1+incompatible
github.com/bmatcuk/doublestar v1.3.4
github.com/cheggaaa/pb/v3 v3.1.5
Expand All @@ -29,24 +29,24 @@ require (
github.com/pivotal-cf/pivnet-cli/v2 v2.0.2
github.com/pivotal-cf/replicator v0.0.0-20181127185712-7c58987ce14b
github.com/pivotal-cf/winfs-injector v0.0.0-20200827170301-91411420d92f
github.com/vmware/govmomi v0.34.2
golang.org/x/oauth2 v0.16.0
google.golang.org/api v0.162.0
github.com/vmware/govmomi v0.36.1
golang.org/x/oauth2 v0.18.0
google.golang.org/api v0.169.0
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
howett.net/ranger v0.0.0-20171016084633-e2e137620847
)

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.23.4 // indirect
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute v1.25.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
code.cloudfoundry.org/archiver v0.0.0-20200131002800-4ca7245c29b1 // indirect
code.cloudfoundry.org/clock v1.0.0 // indirect
code.cloudfoundry.org/hydrator v0.0.0-20191120195058-919ca7133daa // indirect
code.cloudfoundry.org/tlsconfig v0.0.0-20240116140718-a2c58c2ff70c // indirect
code.cloudfoundry.org/tlsconfig v0.0.0-20240308143921-4b874b341ed6 // indirect
code.cloudfoundry.org/workpool v0.0.0-20200131000409-2ac56b354115 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.23 // indirect
Expand All @@ -64,10 +64,10 @@ require (
github.com/cloudfoundry/bosh-davcli v0.0.44 // indirect
github.com/cloudfoundry/bosh-gcscli v0.0.6 // indirect
github.com/cloudfoundry/bosh-s3cli v0.0.95 // indirect
github.com/cloudfoundry/bosh-utils v0.0.430 // indirect
github.com/cloudfoundry/bosh-utils v0.0.450 // indirect
github.com/cloudfoundry/config-server v0.1.21 // indirect
github.com/cloudfoundry/go-socks5 v0.0.0-20180221174514-54f73bdb8a8e // indirect
github.com/cloudfoundry/socks5-proxy v0.2.108 // indirect
github.com/cloudfoundry/socks5-proxy v0.2.115 // indirect
github.com/cppforlife/go-semi-semantic v0.0.0-20160921010311-576b6af77ae4 // indirect
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
Expand All @@ -85,13 +85,13 @@ require (
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect
Expand All @@ -115,7 +115,7 @@ require (
github.com/pivotal-cf/jhanda v0.0.0-20200619200912-8de8eb943a43 // indirect
github.com/pivotal-cf/paraphernalia v0.0.0-20180203224945-a64ae2051c20 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.6 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
Expand All @@ -124,26 +124,26 @@ require (
github.com/xlab/treeprint v1.2.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
go.opentelemetry.io/otel v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.23.0 // indirect
go.opentelemetry.io/otel/trace v1.23.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand Down
Loading

0 comments on commit fa73b79

Please sign in to comment.