github.com/verrazzano/verrazzano@v1.7.0/platform-operator/internal/config/config.go (about)

     1  // Copyright (c) 2020, 2023, 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 config
     5  
     6  import (
     7  	"path/filepath"
     8  
     9  	"github.com/verrazzano/verrazzano/pkg/nginxutil"
    10  
    11  	"k8s.io/apimachinery/pkg/runtime/schema"
    12  
    13  	"github.com/verrazzano/verrazzano/platform-operator/constants"
    14  )
    15  
    16  const (
    17  	rootDir                         = "/verrazzano"
    18  	platformDirSuffix               = "/platform-operator"
    19  	profilesDirSuffix               = "/platform-operator/manifests/profiles"
    20  	installDirSuffix                = "/platform-operator/scripts/install"
    21  	thirdPartyDirSuffix             = "/platform-operator/thirdparty/charts"
    22  	thirdPartyManifestsDirSuffix    = "/platform-operator/thirdparty/manifests"
    23  	helmConfigDirSuffix             = "/platform-operator/helm_config"
    24  	helmChartsDirSuffix             = "/platform-operator/helm_config/charts"
    25  	helmVPOChartsDirSuffix          = "/platform-operator/helm_config/charts/verrazzano-platform-operator"
    26  	helmVMOChartsDirSuffix          = "/platform-operator/helm_config/charts/verrazzano-monitoring-operator"
    27  	helmAppOpChartsDirSuffix        = "/platform-operator/helm_config/charts/verrazzano-application-operator"
    28  	helmClusterOpChartsDirSuffix    = "/platform-operator/helm_config/charts/verrazzano-cluster-operator"
    29  	helmKialiChartsDirSuffix        = "/platform-operator/thirdparty/charts/kiali-server"
    30  	helmPromOpChartsDirSuffix       = "/platform-operator/thirdparty/charts/prometheus-community/kube-prometheus-stack"
    31  	helmOamChartsDirSuffix          = "/platform-operator/thirdparty/charts/oam-kubernetes-runtime"
    32  	helmOpenSearchOpChartsDirSuffix = "/platform-operator/thirdparty/charts/opensearch-operator"
    33  	helmOverridesDirSuffix          = "/platform-operator/helm_config/overrides"
    34  	integrationChartsDirSuffix      = "/platform-operator/experimental/manifests/integration-charts"
    35  	catalogDirSuffix                = "/platform-operator/manifests/catalog"
    36  	fluentOperatorDirSuffix         = "/platform-operator/thirdparty/charts/fluent-operator"
    37  )
    38  
    39  const defaultBomFilename = "verrazzano-bom.json"
    40  const defaultCatalogFilename = "catalog.yaml"
    41  
    42  // Global override for the default BOM file path
    43  var bomFilePathOverride string
    44  
    45  // TestHelmConfigDir is needed for unit tests
    46  var TestHelmConfigDir string
    47  
    48  // TestProfilesDir is needed for unit tests
    49  var TestProfilesDir string
    50  
    51  // TestIntegrationChartsDis is needed for unit tests
    52  var TestIntegrationChartsDis string
    53  
    54  // TestCatalogDir  is needed for unit tests
    55  var TestCatalogDir string
    56  
    57  // TestThirdPartyManifestDir is needed for unit tests
    58  var TestThirdPartyManifestDir string
    59  
    60  // OperatorConfig specifies the Verrazzano Platform Operator Config
    61  type OperatorConfig struct {
    62  
    63  	// The CertDir directory containing tls.crt and tls.key
    64  	CertDir string
    65  
    66  	// MetricsAddr is the address the metric endpoint binds to
    67  	MetricsAddr string
    68  
    69  	// LeaderElectionEnabled  enables/disables ensuring that there is only one active controller manager
    70  	LeaderElectionEnabled bool
    71  
    72  	// VersionCheckEnabled enables/disables version checking for upgrade.
    73  	VersionCheckEnabled bool
    74  
    75  	// RunWebhooks Runs the webhooks instead of the operator instead of the operator reconciler
    76  	RunWebhooks bool
    77  
    78  	// RunWebhookInit Runs the webhook init path instead of the operator reconciler
    79  	RunWebhookInit bool
    80  
    81  	// ResourceRequirementsValidation toggles the suppression of resource requirement validation webhook
    82  	// default-value: false, disabling the validation
    83  	ResourceRequirementsValidation bool
    84  
    85  	// CloudCredentialWatchEnabled enables/disables watching the cloud credentials for updates
    86  	CloudCredentialWatchEnabled bool
    87  
    88  	// WebhookValidationEnabled enables/disables webhook validation without removing the webhook itself
    89  	WebhookValidationEnabled bool
    90  
    91  	// VerrazzanoRootDir is the root Verrazzano directory in the image
    92  	VerrazzanoRootDir string
    93  
    94  	// HealthCheckPeriodSeconds period for health check background task in seconds; a value of 0 disables health checks
    95  	HealthCheckPeriodSeconds int64
    96  
    97  	// MySQLCheckPeriodSeconds period for MySQL check background task in seconds; a value of 0 disables MySQL checks
    98  	MySQLCheckPeriodSeconds int64
    99  
   100  	// NamespacePeriodSeconds period to watch Namespaces in seconds; a value of 0 disables Namespace watcher
   101  	NamespacePeriodSeconds int64
   102  
   103  	// MySQLRepairTimeoutSeconds is the amount of time the MySQL check background thread will allow to transpire between
   104  	// detecting a possible condition to repair, and initiating the repair logic.
   105  	MySQLRepairTimeoutSeconds int64
   106  
   107  	// DryRun Run installs in a dry-run mode
   108  	DryRun bool
   109  }
   110  
   111  // The singleton instance of the operator config
   112  var instance = OperatorConfig{
   113  	CertDir:                        "/etc/webhook/certs",
   114  	MetricsAddr:                    ":8080",
   115  	LeaderElectionEnabled:          false,
   116  	VersionCheckEnabled:            true,
   117  	RunWebhookInit:                 false,
   118  	RunWebhooks:                    false,
   119  	ResourceRequirementsValidation: false,
   120  	WebhookValidationEnabled:       true,
   121  	CloudCredentialWatchEnabled:    false,
   122  	VerrazzanoRootDir:              rootDir,
   123  	HealthCheckPeriodSeconds:       60,
   124  	MySQLCheckPeriodSeconds:        60,
   125  	NamespacePeriodSeconds:         60,
   126  	MySQLRepairTimeoutSeconds:      120,
   127  }
   128  
   129  // Set saves the operator config.  This should only be called at operator startup and during unit tests
   130  func Set(config OperatorConfig) {
   131  	instance = config
   132  }
   133  
   134  // Get returns the singleton instance of the operator config
   135  func Get() OperatorConfig {
   136  	return instance
   137  }
   138  
   139  // GetHelmConfigDir returns the helm config dir
   140  func GetHelmConfigDir() string {
   141  	if TestHelmConfigDir != "" {
   142  		return TestHelmConfigDir
   143  	}
   144  	return filepath.Join(instance.VerrazzanoRootDir, helmConfigDirSuffix)
   145  }
   146  
   147  // GetHelmChartsDir returns the helm charts dir
   148  func GetHelmChartsDir() string {
   149  	if TestHelmConfigDir != "" {
   150  		return filepath.Join(TestHelmConfigDir, "/charts")
   151  	}
   152  	return filepath.Join(instance.VerrazzanoRootDir, helmChartsDirSuffix)
   153  }
   154  
   155  // GetHelmVPOChartsDir returns the verrazzano-platform-operator helm charts dir
   156  func GetHelmVPOChartsDir() string {
   157  	if TestHelmConfigDir != "" {
   158  		return filepath.Join(TestHelmConfigDir, "/charts/verrazzano-platform-operator")
   159  	}
   160  	return filepath.Join(instance.VerrazzanoRootDir, helmVPOChartsDirSuffix)
   161  }
   162  
   163  // GetHelmVMOChartsDir returns the verrazzano-monitoring-operator helm charts dir
   164  func GetHelmVMOChartsDir() string {
   165  	if TestHelmConfigDir != "" {
   166  		return filepath.Join(TestHelmConfigDir, "/charts/verrazzano-monitoring-operator")
   167  	}
   168  	return filepath.Join(instance.VerrazzanoRootDir, helmVMOChartsDirSuffix)
   169  }
   170  
   171  // GetHelmFluentOperatorChartsDir returns the fluent operator helm charts dir
   172  func GetHelmFluentOperatorChartsDir() string {
   173  	return filepath.Join(instance.VerrazzanoRootDir, fluentOperatorDirSuffix)
   174  }
   175  
   176  // GetHelmAppOpChartsDir returns the Verrazzano Application Operator helm charts dir
   177  func GetHelmAppOpChartsDir() string {
   178  	if TestHelmConfigDir != "" {
   179  		return filepath.Join(TestHelmConfigDir, "/charts/verrazzano-application-operator")
   180  	}
   181  	return filepath.Join(instance.VerrazzanoRootDir, helmAppOpChartsDirSuffix)
   182  }
   183  
   184  // GetHelmClusterOpChartsDir returns the Verrazzano Cluster Operator helm charts dir
   185  func GetHelmClusterOpChartsDir() string {
   186  	if TestHelmConfigDir != "" {
   187  		return filepath.Join(TestHelmConfigDir, "/charts/verrazzano-cluster-operator")
   188  	}
   189  	return filepath.Join(instance.VerrazzanoRootDir, helmClusterOpChartsDirSuffix)
   190  }
   191  
   192  func GetHelmOpenSearchOpChartsDir() string {
   193  	if TestHelmConfigDir != "" {
   194  		return filepath.Join(TestHelmConfigDir, "/charts/opensearch-operator")
   195  	}
   196  	return filepath.Join(instance.VerrazzanoRootDir, helmOpenSearchOpChartsDirSuffix)
   197  }
   198  
   199  // GetHelmPromOpChartsDir returns the Prometheus Operator helm charts dir
   200  func GetHelmPromOpChartsDir() string {
   201  	if TestHelmConfigDir != "" {
   202  		return filepath.Join(TestHelmConfigDir, "/charts/prometheus-community/kube-prometheus-stack")
   203  	}
   204  	return filepath.Join(instance.VerrazzanoRootDir, helmPromOpChartsDirSuffix)
   205  }
   206  
   207  // GetHelmKialiChartsDir returns the Kiali helm charts dir
   208  func GetHelmKialiChartsDir() string {
   209  	if TestHelmConfigDir != "" {
   210  		return filepath.Join(TestHelmConfigDir, "/charts/kiali-server")
   211  	}
   212  	return filepath.Join(instance.VerrazzanoRootDir, helmKialiChartsDirSuffix)
   213  }
   214  
   215  // GetHelmOamChartsDir returns the oam-kubernetes-runtime helm charts dir
   216  func GetHelmOamChartsDir() string {
   217  	if TestHelmConfigDir != "" {
   218  		return filepath.Join(TestHelmConfigDir, "/charts/oam-kubernetes-runtime")
   219  	}
   220  	return filepath.Join(instance.VerrazzanoRootDir, helmOamChartsDirSuffix)
   221  }
   222  
   223  // GetHelmOverridesDir returns the helm overrides dir
   224  func GetHelmOverridesDir() string {
   225  	if TestHelmConfigDir != "" {
   226  		return filepath.Join(TestHelmConfigDir, "/overrides")
   227  	}
   228  	return filepath.Join(instance.VerrazzanoRootDir, helmOverridesDirSuffix)
   229  }
   230  
   231  // GetInstallDir returns the install dir
   232  func GetInstallDir() string {
   233  	return filepath.Join(instance.VerrazzanoRootDir, installDirSuffix)
   234  }
   235  
   236  // GetPlatformDir returns the platform dir
   237  func GetPlatformDir() string {
   238  	return filepath.Join(instance.VerrazzanoRootDir, platformDirSuffix)
   239  }
   240  
   241  // GetThirdPartyDir returns the thirdparty dir
   242  func GetThirdPartyDir() string {
   243  	return filepath.Join(instance.VerrazzanoRootDir, thirdPartyDirSuffix)
   244  }
   245  
   246  func GetThirdPartyManifestsDir() string {
   247  	if TestThirdPartyManifestDir != "" {
   248  		return TestThirdPartyManifestDir
   249  	}
   250  	return filepath.Join(instance.VerrazzanoRootDir, thirdPartyManifestsDirSuffix)
   251  }
   252  
   253  // GetProfilesDir returns the profiles dir
   254  func GetProfilesDir() string {
   255  	if TestProfilesDir != "" {
   256  		return TestProfilesDir
   257  	}
   258  	return filepath.Join(instance.VerrazzanoRootDir, profilesDirSuffix)
   259  }
   260  
   261  // GetIntegrationChartsDir returns the integration charts dir
   262  func GetIntegrationChartsDir() string {
   263  	if TestIntegrationChartsDis != "" {
   264  		return TestIntegrationChartsDis
   265  	}
   266  	return filepath.Join(instance.VerrazzanoRootDir, integrationChartsDirSuffix)
   267  }
   268  
   269  // GetCatalogPath gets the module catalog path
   270  func GetCatalogPath() string {
   271  	if TestCatalogDir != "" {
   272  		return filepath.Join(TestCatalogDir, defaultCatalogFilename)
   273  	}
   274  	return filepath.Join(instance.VerrazzanoRootDir, catalogDirSuffix, defaultCatalogFilename)
   275  }
   276  
   277  // GetProfile returns API profiles dir
   278  func GetProfile(groupVersion schema.GroupVersion, profile string) string {
   279  	return filepath.Join(GetProfilesDir()+"/"+groupVersion.Version, profile+".yaml")
   280  }
   281  
   282  // SetDefaultBomFilePath Sets the global default location for the BOM file
   283  func SetDefaultBomFilePath(p string) {
   284  	bomFilePathOverride = p
   285  }
   286  
   287  // GetDefaultBOMFilePath returns BOM file path for the platform operator
   288  func GetDefaultBOMFilePath() string {
   289  	if bomFilePathOverride != "" {
   290  		return bomFilePathOverride
   291  	}
   292  	return filepath.Join(GetPlatformDir(), defaultBomFilename)
   293  }
   294  
   295  func GetInjectedSystemNamespaces() []string {
   296  	return []string{constants.VerrazzanoSystemNamespace, constants.VerrazzanoMonitoringNamespace, nginxutil.IngressNGINXNamespace(), constants.KeycloakNamespace}
   297  }
   298  
   299  func GetNoInjectionComponents() []string {
   300  	return []string{"coherence-operator", "oam-kubernetes-runtime", "verrazzano-application-operator", "verrazzano-cluster-operator"}
   301  }