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
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ manager: generate fmt vet
go build $(GO_STATIC_FLAGS) -o $(BUILD_DIR)/bin/manager main.go

KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
test: install-envtest test-api ## Run all tests
test: fix install-envtest test-api ## Run all tests
HTTPS_PROXY="" HTTP_PROXY="" \
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
GIT_CONFIG_GLOBAL=/dev/null \
Expand Down Expand Up @@ -115,6 +115,10 @@ fmt: ## Run go fmt against code
go fmt ./...
cd api; go fmt ./...

fix: ## Run go fix against code
go fix ./...
cd api ; go fix ./...

vet: ## Run go vet against code
go vet ./...
cd api; go vet ./...
Expand Down Expand Up @@ -204,7 +208,7 @@ fuzz-smoketest: fuzz-build
bash -c "/runner.sh"

# Run fuzz tests for the duration set in FUZZ_TIME.
fuzz-native:
fuzz-native:
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
FUZZ_TIME=$(FUZZ_TIME) \
./tests/fuzz/native_go_run.sh
3 changes: 1 addition & 2 deletions internal/bucket/azure/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
Expand Down Expand Up @@ -259,7 +258,7 @@ func ValidateSecret(secret *corev1.Secret) error {
// exists, or returns a (client) error.
func (c *BlobClient) BucketExists(ctx context.Context, bucketName string) (bool, error) {
items := c.Client.NewListBlobsFlatPager(bucketName, &azblob.ListBlobsFlatOptions{
MaxResults: to.Ptr(int32(1)),
MaxResults: new(int32(1)),
})
// We call next page only once since we just want to see if we get an error
if _, err := items.NextPage(ctx); err != nil {
Expand Down
34 changes: 11 additions & 23 deletions internal/bucket/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"cloud.google.com/go/compute/metadata"
gcpstorage "cloud.google.com/go/storage"
. "github.com/onsi/gomega"
"google.golang.org/api/googleapi"
"google.golang.org/api/option"
raw "google.golang.org/api/storage/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -61,40 +60,32 @@ var (
close func()
err error
secret = corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: "gcp-secret",
Namespace: "default",
},
Name: "gcp-secret",
Namespace: "default",
Data: map[string][]byte{
"serviceaccount": []byte(serviceAccountJSON),
},
Type: "Opaque",
}
badSecret = corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: "gcp-secret",
Namespace: "default",
},
Name: "gcp-secret",
Namespace: "default",
Data: map[string][]byte{
"username": []byte("test-user"),
},
Type: "Opaque",
}
malformedSecret = corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: "gcp-secret",
Namespace: "default",
},
Name: "gcp-secret",
Namespace: "default",
Data: map[string][]byte{
"serviceaccount": []byte("not-json"),
},
Type: "Opaque",
}
externalAccountSecret = corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: "gcp-secret",
Namespace: "default",
},
Name: "gcp-secret",
Namespace: "default",
Data: map[string][]byte{
"serviceaccount": []byte(externalAccountJSON),
},
Expand Down Expand Up @@ -134,10 +125,8 @@ const externalAccountJSON = `{
// createTestBucket creates a test bucket for testing purposes
func createTestBucket() *sourcev1.Bucket {
return &sourcev1.Bucket{
ObjectMeta: v1.ObjectMeta{
Name: "test-bucket",
Namespace: "default",
},
Name: "test-bucket",
Namespace: "default",
Spec: sourcev1.BucketSpec{
BucketName: bucketName,
Endpoint: "storage.googleapis.com",
Expand Down Expand Up @@ -325,7 +314,6 @@ func TestProxy(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
opts := []Option{WithProxyURL(tt.proxyURL)}
opts = append(opts, func(o *options) {
Expand Down Expand Up @@ -567,7 +555,7 @@ func getBucket() *raw.Bucket {
},
Condition: &raw.BucketLifecycleRuleCondition{
Age: &age,
IsLive: googleapi.Bool(true),
IsLive: new(true),
CreatedBefore: "2021-01-02",
MatchesStorageClass: matchClasses,
NumNewerVersions: 3,
Expand Down
37 changes: 13 additions & 24 deletions internal/bucket/minio/minio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/minio/minio-go/v7/pkg/credentials"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/sourceignore"
Expand Down Expand Up @@ -80,29 +79,23 @@ var (
bucketName = "test-bucket-minio" + uuid.New().String()
prefix = ""
secret = corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: "minio-secret",
Namespace: "default",
},
Name: "minio-secret",
Namespace: "default",
Data: map[string][]byte{
"accesskey": []byte(testAccessKey),
"secretkey": []byte(testSecretKey),
},
Type: "Opaque",
}
emptySecret = corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: "minio-secret",
Namespace: "default",
},
Data: map[string][]byte{},
Type: "Opaque",
Name: "minio-secret",
Namespace: "default",
Data: map[string][]byte{},
Type: "Opaque",
}
bucket = sourcev1.Bucket{
ObjectMeta: v1.ObjectMeta{
Name: "minio-test-bucket",
Namespace: "default",
},
Name: "minio-test-bucket",
Namespace: "default",
Spec: sourcev1.BucketSpec{
BucketName: bucketName,
Provider: "generic",
Expand All @@ -112,10 +105,8 @@ var (
},
}
bucketAwsProvider = sourcev1.Bucket{
ObjectMeta: v1.ObjectMeta{
Name: "minio-test-bucket",
Namespace: "default",
},
Name: "minio-test-bucket",
Namespace: "default",
Spec: sourcev1.BucketSpec{
BucketName: bucketName,
Provider: "aws",
Expand Down Expand Up @@ -193,10 +184,8 @@ func TestNewClientEmptySecret(t *testing.T) {
func TestNewClientAWSProvider(t *testing.T) {
t.Run("with secret", func(t *testing.T) {
validSecret := corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Name: "valid-secret",
Namespace: "default",
},
Name: "valid-secret",
Namespace: "default",
Data: map[string][]byte{
"accesskey": []byte(testAccessKey),
"secretkey": []byte(testSecretKey),
Expand Down Expand Up @@ -716,7 +705,7 @@ func TestValidateSTSSecret(t *testing.T) {
{
name: "empty ldap secret",
provider: "ldap",
secret: &corev1.Secret{ObjectMeta: v1.ObjectMeta{Name: "ldap-secret"}},
secret: &corev1.Secret{Name: "ldap-secret"},
err: "invalid 'ldap-secret' secret data for 'ldap' STS provider: required fields username, password",
},
{
Expand Down
10 changes: 5 additions & 5 deletions internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Cache struct {
// Item is an item stored in the cache.
type Item struct {
// Object is the item's value.
Object interface{}
Object any
// Expiration is the item's expiration time.
Expiration int64
}
Expand All @@ -50,7 +50,7 @@ func (c *cache) ItemCount() int {
return n
}

func (c *cache) set(key string, value interface{}, expiration time.Duration) {
func (c *cache) set(key string, value any, expiration time.Duration) {
var e int64
if expiration > 0 {
e = time.Now().Add(expiration).UnixNano()
Expand All @@ -65,7 +65,7 @@ func (c *cache) set(key string, value interface{}, expiration time.Duration) {
// Set adds an item to the cache, replacing any existing item.
// If expiration is zero, the item never expires.
// If the cache is full, Set will return an error.
func (c *cache) Set(key string, value interface{}, expiration time.Duration) error {
func (c *cache) Set(key string, value any, expiration time.Duration) error {
c.mu.Lock()
_, found := c.Items[key]
if found {
Expand All @@ -87,7 +87,7 @@ func (c *cache) Set(key string, value interface{}, expiration time.Duration) err
// Add an item to the cache, existing items will not be overwritten.
// To overwrite existing items, use Set.
// If the cache is full, Add will return an error.
func (c *cache) Add(key string, value interface{}, expiration time.Duration) error {
func (c *cache) Add(key string, value any, expiration time.Duration) error {
c.mu.Lock()
_, found := c.Items[key]
if found {
Expand All @@ -107,7 +107,7 @@ func (c *cache) Add(key string, value interface{}, expiration time.Duration) err

// Get an item from the cache. Returns the item or nil, and a bool indicating
// whether the key was found.
func (c *cache) Get(key string) (interface{}, bool) {
func (c *cache) Get(key string) (any, bool) {
c.mu.RLock()
item, found := c.Items[key]
if !found {
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/artifact_matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type matchArtifact struct {
expected *meta.Artifact
}

func (m matchArtifact) Match(actual interface{}) (success bool, err error) {
func (m matchArtifact) Match(actual any) (success bool, err error) {
actualArtifact, ok := actual.(*meta.Artifact)
if !ok {
return false, fmt.Errorf("actual should be a pointer to an Artifact")
Expand All @@ -59,10 +59,10 @@ func (m matchArtifact) Match(actual interface{}) (success bool, err error) {
return ok, err
}

func (m matchArtifact) FailureMessage(actual interface{}) (message string) {
func (m matchArtifact) FailureMessage(actual any) (message string) {
return fmt.Sprintf("expected\n\t%#v\nto match\n\t%#v\n", actual, m.expected)
}

func (m matchArtifact) NegatedFailureMessage(actual interface{}) (message string) {
func (m matchArtifact) NegatedFailureMessage(actual any) (message string) {
return fmt.Sprintf("expected\n\t%#v\nto not match\n\t%#v\n", actual, m.expected)
}
6 changes: 2 additions & 4 deletions internal/controller/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,10 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial

provider, err := r.createBucketProvider(ctx, obj, creds)
if err != nil {
var stallingErr *serror.Stalling
var genericErr *serror.Generic
if errors.As(err, &stallingErr) {
if stallingErr, ok := errors.AsType[*serror.Stalling](err); ok {
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, stallingErr.Reason, "%s", stallingErr)
return sreconcile.ResultEmpty, stallingErr
} else if errors.As(err, &genericErr) {
} else if genericErr, ok := errors.AsType[*serror.Generic](err); ok {
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, genericErr.Reason, "%s", genericErr)
return sreconcile.ResultEmpty, genericErr
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/bucket_controller_fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func Test_fetchFiles(t *testing.T) {
tmp := t.TempDir()

client := mockBucketClient{bucketName: bucketName}
for i := 0; i < 2*maxConcurrentBucketFetches; i++ {
for i := range 2 * maxConcurrentBucketFetches {
f := fmt.Sprintf("file-%d", i)
client.addObject(f, mockBucketObject{etag: f, data: f})
}
Expand Down
Loading