github.com/verrazzano/verrazzano@v1.7.1/tools/vz/pkg/internal/util/cluster/rancher/catalogapps.go (about) 1 // Copyright (c) 2023, 2024, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package rancher 5 6 import ( 7 "fmt" 8 "path/filepath" 9 10 "github.com/verrazzano/verrazzano/tools/vz/pkg/internal/util/files" 11 "github.com/verrazzano/verrazzano/tools/vz/pkg/internal/util/report" 12 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 13 ) 14 15 const catalogAppResource = "app.catalog.cattle.io" 16 17 // Minimal definition of object that only contains the fields that will be analyzed 18 type catalogAppList struct { 19 metav1.TypeMeta `json:",inline"` 20 metav1.ListMeta `json:"metadata,omitempty"` 21 Items []catalogApp `json:"items"` 22 } 23 type catalogApp struct { 24 metav1.TypeMeta `json:",inline"` 25 metav1.ObjectMeta `json:"metadata,omitempty"` 26 Status catalogAppStatus `json:"status,omitempty"` 27 } 28 type catalogAppStatus struct { 29 Summary *catalogAppSummary `json:"summary,omitempty"` 30 } 31 32 type catalogAppSummary struct { 33 Error bool `json:"error,omitempty"` 34 State string `json:"state,omitempty"` 35 Transitioning bool `json:"transitioning,omitempty"` 36 } 37 38 // AnalyzeCatalogApps - analyze the status of CatalogApp objects 39 func AnalyzeCatalogApps(clusterRoot string, namespace string, issueReporter *report.IssueReporter) error { 40 resourceRoot := clusterRoot 41 if len(namespace) != 0 { 42 resourceRoot = filepath.Join(clusterRoot, namespace) 43 } 44 45 list := &catalogAppList{} 46 err := files.UnmarshallFileInClusterRoot(resourceRoot, fmt.Sprintf("%s.json", catalogAppResource), list) 47 if err != nil { 48 return err 49 } 50 51 for _, catalogApp := range list.Items { 52 err = analyzeCatalogApp(clusterRoot, catalogApp, issueReporter) 53 if err != nil { 54 return err 55 } 56 } 57 58 return nil 59 } 60 61 // analyzeCatalogApp - analyze a single CatalogApp and report any issues 62 func analyzeCatalogApp(clusterRoot string, catalogApp catalogApp, issueReporter *report.IssueReporter) error { 63 64 var messages []string 65 66 summary := catalogApp.Status.Summary 67 if summary != nil && summary.Error { 68 message := fmt.Sprintf("Rancher %s resource %q in namespace %s is in state %s", catalogAppResource, catalogApp.Name, catalogApp.Namespace, catalogApp.Status.Summary.State) 69 messages = append([]string{message}, messages...) 70 } 71 72 if len(messages) > 0 { 73 issueReporter.AddKnownIssueMessagesFiles(report.RancherIssues, clusterRoot, messages, []string{}) 74 } 75 76 return nil 77 }