Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACM-7676] Removed additional promrules and servicemonitors from openshift-monitor… #528

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 0 additions & 72 deletions api/v1/multicluster_methods_test.go

This file was deleted.

115 changes: 99 additions & 16 deletions api/v1/multiclusterengine_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,76 @@ limitations under the License.

package v1

import "fmt"

const (
ManagedServiceAccount = "managedserviceaccount"
ManagedServiceAccountPreview = "managedserviceaccount-preview"
ConsoleMCE = "console-mce"
Discovery = "discovery"
Hive = "hive"
AssistedService = "assisted-service"
ClusterLifecycle = "cluster-lifecycle"
ClusterManager = "cluster-manager"
ServerFoundation = "server-foundation"
HyperShift = "hypershift"
HyperShiftPreview = "hypershift-preview"
ClusterProxyAddon = "cluster-proxy-addon"
ConsoleMCE = "console-mce"
Discovery = "discovery"
Hive = "hive"
HyperShift = "hypershift"
HypershiftLocalHosting = "hypershift-local-hosting"
HyperShiftPreview = "hypershift-preview"
LocalCluster = "local-cluster"
ManagedServiceAccount = "managedserviceaccount"
ManagedServiceAccountPreview = "managedserviceaccount-preview"
ServerFoundation = "server-foundation"
)

var allComponents = []string{
AssistedService,
ClusterLifecycle,
ClusterManager,
ClusterProxyAddon,
ConsoleMCE,
Discovery,
Hive,
ServerFoundation,
ConsoleMCE,
HyperShift,
HypershiftLocalHosting,
HyperShiftPreview,
LocalCluster,
ManagedServiceAccount,
ManagedServiceAccountPreview,
ServerFoundation,
}

// MCEComponents is a slice containing component names specific to the "MCE" category.
var MCEComponents = []string{
AssistedService,
ClusterLifecycle,
ClusterManager,
ClusterProxyAddon,
ConsoleMCE,
Discovery,
Hive,
HyperShift,
HyperShiftPreview,
HypershiftLocalHosting,
ClusterProxyAddon,
LocalCluster,
ManagedServiceAccount,
ServerFoundation,
}

var LegacyPrometheusKind = []string{"PrometheusRule", "ServiceMonitor"}

// MCEPrometheusRules is a map that associates certain component names with their corresponding prometheus rules.
var MCEPrometheusRules = map[string]string{
ConsoleMCE: "acm-console-prometheus-rules",
// Add other components here when PrometheusRules is required.
}

// MCEServiceMonitors is a map that associates certain component names with their corresponding service monitors.
var MCEServiceMonitors = map[string]string{
ClusterLifecycle: "clusterlifecycle-state-metrics-v2",
ConsoleMCE: "console-mce-monitor",
// Add other components here when ServiceMonitors is required.
}

/*
ComponentPresent checks if a component with the given name is present in the MultiClusterEngine's Overrides.
Returns true if the component is present, otherwise false.
*/
func (mce *MultiClusterEngine) ComponentPresent(s string) bool {
if mce.Spec.Overrides == nil {
return false
Expand All @@ -64,6 +100,10 @@ func (mce *MultiClusterEngine) ComponentPresent(s string) bool {
return false
}

/*
Enabled checks if a component with the given name is enabled in the MultiClusterEngine's Overrides.
Returns true if the component is enabled, otherwise false.
*/
func (mce *MultiClusterEngine) Enabled(s string) bool {
if mce.Spec.Overrides == nil {
return false
Expand All @@ -73,10 +113,13 @@ func (mce *MultiClusterEngine) Enabled(s string) bool {
return c.Enabled
}
}

return false
}

/*
Enable enables a component with the given name in the MultiClusterEngine's Overrides.
If the component is not present, it adds it and sets it as enabled.
*/
func (mce *MultiClusterEngine) Enable(s string) {
if mce.Spec.Overrides == nil {
mce.Spec.Overrides = &Overrides{}
Expand All @@ -93,7 +136,10 @@ func (mce *MultiClusterEngine) Enable(s string) {
})
}

// Prune removes the component from the component list. Returns true if changes are made
/*
Prune removes a component with the given name from the MultiClusterEngine's Overrides.
Returns true if the component is pruned, indicating changes were made.
*/
func (mce *MultiClusterEngine) Prune(s string) bool {
if mce.Spec.Overrides == nil {
return false
Expand All @@ -115,6 +161,10 @@ func (mce *MultiClusterEngine) Prune(s string) bool {
return false
}

/*
Disable disables a component with the given name in the MultiClusterEngine's Overrides.
If the component is not present, it adds it and sets it as disabled.
*/
func (mce *MultiClusterEngine) Disable(s string) {
if mce.Spec.Overrides == nil {
mce.Spec.Overrides = &Overrides{}
Expand All @@ -131,7 +181,10 @@ func (mce *MultiClusterEngine) Disable(s string) {
})
}

// a component is valid if its name matches a known component
/*
validComponent checks if a ComponentConfig is valid by comparing its name to a list of known component names.
Returns true if the component is valid, otherwise false.
*/
func validComponent(c ComponentConfig) bool {
for _, name := range allComponents {
if c.Name == name {
Expand All @@ -141,6 +194,10 @@ func validComponent(c ComponentConfig) bool {
return false
}

/*
IsInHostedMode checks if the MultiClusterEngine has an annotation indicating it is in hosted mode.
Returns true if the annotation is present and its value is "ModeHosted," otherwise false.
*/
func IsInHostedMode(mce *MultiClusterEngine) bool {
a := mce.GetAnnotations()
if a == nil {
Expand All @@ -151,3 +208,29 @@ func IsInHostedMode(mce *MultiClusterEngine) bool {
}
return false
}

/*
GetLegacyPrometheusKind returns a list of legacy kind resources that are required to be removed before updating to
ACM 2.9 and later.
*/
func GetLegacyPrometheusKind() []string {
return LegacyPrometheusKind
}

// GetPrometheusRulesName returns the name of the PrometheusRules based on the provided component name.
func GetPrometheusRulesName(component string) (string, error) {
if val, ok := MCEPrometheusRules[component]; !ok {
return val, fmt.Errorf("failed to find PrometheusRules name for: %s component", component)
} else {
return val, nil
}
}

// GetServiceMonitorName returns the name of the ServiceMonitors based on the provided component name.
func GetServiceMonitorName(component string) (string, error) {
if val, ok := MCEServiceMonitors[component]; !ok {
return val, fmt.Errorf("failed to find ServiceMonitors name for: %s component", component)
} else {
return val, nil
}
}
Loading
Loading