github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/pkg/clients/gitops/deploymenttargetclaims.go (about) 1 package gitops 2 3 import ( 4 "context" 5 "fmt" 6 7 appservice "github.com/redhat-appstudio/application-api/api/v1alpha1" 8 "github.com/redhat-appstudio/e2e-tests/pkg/logs" 9 k8sErrors "k8s.io/apimachinery/pkg/api/errors" 10 "sigs.k8s.io/controller-runtime/pkg/client" 11 ) 12 13 // Returns a list of a deploymenttargetclaims from a specific namespace in the kubernetes cluster 14 func (g *GitopsController) GetDeploymentTargetClaimsList(namespace string) (*appservice.DeploymentTargetClaimList, error) { 15 deploymentTargetClaimList := &appservice.DeploymentTargetClaimList{} 16 17 opts := []client.ListOption{ 18 client.InNamespace(namespace), 19 } 20 21 err := g.KubeRest().List(context.Background(), deploymentTargetClaimList, opts...) 22 if err != nil && !k8sErrors.IsNotFound(err) { 23 return nil, fmt.Errorf("error occurred while trying to list DeploymentTargetClaim in %s namespace: %v", namespace, err) 24 } 25 26 return deploymentTargetClaimList, nil 27 } 28 29 // StoreDeploymentTargetClaim stores a given DeploymentTargetClaim as an artifact. 30 func (g *GitopsController) StoreDeploymentTargetClaim(deploymentTargetClaim *appservice.DeploymentTargetClaim) error { 31 return logs.StoreResourceYaml(deploymentTargetClaim, "deploymentTargetClaim-"+deploymentTargetClaim.Name) 32 } 33 34 // StoreAllDeploymentTargetClaims stores all DeploymentTargetClaims in a given namespace. 35 func (g *GitopsController) StoreAllDeploymentTargetClaims(namespace string) error { 36 deploymentTargetClaimList, err := g.GetDeploymentTargetClaimsList(namespace) 37 if err != nil { 38 return err 39 } 40 41 for _, deploymentTargetClaim := range deploymentTargetClaimList.Items { 42 if err := g.StoreDeploymentTargetClaim(&deploymentTargetClaim); err != nil { 43 return err 44 } 45 } 46 return nil 47 }