Relax validation to permit app with no manifests (#832)

This commit is contained in:
Zvi Cahana 2018-11-27 12:52:46 +02:00 committed by Jesse Suen
parent b53ad60b48
commit 2b23812e6e
2 changed files with 15 additions and 14 deletions

View file

@ -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.

View file

@ -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
}