github.com/verrazzano/verrazzano@v1.7.1/tools/vz/pkg/internal/util/cluster/verrazzano.go (about)

     1  // Copyright (c) 2021, 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 handles cluster analysis
     5  package cluster
     6  
     7  import (
     8  	"strings"
     9  
    10  	"github.com/verrazzano/verrazzano/tools/vz/pkg/constants"
    11  	"github.com/verrazzano/verrazzano/tools/vz/pkg/internal/util/files"
    12  	"github.com/verrazzano/verrazzano/tools/vz/pkg/internal/util/report"
    13  	"go.uber.org/zap"
    14  	appsv1 "k8s.io/api/apps/v1"
    15  )
    16  
    17  // TODO: Helpers to access this info as needed
    18  
    19  // allNamespacesFound is a list of the namespaces found
    20  var allNamespacesFound []string
    21  
    22  // verrazzanoNamespacesFound is a list of the Verrazzano namespaces found
    23  var verrazzanoNamespacesFound []string
    24  
    25  // TODO: CRDs related to verrazzano
    26  // TODO: Can we determine the underlying platform that is being used? This may generally help in terms
    27  //       of the analysis (ie: message formatting), but it also is generally useful in terms of how we
    28  //       provide action advice as well. Inspecting the nodes.json seems like the a good place to determine this
    29  
    30  // verrazzanoDeployments related to verrazzano
    31  var verrazzanoDeployments = make(map[string]appsv1.Deployment)
    32  var problematicVerrazzanoDeploymentNames = make([]string, 0)
    33  
    34  var verrazzanoAnalysisFunctions = map[string]func(log *zap.SugaredLogger, clusterRoot string, issueReporter *report.IssueReporter) (err error){
    35  	"Verrazzano Resource Status": AnalyzeVerrazzanoResource,
    36  	"Installation status":        installationStatus,
    37  }
    38  
    39  // AnalyzeVerrazzano handles high level checking for Verrazzano itself. Note that we are not necessarily going to drill deeply here and
    40  // we may actually handle scenarios as part of the other drill-downs separately
    41  func AnalyzeVerrazzano(log *zap.SugaredLogger, clusterRoot string) (err error) {
    42  	log.Debugf("AnalyzeVerrazzano called for %s", clusterRoot)
    43  
    44  	var issueReporter = report.IssueReporter{
    45  		PendingIssues: make(map[string]report.Issue),
    46  	}
    47  
    48  	// Call the Verrazzano analysis functions
    49  	for functionName, function := range verrazzanoAnalysisFunctions {
    50  		err := function(log, clusterRoot, &issueReporter)
    51  		if err != nil {
    52  			// Log the error and continue on
    53  			log.Errorf("Error processing analysis function %s", functionName, err)
    54  		}
    55  	}
    56  	issueReporter.Contribute(log, clusterRoot)
    57  	return nil
    58  }
    59  
    60  // Determine the state of the Verrazzano Installation
    61  func installationStatus(log *zap.SugaredLogger, clusterRoot string, issueReporter *report.IssueReporter) (err error) {
    62  	// TODO: Is verrazzano:
    63  	//      installed, installed-but-not-running, uninstalled-success-no-cruft, failed-install, failed-uninstall,
    64  	//      uninstall-success-but-cruft-remaining, etc...
    65  	// The intention is that we should at least give an Informational on what the state is.
    66  
    67  	// Enumerate the namespaces that we found overall and the Verrazzano specific ones separately
    68  	// Also look at the deployments in the Verrazzano related namespaces
    69  	allNamespacesFound, err = files.FindNamespaces(log, clusterRoot)
    70  	if err != nil {
    71  		return err
    72  	}
    73  
    74  	for _, namespace := range allNamespacesFound {
    75  		// These are Verrazzano owned namespaces
    76  		if strings.Contains(namespace, "verrazzano") {
    77  			verrazzanoNamespacesFound = append(verrazzanoNamespacesFound, namespace)
    78  			deploymentList, err := GetDeploymentList(log, files.FormFilePathInNamespace(clusterRoot, namespace, constants.DeploymentsJSON))
    79  			if err != nil {
    80  				// Log the error and continue on
    81  				log.Debugf("Error getting deployments in %s", namespace, err)
    82  			}
    83  			if deploymentList != nil && len(deploymentList.Items) > 0 {
    84  				for i, deployment := range deploymentList.Items {
    85  					verrazzanoDeployments[deployment.ObjectMeta.Name] = deployment
    86  					if IsDeploymentProblematic(&deploymentList.Items[i]) {
    87  						problematicVerrazzanoDeploymentNames = append(problematicVerrazzanoDeploymentNames, deployment.ObjectMeta.Name)
    88  					}
    89  				}
    90  			}
    91  		}
    92  		// TBD: For now not enumerating out potentially related namespaces that could be here even
    93  		// without Verrazzano (cattle, keycloak, etc...). Those will still be in the AllNamespacesFound if present
    94  		// so until there is an explicit need to separate those, not doing that here (we could though)
    95  	}
    96  
    97  	// TODO: Inspect the verrazzano-install namespace platform operator logs. We should be able to glean state from the
    98  	//       the logs here, and what the name of the install job resource to look for is.
    99  	// TODO: Inspect the default namespace for a Verrazzano install job pod logs. Inspecting the logs should here should
   100  	//       tell us whether an install/uninstall was done and what state it thinks it is in. NOTE, a user can name this
   101  	//       how they want, so use the resource gleaned above on what to look for here.
   102  	// TODO: Inspect the verrazzano-system namespace. The deployments/status here will tell us what we need to fan out
   103  	//       and drill into
   104  	// TODO: Inspect the verrazzano-mc namespace (TBD)
   105  
   106  	// TODO: verrazzanoApiResourceMatches := files.SearchFile(log, files.FindFileInCluster(cluserRoot, "api_resources.out"), ".*verrazzano.*")
   107  	// TODO: verrazzanoResources (json file)
   108  
   109  	// Get more details on problematicVerrazzanoDeploymentNames and find a way to report
   110  	return nil
   111  }