Skip to content

Commit

Permalink
ROX-17225: expose openshift monitoring in operator (#6763)
Browse files Browse the repository at this point in the history
  • Loading branch information
janisz committed Jul 26, 2023
1 parent 3436483 commit 774a370
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 0 deletions.
23 changes: 23 additions & 0 deletions operator/apis/platform/v1alpha1/central_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ type CentralSpec struct {
// Overlays
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName=Overlays,order=8,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:hidden"}
Overlays []*K8sObjectOverlay `json:"overlays,omitempty"`

// Monitoring configuration.
//+operator-sdk:csv:customresourcedefinitions:type=spec,order=9,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced"}
Monitoring *GlobalMonitoring `json:"monitoring,omitempty"`
}

// GlobalMonitoring defines settings related to monitoring.
type GlobalMonitoring struct {
OpenShiftMonitoring *OpenShiftMonitoring `json:"openshift,omitempty"`
}

// OpenShiftMonitoring defines settings related to OpenShift Monitoring
type OpenShiftMonitoring struct {
//+kubebuilder:validation:Default=true
//+kubebuilder:default=false
//+operator-sdk:csv:customresourcedefinitions:type=spec,order=1,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
Enabled bool `json:"enabled"`
}

// IsOpenShiftMonitoringEnabled returns true if OpenShiftMonitoring is enabled.
// This function is nil safe.
func (m *GlobalMonitoring) IsOpenShiftMonitoringEnabled() bool {
return m != nil && m.OpenShiftMonitoring != nil && m.OpenShiftMonitoring.Enabled
}

// Egress defines settings related to outgoing network traffic.
Expand Down
40 changes: 40 additions & 0 deletions operator/apis/platform/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions operator/bundle/manifests/platform.stackrox.io_centrals.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions operator/config/crd/bases/platform.stackrox.io_centrals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,20 @@ spec:
interfere with other workloads.
type: boolean
type: object
monitoring:
description: Monitoring configuration.
properties:
openshift:
description: OpenShiftMonitoring defines settings related to OpenShift
Monitoring
properties:
enabled:
default: false
type: boolean
required:
- enabled
type: object
type: object
overlays:
description: Overlays
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ spec:
other workloads.
displayName: Create SecurityContextConstraints for Operand
path: misc.createSCCs
- displayName: Enabled
path: monitoring.openshift.enabled
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: Resource API version.
displayName: API Version
path: overlays[0].apiVersion
Expand Down Expand Up @@ -328,6 +332,11 @@ spec:
path: overlays
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:hidden
- description: Monitoring configuration.
displayName: Monitoring
path: monitoring
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:advanced
- description: Stores persistent data on a directory on the host. This is not
recommended, and should only be used together with a node selector (only
available in YAML view).
Expand Down
10 changes: 10 additions & 0 deletions operator/pkg/central/values/translation/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func (t Translator) translate(ctx context.Context, c platform.Central) (chartuti
namespace: c.GetNamespace(),
}

monitoring := c.Spec.Monitoring
v.AddChild("monitoring", globalMonitoring(monitoring))
central, err := getCentralComponentValues(centralSpec, checker, obsoletePVC)
if err != nil {
return nil, err
Expand All @@ -108,6 +110,14 @@ func (t Translator) translate(ctx context.Context, c platform.Central) (chartuti
return v.Build()
}

func globalMonitoring(m *platform.GlobalMonitoring) *translation.ValuesBuilder {
enabled := translation.NewValuesBuilder()
enabled.SetBoolValue("enabled", m.IsOpenShiftMonitoringEnabled())
openshift := translation.NewValuesBuilder()
openshift.AddChild("openshift", &enabled)
return &openshift
}

func getEnv(c platform.Central) *translation.ValuesBuilder {
env := translation.NewValuesBuilder()

Expand Down
75 changes: 75 additions & 0 deletions operator/pkg/central/values/translation/translation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func TestTranslate(t *testing.T) {
pvcs: []*corev1.PersistentVolumeClaim{defaultPvc},
},
want: chartutil.Values{
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
"central": map[string]interface{}{
"exposeMonitoring": false,
"persistence": map[string]interface{}{
Expand Down Expand Up @@ -123,6 +128,11 @@ func TestTranslate(t *testing.T) {
},
},
},
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
},
},

Expand Down Expand Up @@ -150,6 +160,11 @@ func TestTranslate(t *testing.T) {
},
},
},
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
},
},

Expand All @@ -171,6 +186,11 @@ func TestTranslate(t *testing.T) {
{Name: "ca2-name", Content: "ca2-content"},
},
},
Monitoring: &platform.GlobalMonitoring{
OpenShiftMonitoring: &platform.OpenShiftMonitoring{
Enabled: true,
},
},
Central: &platform.CentralComponentSpec{
DeploymentSpec: platform.DeploymentSpec{
NodeSelector: map[string]string{
Expand Down Expand Up @@ -344,6 +364,11 @@ func TestTranslate(t *testing.T) {
),
},
want: chartutil.Values{
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": true,
},
},
"additionalCAs": map[string]interface{}{
"ca1-name": "ca1-content",
"ca2-name": "ca2-content",
Expand Down Expand Up @@ -540,6 +565,11 @@ func TestTranslate(t *testing.T) {
},
},
want: chartutil.Values{
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
"central": map[string]interface{}{
"exposeMonitoring": false,
"persistence": map[string]interface{}{
Expand Down Expand Up @@ -601,6 +631,11 @@ func TestTranslate(t *testing.T) {
},
},
},
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
},
},

Expand Down Expand Up @@ -638,6 +673,11 @@ func TestTranslate(t *testing.T) {
},
},
},
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
},
},

Expand All @@ -663,6 +703,11 @@ func TestTranslate(t *testing.T) {
pvcs: []*corev1.PersistentVolumeClaim{defaultPvc},
},
want: chartutil.Values{
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
"central": map[string]interface{}{
"exposeMonitoring": false,
"persistence": map[string]interface{}{
Expand Down Expand Up @@ -704,6 +749,11 @@ func TestTranslate(t *testing.T) {
pvcs: []*corev1.PersistentVolumeClaim{defaultPvc},
},
want: chartutil.Values{
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
"central": map[string]interface{}{
"exposure": map[string]interface{}{
"route": map[string]interface{}{
Expand Down Expand Up @@ -739,6 +789,11 @@ func TestTranslate(t *testing.T) {
pvcs: []*corev1.PersistentVolumeClaim{defaultPvc},
},
want: chartutil.Values{
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
"central": map[string]interface{}{
"exposeMonitoring": false,
"persistence": map[string]interface{}{
Expand Down Expand Up @@ -777,6 +832,11 @@ func TestTranslate(t *testing.T) {
pvcs: []*corev1.PersistentVolumeClaim{defaultPvc},
},
want: chartutil.Values{
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
"central": map[string]interface{}{
"exposeMonitoring": false,
"persistence": map[string]interface{}{"persistentVolumeClaim": map[string]interface{}{"createClaim": false}},
Expand Down Expand Up @@ -814,6 +874,11 @@ func TestTranslate(t *testing.T) {
},
},
},
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
},
},
"enabled telemetry in dev": {
Expand Down Expand Up @@ -856,6 +921,11 @@ func TestTranslate(t *testing.T) {
},
},
},
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
},
},
"enabled telemetry no key": {
Expand Down Expand Up @@ -886,6 +956,11 @@ func TestTranslate(t *testing.T) {
},
},
},
"monitoring": map[string]interface{}{
"openshift": map[string]interface{}{
"enabled": false,
},
},
},
},
}
Expand Down

0 comments on commit 774a370

Please sign in to comment.