From a2f84e127913ecee84173355928f32305af82d64 Mon Sep 17 00:00:00 2001 From: Dipti Pai Date: Thu, 22 Aug 2024 10:07:00 -0700 Subject: [PATCH] Remove dependencies on controller-runtime and k8s packages Signed-off-by: Dipti Pai --- auth/{constants.go => auth.go} | 4 ---- auth/azure/token_provider_test.go | 4 ++-- auth/go.mod | 1 - auth/go.sum | 2 -- git/credentials.go | 7 +++++-- git/credentials_test.go | 9 ++++----- git/go.mod | 2 +- git/gogit/client.go | 4 ++-- git/gogit/go.mod | 3 +-- git/gogit/go.sum | 2 -- git/internal/e2e/go.mod | 2 +- git/internal/e2e/go.sum | 2 -- 12 files changed, 16 insertions(+), 26 deletions(-) rename auth/{constants.go => auth.go} (94%) diff --git a/auth/constants.go b/auth/auth.go similarity index 94% rename from auth/constants.go rename to auth/auth.go index c073c149..b5fdec4c 100644 --- a/auth/constants.go +++ b/auth/auth.go @@ -15,7 +15,3 @@ limitations under the License. */ package auth - -const ( - ProviderAzure = "azure" -) diff --git a/auth/azure/token_provider_test.go b/auth/azure/token_provider_test.go index cc1ef92e..fa08a3df 100644 --- a/auth/azure/token_provider_test.go +++ b/auth/azure/token_provider_test.go @@ -24,7 +24,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" . "github.com/onsi/gomega" - "k8s.io/utils/pointer" ) func TestGetProviderToken(t *testing.T) { @@ -67,7 +66,8 @@ func TestGetProviderToken(t *testing.T) { g := NewWithT(t) provider := NewProvider(tt.opts...) provider.credential = tt.tokenCred - ctx := context.WithValue(context.TODO(), "scope", pointer.String("")) + str := "" + ctx := context.WithValue(context.TODO(), "scope", &str) token, err := provider.GetToken(ctx) if tt.wantErr != nil { diff --git a/auth/go.mod b/auth/go.mod index 02432110..c36bdb2b 100644 --- a/auth/go.mod +++ b/auth/go.mod @@ -6,7 +6,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 github.com/onsi/gomega v1.33.1 - k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 ) require ( diff --git a/auth/go.sum b/auth/go.sum index 37c6c930..4b6a3e9f 100644 --- a/auth/go.sum +++ b/auth/go.sum @@ -54,5 +54,3 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak= -k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= diff --git a/git/credentials.go b/git/credentials.go index 54f5bf0f..7026e4e1 100644 --- a/git/credentials.go +++ b/git/credentials.go @@ -21,10 +21,13 @@ import ( "fmt" "time" - "github.com/fluxcd/pkg/auth" "github.com/fluxcd/pkg/auth/azure" ) +const ( + ProviderAzure = "azure" +) + // Credentials contains authentication data needed in order to access a Git // repository. type Credentials struct { @@ -39,7 +42,7 @@ func GetCredentials(ctx context.Context, url string, providerOpts *ProviderOptio expiresOn time.Time ) switch providerOpts.Name { - case auth.ProviderAzure: + case ProviderAzure: opts := providerOpts.AzureOpts if providerOpts.AzureOpts == nil { opts = []azure.ProviderOptFunc{ diff --git a/git/credentials_test.go b/git/credentials_test.go index b6361f4a..922bccb8 100644 --- a/git/credentials_test.go +++ b/git/credentials_test.go @@ -22,10 +22,8 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" - "github.com/fluxcd/pkg/auth" "github.com/fluxcd/pkg/auth/azure" . "github.com/onsi/gomega" - "k8s.io/utils/pointer" ) func TestGetCredentials(t *testing.T) { @@ -41,7 +39,7 @@ func TestGetCredentials(t *testing.T) { name: "get credentials from azure", url: "https://dev.azure.com/foo/bar/_git/baz", provider: &ProviderOptions{ - Name: auth.ProviderAzure, + Name: ProviderAzure, AzureOpts: []azure.ProviderOptFunc{ azure.WithCredential(&azure.FakeTokenCredential{ Token: "ado-token", @@ -59,7 +57,7 @@ func TestGetCredentials(t *testing.T) { name: "get credentials from azure without scope", url: "https://dev.azure.com/foo/bar/_git/baz", provider: &ProviderOptions{ - Name: auth.ProviderAzure, + Name: ProviderAzure, AzureOpts: []azure.ProviderOptFunc{ azure.WithCredential(&azure.FakeTokenCredential{ Token: "ado-token", @@ -85,7 +83,8 @@ func TestGetCredentials(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - ctx := context.WithValue(context.TODO(), "scope", pointer.String("")) + str := "" + ctx := context.WithValue(context.TODO(), "scope", &str) creds, expiry, err := GetCredentials(ctx, tt.url, tt.provider) if tt.wantCredentials != nil { diff --git a/git/go.mod b/git/go.mod index befe4ce2..92b01775 100644 --- a/git/go.mod +++ b/git/go.mod @@ -11,7 +11,6 @@ require ( github.com/fluxcd/pkg/auth v0.0.0-00010101000000-000000000000 github.com/fluxcd/pkg/cache v0.0.3 github.com/onsi/gomega v1.34.1 - k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 ) require ( @@ -76,6 +75,7 @@ require ( k8s.io/client-go v0.31.0 // indirect k8s.io/klog/v2 v2.130.1 // indirect k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect + k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kustomize/api v0.17.3 // indirect sigs.k8s.io/kustomize/kyaml v0.17.2 // indirect diff --git a/git/gogit/client.go b/git/gogit/client.go index c0c68d5c..57ab18a6 100644 --- a/git/gogit/client.go +++ b/git/gogit/client.go @@ -40,7 +40,7 @@ import ( "github.com/go-git/go-git/v5/storage" "github.com/go-git/go-git/v5/storage/filesystem" "github.com/go-git/go-git/v5/storage/memory" - "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/go-logr/logr" ) func init() { @@ -257,8 +257,8 @@ func (g *Client) Clone(ctx context.Context, url string, cfg repository.CloneConf err error ) - log := log.FromContext(ctx) if g.authOpts != nil && g.authOpts.ProviderOpts != nil && g.authOpts.BearerToken == "" { + log := logr.FromContextOrDiscard(ctx) if g.authOpts.Cache != nil { cachedCreds, exists, err := getObjectFromCache(g.authOpts.Cache, url) if err != nil { diff --git a/git/gogit/go.mod b/git/gogit/go.mod index 97ff3c6e..35d1cea4 100644 --- a/git/gogit/go.mod +++ b/git/gogit/go.mod @@ -24,9 +24,9 @@ require ( github.com/fluxcd/pkg/version v0.4.0 github.com/go-git/go-billy/v5 v5.5.0 github.com/go-git/go-git/v5 v5.12.0 + github.com/go-logr/logr v1.4.2 github.com/onsi/gomega v1.34.1 golang.org/x/crypto v0.26.0 - sigs.k8s.io/controller-runtime v0.19.0 ) require ( @@ -50,7 +50,6 @@ require ( 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-logr/logr v1.4.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 diff --git a/git/gogit/go.sum b/git/gogit/go.sum index 3f907db5..ba4ea73c 100644 --- a/git/gogit/go.sum +++ b/git/gogit/go.sum @@ -408,8 +408,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= diff --git a/git/internal/e2e/go.mod b/git/internal/e2e/go.mod index 1a73b2a3..86ae7002 100644 --- a/git/internal/e2e/go.mod +++ b/git/internal/e2e/go.mod @@ -94,6 +94,7 @@ require ( github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xlab/treeprint v1.2.0 // indirect go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect + go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect golang.org/x/mod v0.20.0 // indirect @@ -118,7 +119,6 @@ require ( k8s.io/klog/v2 v2.130.1 // indirect k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect - sigs.k8s.io/controller-runtime v0.19.0 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kustomize/api v0.17.3 // indirect sigs.k8s.io/kustomize/kyaml v0.17.2 // indirect diff --git a/git/internal/e2e/go.sum b/git/internal/e2e/go.sum index 22abde29..0160f839 100644 --- a/git/internal/e2e/go.sum +++ b/git/internal/e2e/go.sum @@ -439,8 +439,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=