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

disable OpenShift monitoring for internal Centrals #1447

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions fleetshard/pkg/central/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func (r *CentralReconciler) applyCentralConfig(remoteCentral *private.ManagedCen
r.applyProxyConfig(central)
r.applyDeclarativeConfig(central)
r.applyAnnotations(central)
r.applyMonitoring(remoteCentral, central)
return nil
}

Expand Down Expand Up @@ -359,6 +360,22 @@ func (r *CentralReconciler) applyTelemetry(remoteCentral *private.ManagedCentral
central.Spec.Central.Telemetry = telemetry
}

func (r *CentralReconciler) applyMonitoring(remoteCentral *private.ManagedCentral, central *v1alpha1.Central) {
stehessel marked this conversation as resolved.
Show resolved Hide resolved
if central.Spec.Central == nil {
central.Spec.Central = &v1alpha1.CentralComponentSpec{}
}
// Disable OpenShift monitoring for internal Centrals to avoid overloading Telemeter with probe service metrics.
if remoteCentral.Metadata.Internal {
if central.Spec.Monitoring == nil {
central.Spec.Monitoring = &v1alpha1.GlobalMonitoring{}
}
if central.Spec.Monitoring.OpenShiftMonitoring == nil {
central.Spec.Monitoring.OpenShiftMonitoring = &v1alpha1.OpenShiftMonitoring{}
}
central.Spec.Monitoring.OpenShiftMonitoring.Enabled = false
}
}

func (r *CentralReconciler) restoreCentralSecrets(ctx context.Context, remoteCentral private.ManagedCentral) error {
restoreSecrets := []string{}
for _, secretName := range remoteCentral.Metadata.SecretsStored { // pragma: allowlist secret
Expand Down
76 changes: 75 additions & 1 deletion fleetshard/pkg/central/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2010,8 +2010,82 @@ func Test_getCentralConfig_telemetry(t *testing.T) {
}
}

func TestReconciler_applyRoutes(t *testing.T) {
func Test_getCentralConfig_monitoring(t *testing.T) {
type args struct {
isInternal bool
central *v1alpha1.Central
}

tcs := []struct {
name string
args args
assert func(t *testing.T, c *v1alpha1.Central)
}{
{
name: "should disable OpenShift monitoring when Central is internal",
args: args{
isInternal: true,
central: &v1alpha1.Central{
Spec: v1alpha1.CentralSpec{
Monitoring: &v1alpha1.GlobalMonitoring{
OpenShiftMonitoring: &v1alpha1.OpenShiftMonitoring{
Enabled: true,
},
},
},
},
},
assert: func(t *testing.T, c *v1alpha1.Central) {
assert.False(t, c.Spec.Monitoring.OpenShiftMonitoring.Enabled)
},
},
{
name: "should disable OpenShift monitoring when not defined and Central is internal",
args: args{
isInternal: true,
central: &v1alpha1.Central{
Spec: v1alpha1.CentralSpec{},
},
},
assert: func(t *testing.T, c *v1alpha1.Central) {
assert.False(t, c.Spec.Monitoring.OpenShiftMonitoring.Enabled)
},
},
{
name: "should leave OpenShift monitoring enabled when Central is not internal",
args: args{
isInternal: false,
central: &v1alpha1.Central{
Spec: v1alpha1.CentralSpec{
Monitoring: &v1alpha1.GlobalMonitoring{
OpenShiftMonitoring: &v1alpha1.OpenShiftMonitoring{
Enabled: true,
},
},
},
},
},
assert: func(t *testing.T, c *v1alpha1.Central) {
assert.True(t, c.Spec.Monitoring.OpenShiftMonitoring.Enabled)
},
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
r := &CentralReconciler{}
mc := &private.ManagedCentral{
Metadata: private.ManagedCentralAllOfMetadata{
Internal: tc.args.isInternal,
},
}
r.applyMonitoring(mc, tc.args.central)
tc.assert(t, tc.args.central)
})
}
}

func TestReconciler_applyRoutes(t *testing.T) {
type args struct {
useRoutes bool
}
Expand Down
Loading