argo-cd/test/e2e/fixture/admin/utils/backup.go
Ville Vesilehto 5101db5225
chore(deps): migrate to go.yaml.in/yaml/v3 (#27063)
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2026-04-01 16:34:18 +02:00

48 lines
1.1 KiB
Go

package utils
import (
"fmt"
"strings"
"github.com/argoproj/argo-cd/gitops-engine/pkg/utils/kube"
yaml "go.yaml.in/yaml/v3"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
type ExportedResources []unstructured.Unstructured
func GetExportedResourcesFromOutput(output string) (ExportedResources, error) {
var resources []unstructured.Unstructured
docs := strings.SplitSeq(output, "\n---\n")
for doc := range docs {
doc = strings.TrimSpace(doc)
if doc == "" {
continue
}
var resourceData map[string]any
if err := yaml.Unmarshal([]byte(doc), &resourceData); err != nil {
return nil, fmt.Errorf("error unmarshaling YAML: %w", err)
}
resource := unstructured.Unstructured{Object: resourceData}
resources = append(resources, resource)
}
return resources, nil
}
func (e ExportedResources) HasResource(resource kube.ResourceKey) bool {
for _, res := range e {
if res.GetObjectKind().GroupVersionKind().Group == resource.Group &&
res.GetKind() == resource.Kind &&
res.GetName() == resource.Name &&
res.GetNamespace() == resource.Namespace {
return true
}
}
return false
}