Skip to content
Open
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
13 changes: 13 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ type MonitoringConfig struct {
//+kubebuilder:validation:XValidation:rule=(self || !oldSelf),message=Feature cannot be disabled
//+kubebuilder:default:=true
Enabled bool `json:"enabled"`
// If true, the Operator will create ServiceMonitor resources for metrics collection.
// When not specified, defaults to true on OpenShift and false on other platforms.
//+optional
ServiceMonitor *bool `json:"serviceMonitor,omitempty"`
}

// IsServiceMonitorEnabled returns whether ServiceMonitor resources should be created.
// If ServiceMonitor is explicitly set, returns that value, otherwise returns the default.
func (m *MonitoringConfig) IsServiceMonitorEnabled(defaultVal bool) bool {
if m.ServiceMonitor != nil {
return *m.ServiceMonitor
}
return defaultVal
}

type MonitoringWithTLogConfig struct {
Expand Down
80 changes: 80 additions & 0 deletions api/v1alpha1/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package v1alpha1

import (
"testing"

"k8s.io/utils/ptr"
)

func TestMonitoringConfig_IsServiceMonitorEnabled(t *testing.T) {
tests := []struct {
name string
config MonitoringConfig
isOpenShift bool
expectedResult bool
}{
{
name: "ServiceMonitor explicitly set to true",
config: MonitoringConfig{
Enabled: true,
ServiceMonitor: ptr.To(true),
},
isOpenShift: false,
expectedResult: true,
},
{
name: "ServiceMonitor explicitly set to false",
config: MonitoringConfig{
Enabled: true,
ServiceMonitor: ptr.To(false),
},
isOpenShift: true,
expectedResult: false,
},
{
name: "ServiceMonitor nil on OpenShift defaults to true",
config: MonitoringConfig{
Enabled: true,
ServiceMonitor: nil,
},
isOpenShift: true,
expectedResult: true,
},
{
name: "ServiceMonitor nil on non-OpenShift defaults to false",
config: MonitoringConfig{
Enabled: true,
ServiceMonitor: nil,
},
isOpenShift: false,
expectedResult: false,
},
{
name: "ServiceMonitor explicitly true overrides platform on non-OpenShift",
config: MonitoringConfig{
Enabled: true,
ServiceMonitor: ptr.To(true),
},
isOpenShift: false,
expectedResult: true,
},
{
name: "ServiceMonitor explicitly false overrides platform on OpenShift",
config: MonitoringConfig{
Enabled: true,
ServiceMonitor: ptr.To(false),
},
isOpenShift: true,
expectedResult: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.config.IsServiceMonitorEnabled(tt.isOpenShift)
if result != tt.expectedResult {
t.Errorf("IsServiceMonitorEnabled() = %v, want %v", result, tt.expectedResult)
}
})
}
}
17 changes: 11 additions & 6 deletions api/v1alpha1/zz_generated.deepcopy.go

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

5 changes: 5 additions & 0 deletions config/crd/bases/rhtas.redhat.com_ctlogs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
required:
- enabled
type: object
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/rhtas.redhat.com_fulcios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
required:
- enabled
type: object
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/rhtas.redhat.com_rekors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
tlog:
description: Configuration for Rekor transparency log monitoring
properties:
Expand Down
25 changes: 25 additions & 0 deletions config/crd/bases/rhtas.redhat.com_securesigns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
required:
- enabled
type: object
Expand Down Expand Up @@ -2526,6 +2531,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
required:
- enabled
type: object
Expand Down Expand Up @@ -3876,6 +3886,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
tlog:
description: Configuration for Rekor transparency log monitoring
properties:
Expand Down Expand Up @@ -5494,6 +5509,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
required:
- enabled
type: object
Expand Down Expand Up @@ -8631,6 +8651,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
required:
- enabled
type: object
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/rhtas.redhat.com_timestampauthorities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
required:
- enabled
type: object
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/rhtas.redhat.com_trillians.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ spec:
x-kubernetes-validations:
- message: Feature cannot be disabled
rule: (self || !oldSelf)
serviceMonitor:
description: |-
If true, the Operator will create ServiceMonitor resources for metrics collection.
When not specified, defaults to true on OpenShift and false on other platforms.
type: boolean
required:
- enabled
type: object
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/ctlog/actions/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func (i monitoringAction) Name() string {

func (i monitoringAction) CanHandle(_ context.Context, instance *rhtasv1alpha1.CTlog) bool {
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
return (c.Reason == constants.Creating || c.Reason == constants.Ready) && instance.Spec.Monitoring.Enabled
return (c.Reason == constants.Creating || c.Reason == constants.Ready) &&
instance.Spec.Monitoring.Enabled &&
instance.Spec.Monitoring.IsServiceMonitorEnabled(kubernetes.IsOpenShift())
}

func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.CTlog) *action.Result {
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/fulcio/actions/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func (i monitoringAction) Name() string {

func (i monitoringAction) CanHandle(_ context.Context, instance *rhtasv1alpha1.Fulcio) bool {
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
return (c.Reason == constants.Creating || c.Reason == constants.Ready) && instance.Spec.Monitoring.Enabled
return (c.Reason == constants.Creating || c.Reason == constants.Ready) &&
instance.Spec.Monitoring.Enabled &&
instance.Spec.Monitoring.IsServiceMonitorEnabled(kubernetes.IsOpenShift())
}

func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Fulcio) *action.Result {
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/rekor/actions/monitor/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package monitor
import (
"github.com/securesign/operator/api/v1alpha1"
"github.com/securesign/operator/internal/utils"
"github.com/securesign/operator/internal/utils/kubernetes"
)

func enabled(instance *v1alpha1.Rekor) bool {
return utils.IsEnabled(&instance.Spec.Monitoring.TLog.Enabled)
return utils.IsEnabled(&instance.Spec.Monitoring.TLog.Enabled) &&
instance.Spec.Monitoring.IsServiceMonitorEnabled(kubernetes.IsOpenShift())
}
4 changes: 3 additions & 1 deletion internal/controller/rekor/actions/server/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func (i monitoringAction) Name() string {

func (i monitoringAction) CanHandle(_ context.Context, instance *rhtasv1alpha1.Rekor) bool {
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
return (c.Reason == constants.Creating || c.Reason == constants.Ready) && instance.Spec.Monitoring.Enabled
return (c.Reason == constants.Creating || c.Reason == constants.Ready) &&
instance.Spec.Monitoring.Enabled &&
instance.Spec.Monitoring.IsServiceMonitorEnabled(kubernetes.IsOpenShift())
}

func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Rekor) *action.Result {
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/trillian/actions/logserver/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func (i monitoringAction) Name() string {

func (i monitoringAction) CanHandle(_ context.Context, instance *rhtasv1alpha1.Trillian) bool {
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
return (c.Reason == constants.Creating || c.Reason == constants.Ready) && instance.Spec.Monitoring.Enabled
return (c.Reason == constants.Creating || c.Reason == constants.Ready) &&
instance.Spec.Monitoring.Enabled &&
instance.Spec.Monitoring.IsServiceMonitorEnabled(kubernetes.IsOpenShift())
}

func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Trillian) *action.Result {
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/trillian/actions/logsigner/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func (i monitoringAction) Name() string {

func (i monitoringAction) CanHandle(_ context.Context, instance *rhtasv1alpha1.Trillian) bool {
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
return (c.Reason == constants.Creating || c.Reason == constants.Ready) && instance.Spec.Monitoring.Enabled
return (c.Reason == constants.Creating || c.Reason == constants.Ready) &&
instance.Spec.Monitoring.Enabled &&
instance.Spec.Monitoring.IsServiceMonitorEnabled(kubernetes.IsOpenShift())
}

func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Trillian) *action.Result {
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/tsa/actions/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func (i monitoringAction) Name() string {

func (i monitoringAction) CanHandle(_ context.Context, instance *rhtasv1alpha1.TimestampAuthority) bool {
c := meta.FindStatusCondition(instance.Status.Conditions, constants.Ready)
return (c.Reason == constants.Creating || c.Reason == constants.Ready) && instance.Spec.Monitoring.Enabled
return (c.Reason == constants.Creating || c.Reason == constants.Ready) &&
instance.Spec.Monitoring.Enabled &&
instance.Spec.Monitoring.IsServiceMonitorEnabled(kubernetes.IsOpenShift())
}

func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.TimestampAuthority) *action.Result {
Expand Down
Loading