github.com/verrazzano/verrazzano@v1.7.1/tools/vz/pkg/internal/util/cluster/rancher/kontainerdrivers.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 corev1 "k8s.io/api/core/v1" 13 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 14 ) 15 16 const kontainerDriverResource = "kontainerdriver.management.cattle.io" 17 18 // KontainerDriverList has the minimal definition of KontainerDriver object. 19 type KontainerDriverList struct { 20 metav1.TypeMeta `json:",inline"` 21 metav1.ListMeta `json:"metadata,omitempty"` 22 Items []KontainerDriver `json:"items"` 23 } 24 type KontainerDriver struct { 25 metav1.TypeMeta `json:",inline"` 26 metav1.ObjectMeta `json:"metadata,omitempty"` 27 Status KontainerDriverStatus `json:"status,omitempty"` 28 } 29 type KontainerDriverStatus struct { 30 Conditions []KontainerDriverCondition `json:"conditions,omitempty"` 31 } 32 type KontainerDriverCondition struct { 33 Status corev1.ConditionStatus `json:"status"` 34 Type string `json:"type"` 35 } 36 37 // AnalyzeKontainerDrivers handles the checking of the status of KontainerDriver resources. 38 func AnalyzeKontainerDrivers(clusterRoot string, namespace string, issueReporter *report.IssueReporter) error { 39 resourceRoot := clusterRoot 40 if len(namespace) != 0 { 41 resourceRoot = filepath.Join(clusterRoot, namespace) 42 } 43 44 kontainerDriverList := &KontainerDriverList{} 45 err := files.UnmarshallFileInClusterRoot(resourceRoot, fmt.Sprintf("%s.json", kontainerDriverResource), kontainerDriverList) 46 if err != nil { 47 return fmt.Errorf("failed to unmarshal KontainerDriver list from cluster snapshot: %s", err) 48 } 49 50 // Analyze each KontainerDriver resource. 51 for _, kontainerDriver := range kontainerDriverList.Items { 52 reportKontainerDriverIssue(clusterRoot, kontainerDriver, issueReporter) 53 } 54 55 return nil 56 } 57 58 // reportKontainerDriverIssue will check the ociocneengine and oraclecontainerengine KontainerDriver resources and 59 // report any issues that are found with them. 60 func reportKontainerDriverIssue(clusterRoot string, driver KontainerDriver, issueReporter *report.IssueReporter) error { 61 var messages []string 62 if driver.Name == "ociocneengine" || driver.Name == "oraclecontainerengine" { 63 for _, condition := range driver.Status.Conditions { 64 switch condition.Type { 65 case "Active", "Downloaded", "Installed": 66 if condition.Status != "True" { 67 messages = append(messages, fmt.Sprintf("\tcondition type \"%s\" has a status of \"%s\"", condition.Type, condition.Status)) 68 } 69 } 70 } 71 72 if len(messages) != 0 { 73 messages = append([]string{fmt.Sprintf("Rancher %s resource \"%s\" is not ready per it's resource status", kontainerDriverResource, driver.Name)}, messages...) 74 issueReporter.AddKnownIssueMessagesFiles(report.RancherIssues, clusterRoot, messages, []string{}) 75 } 76 } 77 78 return nil 79 }