Skip to content
3 changes: 2 additions & 1 deletion dev-tools/cmd/buildfleetcfg/buildfleetcfg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dev-tools/mage/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
func HaveDockerCompose() error {
_, err := exec.LookPath("docker-compose")
if err != nil {
return fmt.Errorf("docker-compose is not available")
return errors.New("docker-compose is not available")
}
return nil
}
Expand All @@ -223,7 +223,7 @@
func HaveKubectl() error {
_, err := exec.LookPath("kubectl")
if err != nil {
return fmt.Errorf("kubectl is not available")
return errors.New("kubectl is not available")
}
return nil
}
Expand Down Expand Up @@ -461,7 +461,7 @@

switch header.Typeflag {
case tar.TypeDir:
if err = os.MkdirAll(path, os.FileMode(header.Mode)); err != nil {

Check failure on line 464 in dev-tools/mage/common.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

G115: integer overflow conversion int64 -> uint32 (gosec)
return err
}
case tar.TypeReg:
Expand All @@ -479,7 +479,7 @@
return err
}

if err = os.Chmod(path, os.FileMode(header.Mode)); err != nil {

Check failure on line 482 in dev-tools/mage/common.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

G115: integer overflow conversion int64 -> uint32 (gosec)
return err
}

Expand Down Expand Up @@ -969,7 +969,7 @@
}

if len(versionSet) == 0 {
return nil, fmt.Errorf("no GLIBC symbols found in binary (is this a static binary?)")
return nil, errors.New("no GLIBC symbols found in binary (is this a static binary?)")
}

versions := make([]SemanticVersion, 0, len(versionSet))
Expand Down
3 changes: 2 additions & 1 deletion dev-tools/mage/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package mage

import (
"errors"
"fmt"
"io"
"io/fs"
Expand Down Expand Up @@ -110,7 +111,7 @@ func (t *CopyTask) fileCopy(src, dest string, entry fs.DirEntry) error {
}

if !info.Mode().IsRegular() {
return fmt.Errorf("failed to copy source file because it is not a regular file")
return errors.New("failed to copy source file because it is not a regular file")
}

mode := t.Mode
Expand Down
5 changes: 3 additions & 2 deletions dev-tools/mage/crossbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package mage

import (
"errors"
"fmt"
"go/build"
"log"
Expand Down Expand Up @@ -149,7 +150,7 @@ func CrossBuild(options ...CrossBuildOption) error {
for _, platform := range params.Platforms {
if platform.GOOS() == "aix" {
if len(params.Platforms) != 1 {
return fmt.Errorf("platform AIX cannot be crossbuilt with other platforms. Set PLATFORMS='aix/ppc64'")
return errors.New("platform AIX cannot be crossbuilt with other platforms. Set PLATFORMS='aix/ppc64'")
}
// This is basically a short-out so we can attempt to build on AIX in a relatively generic way
log.Printf("Target is building for AIX, skipping normal crossbuild process")
Expand All @@ -161,7 +162,7 @@ func CrossBuild(options ...CrossBuildOption) error {
}
}
// If we're here, something isn't set.
return fmt.Errorf("cannot crossbuild on AIX. Either run `mage build` or set PLATFORMS='aix/ppc64'")
return errors.New("cannot crossbuild on AIX. Either run `mage build` or set PLATFORMS='aix/ppc64'")
}

// Docker is required for this target.
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/mage/downloads/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *ArtifactURLResolver) Resolve() (string, string, error) {
slog.String("name", artifactName),
slog.String("version", version),
)
return "", "", fmt.Errorf("object not found in Artifact API")
return "", "", errors.New("object not found in Artifact API")
}

downloadURL, ok := downloadObject.Path("url").Data().(string)
Expand Down Expand Up @@ -408,7 +408,7 @@ func (asur *ArtifactsSnapshotURLResolver) Resolve() (string, string, error) {
func findSnapshotPackage(jsonParsed map[string]interface{}, fullName string) (string, string, error) {
projects, ok := jsonParsed["projects"].(map[string]interface{})
if !ok {
return "", "", fmt.Errorf("key 'projects' does not exist")
return "", "", errors.New("key 'projects' does not exist")
}

for _, project := range projects {
Expand Down Expand Up @@ -498,7 +498,7 @@ func (r *ReleaseURLResolver) Resolve() (string, string, error) {
}

if !found {
return "", "", fmt.Errorf("download could not be found at the Elastic downloads API")
return "", "", errors.New("download could not be found at the Elastic downloads API")
}

return url, shaURL, nil
Expand Down
8 changes: 4 additions & 4 deletions dev-tools/mage/downloads/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func ExtractCommitHash(input string) (string, error) {
matches := re.FindStringSubmatch(input)

if len(matches) < 2 {
return "", fmt.Errorf("commit hash not found")
return "", errors.New("commit hash not found")
}

return matches[1], nil
Expand Down Expand Up @@ -310,7 +310,7 @@ func FetchProjectBinary(ctx context.Context, project string, artifactName string
// to be downloaded will be defined by the snapshot produced by the Beats CI or Fleet CI for that commit.
func FetchProjectBinaryForSnapshots(ctx context.Context, useCISnapshots bool, project string, artifactName string, artifact string, version string, timeoutFactor int, xpack bool, downloadPath string, downloadSHAFile bool) (string, error) {
if BeatsLocalPath != "" {
return "", fmt.Errorf("⚠️ Beats local path usage is deprecated and not used to fetch the binaries. Please use the packaging job to generate the artifacts to be consumed by these tests")
return "", errors.New("⚠️ Beats local path usage is deprecated and not used to fetch the binaries. Please use the packaging job to generate the artifacts to be consumed by these tests")
}

if downloadPath == "" {
Expand Down Expand Up @@ -488,7 +488,7 @@ func getDownloadURLFromResolvers(resolvers []DownloadURLResolver) (string, strin
return url, shaURL, nil
}

return "", "", fmt.Errorf("the artifact was not found")
return "", "", errors.New("the artifact was not found")
}

// getObjectURLFromResolvers extracts the media URL for the desired artifact from the
Expand All @@ -511,7 +511,7 @@ func getObjectURLFromResolvers(resolvers []BucketURLResolver, maxtimeout time.Du
return downloadURL, nil
}

return "", fmt.Errorf("the artifact was not found")
return "", errors.New("the artifact was not found")
}

// getObjectURLFromBucket extracts the media URL for the desired artifact from the
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}

func makeGoTestArgs(name string) GoTestArgs {
fileName := fmt.Sprintf("build/TEST-go-%s", strings.Replace(strings.ToLower(name), " ", "_", -1))

Check failure on line 49 in dev-tools/mage/gotest.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1004: could use strings.ReplaceAll instead (staticcheck)
params := GoTestArgs{
LogName: name,
Race: RaceDetector,
Expand All @@ -64,8 +64,8 @@

func makeGoTestArgsForModule(name, module string) GoTestArgs {
fileName := fmt.Sprintf("build/TEST-go-%s-%s",
strings.Replace(strings.ToLower(name), " ", "_", -1),

Check failure on line 67 in dev-tools/mage/gotest.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1004: could use strings.ReplaceAll instead (staticcheck)
strings.Replace(strings.ToLower(module), " ", "_", -1),

Check failure on line 68 in dev-tools/mage/gotest.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1004: could use strings.ReplaceAll instead (staticcheck)
)
params := GoTestArgs{
LogName: fmt.Sprintf("%s-%s", name, module),
Expand Down Expand Up @@ -184,7 +184,7 @@

func GoTestBuild(ctx context.Context, params GoTestArgs) error {
if params.OutputFile == "" {
return fmt.Errorf("missing output file")
return errors.New("missing output file")
}

fmt.Println(">> go test:", params.LogName, "Building Test Binary")
Expand Down
3 changes: 2 additions & 1 deletion dev-tools/mage/gotool/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package gotool

import (
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -90,7 +91,7 @@ func ListDepsLocation(pkg string) (map[string]string, error) {
for _, l := range lines {
parts := strings.Split(l, ";")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid number of parts")
return nil, errors.New("invalid number of parts")
}
deps[parts[0]] = parts[1]
}
Expand Down
4 changes: 2 additions & 2 deletions dev-tools/mage/integtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
}
tester, ok := globalIntegrationTesters["docker"]
if !ok {
return nil, fmt.Errorf("docker integration test runner not registered")
return nil, errors.New("docker integration test runner not registered")
}
runner, err := initRunner(tester, dir, passInEnv)
if err != nil {
Expand All @@ -191,7 +191,7 @@
}
tester, ok := globalIntegrationTesters["docker"]
if !ok {
return nil, fmt.Errorf("docker integration test runner not registered")
return nil, errors.New("docker integration test runner not registered")
}
return initRunner(tester, cwd, nil, passThroughEnvVars...)
}
Expand Down Expand Up @@ -248,7 +248,7 @@
err := r.tester.HasRequirements()
if err != nil {
fmt.Printf("skipping test run with %s due to missing requirements: %s\n", r.tester.Name(), err)
//nolint:nilerr // log error; and return (otherwise on machines without requirements it will mark the tests as failed)

Check failure on line 251 in dev-tools/mage/integtest.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

directive `//nolint:nilerr // log error; and return (otherwise on machines without requirements it will mark the tests as failed)` is unused for linter "nilerr" (nolintlint)
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions dev-tools/mage/kubernetes/kuberemote.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"crypto/x509"
"encoding/hex"
"encoding/pem"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -70,7 +71,7 @@
if err != nil {
return nil, err
}
name = strings.Replace(name, "_", "-", -1)

Check failure on line 74 in dev-tools/mage/kubernetes/kuberemote.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

QF1004: could use strings.ReplaceAll instead (staticcheck)
svcAccName := fmt.Sprintf("%s-sa", name)
secretName := fmt.Sprintf("%s-ssh-key", name)
privateKey, publicKey, err := generateSSHKeyPair()
Expand Down Expand Up @@ -146,7 +147,7 @@

// return error on failure
if pod.Status.Phase == apiv1.PodFailed {
return fmt.Errorf("execute pod test failed")
return errors.New("execute pod test failed")
}
return nil
}
Expand Down Expand Up @@ -338,7 +339,7 @@
return 0, err
}
defer l.Close()
return uint16(l.Addr().(*net.TCPAddr).Port), nil

Check failure on line 342 in dev-tools/mage/kubernetes/kuberemote.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

G115: integer overflow conversion int -> uint16 (gosec)
}

// createSecretManifest creates the secret object to create in the cluster.
Expand Down Expand Up @@ -584,7 +585,7 @@
} else if status.State.Terminated != nil {
return false, nil
} else {
return false, fmt.Errorf("unknown container state")
return false, errors.New("unknown container state")
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion dev-tools/mage/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package kubernetes

import (
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (d *IntegrationTester) Test(dir string, mageTarget string, env map[string]s
manifestPath := filepath.Join(dir, "kubernetes.yml")
if _, err := os.Stat(manifestPath); os.IsNotExist(err) {
// defensive, as `Use` should cause this runner not to be used if no file.
return fmt.Errorf("no kubernetes.yml")
return errors.New("no kubernetes.yml")
}

kubeConfig := env["KUBECONFIG"]
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const (
)

// ErrUnknownProjectType is returned if an unknown ProjectType value is used.
var ErrUnknownProjectType = fmt.Errorf("unknown ProjectType")
var ErrUnknownProjectType = errors.New("unknown ProjectType")

// EnvMap returns map containing the common settings variables and all variables
// from the environment. args are appended to the output prior to adding the
Expand Down
3 changes: 2 additions & 1 deletion dev-tools/packaging/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package packaging
import (
"bytes"
_ "embed"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -228,7 +229,7 @@ func parsePackageSettings(r io.Reader) (*packagesConfig, error) {
// Components returns a *copy* of all the binary specs loaded from packages.yml
func Components() ([]BinarySpec, error) {
if settings == nil {
return nil, fmt.Errorf("package settings not loaded")
return nil, errors.New("package settings not loaded")
}
ret := make([]BinarySpec, len(settings.Components))
copy(ret, settings.Components)
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/packaging/testing/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ func readDocker(dockerFile string, filterWorkingDir bool) (*packageFile, *docker
}

if len(info.Config.Entrypoint) == 0 {
return nil, nil, fmt.Errorf("no entrypoint")
return nil, nil, errors.New("no entrypoint")
}

workingDir := info.Config.WorkingDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// This may occur if the user sends multiple diagnostics actions to an agent in a short duration
// or if the agent goes offline and retrieves multiple diagnostics actions.
// In either case the 1st action will succeed and the others will ack with an the error.
var ErrRateLimit = fmt.Errorf("rate limit exceeded")
var ErrRateLimit = errors.New("rate limit exceeded")

// getCPUDiag is a wrapper around diagnostics.CreateCPUProfile so it can be replaced in unit-tests.
var getCPUDiag = func(ctx context.Context, d time.Duration) ([]byte, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ func (c *Coordinator) PerformComponentDiagnostics(ctx context.Context, additiona
// Called from external goroutines.
func (c *Coordinator) SetLogLevel(ctx context.Context, lvl *logp.Level) error {
if lvl == nil {
return fmt.Errorf("logp.Level passed to Coordinator.SetLogLevel() must be not nil")
return errors.New("logp.Level passed to Coordinator.SetLogLevel() must be not nil")
}
select {
case <-ctx.Done():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ func TestCoordinator_InvalidComponentRevertsMigration(t *testing.T) {
}

failingComponentNotify := func(_ context.Context, _ *fleetapi.ActionMigrate) error {
return fmt.Errorf("failed to notify")
return errors.New("failed to notify")
}

err = coord.Migrate(ctx, action, backoffFactory, failingComponentNotify)
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/agent/application/dispatcher/retryconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package dispatcher

import (
"fmt"
"errors"
"time"
)

var ErrNoRetry = fmt.Errorf("no retry attempts remaining")
var ErrNoRetry = errors.New("no retry attempts remaining")

type retryConfig struct {
steps []time.Duration
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/agent/application/enroll/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package enroll

import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -77,7 +78,7 @@ func (e *EnrollOptions) RemoteConfig(failOnInsecureMismatch bool) (remote.Config
return remote.Config{}, err
}
if failOnInsecureMismatch && cfg.Protocol == remote.ProtocolHTTP && !e.Insecure {
return remote.Config{}, fmt.Errorf("connection to fleet-server is insecure, strongly recommended to use a secure connection (override with --insecure)")
return remote.Config{}, errors.New("connection to fleet-server is insecure, strongly recommended to use a secure connection (override with --insecure)")
}

cfg.Headers = e.Headers
Expand Down Expand Up @@ -125,7 +126,7 @@ func MergeOptionsWithMigrateAction(action *fleetapi.ActionMigrate, options Enrol
// i'm keeping it this way (michal)
if action.Data.EnrollmentToken == "" ||
action.Data.TargetURI == "" {
return EnrollOptions{}, fmt.Errorf("required fields missing")
return EnrollOptions{}, errors.New("required fields missing")
}

configMap := make(map[string]interface{})
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/agent/application/filelock/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
package filelock

import (
"fmt"
"errors"
"os"
"path/filepath"

"github.com/gofrs/flock"
)

// ErrAppAlreadyRunning error returned when another elastic-agent is already holding the lock.
var ErrAppAlreadyRunning = fmt.Errorf("another elastic-agent is already running")
var ErrAppAlreadyRunning = errors.New("another elastic-agent is already running")

// AppLocker locks the agent.lock file inside the provided directory.
type AppLocker struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/fleet_server_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func FleetServerComponentModifier(serverCfg *configuration.FleetServerConfig) co
// addBootrapCfg will transform the passed configuration.Elasticsearch to a map and add it to dst under the bootstrap key.
func addBootstrapCfg(dst map[string]interface{}, es *configuration.Elasticsearch) error {
if es == nil {
return fmt.Errorf("fleet-server bootstrap output config is undefined")
return errors.New("fleet-server bootstrap output config is undefined")
}
mp, err := toMapStr(es)
if err != nil {
Expand Down
Loading
Loading