Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
Signed-off-by: Wes <[email protected]>
  • Loading branch information
wrmedford authored Dec 31, 2024
2 parents ac97c7c + 8126508 commit 1e36bf6
Show file tree
Hide file tree
Showing 192 changed files with 929 additions and 803 deletions.
9 changes: 8 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ linters:
- gomodguard
- gosimple
- govet
- importas
- ineffassign
- misspell
- perfsprint
Expand Down Expand Up @@ -47,13 +48,19 @@ linters-settings:
- github.com/pkg/errors:
recommendations:
- errors
importas:
alias:
- alias: metav1
pkg: k8s.io/apimachinery/pkg/apis/meta/v1
- alias: stderrors
pkg: errors
perfsprint:
# Optimizes even if it requires an int or uint type cast.
int-conversion: true
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
err-error: true
# Optimizes `fmt.Errorf`.
errorf: false
errorf: true
# Optimizes `fmt.Sprintf` with only one argument.
sprintf1: true
# Optimizes into strings concatenation.
Expand Down
9 changes: 5 additions & 4 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
"testing"
Expand Down Expand Up @@ -1864,7 +1865,7 @@ func TestRequeueGeneratorFails(t *testing.T) {
generatorMock.On("GetTemplate", &generator).
Return(&v1alpha1.ApplicationSetTemplate{})
generatorMock.On("GenerateParams", &generator, mock.AnythingOfType("*v1alpha1.ApplicationSet"), mock.Anything).
Return([]map[string]interface{}{}, fmt.Errorf("Simulated error generating params that could be related to an external service/API call"))
Return([]map[string]interface{}{}, errors.New("Simulated error generating params that could be related to an external service/API call"))

metrics := appsetmetrics.NewFakeAppsetMetrics(client)

Expand Down Expand Up @@ -1969,7 +1970,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
},
},
},
validationErrors: map[int]error{0: fmt.Errorf("application destination spec is invalid: application destination can't have both name and server defined: my-cluster my-server")},
validationErrors: map[int]error{0: errors.New("application destination spec is invalid: application destination can't have both name and server defined: my-cluster my-server")},
},
{
name: "project mismatch should return error",
Expand All @@ -1991,7 +1992,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
},
},
},
validationErrors: map[int]error{0: fmt.Errorf("application references project DOES-NOT-EXIST which does not exist")},
validationErrors: map[int]error{0: errors.New("application references project DOES-NOT-EXIST which does not exist")},
},
{
name: "valid app should return true",
Expand Down Expand Up @@ -2035,7 +2036,7 @@ func TestValidateGeneratedApplications(t *testing.T) {
},
},
},
validationErrors: map[int]error{0: fmt.Errorf("application destination spec is invalid: unable to find destination server: there are no clusters with this name: nonexistent-cluster")},
validationErrors: map[int]error{0: errors.New("application destination spec is invalid: unable to find destination server: there are no clusters with this name: nonexistent-cluster")},
},
} {
t.Run(cc.name, func(t *testing.T) {
Expand Down
56 changes: 28 additions & 28 deletions applicationset/controllers/clustereventhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "no application sets should mean no requests",
items: []argov1alpha1.ApplicationSet{},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -53,7 +53,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a cluster generator should produce a request",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand All @@ -67,7 +67,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -83,7 +83,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "multiple cluster generators should produce multiple requests",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand All @@ -96,7 +96,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set2",
Namespace: "argocd",
},
Expand All @@ -110,7 +110,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -127,7 +127,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "non-cluster generator should not match",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "another-namespace",
},
Expand All @@ -140,7 +140,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "app-set-non-cluster",
Namespace: "argocd",
},
Expand All @@ -154,7 +154,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -170,7 +170,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "non-argo cd secret should not match",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "another-namespace",
},
Expand All @@ -184,7 +184,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-non-argocd-secret",
},
Expand All @@ -195,7 +195,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a matrix generator with a cluster generator should produce a request",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand All @@ -215,7 +215,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -231,7 +231,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a matrix generator with non cluster generator should not match",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand All @@ -251,7 +251,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -265,7 +265,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a matrix generator with a nested matrix generator containing a cluster generator should produce a request",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -317,7 +317,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a matrix generator with a nested matrix generator containing non cluster generator should not match",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -366,7 +366,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a merge generator with a cluster generator should produce a request",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand All @@ -386,7 +386,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -402,7 +402,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a matrix generator with non cluster generator should not match",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand All @@ -422,7 +422,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -436,7 +436,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a merge generator with a nested merge generator containing a cluster generator should produce a request",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand All @@ -488,7 +488,7 @@ func TestClusterEventHandler(t *testing.T) {
name: "a merge generator with a nested merge generator containing non cluster generator should not match",
items: []argov1alpha1.ApplicationSet{
{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-set",
Namespace: "argocd",
},
Expand Down Expand Up @@ -523,7 +523,7 @@ func TestClusterEventHandler(t *testing.T) {
},
},
secret: corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: "argocd",
Name: "my-secret",
Labels: map[string]string{
Expand Down
6 changes: 3 additions & 3 deletions applicationset/controllers/template/template_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package template

import (
"fmt"
"errors"
"maps"
"testing"

Expand Down Expand Up @@ -53,7 +53,7 @@ func TestGenerateApplications(t *testing.T) {
},
{
name: "Handles error from the generator",
generateParamsError: fmt.Errorf("error"),
generateParamsError: errors.New("error"),
expectErr: true,
expectedReason: v1alpha1.ApplicationSetReasonApplicationParamsGenerationError,
},
Expand All @@ -68,7 +68,7 @@ func TestGenerateApplications(t *testing.T) {
},
Spec: v1alpha1.ApplicationSpec{},
},
rendererError: fmt.Errorf("error"),
rendererError: errors.New("error"),
expectErr: true,
expectedReason: v1alpha1.ApplicationSetReasonRenderTemplateParamsError,
},
Expand Down
8 changes: 4 additions & 4 deletions applicationset/generators/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package generators

import (
"context"
"fmt"
"errors"
"testing"

corev1 "k8s.io/api/core/v1"
Expand All @@ -27,7 +27,7 @@ type possiblyErroringFakeCtrlRuntimeClient struct {

func (p *possiblyErroringFakeCtrlRuntimeClient) List(ctx context.Context, secretList client.ObjectList, opts ...client.ListOption) error {
if p.shouldError {
return fmt.Errorf("could not list Secrets")
return errors.New("could not list Secrets")
}
return p.Client.List(ctx, secretList, opts...)
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestGenerateParams(t *testing.T) {
values: nil,
expected: nil,
clientError: true,
expectedError: fmt.Errorf("error getting cluster secrets: could not list Secrets"),
expectedError: errors.New("error getting cluster secrets: could not list Secrets"),
},
{
name: "flat mode without selectors",
Expand Down Expand Up @@ -677,7 +677,7 @@ func TestGenerateParamsGoTemplate(t *testing.T) {
values: nil,
expected: nil,
clientError: true,
expectedError: fmt.Errorf("error getting cluster secrets: could not list Secrets"),
expectedError: errors.New("error getting cluster secrets: could not list Secrets"),
},
{
name: "Clusters with flat list mode and no selector",
Expand Down
Loading

0 comments on commit 1e36bf6

Please sign in to comment.