diff --git a/controller/sync.go b/controller/sync.go index 278aa1cba3..38b9ccf5a8 100644 --- a/controller/sync.go +++ b/controller/sync.go @@ -173,6 +173,14 @@ func (sc *syncContext) sync() { if !successful { return } + + // If no sync tasks were generated (e.g., in case all application manifests have been removed), + // set the sync operation as successful. + if len(syncTasks) == 0 { + sc.setOperationPhase(appv1.OperationSucceeded, "successfully synced (no manifests)") + return + } + // Perform a `kubectl apply --dry-run` against all the manifests. This will detect most (but // not all) validation issues with the user's manifests (e.g. will detect syntax issues, but // will not not detect if they are mutating immutable fields). If anything fails, we will refuse @@ -250,15 +258,9 @@ func (sc *syncContext) generateSyncTasks() ([]syncTask, bool) { syncTasks = append(syncTasks, syncTask) } } - if len(syncTasks) == 0 { - if len(sc.resources) == 0 { - sc.setOperationPhase(appv1.OperationError, fmt.Sprintf("Application has no resources")) - } else { - sc.setOperationPhase(appv1.OperationError, fmt.Sprintf("Specified resources filter does not match any application resource")) - } - } + sort.Sort(newKindSorter(syncTasks, resourceOrder)) - return syncTasks, len(syncTasks) > 0 + return syncTasks, true } // startedPreSyncPhase detects if we already started the PreSync stage of a sync operation. diff --git a/util/argo/argo.go b/util/argo/argo.go index 02bcd5b82b..5d3a800689 100644 --- a/util/argo/argo.go +++ b/util/argo/argo.go @@ -458,18 +458,17 @@ func verifyGenerateManifests(ctx context.Context, repoRes *argoappv1.Repository, req.Repo.Password = repoRes.Password req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey } - manRes, err := repoClient.GenerateManifest(ctx, &req) + + // Only check whether we can access the application's path, + // and not whether it actually contains any manifests. + _, err := repoClient.GenerateManifest(ctx, &req) if err != nil { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: fmt.Sprintf("Unable to generate manifests in %s: %v", spec.Source.Path, err), }) - } else if len(manRes.Manifests) == 0 { - conditions = append(conditions, argoappv1.ApplicationCondition{ - Type: argoappv1.ApplicationConditionInvalidSpecError, - Message: fmt.Sprintf("Path '%s' contained no kubernetes manifests", spec.Source.Path), - }) } + return conditions }