Skip to content

Commit

Permalink
chore: Reused argo define api Kind and Group (argoproj#11844)
Browse files Browse the repository at this point in the history
Signed-off-by: yanggang <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
  • Loading branch information
杨刚 (成都) and crenshaw-dev authored Mar 24, 2023
1 parent cc0072c commit 707cab1
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 86 deletions.
4 changes: 3 additions & 1 deletion applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
argoutil "github.com/argoproj/argo-cd/v2/util/argo"

"github.com/argoproj/argo-cd/v2/pkg/apis/application"
)

const (
Expand Down Expand Up @@ -563,7 +565,7 @@ func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context,
Namespace: generatedApp.Namespace,
},
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
}
Expand Down
50 changes: 26 additions & 24 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned/fake"
"github.com/argoproj/argo-cd/v2/util/collections"
dbmocks "github.com/argoproj/argo-cd/v2/util/db/mocks"

"github.com/argoproj/argo-cd/v2/pkg/apis/application"
)

type generatorMock struct {
Expand Down Expand Up @@ -354,7 +356,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -383,7 +385,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -409,7 +411,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -441,7 +443,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -467,7 +469,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -499,7 +501,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -527,7 +529,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -561,7 +563,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -589,7 +591,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -621,7 +623,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -655,7 +657,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -695,7 +697,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -731,7 +733,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -773,7 +775,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -805,7 +807,7 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1244,7 +1246,7 @@ func TestCreateApplications(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1272,7 +1274,7 @@ func TestCreateApplications(t *testing.T) {
existsApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1298,7 +1300,7 @@ func TestCreateApplications(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1329,7 +1331,7 @@ func TestCreateApplications(t *testing.T) {
existsApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1355,7 +1357,7 @@ func TestCreateApplications(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1441,7 +1443,7 @@ func TestDeleteInCluster(t *testing.T) {
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1455,7 +1457,7 @@ func TestDeleteInCluster(t *testing.T) {
},
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1481,7 +1483,7 @@ func TestDeleteInCluster(t *testing.T) {
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1497,7 +1499,7 @@ func TestDeleteInCluster(t *testing.T) {
notExpected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down
12 changes: 7 additions & 5 deletions cmd/argocd/commands/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/util/errors"
"github.com/argoproj/argo-cd/v2/util/settings"

"github.com/argoproj/argo-cd/v2/pkg/apis/application"
)

const (
Expand All @@ -27,9 +29,9 @@ const (
var (
configMapResource = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmaps"}
secretResource = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "secrets"}
applicationsResource = schema.GroupVersionResource{Group: "argoproj.io", Version: "v1alpha1", Resource: "applications"}
appprojectsResource = schema.GroupVersionResource{Group: "argoproj.io", Version: "v1alpha1", Resource: "appprojects"}
appplicationSetResource = schema.GroupVersionResource{Group: "argoproj.io", Version: "v1alpha1", Resource: "applicationsets"}
applicationsResource = schema.GroupVersionResource{Group: application.Group, Version: "v1alpha1", Resource: application.ApplicationPlural}
appprojectsResource = schema.GroupVersionResource{Group: application.Group, Version: "v1alpha1", Resource: application.AppProjectPlural}
appplicationSetResource = schema.GroupVersionResource{Group: application.Group, Version: "v1alpha1", Resource: application.ApplicationSetPlural}
)

// NewAdminCommand returns a new instance of an argocd command
Expand Down Expand Up @@ -193,11 +195,11 @@ func specsEqual(left, right unstructured.Unstructured) bool {
leftData, _, _ := unstructured.NestedMap(left.Object, "data")
rightData, _, _ := unstructured.NestedMap(right.Object, "data")
return reflect.DeepEqual(leftData, rightData)
case "AppProject":
case application.AppProjectKind:
leftSpec, _, _ := unstructured.NestedMap(left.Object, "spec")
rightSpec, _, _ := unstructured.NestedMap(right.Object, "spec")
return reflect.DeepEqual(leftSpec, rightSpec)
case "Application":
case application.ApplicationKind:
leftSpec, _, _ := unstructured.NestedMap(left.Object, "spec")
rightSpec, _, _ := unstructured.NestedMap(right.Object, "spec")
leftStatus, _, _ := unstructured.NestedMap(left.Object, "status")
Expand Down
25 changes: 13 additions & 12 deletions cmd/argocd/commands/admin/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"k8s.io/client-go/tools/clientcmd"

"github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/pkg/apis/application"
"github.com/argoproj/argo-cd/v2/util/cli"
"github.com/argoproj/argo-cd/v2/util/errors"
)
Expand Down Expand Up @@ -176,12 +177,12 @@ func NewImportCommand() *cobra.Command {
applications, err := acdClients.applications.List(ctx, v1.ListOptions{})
errors.CheckError(err)
for _, app := range applications.Items {
pruneObjects[kube.ResourceKey{Group: "argoproj.io", Kind: "Application", Name: app.GetName()}] = app
pruneObjects[kube.ResourceKey{Group: application.Group, Kind: application.ApplicationKind, Name: app.GetName()}] = app
}
projects, err := acdClients.projects.List(ctx, v1.ListOptions{})
errors.CheckError(err)
for _, proj := range projects.Items {
pruneObjects[kube.ResourceKey{Group: "argoproj.io", Kind: "AppProject", Name: proj.GetName()}] = proj
pruneObjects[kube.ResourceKey{Group: application.Group, Kind: application.AppProjectKind, Name: proj.GetName()}] = proj
}
applicationSets, err := acdClients.applicationSets.List(ctx, v1.ListOptions{})
if apierr.IsForbidden(err) || apierr.IsNotFound(err) {
Expand All @@ -191,7 +192,7 @@ func NewImportCommand() *cobra.Command {
}
if applicationSets != nil {
for _, appSet := range applicationSets.Items {
pruneObjects[kube.ResourceKey{Group: "argoproj.io", Kind: "ApplicationSet", Name: appSet.GetName()}] = appSet
pruneObjects[kube.ResourceKey{Group: application.Group, Kind: application.ApplicationSetKind, Name: appSet.GetName()}] = appSet
}
}

Expand All @@ -209,11 +210,11 @@ func NewImportCommand() *cobra.Command {
dynClient = acdClients.secrets
case "ConfigMap":
dynClient = acdClients.configMaps
case "AppProject":
case application.AppProjectKind:
dynClient = acdClients.projects
case "Application":
case application.ApplicationKind:
dynClient = acdClients.applications
case "ApplicationSet":
case application.ApplicationSetKind:
dynClient = acdClients.applicationSets
}
if !exists {
Expand Down Expand Up @@ -260,9 +261,9 @@ func NewImportCommand() *cobra.Command {
switch key.Kind {
case "Secret":
dynClient = acdClients.secrets
case "AppProject":
case application.AppProjectKind:
dynClient = acdClients.projects
case "Application":
case application.ApplicationKind:
dynClient = acdClients.applications
if !dryRun {
if finalizers := liveObj.GetFinalizers(); len(finalizers) > 0 {
Expand All @@ -274,7 +275,7 @@ func NewImportCommand() *cobra.Command {
}
}
}
case "ApplicationSet":
case application.ApplicationSetKind:
dynClient = acdClients.applicationSets
default:
log.Fatalf("Unexpected kind '%s' in prune list", key.Kind)
Expand Down Expand Up @@ -314,7 +315,7 @@ func checkAppHasNoNeedToStopOperation(liveObj unstructured.Unstructured, stopOpe
return true
}
switch liveObj.GetKind() {
case "Application":
case application.ApplicationKind:
return liveObj.Object["operation"] == nil
}
return true
Expand Down Expand Up @@ -353,9 +354,9 @@ func updateLive(bak, live *unstructured.Unstructured, stopOperation bool) *unstr
switch live.GetKind() {
case "Secret", "ConfigMap":
newLive.Object["data"] = bak.Object["data"]
case "AppProject":
case application.AppProjectKind:
newLive.Object["spec"] = bak.Object["spec"]
case "Application":
case application.ApplicationKind:
newLive.Object["spec"] = bak.Object["spec"]
if _, ok := bak.Object["status"]; ok {
newLive.Object["status"] = bak.Object["status"]
Expand Down
3 changes: 2 additions & 1 deletion cmd/argocd/commands/admin/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import (
settings "github.com/argoproj/argo-cd/v2/util/notification/settings"
"github.com/argoproj/argo-cd/v2/util/tls"

"github.com/argoproj/argo-cd/v2/pkg/apis/application"
"github.com/argoproj/notifications-engine/pkg/cmd"
"github.com/spf13/cobra"
)

var (
applications = schema.GroupVersionResource{Group: "argoproj.io", Version: "v1alpha1", Resource: "applications"}
applications = schema.GroupVersionResource{Group: application.Group, Version: "v1alpha1", Resource: application.ApplicationPlural}
)

func NewNotificationsCommand() *cobra.Command {
Expand Down
Loading

0 comments on commit 707cab1

Please sign in to comment.