github.com/argoproj/argo-cd/v3@v3.2.1/test/e2e/fixture/admin/utils/backup.go (about) 1 package utils 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/argoproj/gitops-engine/pkg/utils/kube" 8 yaml "gopkg.in/yaml.v3" 9 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 10 ) 11 12 type ExportedResources []unstructured.Unstructured 13 14 func GetExportedResourcesFromOutput(output string) (ExportedResources, error) { 15 var resources []unstructured.Unstructured 16 docs := strings.Split(output, "\n---\n") 17 18 for _, doc := range docs { 19 doc = strings.TrimSpace(doc) 20 if doc == "" { 21 continue 22 } 23 24 var resourceData map[string]any 25 26 if err := yaml.Unmarshal([]byte(doc), &resourceData); err != nil { 27 return nil, fmt.Errorf("error unmarshaling YAML: %w", err) 28 } 29 30 resource := unstructured.Unstructured{Object: resourceData} 31 resources = append(resources, resource) 32 } 33 34 return resources, nil 35 } 36 37 func (e ExportedResources) HasResource(resource kube.ResourceKey) bool { 38 for _, res := range e { 39 if res.GetObjectKind().GroupVersionKind().Group == resource.Group && 40 res.GetKind() == resource.Kind && 41 res.GetName() == resource.Name && 42 res.GetNamespace() == resource.Namespace { 43 return true 44 } 45 } 46 47 return false 48 }