github.com/verrazzano/verrazzano@v1.7.1/tools/vz/pkg/internal/util/cluster/clusterapi.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 cluster 5 6 import ( 7 "fmt" 8 "os" 9 "strings" 10 11 capi "github.com/verrazzano/verrazzano/tools/vz/pkg/internal/util/cluster/clusterapi" 12 "github.com/verrazzano/verrazzano/tools/vz/pkg/internal/util/report" 13 "go.uber.org/zap" 14 ) 15 16 // AnalyzeClusterAPI handles the checking of the status of Cluster API resources. 17 func AnalyzeClusterAPI(log *zap.SugaredLogger, clusterRoot string) error { 18 log.Debugf("AnalyzeClusterAPI called for %s", clusterRoot) 19 20 var issueReporter = report.IssueReporter{ 21 PendingIssues: make(map[string]report.Issue), 22 } 23 24 var err error 25 var errors []string 26 27 // First, process the cluster scoped resources. 28 analyzers := []func(clusterRoot string, namespace string, issueReporter *report.IssueReporter) error{} 29 for _, analyze := range analyzers { 30 if err = analyze(clusterRoot, "", &issueReporter); err != nil { 31 errors = append(errors, err.Error()) 32 } 33 } 34 35 // Second, process the namespaced resources. 36 namespaceAnalyzers := []func(clusterRoot string, namespace string, issueReporter *report.IssueReporter) error{ 37 capi.AnalyzeClusters, capi.AnalyzeOCIClusters, capi.AnalyzeOCNEControlPlanes, 38 capi.AnalyzeMachines, capi.AnalyzeMachineDeployments, capi.AnalyzeOCNEConfigs, 39 capi.AnalyzeOCIMachines, capi.AnalyzeMachineSets, capi.AnalyzeClusterResourceSets, 40 } 41 snapshotFiles, err := os.ReadDir(clusterRoot) 42 if err != nil { 43 return err 44 } 45 for _, f := range snapshotFiles { 46 if f.IsDir() { 47 for _, analyze := range namespaceAnalyzers { 48 if err = analyze(clusterRoot, f.Name(), &issueReporter); err != nil { 49 errors = append(errors, err.Error()) 50 } 51 } 52 } 53 } 54 55 issueReporter.Contribute(log, clusterRoot) 56 57 if len(errors) > 0 { 58 return fmt.Errorf("Errors analyzing Cluster API reources: %s", fmt.Sprintf(strings.Join(errors[:], ","))) 59 } 60 61 return nil 62 }