diff --git a/apps/provisioning/pkg/jobs/validator.go b/apps/provisioning/pkg/jobs/validator.go index 7ce7664e856..4eb1715c8b7 100644 --- a/apps/provisioning/pkg/jobs/validator.go +++ b/apps/provisioning/pkg/jobs/validator.go @@ -101,7 +101,11 @@ func validateExportJobOptions(opts *provisioning.ExportJobOptions) field.ErrorLi } // Validate resources if specified - if len(opts.Resources) > 0 { + // If Resources is provided, it must not be empty + if opts.Resources != nil { + if len(opts.Resources) == 0 { + list = append(list, field.Required(field.NewPath("spec", "push", "resources"), "resources list cannot be empty when specified")) + } for i, r := range opts.Resources { resourcePath := field.NewPath("spec", "push", "resources").Index(i) diff --git a/pkg/tests/apis/provisioning/export_resources_test.go b/pkg/tests/apis/provisioning/export_resources_test.go index 6c8f44c8e1a..5c53e4ad0b8 100644 --- a/pkg/tests/apis/provisioning/export_resources_test.go +++ b/pkg/tests/apis/provisioning/export_resources_test.go @@ -47,10 +47,11 @@ func TestIntegrationProvisioning_ExportSpecificResources(t *testing.T) { // Create repository const repo = "export-resources-test-repo" testRepo := TestRepo{ - Name: repo, - Copies: map[string]string{}, - ExpectedDashboards: 0, // No dashboards expected after sync (we'll export manually) - ExpectedFolders: 0, + Name: repo, + Copies: map[string]string{}, + ExpectedDashboards: 0, // No dashboards expected after sync (we'll export manually) + ExpectedFolders: 0, + SkipResourceAssertions: true, // Skip assertions since we created dashboards before repo } helper.CreateRepo(t, testRepo) @@ -115,10 +116,11 @@ func TestIntegrationProvisioning_ExportSpecificResourcesWithPath(t *testing.T) { // Create repository const repo = "export-resources-path-test-repo" testRepo := TestRepo{ - Name: repo, - Copies: map[string]string{}, - ExpectedDashboards: 0, - ExpectedFolders: 0, + Name: repo, + Copies: map[string]string{}, + ExpectedDashboards: 0, + ExpectedFolders: 0, + SkipResourceAssertions: true, // Skip assertions since we created dashboard before repo } helper.CreateRepo(t, testRepo) @@ -176,10 +178,11 @@ func TestIntegrationProvisioning_ExportSpecificResourcesRejectsFolders(t *testin // Create repository const repo = "export-reject-folders-test-repo" testRepo := TestRepo{ - Name: repo, - Copies: map[string]string{}, - ExpectedDashboards: 0, - ExpectedFolders: 0, + Name: repo, + Copies: map[string]string{}, + ExpectedDashboards: 0, + ExpectedFolders: 0, + SkipResourceAssertions: true, // Skip assertions since we created folder before repo } helper.CreateRepo(t, testRepo) @@ -241,13 +244,15 @@ func TestIntegrationProvisioning_ExportSpecificResourcesRejectsManagedResources( manager, found := managedDashboard.GetAnnotations()[utils.AnnoKeyManagerIdentity] require.True(t, found && manager != "", "dashboard should be managed") - // Create another repository for export + // Create another repository for export (must be folder target since instance can only exist alone) const exportRepo = "export-managed-reject-test-repo" exportTestRepo := TestRepo{ - Name: exportRepo, - Copies: map[string]string{}, - ExpectedDashboards: 0, - ExpectedFolders: 0, + Name: exportRepo, + Target: "folder", + Copies: map[string]string{}, + ExpectedDashboards: 0, + ExpectedFolders: 0, + SkipResourceAssertions: true, // Skip assertions since we're testing export, not sync } helper.CreateRepo(t, exportTestRepo) @@ -333,10 +338,11 @@ func TestIntegrationProvisioning_ExportSpecificResourcesWithFolderStructure(t *t // Create repository const repo = "export-folder-structure-test-repo" testRepo := TestRepo{ - Name: repo, - Copies: map[string]string{}, - ExpectedDashboards: 0, - ExpectedFolders: 0, + Name: repo, + Copies: map[string]string{}, + ExpectedDashboards: 0, + ExpectedFolders: 0, + SkipResourceAssertions: true, // Skip assertions since we created folder and dashboard before repo } helper.CreateRepo(t, testRepo)