Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.go text eol=lf
stembuild/vendor/** -text
Å
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
26 changes: 26 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: go
on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint: # <- name
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: golangci/golangci-lint-action@v8

test-unit: # <- name
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: make test
19 changes: 0 additions & 19 deletions .github/workflows/run-test-pyramid.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "2"

linters:
default: standard

settings:
errcheck:
check-blank: true # assignment to blank identifier: `_ := someFunc()`.

formatters:
enable:
- goimports
16 changes: 8 additions & 8 deletions backup/backup_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (backupDirectory *BackupDirectory) DeploymentMatches(deployment string, ins

for _, inst := range meta.MetadataForEachInstance {
present := backupDirectory.backupInstanceIsPresent(inst, instances)
if present != true {
if present != true { //nolint:staticcheck
backupDirectory.Debug("bbr", "Instance %v/%v not found in %v", inst.Name, inst.Index, instances)
return false, nil
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func (backupDirectory *BackupDirectory) FetchChecksum(artifactIdentifier orchest

func logName(artifactIdentifer orchestrator.ArtifactIdentifier) string {
if artifactIdentifer.HasCustomName() {
return fmt.Sprintf("%s", artifactIdentifer.Name())
return fmt.Sprintf("%s", artifactIdentifer.Name()) //nolint:staticcheck
}
return fmt.Sprintf("%s/%s", artifactIdentifer.Name(), artifactIdentifer.InstanceIndex())
}
Expand All @@ -152,7 +152,7 @@ func (backupDirectory *BackupDirectory) CalculateChecksum(artifactIdentifier orc
if err != nil {
return nil, backupDirectory.logAndReturn(err, "Error opening artifact file %v", artifactIdentifier)
}
defer file.Close()
defer file.Close() //nolint:errcheck

tarReader := tar.NewReader(file)
checksum := map[string]string{}
Expand All @@ -172,7 +172,7 @@ func (backupDirectory *BackupDirectory) CalculateChecksum(artifactIdentifier orc
if _, err := io.Copy(fileShasum, tarReader); err != nil {
return nil, backupDirectory.logAndReturn(err, "Error calculating sha for %s", logName(artifactIdentifier))
}
backupDirectory.Logger.Debug("bbr", "Calculating shasum for local file %s", tarHeader.Name)
backupDirectory.Logger.Debug("bbr", "Calculating shasum for local file %s", tarHeader.Name) //nolint:staticcheck
checksum[tarHeader.Name] = fmt.Sprintf("%x", fileShasum.Sum(nil))
}

Expand Down Expand Up @@ -209,7 +209,7 @@ func (backupDirectory *BackupDirectory) AddChecksum(artifactIdentifier orchestra
}

func (backupDirectory *BackupDirectory) CreateMetadataFileWithStartTime(startTime time.Time) error {
exists, _ := backupDirectory.metadataExistsAndIsReadable()
exists, _ := backupDirectory.metadataExistsAndIsReadable() //nolint:errcheck
if exists {
message := "metadata file already exists"
backupDirectory.Debug("bbr", "%s: %v", message, nil)
Expand All @@ -221,7 +221,7 @@ func (backupDirectory *BackupDirectory) CreateMetadataFileWithStartTime(startTim
StartTime: startTime.Format(timestampFormat),
},
}
metadata.save(backupDirectory.metadataFilename())
metadata.save(backupDirectory.metadataFilename()) //nolint:errcheck

return nil
}
Expand All @@ -235,7 +235,7 @@ func (backupDirectory *BackupDirectory) AddFinishTime(finishTime time.Time) erro
}

metadata.MetadataForBackupActivity.FinishTime = finishTime.Format(timestampFormat)
metadata.save(backupDirectory.metadataFilename())
metadata.save(backupDirectory.metadataFilename()) //nolint:errcheck

return nil
}
Expand All @@ -251,7 +251,7 @@ func (backupDirectory *BackupDirectory) Valid() (bool, error) {
}

for _, artifact := range meta.MetadataForEachArtifact {
actualArtifactChecksum, _ := backupDirectory.CalculateChecksum(makeCustomArtifactIdentifier(artifact))
actualArtifactChecksum, _ := backupDirectory.CalculateChecksum(makeCustomArtifactIdentifier(artifact)) //nolint:errcheck
match, _ := actualArtifactChecksum.Match(artifact.Checksum)
if !match {
return false, backupDirectory.logAndReturn(err, "Can't match checksums for %s, in metadata: %v, in actual file: %v", artifact.Name, actualArtifactChecksum, artifact.Checksum)
Expand Down
26 changes: 13 additions & 13 deletions backup/backup_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("BackupDirectory", func() {
instance2.NameReturns("redis")
instance2.IndexReturns("1")

artifact, _ = backupDirectoryManager.Open(backupName, logger)
artifact, _ = backupDirectoryManager.Open(backupName, logger) //nolint:errcheck
})

Context("when the backup on disk matches the current deployment", func() {
Expand All @@ -68,7 +68,7 @@ instances:
})

It("returns true", func() {
match, _ := artifact.DeploymentMatches(backupName, []orchestrator.Instance{instance1, instance2})
match, _ := artifact.DeploymentMatches(backupName, []orchestrator.Instance{instance1, instance2}) //nolint:errcheck
Expect(match).To(BeTrue())
})
})
Expand All @@ -90,7 +90,7 @@ instances:
})

It("returns false", func() {
match, _ := artifact.DeploymentMatches(backupName, []orchestrator.Instance{instance1, instance2})
match, _ := artifact.DeploymentMatches(backupName, []orchestrator.Instance{instance1, instance2}) //nolint:errcheck
Expect(match).To(BeFalse())
})
})
Expand Down Expand Up @@ -300,7 +300,7 @@ instances:
var fakeBackupArtifact *fakes.FakeBackupArtifact

BeforeEach(func() {
artifact, _ = backupDirectoryManager.Create("", backupName, logger)
artifact, _ = backupDirectoryManager.Create("", backupName, logger) //nolint:errcheck
fakeBackupArtifact = new(fakes.FakeBackupArtifact)
fakeBackupArtifact.InstanceNameReturns("redis-server")
fakeBackupArtifact.InstanceIndexReturns("0")
Expand All @@ -319,7 +319,7 @@ instances:
})

It("writer writes contents to the file", func() {
writer.Write([]byte("lalala a file"))
writer.Write([]byte("lalala a file")) //nolint:errcheck
Expect(os.ReadFile(backupName + "/redis-server-0-redis.tar")).To(Equal([]byte("lalala a file")))
})

Expand All @@ -339,7 +339,7 @@ instances:
})

It("writer writes contents to the file", func() {
writer.Write([]byte("lalala a file"))
writer.Write([]byte("lalala a file")) //nolint:errcheck
Expect(os.ReadFile(backupName + "/my-backup-artifact.tar")).To(Equal([]byte("lalala a file")))
})

Expand All @@ -364,7 +364,7 @@ instances:
var saveManifestError error

BeforeEach(func() {
artifact, _ = backupDirectoryManager.Create("", backupName, logger)
artifact, _ = backupDirectoryManager.Create("", backupName, logger) //nolint:errcheck
})

AfterEach(func() {
Expand All @@ -390,7 +390,7 @@ instances:
var fakeBackupArtifact *fakes.FakeBackupArtifact

BeforeEach(func() {
artifact, _ = backupDirectoryManager.Open(backupName, logger)
artifact, _ = backupDirectoryManager.Open(backupName, logger) //nolint:errcheck
fakeBackupArtifact = new(fakes.FakeBackupArtifact)
fakeBackupArtifact.InstanceNameReturns("redis-server")
fakeBackupArtifact.InstanceIndexReturns("0")
Expand Down Expand Up @@ -472,7 +472,7 @@ instances:
fakeBackupArtifact.InstanceIndexReturns("0")
})
JustBeforeEach(func() {
artifact, _ = backupDirectoryManager.Create("", backupName, logger)
artifact, _ = backupDirectoryManager.Create("", backupName, logger) //nolint:errcheck
})
Context("file exists", func() {
Context("default artifact", func() {
Expand All @@ -490,7 +490,7 @@ instances:
"todo.txt": "Get animal handling license.",
})

writer.Write(contents)
writer.Write(contents) //nolint:errcheck
Expect(writer.Close()).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -519,7 +519,7 @@ instances:
"todo.txt": "Get animal handling license.",
})

writer.Write(contents)
writer.Write(contents) //nolint:errcheck
Expect(writer.Close()).NotTo(HaveOccurred())
})

Expand All @@ -541,7 +541,7 @@ instances:

contents := []byte("this ain't a tarball")

writer.Write(contents)
writer.Write(contents) //nolint:errcheck
Expect(writer.Close()).NotTo(HaveOccurred())
})

Expand All @@ -567,7 +567,7 @@ instances:
var startTime time.Time

BeforeEach(func() {
artifact, _ = backupDirectoryManager.Create("", backupName, logger)
artifact, _ = backupDirectoryManager.Create("", backupName, logger) //nolint:errcheck
startTime = time.Date(2015, 10, 21, 1, 2, 3, 0, time.UTC)
Expect(artifact.CreateMetadataFileWithStartTime(startTime)).To(Succeed())
fakeBackupArtifact = new(fakes.FakeBackupArtifact)
Expand Down
18 changes: 9 additions & 9 deletions bosh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ type Logger interface {
}

func (c Client) FindInstances(deploymentName string) ([]orchestrator.Instance, error) {
deployment, err := c.Director.FindDeployment(deploymentName)
deployment, err := c.Director.FindDeployment(deploymentName) //nolint:staticcheck
if err != nil {
return nil, errors.Wrap(err, "couldn't find deployment "+deploymentName)
}

c.Logger.Debug("bbr", "Finding VMs...")
c.Logger.Debug("bbr", "Finding VMs...") //nolint:staticcheck
vms, err := deployment.VMInfos()
if err != nil {
return nil, errors.Wrap(err, "couldn't get vm infos")
Expand All @@ -70,7 +70,7 @@ func (c Client) FindInstances(deploymentName string) ([]orchestrator.Instance, e
if err != nil {
return nil, errors.Wrap(err, "failed to generate ssh options")
}
c.Logger.Debug("bbr", "SSH user generated: %s", sshOpts.Username)
c.Logger.Debug("bbr", "SSH user generated: %s", sshOpts.Username) //nolint:staticcheck

var instances []orchestrator.Instance
var slugs []director.AllOrInstanceGroupOrInstanceSlug
Expand All @@ -86,7 +86,7 @@ func (c Client) FindInstances(deploymentName string) ([]orchestrator.Instance, e
}

for _, instanceGroupName := range uniqueInstanceGroupNamesFromVMs(vms) {
c.Logger.Debug("bbr", "Setting up SSH for job %s", instanceGroupName)
c.Logger.Debug("bbr", "Setting up SSH for job %s", instanceGroupName) //nolint:staticcheck

allVmInstances, err := director.NewAllOrInstanceGroupOrInstanceSlugFromString(instanceGroupName)
if err != nil {
Expand All @@ -105,7 +105,7 @@ func (c Client) FindInstances(deploymentName string) ([]orchestrator.Instance, e

var err error

c.Logger.Debug("bbr", "Attempting to SSH onto %s, %s", host.Host, host.IndexOrID)
c.Logger.Debug("bbr", "Attempting to SSH onto %s, %s", host.Host, host.IndexOrID) //nolint:staticcheck

hostPublicKey, _, _, _, err := gossh.ParseAuthorizedKey([]byte(host.HostPublicKey))
if err != nil {
Expand All @@ -128,7 +128,7 @@ func (c Client) FindInstances(deploymentName string) ([]orchestrator.Instance, e
}

if isWindows {
c.Logger.Warn("bbr", "skipping Windows instance %s/%s", instanceGroupName, host.IndexOrID)
c.Logger.Warn("bbr", "skipping Windows instance %s/%s", instanceGroupName, host.IndexOrID) //nolint:staticcheck
continue
}

Expand Down Expand Up @@ -159,7 +159,7 @@ func (c Client) FindInstances(deploymentName string) ([]orchestrator.Instance, e
)

if len(jobs) == 0 {
c.Logger.Debug("bbr", "no scripts found on instance %s/%s, skipping rest of the instances for %s", instanceGroupName, host.IndexOrID, instanceGroupName)
c.Logger.Debug("bbr", "no scripts found on instance %s/%s, skipping rest of the instances for %s", instanceGroupName, host.IndexOrID, instanceGroupName) //nolint:staticcheck
break
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ func isInstanceABootstrapNode(jobName, ip string, vms []director.VMInfo) bool {
}

func (c Client) GetManifest(deploymentName string) (string, error) {
deployment, err := c.Director.FindDeployment(deploymentName)
deployment, err := c.Director.FindDeployment(deploymentName) //nolint:staticcheck
if err != nil {
return "", errors.Wrap(err, "couldn't find deployment "+deploymentName)
}
Expand Down Expand Up @@ -237,6 +237,6 @@ func contains(s []string, e string) bool {

func cleanupAlreadyMadeConnections(deployment director.Deployment, slugs []director.AllOrInstanceGroupOrInstanceSlug, opts director.SSHOpts) {
for _, slug := range slugs {
deployment.CleanUpSSH(slug, director.SSHOpts{Username: opts.Username})
deployment.CleanUpSSH(slug, director.SSHOpts{Username: opts.Username}) //nolint:errcheck
}
}
2 changes: 1 addition & 1 deletion bosh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var _ = Describe("Director", func() {
),
}

fakeJobFinder.FindJobsReturns(append(expectedJobs), nil)
fakeJobFinder.FindJobsReturns(append(expectedJobs), nil) //nolint:errcheck,govet,staticcheck

manifestQuerierCreator.Returns(manifestQuerier, nil)
})
Expand Down
2 changes: 1 addition & 1 deletion bosh/deployed_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ func (i *BoshDeployedInstance) CleanupPrevious() error {
}

func (i *BoshDeployedInstance) cleanupSSHConnections() error {
i.Logger.Debug("bbr", "Cleaning up SSH connection on instance %s %s", i.Name(), i.ID())
i.Logger.Debug("bbr", "Cleaning up SSH connection on instance %s %s", i.Name(), i.ID()) //nolint:staticcheck
return i.Deployment.CleanUpSSH(director.NewAllOrInstanceGroupOrInstanceSlug(i.Name(), i.ID()), director.SSHOpts{Username: i.ConnectedUsername()})
}
8 changes: 4 additions & 4 deletions bosh/manifest_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func (mq BoshManifestQuerier) IsJobBackupOneRestoreAll(instanceGroupName, jobNam
backupOneRestoreAllPropertyPath = fmt.Sprintf("/jobs/name=%s/properties/bbr/backup_one_restore_all", instanceGroupName)
}

jobPathPointer, _ := patch.NewPointerFromString(jobPath)
jobPathPointer, _ := patch.NewPointerFromString(jobPath) //nolint:errcheck
_, err := patch.FindOp{Path: jobPathPointer}.Apply(mq.manifest)
if err != nil {
return false, errors.Wrap(err, fmt.Sprintf("error finding job %s in instance group %s", jobName, instanceGroupName))
}

backupOneRestoreAllPropertyPointer, _ := patch.NewPointerFromString(backupOneRestoreAllPropertyPath)
backupOneRestoreAllPropertyPointer, _ := patch.NewPointerFromString(backupOneRestoreAllPropertyPath) //nolint:errcheck
backupOneRestoreAll, err := patch.FindOp{Path: backupOneRestoreAllPropertyPointer}.Apply(mq.manifest)
if err != nil {
return false, nil
Expand All @@ -75,9 +75,9 @@ func (mq BoshManifestQuerier) IsJobBackupOneRestoreAll(instanceGroupName, jobNam
}

func isV2Manifest(manifest interface{}) bool {
instanceGroupPath := patch.MustNewPointerFromString(fmt.Sprintf("/instance_groups"))
instanceGroupPath := patch.MustNewPointerFromString(fmt.Sprintf("/instance_groups")) //nolint:staticcheck
_, err := patch.FindOp{Path: instanceGroupPath}.Apply(manifest)
if err != nil {
if err != nil { //nolint:staticcheck
return false
}
return true
Expand Down
Loading
Loading