Skip to content

Commit

Permalink
chore: Clean up repeated package import (argoproj#12431)
Browse files Browse the repository at this point in the history
Signed-off-by: Zechun Chen <[email protected]>
  • Loading branch information
Fish-pro authored Mar 24, 2023
1 parent 21ce221 commit cc0072c
Show file tree
Hide file tree
Showing 9 changed files with 854 additions and 864 deletions.
1,661 changes: 830 additions & 831 deletions applicationset/controllers/applicationset_controller_test.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"k8s.io/client-go/tools/clientcmd"

"github.com/argoproj/argo-cd/v2/applicationset/services"
appsetv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appv1alpha1 "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/util/cli"
Expand Down Expand Up @@ -60,7 +59,6 @@ func NewCommand() *cobra.Command {
)
scheme := runtime.NewScheme()
_ = clientgoscheme.AddToScheme(scheme)
_ = appsetv1alpha1.AddToScheme(scheme)
_ = appv1alpha1.AddToScheme(scheme)
var command = cobra.Command{
Use: "controller",
Expand Down
5 changes: 2 additions & 3 deletions reposerver/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"

. "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
cacheutil "github.com/argoproj/argo-cd/v2/util/cache"
)
Expand Down Expand Up @@ -114,7 +113,7 @@ func TestCache_GetAppDetails(t *testing.T) {
cache := newFixtures().Cache
// cache miss
value := &apiclient.RepoAppDetailsResponse{}
emptyRefSources := map[string]*appv1.RefTarget{}
emptyRefSources := map[string]*RefTarget{}
err := cache.GetAppDetails("my-revision", &ApplicationSource{}, emptyRefSources, value, "", nil)
assert.Equal(t, ErrCacheMiss, err)
res := &apiclient.RepoAppDetailsResponse{Type: "my-type"}
Expand Down Expand Up @@ -153,7 +152,7 @@ func TestCachedManifestResponse_HashBehavior(t *testing.T) {
Revision: "revision",
Manifests: []string{"sample-text"},
}
appSrc := &appv1.ApplicationSource{}
appSrc := &ApplicationSource{}
appKey := "key"
appValue := "value"

Expand Down
3 changes: 1 addition & 2 deletions server/applicationset/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
servercache "github.com/argoproj/argo-cd/v2/server/cache"
"github.com/argoproj/argo-cd/v2/server/rbacpolicy"
"github.com/argoproj/argo-cd/v2/util/argo"
argoutil "github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/db"
"github.com/argoproj/argo-cd/v2/util/rbac"
"github.com/argoproj/argo-cd/v2/util/session"
Expand Down Expand Up @@ -115,7 +114,7 @@ func (s *Server) List(ctx context.Context, q *applicationset.ApplicationSetListQ
}
}

newItems = argoutil.FilterAppSetsByProjects(newItems, q.Projects)
newItems = argo.FilterAppSetsByProjects(newItems, q.Projects)

// Sort found applicationsets by name
sort.Slice(newItems, func(i, j int) bool {
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/fixture/applicationsets/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"k8s.io/apimachinery/pkg/util/wait"

"github.com/argoproj/argo-cd/v2/common"
argocommon "github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets/utils"
"github.com/argoproj/argo-cd/v2/util/clusterauth"
Expand Down Expand Up @@ -109,8 +108,8 @@ func (a *Actions) CreateClusterSecret(secretName string, clusterName string, clu
Name: secretName,
Namespace: fixture.TestNamespace(),
Labels: map[string]string{
argocommon.LabelKeySecretType: argocommon.LabelValueSecretTypeCluster,
utils.TestingLabel: "true",
common.LabelKeySecretType: common.LabelValueSecretTypeCluster,
utils.TestingLabel: "true",
},
},
Data: map[string][]byte{
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/fixture/applicationsets/consequences.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets/utils"
)

Expand Down Expand Up @@ -61,7 +60,7 @@ func (c *Consequences) When() *Actions {
return c.actions
}

func (c *Consequences) app(name string) *argov1alpha1.Application {
func (c *Consequences) app(name string) *v1alpha1.Application {
apps := c.apps()

for index, app := range apps {
Expand All @@ -73,14 +72,14 @@ func (c *Consequences) app(name string) *argov1alpha1.Application {
return nil
}

func (c *Consequences) apps() []argov1alpha1.Application {
func (c *Consequences) apps() []v1alpha1.Application {

fixtureClient := utils.GetE2EFixtureK8sClient()
list, err := fixtureClient.AppClientset.ArgoprojV1alpha1().Applications(fixture.TestNamespace()).List(context.Background(), metav1.ListOptions{})
errors.CheckError(err)

if list == nil {
list = &argov1alpha1.ApplicationList{}
list = &v1alpha1.ApplicationList{}
}

return list.Items
Expand Down
19 changes: 9 additions & 10 deletions test/e2e/fixture/applicationsets/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets/utils"
)

Expand Down Expand Up @@ -58,7 +57,7 @@ func Error(message, err string) Expectation {

// ApplicationsExist checks whether each of the 'expectedApps' exist in the namespace, and are
// equivalent to provided values.
func ApplicationsExist(expectedApps []argov1alpha1.Application) Expectation {
func ApplicationsExist(expectedApps []v1alpha1.Application) Expectation {
return func(c *Consequences) (state, string) {

for _, expectedApp := range expectedApps {
Expand Down Expand Up @@ -107,7 +106,7 @@ func ApplicationSetHasConditions(applicationSetName string, expectedConditions [
}

// ApplicationsDoNotExist checks that each of the 'expectedApps' no longer exist in the namespace
func ApplicationsDoNotExist(expectedApps []argov1alpha1.Application) Expectation {
func ApplicationsDoNotExist(expectedApps []v1alpha1.Application) Expectation {
return func(c *Consequences) (state, string) {

for _, expectedApp := range expectedApps {
Expand Down Expand Up @@ -145,7 +144,7 @@ func pods(namespace string) (*corev1.PodList, error) {
}

// getDiff returns a string containing a comparison result of two applications (for test output/debug purposes)
func getDiff(orig, new argov1alpha1.Application) (string, error) {
func getDiff(orig, new v1alpha1.Application) (string, error) {

bytes, _, err := diff.CreateTwoWayMergePatch(orig, new, orig)
if err != nil {
Expand Down Expand Up @@ -177,27 +176,27 @@ func getConditionDiff(orig, new []v1alpha1.ApplicationSetCondition) (string, err
}

// filterFields returns a copy of Application, but with unnecessary (for testing) fields removed
func filterFields(input argov1alpha1.Application) argov1alpha1.Application {
func filterFields(input v1alpha1.Application) v1alpha1.Application {

spec := input.Spec

metaCopy := input.ObjectMeta.DeepCopy()

output := argov1alpha1.Application{
output := v1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Labels: metaCopy.Labels,
Annotations: metaCopy.Annotations,
Name: metaCopy.Name,
Namespace: metaCopy.Namespace,
Finalizers: metaCopy.Finalizers,
},
Spec: argov1alpha1.ApplicationSpec{
Source: &argov1alpha1.ApplicationSource{
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
Path: spec.GetSource().Path,
RepoURL: spec.GetSource().RepoURL,
TargetRevision: spec.GetSource().TargetRevision,
},
Destination: argov1alpha1.ApplicationDestination{
Destination: v1alpha1.ApplicationDestination{
Server: spec.Destination.Server,
Name: spec.Destination.Name,
Namespace: spec.Destination.Namespace,
Expand Down Expand Up @@ -227,7 +226,7 @@ func filterConditionFields(input *[]v1alpha1.ApplicationSetCondition) *[]v1alpha
}

// appsAreEqual returns true if the apps are equal, comparing only fields of interest
func appsAreEqual(one argov1alpha1.Application, two argov1alpha1.Application) bool {
func appsAreEqual(one v1alpha1.Application, two v1alpha1.Application) bool {
return reflect.DeepEqual(filterFields(one), filterFields(two))
}

Expand Down
13 changes: 6 additions & 7 deletions util/argo/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/go-logr/logr"

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/argo/managedfields"
appstatecache "github.com/argoproj/argo-cd/v2/util/cache/appstate"
Expand Down Expand Up @@ -40,7 +39,7 @@ func (b *DiffConfigBuilder) WithDiffSettings(id []v1alpha1.ResourceIgnoreDiffere

overrides := o
if overrides == nil {
overrides = make(map[string]appv1.ResourceOverride)
overrides = make(map[string]v1alpha1.ResourceOverride)
}
b.diffConfig.overrides = overrides
b.diffConfig.ignoreAggregatedRoles = ignoreAggregatedRoles
Expand Down Expand Up @@ -113,7 +112,7 @@ type DiffConfig interface {
Validate() error
// DiffFromCache will verify if it should retrieve the cached ResourceDiff based on this
// DiffConfig.
DiffFromCache(appName string) (bool, []*appv1.ResourceDiff)
DiffFromCache(appName string) (bool, []*v1alpha1.ResourceDiff)
// Ignores Application level ignore difference configurations.
Ignores() []v1alpha1.ResourceIgnoreDifferences
// Overrides is map of system configurations to override the Application ones.
Expand Down Expand Up @@ -267,13 +266,13 @@ func StateDiffs(lives, configs []*unstructured.Unstructured, diffConfig DiffConf
return diff.DiffArray(normResults.Targets, normResults.Lives, diffOpts...)
}

func diffArrayCached(configArray []*unstructured.Unstructured, liveArray []*unstructured.Unstructured, cachedDiff []*appv1.ResourceDiff, opts ...diff.Option) (*diff.DiffResultList, error) {
func diffArrayCached(configArray []*unstructured.Unstructured, liveArray []*unstructured.Unstructured, cachedDiff []*v1alpha1.ResourceDiff, opts ...diff.Option) (*diff.DiffResultList, error) {
numItems := len(configArray)
if len(liveArray) != numItems {
return nil, fmt.Errorf("left and right arrays have mismatched lengths")
}

diffByKey := map[kube.ResourceKey]*appv1.ResourceDiff{}
diffByKey := map[kube.ResourceKey]*v1alpha1.ResourceDiff{}
for i := range cachedDiff {
res := cachedDiff[i]
diffByKey[kube.NewResourceKey(res.Group, res.Kind, res.Namespace, res.Name)] = cachedDiff[i]
Expand Down Expand Up @@ -322,11 +321,11 @@ func diffArrayCached(configArray []*unstructured.Unstructured, liveArray []*unst
// DiffFromCache will verify if it should retrieve the cached ResourceDiff based on this
// DiffConfig. Returns true and the cached ResourceDiff if configured to use the cache.
// Returns false and nil otherwise.
func (c *diffConfig) DiffFromCache(appName string) (bool, []*appv1.ResourceDiff) {
func (c *diffConfig) DiffFromCache(appName string) (bool, []*v1alpha1.ResourceDiff) {
if c.noCache || c.stateCache == nil || appName == "" {
return false, nil
}
cachedDiff := make([]*appv1.ResourceDiff, 0)
cachedDiff := make([]*v1alpha1.ResourceDiff, 0)
if c.stateCache != nil && c.stateCache.GetAppManagedResources(appName, &cachedDiff) == nil {
return true, cachedDiff
}
Expand Down
3 changes: 1 addition & 2 deletions util/notification/argocd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
repoapiclient "github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/argoproj/argo-cd/v2/util/db"
"github.com/argoproj/argo-cd/v2/util/settings"
)
Expand All @@ -22,7 +21,7 @@ type Service interface {
GetAppDetails(ctx context.Context, appSource *v1alpha1.ApplicationSource) (*shared.AppDetail, error)
}

func NewArgoCDService(clientset kubernetes.Interface, namespace string, repoClientset repoapiclient.Clientset) (*argoCDService, error) {
func NewArgoCDService(clientset kubernetes.Interface, namespace string, repoClientset apiclient.Clientset) (*argoCDService, error) {
ctx, cancel := context.WithCancel(context.Background())
settingsMgr := settings.NewSettingsManager(ctx, clientset, namespace)
closer, repoClient, err := repoClientset.NewRepoServerClient()
Expand Down

0 comments on commit cc0072c

Please sign in to comment.