diff --git a/oci/auth/aws/auth.go b/oci/auth/aws/auth.go index d2086470..735086d5 100644 --- a/oci/auth/aws/auth.go +++ b/oci/auth/aws/auth.go @@ -29,8 +29,8 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/ecr" + "github.com/go-logr/logr" "github.com/google/go-containerregistry/pkg/authn" - "sigs.k8s.io/controller-runtime/pkg/log" "github.com/fluxcd/pkg/oci" ) @@ -137,7 +137,7 @@ func (c *Client) getLoginAuth(ctx context.Context, awsEcrRegion string) (authn.A // It returns the authentication material and the expiry time of the token. func (c *Client) LoginWithExpiry(ctx context.Context, autoLogin bool, image string) (authn.Authenticator, time.Time, error) { if autoLogin { - log.FromContext(ctx).Info("logging in to AWS ECR for " + image) + logr.FromContextOrDiscard(ctx).Info("logging in to AWS ECR for " + image) _, awsEcrRegion, ok := ParseRegistry(image) if !ok { return nil, time.Time{}, errors.New("failed to parse AWS ECR image, invalid ECR image") diff --git a/oci/auth/azure/auth.go b/oci/auth/azure/auth.go index f6ab2ce8..d4ead684 100644 --- a/oci/auth/azure/auth.go +++ b/oci/auth/azure/auth.go @@ -27,9 +27,9 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/go-logr/logr" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" - "sigs.k8s.io/controller-runtime/pkg/log" "github.com/fluxcd/pkg/oci" ) @@ -135,13 +135,13 @@ func ValidHost(host string) bool { // The caller can ensure that the passed image is a valid ACR image using ValidHost(). func (c *Client) LoginWithExpiry(ctx context.Context, autoLogin bool, image string, ref name.Reference) (authn.Authenticator, time.Time, error) { if autoLogin { - log.FromContext(ctx).Info("logging in to Azure ACR for " + image) + logr.FromContextOrDiscard(ctx).Info("logging in to Azure ACR for " + image) // get registry host from image strArr := strings.SplitN(image, "/", 2) endpoint := fmt.Sprintf("%s://%s", c.scheme, strArr[0]) authConfig, expiresAt, err := c.getLoginAuth(ctx, endpoint) if err != nil { - log.FromContext(ctx).Info("error logging into ACR " + err.Error()) + logr.FromContextOrDiscard(ctx).Info("error logging into ACR " + err.Error()) return nil, time.Time{}, err } @@ -167,7 +167,7 @@ func (c *Client) Login(ctx context.Context, autoLogin bool, image string, ref na func (c *Client) OIDCLogin(ctx context.Context, registryUrl string) (authn.Authenticator, error) { authConfig, _, err := c.getLoginAuth(ctx, registryUrl) if err != nil { - log.FromContext(ctx).Info("error logging into ACR " + err.Error()) + logr.FromContextOrDiscard(ctx).Info("error logging into ACR " + err.Error()) return nil, err } diff --git a/oci/auth/gcp/auth.go b/oci/auth/gcp/auth.go index f5952fea..52b5f0d6 100644 --- a/oci/auth/gcp/auth.go +++ b/oci/auth/gcp/auth.go @@ -25,9 +25,9 @@ import ( "strings" "time" + "github.com/go-logr/logr" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" - "sigs.k8s.io/controller-runtime/pkg/log" "github.com/fluxcd/pkg/oci" ) @@ -111,10 +111,10 @@ func (c *Client) getLoginAuth(ctx context.Context) (authn.AuthConfig, time.Time, // The caller can ensure that the passed image is a valid GCR image using ValidHost(). func (c *Client) LoginWithExpiry(ctx context.Context, autoLogin bool, image string, ref name.Reference) (authn.Authenticator, time.Time, error) { if autoLogin { - log.FromContext(ctx).Info("logging in to GCP GCR for " + image) + logr.FromContextOrDiscard(ctx).Info("logging in to GCP GCR for " + image) authConfig, expiresAt, err := c.getLoginAuth(ctx) if err != nil { - log.FromContext(ctx).Info("error logging into GCP " + err.Error()) + logr.FromContextOrDiscard(ctx).Info("error logging into GCP " + err.Error()) return nil, time.Time{}, err } @@ -137,7 +137,7 @@ func (c *Client) Login(ctx context.Context, autoLogin bool, image string, ref na func (c *Client) OIDCLogin(ctx context.Context) (authn.Authenticator, error) { authConfig, _, err := c.getLoginAuth(ctx) if err != nil { - log.FromContext(ctx).Info("error logging into GCP " + err.Error()) + logr.FromContextOrDiscard(ctx).Info("error logging into GCP " + err.Error()) return nil, err } diff --git a/oci/auth/login/login.go b/oci/auth/login/login.go index 6b7b92c4..e5791575 100644 --- a/oci/auth/login/login.go +++ b/oci/auth/login/login.go @@ -22,9 +22,9 @@ import ( "net/url" "strings" + "github.com/go-logr/logr" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" - "sigs.k8s.io/controller-runtime/pkg/log" "github.com/fluxcd/pkg/cache" "github.com/fluxcd/pkg/oci" @@ -112,7 +112,7 @@ func (m *Manager) WithACRClient(c *azure.Client) *Manager { // Login performs authentication against a registry and returns the Authenticator. // For generic registry provider, it is no-op. func (m *Manager) Login(ctx context.Context, url string, ref name.Reference, opts ProviderOptions) (authn.Authenticator, error) { - log := log.FromContext(ctx) + log := logr.FromContextOrDiscard(ctx) provider := ImageRegistryProvider(url, ref) var ( key string @@ -191,19 +191,19 @@ func (m *Manager) OIDCLogin(ctx context.Context, registryURL string, opts Provid if !opts.AwsAutoLogin { return nil, fmt.Errorf("ECR authentication failed: %w", oci.ErrUnconfiguredProvider) } - log.FromContext(ctx).Info("logging in to AWS ECR for " + u.Host) + logr.FromContextOrDiscard(ctx).Info("logging in to AWS ECR for " + u.Host) return m.ecr.OIDCLogin(ctx, u.Host) case oci.ProviderGCP: if !opts.GcpAutoLogin { return nil, fmt.Errorf("GCR authentication failed: %w", oci.ErrUnconfiguredProvider) } - log.FromContext(ctx).Info("logging in to GCP GCR for " + u.Host) + logr.FromContextOrDiscard(ctx).Info("logging in to GCP GCR for " + u.Host) return m.gcr.OIDCLogin(ctx) case oci.ProviderAzure: if !opts.AzureAutoLogin { return nil, fmt.Errorf("ACR authentication failed: %w", oci.ErrUnconfiguredProvider) } - log.FromContext(ctx).Info("logging in to Azure ACR for " + u.Host) + logr.FromContextOrDiscard(ctx).Info("logging in to Azure ACR for " + u.Host) return m.acr.OIDCLogin(ctx, fmt.Sprintf("%s://%s", u.Scheme, u.Host)) } return nil, nil diff --git a/oci/client/suite_test.go b/oci/client/suite_test.go index 9ef13984..7fec6ef1 100644 --- a/oci/client/suite_test.go +++ b/oci/client/suite_test.go @@ -31,7 +31,6 @@ import ( _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/phayes/freeport" "github.com/sirupsen/logrus" - ctrl "sigs.k8s.io/controller-runtime" ) var ( @@ -66,7 +65,8 @@ func setupRegistryServer(ctx context.Context) error { } func TestMain(m *testing.M) { - ctx := ctrl.SetupSignalHandler() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() err := setupRegistryServer(ctx) if err != nil { panic(fmt.Sprintf("failed to start docker registry: %s", err)) diff --git a/oci/go.mod b/oci/go.mod index 8af24cfd..acff1fa3 100644 --- a/oci/go.mod +++ b/oci/go.mod @@ -22,11 +22,11 @@ require ( github.com/fluxcd/pkg/sourceignore v0.8.0 github.com/fluxcd/pkg/tar v0.8.0 github.com/fluxcd/pkg/version v0.4.0 + github.com/go-logr/logr v1.4.2 github.com/google/go-containerregistry v0.20.2 github.com/onsi/gomega v1.34.1 github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 github.com/sirupsen/logrus v1.9.3 - sigs.k8s.io/controller-runtime v0.19.0 ) require ( @@ -59,23 +59,19 @@ require ( github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect github.com/docker/go-metrics v0.0.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect - github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fluxcd/cli-utils v0.36.0-flux.9 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-errors/errors v1.5.1 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect github.com/go-git/go-git/v5 v5.12.0 // indirect - github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.4 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v5 v5.2.1 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect @@ -148,7 +144,6 @@ require ( golang.org/x/term v0.23.0 // indirect golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.6.0 // indirect - gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect google.golang.org/grpc v1.65.0 // indirect @@ -159,7 +154,6 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.31.0 // indirect - k8s.io/apiextensions-apiserver v0.31.0 // indirect k8s.io/apimachinery v0.31.0 // indirect k8s.io/cli-runtime v0.31.0 // indirect k8s.io/client-go v0.31.0 // indirect diff --git a/oci/go.sum b/oci/go.sum index 277cf88a..5fd457c5 100644 --- a/oci/go.sum +++ b/oci/go.sum @@ -103,18 +103,12 @@ github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxER github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI= -github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= -github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwCFad8crR9dcMQWvV9Hvulu6hwUh4tWPJnM= github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fluxcd/cli-utils v0.36.0-flux.9 h1:RITKdwIAqT3EFKXl7B91mj6usVjxcy7W8PJZlxqUa84= github.com/fluxcd/cli-utils v0.36.0-flux.9/go.mod h1:q6lXQpbAlrZmTB4Qe5oAENkv0y2kwMWcqTMDHrRo2Is= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= @@ -133,8 +127,6 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= -github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= @@ -152,8 +144,6 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -393,10 +383,6 @@ go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93V go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= -go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= -go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -470,8 +456,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T 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= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= -gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -519,8 +503,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo= k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE= -k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk= -k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk= k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc= k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= k8s.io/cli-runtime v0.31.0 h1:V2Q1gj1u3/WfhD475HBQrIYsoryg/LrhhK4RwpN+DhA= @@ -537,8 +519,6 @@ k8s.io/kubectl v0.31.0 h1:kANwAAPVY02r4U4jARP/C+Q1sssCcN/1p9Nk+7BQKVg= k8s.io/kubectl v0.31.0/go.mod h1:pB47hhFypGsaHAPjlwrNbvhXgmuAr01ZBvAIIUaI8d4= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q= -sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/kustomize/api v0.17.3 h1:6GCuHSsxq7fN5yhF2XrC+AAr8gxQwhexgHflOAD/JJU=