Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: import packages only once #15329

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 1 addition & 2 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"github.com/argoproj/argo-cd/v2/controller/sharding"
"github.com/argoproj/argo-cd/v2/pkg/apis/application"
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
argov1alpha "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
"github.com/argoproj/argo-cd/v2/pkg/client/informers/externalversions/application/v1alpha1"
applisters "github.com/argoproj/argo-cd/v2/pkg/client/listers/application/v1alpha1"
Expand Down Expand Up @@ -2029,4 +2028,4 @@ func (ctrl *ApplicationController) toAppQualifiedName(appName, appNamespace stri
return fmt.Sprintf("%s/%s", appNamespace, appName)
}

type ClusterFilterFunction func(c *argov1alpha.Cluster, distributionFunction sharding.DistributionFunction) bool
type ClusterFilterFunction func(c *appv1.Cluster, distributionFunction sharding.DistributionFunction) bool
79 changes: 39 additions & 40 deletions server/application/application.go

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions server/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
k8sappsv1 "k8s.io/api/apps/v1"
k8sbatchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -53,7 +52,6 @@ import (
"github.com/argoproj/argo-cd/v2/test"
"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/assets"
"github.com/argoproj/argo-cd/v2/util/cache"
cacheutil "github.com/argoproj/argo-cd/v2/util/cache"
"github.com/argoproj/argo-cd/v2/util/cache/appstate"
"github.com/argoproj/argo-cd/v2/util/db"
Expand Down Expand Up @@ -136,15 +134,15 @@ func newTestAppServer(t *testing.T, objects ...runtime.Object) *Server {
}

func newTestAppServerWithEnforcerConfigure(f func(*rbac.Enforcer), t *testing.T, objects ...runtime.Object) *Server {
kubeclientset := fake.NewSimpleClientset(&v1.ConfigMap{
kubeclientset := fake.NewSimpleClientset(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: "argocd-cm",
Labels: map[string]string{
"app.kubernetes.io/part-of": "argocd",
},
},
}, &v1.Secret{
}, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "argocd-secret",
Namespace: testNamespace,
Expand Down Expand Up @@ -245,7 +243,7 @@ func newTestAppServerWithEnforcerConfigure(f func(*rbac.Enforcer), t *testing.T,
broadcaster.On("OnUpdate", mock.Anything, mock.Anything).Return()
broadcaster.On("OnDelete", mock.Anything).Return()

appStateCache := appstate.NewCache(cache.NewCache(cache.NewInMemoryCache(time.Hour)), time.Hour)
appStateCache := appstate.NewCache(cacheutil.NewCache(cacheutil.NewInMemoryCache(time.Hour)), time.Hour)
// pre-populate the app cache
for _, obj := range objects {
app, ok := obj.(*appsv1.Application)
Expand Down Expand Up @@ -317,15 +315,15 @@ func newTestAppServerWithBenchmark(b *testing.B, objects ...runtime.Object) *Ser
}

func newTestAppServerWithEnforcerConfigureWithBenchmark(f func(*rbac.Enforcer), b *testing.B, objects ...runtime.Object) *Server {
kubeclientset := fake.NewSimpleClientset(&v1.ConfigMap{
kubeclientset := fake.NewSimpleClientset(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: "argocd-cm",
Labels: map[string]string{
"app.kubernetes.io/part-of": "argocd",
},
},
}, &v1.Secret{
}, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "argocd-secret",
Namespace: testNamespace,
Expand Down Expand Up @@ -425,7 +423,7 @@ func newTestAppServerWithEnforcerConfigureWithBenchmark(f func(*rbac.Enforcer),
broadcaster.On("OnUpdate", mock.Anything, mock.Anything).Return()
broadcaster.On("OnDelete", mock.Anything).Return()

appStateCache := appstate.NewCache(cache.NewCache(cache.NewInMemoryCache(time.Hour)), time.Hour)
appStateCache := appstate.NewCache(cacheutil.NewCache(cacheutil.NewInMemoryCache(time.Hour)), time.Hour)
// pre-populate the app cache
for _, obj := range objects {
app, ok := obj.(*appsv1.Application)
Expand Down Expand Up @@ -1849,7 +1847,7 @@ func TestGetCachedAppState(t *testing.T) {
}

err := appServer.getCachedAppState(context.Background(), testApp, func() error {
res := cache.ErrCacheMiss
res := cacheutil.ErrCacheMiss
if retryCount == 1 {
res = nil
}
Expand Down
3 changes: 1 addition & 2 deletions server/application/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/argoproj/argo-cd/v2/util/db"
"github.com/argoproj/argo-cd/v2/util/rbac"
"github.com/argoproj/argo-cd/v2/util/security"
sessionmgr "github.com/argoproj/argo-cd/v2/util/session"
"github.com/argoproj/argo-cd/v2/util/settings"
)

Expand Down Expand Up @@ -154,7 +153,7 @@ func (s *terminalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

fieldLog := log.WithFields(log.Fields{"application": app, "userName": sessionmgr.Username(ctx), "container": container,
fieldLog := log.WithFields(log.Fields{"application": app, "userName": util_session.Username(ctx), "container": container,
"podName": podName, "namespace": namespace, "project": project, "appNamespace": appNamespace})

a, err := s.appLister.Applications(ns).Get(app)
Expand Down
27 changes: 12 additions & 15 deletions server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import (
"time"

"github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
clusterapi "github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
servercache "github.com/argoproj/argo-cd/v2/server/cache"
"github.com/argoproj/argo-cd/v2/test"
cacheutil "github.com/argoproj/argo-cd/v2/util/cache"
Expand All @@ -27,7 +25,6 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/utils/pointer"
Expand Down Expand Up @@ -100,7 +97,7 @@ func TestUpdateCluster_RejectInvalidParams(t *testing.T) {
db.On("ListClusters", mock.Anything).Return(
func(ctx context.Context) *v1alpha1.ClusterList {
return &v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: clusters,
}
},
Expand Down Expand Up @@ -171,7 +168,7 @@ func TestGetCluster_UrlEncodedName(t *testing.T) {
Namespaces: []string{"default", "kube-system"},
}
mockClusterList := v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: []v1alpha1.Cluster{
mockCluster,
},
Expand Down Expand Up @@ -201,7 +198,7 @@ func TestGetCluster_NameWithUrlEncodingButShouldNotBeUnescaped(t *testing.T) {
Namespaces: []string{"default", "kube-system"},
}
mockClusterList := v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: []v1alpha1.Cluster{
mockCluster,
},
Expand Down Expand Up @@ -235,7 +232,7 @@ func TestUpdateCluster_NoFieldsPaths(t *testing.T) {
}

clusterList := v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: clusters,
}

Expand Down Expand Up @@ -513,7 +510,7 @@ func TestListCluster(t *testing.T) {
}

mockClusterList := v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: []v1alpha1.Cluster{fooCluster, barCluster, bazCluster},
}

Expand All @@ -523,8 +520,8 @@ func TestListCluster(t *testing.T) {

tests := []struct {
name string
q *cluster.ClusterQuery
want *appv1.ClusterList
q *clusterapi.ClusterQuery
want *v1alpha1.ClusterList
wantErr bool
}{
{
Expand All @@ -533,7 +530,7 @@ func TestListCluster(t *testing.T) {
Name: fooCluster.Name,
},
want: &v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: []v1alpha1.Cluster{fooCluster},
},
},
Expand All @@ -543,7 +540,7 @@ func TestListCluster(t *testing.T) {
Server: barCluster.Server,
},
want: &v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: []v1alpha1.Cluster{barCluster},
},
},
Expand All @@ -556,7 +553,7 @@ func TestListCluster(t *testing.T) {
},
},
want: &v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: []v1alpha1.Cluster{fooCluster},
},
},
Expand All @@ -569,7 +566,7 @@ func TestListCluster(t *testing.T) {
},
},
want: &v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: []v1alpha1.Cluster{bazCluster},
},
},
Expand All @@ -582,7 +579,7 @@ func TestListCluster(t *testing.T) {
},
},
want: &v1alpha1.ClusterList{
ListMeta: v1.ListMeta{},
ListMeta: metav1.ListMeta{},
Items: []v1alpha1.Cluster{barCluster},
},
},
Expand Down
27 changes: 13 additions & 14 deletions server/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"google.golang.org/grpc/status"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
k8scache "k8s.io/client-go/tools/cache"

Expand All @@ -38,15 +37,15 @@ const testNamespace = "default"

func TestProjectServer(t *testing.T) {
kubeclientset := fake.NewSimpleClientset(&corev1.ConfigMap{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: "argocd-cm",
Labels: map[string]string{
"app.kubernetes.io/part-of": "argocd",
},
},
}, &corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "argocd-secret",
Namespace: testNamespace,
},
Expand All @@ -58,7 +57,7 @@ func TestProjectServer(t *testing.T) {
settingsMgr := settings.NewSettingsManager(context.Background(), kubeclientset, testNamespace)
enforcer := newEnforcer(kubeclientset)
existingProj := v1alpha1.AppProject{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: testNamespace},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: testNamespace},
Spec: v1alpha1.AppProjectSpec{
Destinations: []v1alpha1.ApplicationDestination{
{Namespace: "ns1", Server: "https://server1"},
Expand All @@ -68,7 +67,7 @@ func TestProjectServer(t *testing.T) {
},
}
existingApp := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}, Project: "test", Destination: v1alpha1.ApplicationDestination{Namespace: "ns3", Server: "https://server3"}},
}

Expand All @@ -94,7 +93,7 @@ func TestProjectServer(t *testing.T) {
err := projectServer.NormalizeProjs()
assert.NoError(t, err)

appList, err := projectServer.appclientset.ArgoprojV1alpha1().AppProjects(projectWithRole.Namespace).List(context.Background(), v1.ListOptions{})
appList, err := projectServer.appclientset.ArgoprojV1alpha1().AppProjects(projectWithRole.Namespace).List(context.Background(), metav1.ListOptions{})
assert.NoError(t, err)
assert.Equal(t, appList.Items[0].Status.JWTTokensByRole[roleName].Items[0].IssuedAt, int64(1))
assert.ElementsMatch(t, appList.Items[0].Status.JWTTokensByRole[roleName].Items, appList.Items[0].Spec.Roles[0].JWTTokens)
Expand Down Expand Up @@ -165,7 +164,7 @@ func TestProjectServer(t *testing.T) {

t.Run("TestRemoveDestinationSuccessful", func(t *testing.T) {
existingApp := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}, Project: "test", Destination: v1alpha1.ApplicationDestination{Namespace: "ns3", Server: "https://server3"}},
}

Expand All @@ -182,7 +181,7 @@ func TestProjectServer(t *testing.T) {

t.Run("TestRemoveDestinationUsedByApp", func(t *testing.T) {
existingApp := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}, Project: "test", Destination: v1alpha1.ApplicationDestination{Namespace: "ns1", Server: "https://server1"}},
}

Expand All @@ -201,7 +200,7 @@ func TestProjectServer(t *testing.T) {

t.Run("TestRemoveSourceSuccessful", func(t *testing.T) {
existingApp := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}, Project: "test"},
}

Expand All @@ -218,7 +217,7 @@ func TestProjectServer(t *testing.T) {

t.Run("TestRemoveSourceUsedByApp", func(t *testing.T) {
existingApp := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: v1alpha1.ApplicationSpec{Project: "test", Source: &v1alpha1.ApplicationSource{RepoURL: "https://github.com/argoproj/argo-cd.git"}},
}

Expand All @@ -239,7 +238,7 @@ func TestProjectServer(t *testing.T) {
proj := existingProj.DeepCopy()
proj.Spec.SourceRepos = []string{"https://github.com/argoproj/argo-cd.git", "https://github.com/argoproj/*"}
existingApp := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: v1alpha1.ApplicationSpec{Project: "test", Source: &v1alpha1.ApplicationSource{RepoURL: "https://github.com/argoproj/argo-cd.git"}},
}
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
Expand All @@ -261,7 +260,7 @@ func TestProjectServer(t *testing.T) {
{Namespace: "org1-*", Server: "https://server1"},
}
existingApp := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: v1alpha1.ApplicationSpec{Source: &v1alpha1.ApplicationSource{}, Project: "test", Destination: v1alpha1.ApplicationDestination{
Server: "https://server1",
Namespace: "org1-team1",
Expand Down Expand Up @@ -294,7 +293,7 @@ func TestProjectServer(t *testing.T) {

t.Run("TestDeleteDefaultProjectFailure", func(t *testing.T) {
defaultProj := v1alpha1.AppProject{
ObjectMeta: v1.ObjectMeta{Name: "default", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "default", Namespace: "default"},
Spec: v1alpha1.AppProjectSpec{},
}
argoDB := db.NewDB("default", settingsMgr, kubeclientset)
Expand All @@ -307,7 +306,7 @@ func TestProjectServer(t *testing.T) {

t.Run("TestDeleteProjectReferencedByApp", func(t *testing.T) {
existingApp := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: v1alpha1.ApplicationSpec{Project: "test"},
}

Expand Down
3 changes: 1 addition & 2 deletions server/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/argoproj/argo-cd/v2/common"
repositorypkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appsv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
applisters "github.com/argoproj/argo-cd/v2/pkg/client/listers/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
Expand Down Expand Up @@ -559,7 +558,7 @@ func (s *Server) isRepoPermittedInProject(ctx context.Context, repo string, proj

// isSourceInHistory checks if the supplied application source is either our current application
// source, or was something which we synced to previously.
func isSourceInHistory(app *v1alpha1.Application, source v1alpha1.ApplicationSource) bool {
func isSourceInHistory(app *appsv1.Application, source appsv1.ApplicationSource) bool {
appSource := app.Spec.GetSource()
if source.Equals(&appSource) {
return true
Expand Down
5 changes: 2 additions & 3 deletions server/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"google.golang.org/grpc/status"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/fake"
k8scache "k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -42,7 +41,7 @@ const testNamespace = "default"

var (
argocdCM = corev1.ConfigMap{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: "argocd-cm",
Labels: map[string]string{
Expand All @@ -51,7 +50,7 @@ var (
},
}
argocdSecret = corev1.Secret{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "argocd-secret",
Namespace: testNamespace,
},
Expand Down
Loading