Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmd/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAgentRunOneShot(t *testing.T) {
return
}
t.Log("Running child process")
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
ctx, cancel := context.WithTimeout(t.Context(), time.Second*3)
defer cancel()
cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestAgentRunOneShot$")
var (
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/jetstack/preflight

go 1.23.4
go 1.24.4

require (
github.com/Venafi/vcert/v5 v5.8.1
Expand All @@ -15,7 +15,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.10.0
golang.org/x/sync v0.11.0
golang.org/x/sync v0.15.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.33.0-alpha.1
k8s.io/apimachinery v0.33.0-alpha.1
Expand Down Expand Up @@ -57,9 +57,9 @@ require (
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.36.0 // indirect
golang.org/x/net v0.41.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect
Expand Down Expand Up @@ -95,9 +95,9 @@ require (
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.32.0 // indirect
golang.org/x/text v0.26.0 // indirect
golang.org/x/time v0.7.0 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand All @@ -234,36 +234,36 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
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-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
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.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
10 changes: 5 additions & 5 deletions pkg/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func Test_ValidateAndCombineConfig_VenafiCloudKeyPair(t *testing.T) {
t.Run("server, uploader_id, and cluster name are correctly passed", func(t *testing.T) {
t.Setenv("POD_NAMESPACE", "venafi")

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
log := ktesting.NewLogger(t, ktesting.NewConfig(ktesting.Verbosity(10)))
ctx = klog.NewContext(ctx, log)
Expand Down Expand Up @@ -704,7 +704,7 @@ func Test_ValidateAndCombineConfig_VenafiConnection(t *testing.T) {
t.Setenv("KUBECONFIG", testutil.WithKubeconfig(t, cfg))
srv, cert, setVenafiCloudAssert := testutil.FakeVenafiCloud(t)
for _, obj := range testutil.Parse(
testutil.VenConnRBAC + testutil.Undent(fmt.Sprintf(`
testutil.VenConnRBAC + testutil.Undent(`
---
apiVersion: jetstack.io/v1alpha1
kind: VenafiConnection
Expand Down Expand Up @@ -751,8 +751,8 @@ func Test_ValidateAndCombineConfig_VenafiConnection(t *testing.T) {
- kind: ServiceAccount
name: venafi-connection
namespace: venafi
`))) {
require.NoError(t, kcl.Create(context.Background(), obj))
`)) {
require.NoError(t, kcl.Create(t.Context(), obj))
}

t.Run("err when cluster_id field is empty", func(t *testing.T) {
Expand All @@ -768,7 +768,7 @@ func Test_ValidateAndCombineConfig_VenafiConnection(t *testing.T) {
})

t.Run("the server field is ignored when VenafiConnection is used", func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
log := ktesting.NewLogger(t, ktesting.NewConfig(ktesting.Verbosity(10)))
ctx = klog.NewContext(ctx, log)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client_venconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
//
// [1] https://github.com/kubernetes-sigs/controller-runtime/issues/2341
func TestVenConnClient_PostDataReadingsWithOptions(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
log := ktesting.NewLogger(t, ktesting.NewConfig(ktesting.Verbosity(10)))
ctx = klog.NewContext(ctx, log)
Expand Down
9 changes: 4 additions & 5 deletions pkg/datagatherer/k8s/dynamic_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package k8s

import (
"context"
"encoding/json"
"fmt"
"reflect"
Expand Down Expand Up @@ -117,7 +116,7 @@ func sortGatheredResources(list []*api.GatheredResource) {
}

func TestNewDataGathererWithClientAndDynamicInformer(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
config := ConfigDynamic{
ExcludeNamespaces: []string{"kube-system"},
GroupVersionResource: schema.GroupVersionResource{Group: "foobar", Version: "v1", Resource: "foos"},
Expand Down Expand Up @@ -164,7 +163,7 @@ func TestNewDataGathererWithClientAndDynamicInformer(t *testing.T) {
}

func TestNewDataGathererWithClientAndSharedIndexInformer(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
config := ConfigDynamic{
IncludeNamespaces: []string{"a"},
GroupVersionResource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
Expand Down Expand Up @@ -638,7 +637,7 @@ func TestDynamicGatherer_Fetch(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
var wg sync.WaitGroup
ctx := context.Background()
ctx := t.Context()
gvrToListKind := map[schema.GroupVersionResource]string{
{Group: "foobar", Version: "v1", Resource: "foos"}: "UnstructuredList",
{Group: "apps", Version: "v1", Resource: "deployments"}: "UnstructuredList",
Expand Down Expand Up @@ -958,7 +957,7 @@ func TestDynamicGathererNativeResources_Fetch(t *testing.T) {
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
var wg sync.WaitGroup
ctx := context.Background()
ctx := t.Context()

clientset := fakeclientset.NewSimpleClientset(tc.addObjects...)

Expand Down
3 changes: 1 addition & 2 deletions pkg/echo/echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package echo

import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestEchoServerRequestResponse(t *testing.T) {
}

// generate a request to test the handler containing the JSON data as a body
req, err := http.NewRequestWithContext(context.TODO(), sampleUpload.method, "http://example.com/api/v1/datareadings", bytes.NewBuffer(requestBodyJSON))
req, err := http.NewRequestWithContext(t.Context(), sampleUpload.method, "http://example.com/api/v1/datareadings", bytes.NewBuffer(requestBodyJSON))
if err != nil {
t.Fatalf("[%s]\nfailed to generate request to test echo server: %s", sampleUpload.description, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/internal/cyberark/dataupload/dataupload_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dataupload_test

import (
"context"
"crypto/x509"
"encoding/pem"
"fmt"
Expand Down Expand Up @@ -113,7 +112,7 @@ func TestCyberArkClient_PostDataReadingsWithOptions(t *testing.T) {
cyberArkClient, err := dataupload.NewCyberArkClient(certPool, server.Server.URL, tc.authenticate)
require.NoError(t, err)

err = cyberArkClient.PostDataReadingsWithOptions(context.TODO(), tc.payload, tc.opts)
err = cyberArkClient.PostDataReadingsWithOptions(t.Context(), tc.payload, tc.opts)
tc.requireFn(t, err)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package identity

import (
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -98,7 +97,7 @@ func Test_IdentityAdvanceAuthentication(t *testing.T) {

for name, testSpec := range tests {
t.Run(name, func(t *testing.T) {
ctx := context.Background()
ctx := t.Context()

identityServer := MockIdentityServer()
defer identityServer.Close()
Expand Down
3 changes: 1 addition & 2 deletions pkg/internal/cyberark/identity/start_authentication_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package identity

import (
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -39,7 +38,7 @@ func Test_IdentityStartAuthentication(t *testing.T) {

for name, testSpec := range tests {
t.Run(name, func(t *testing.T) {
ctx := context.Background()
ctx := t.Context()

identityServer := MockIdentityServer()
defer identityServer.Close()
Expand Down
3 changes: 1 addition & 2 deletions pkg/internal/cyberark/servicediscovery/discovery_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package servicediscovery

import (
"context"
"fmt"
"testing"
)
Expand Down Expand Up @@ -46,7 +45,7 @@ func Test_DiscoverIdentityAPIURL(t *testing.T) {

for name, testSpec := range tests {
t.Run(name, func(t *testing.T) {
ctx := context.Background()
ctx := t.Context()

ts := MockDiscoveryServer()
defer ts.Close()
Expand Down
46 changes: 1 addition & 45 deletions pkg/logs/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package logs_test

import (
"bytes"
"context"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -65,7 +64,7 @@ func TestLogs(t *testing.T) {
klog.Warning("klog Warning")
klog.ErrorS(errors.New("fake-error"), "klog Error")
klog.InfoS("klog InfoS", "key", "value")
logger := klog.FromContext(context.Background()).WithName("foo")
logger := klog.FromContext(t.Context()).WithName("foo")
logger.V(3).Info("Contextual Info Level 3", "key", "value")
logger.Error(errors.New("fake-error"), "Contextual error", "key", "value")

Expand Down Expand Up @@ -372,46 +371,3 @@ func Test_replaceWithStaticTimestamps(t *testing.T) {
})
}
}

func TestLogToSlogWriter(t *testing.T) {
// This test makes sure that all the agent's remaining Log calls are correctly
// translated to slog.Error calls where appropriate.
//
// This list was generated using:
// git grep -i "log\.\(print\|fatal\)" pkg/ cmd/ | fgrep -e error -e failed
given := strings.TrimPrefix(`
failed to complete initial sync of %q data gatherer %q: %v
error messages will not show in the pod's events because the POD_NAME environment variable is empty
retrying in %v after error: %s
datagatherer informer for %q has failed and is backing off due to error: %s
this is a happy log that should show as INFO`, "\n")
expect := strings.TrimPrefix(`
level=ERROR msg="failed to complete initial sync of %!q(MISSING) data gatherer %!q(MISSING): %!v(MISSING)" source=agent
level=ERROR msg="error messages will not show in the pod's events because the POD_NAME environment variable is empty" source=agent
level=ERROR msg="retrying in %!v(MISSING) after error: %!s(MISSING)" source=agent
level=ERROR msg="datagatherer informer for %!q(MISSING) has failed and is backing off due to error: %!s(MISSING)" source=agent
level=INFO msg="this is a happy log that should show as INFO" source=agent
`, "\n")

gotBuf := &bytes.Buffer{}
slogHandler := slog.NewTextHandler(gotBuf, &slog.HandlerOptions{
// Remove the timestamp from the logs so that we can compare them.
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
if a.Key == "time" {
return slog.Attr{}
}
return a
},
})
slogLogger := slog.New(slogHandler)

logger := log.New(&bytes.Buffer{}, "", 0)
logger.SetOutput(logs.LogToSlogWriter{Slog: slogLogger, Source: "agent"})

for _, line := range strings.Split(given, "\n") {
// Simulate the current agent's logs.
logger.Printf(line) // nolint:staticcheck
}

assert.Equal(t, expect, gotBuf.String())
}