Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OPERATOR_SDK_VERSION=v1.42.0
REVIEWERS=vivekr-splunk,rlieberman-splunk,patrykw-splunk,Igor-splunk,kasiakoziol,kubabuczak,gabrielm-splunk,minjieqiu,qingw-splunk
GO_VERSION=1.25.8
GO_VERSION=1.26.2
AWSCLI_URL=https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.8.6.zip
KUBECTL_VERSION=v1.29.1
AZ_CLI_VERSION=2.79.0
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG BASE_IMAGE=registry.access.redhat.com/ubi8/ubi-minimal
ARG BASE_IMAGE_VERSION=8.10-1775152441

# Build the manager binary
FROM golang:1.25.8 AS builder
FROM golang:1.26.2 AS builder

WORKDIR /workspace

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.distroless
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.25.8 AS builder
FROM golang:1.26.2 AS builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ docs-preview: ## Preview documentation locally with Jekyll (requires Ruby and bu
@cd docs && bundle exec jekyll serve --livereload
@echo "Documentation available at http://localhost:4000/splunk-operator"

##@ Helm

HELM_OPERATOR_CHART = helm-chart/splunk-operator

.PHONY: helm-lint
helm-lint: ## Lint Helm charts
helm lint $(HELM_OPERATOR_CHART)

.PHONY: helm-test
helm-test: setup/helm-unittest ## Run Helm chart unit tests
helm unittest $(HELM_OPERATOR_CHART)

.PHONY: helm-check
helm-check: helm-lint helm-test ## Run Helm lint and unit tests

##@ Build

build: setup/ginkgo manifests generate fmt vet ## Build manager binary.
Expand Down Expand Up @@ -226,6 +241,7 @@ $(LOCALBIN):
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_TOOLS_VERSION ?= v0.18.0
GOLANGCI_LINT_VERSION ?= v2.1.0
HELM_UNITTEST_VERSION ?= v1.0.3

CONTROLLER_GEN = $(LOCALBIN)/controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
Expand Down Expand Up @@ -464,6 +480,11 @@ setup/ginkgo:
@echo Installing gomega
@go get github.com/onsi/gomega/...

.PHONY: setup/helm-unittest
setup/helm-unittest:
@helm plugin list 2>/dev/null | grep -q unittest || \
helm plugin install https://github.com/helm-unittest/helm-unittest.git --version $(HELM_UNITTEST_VERSION)

.PHONY: build-installer
build-installer: manifests generate kustomize
mkdir -p dist
Expand Down
69 changes: 40 additions & 29 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"path/filepath"
"time"

"github.com/spf13/pflag"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"

intController "github.com/splunk/splunk-operator/internal/controller"
Expand Down Expand Up @@ -89,24 +90,44 @@ func main() {
// TLS certificate configuration for metrics
var metricsCertPath, metricsCertName, metricsCertKey string

flag.StringVar(&logEncoder, "log-encoder", "json", "log encoding ('json' or 'console')")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
pflag.StringVar(&logEncoder, "log-encoder", "json", "log encoding ('json' or 'console')")
pflag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
pflag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&pprofActive, "pprof", true, "Enable pprof endpoint")
flag.IntVar(&logLevel, "log-level", int(zapcore.InfoLevel), "set log level")
flag.IntVar(&leaseDurationSecond, "lease-duration", leaseDurationSecond, "manager lease duration in seconds")
flag.IntVar(&renewDeadlineSecond, "renew-duration", renewDeadlineSecond, "manager renew duration in seconds")
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metrics endpoint binds to. "+
pflag.BoolVar(&pprofActive, "pprof", true, "Enable pprof endpoint")
pflag.IntVar(&logLevel, "log-level", int(zapcore.InfoLevel), "set log level")
pflag.IntVar(&leaseDurationSecond, "lease-duration", leaseDurationSecond, "manager lease duration in seconds")
pflag.IntVar(&renewDeadlineSecond, "renew-duration", renewDeadlineSecond, "manager renew duration in seconds")
pflag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metrics endpoint binds to. "+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
flag.BoolVar(&secureMetrics, "metrics-secure", false,
pflag.BoolVar(&secureMetrics, "metrics-secure", false,
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")

// TLS certificate flags for metrics server
flag.StringVar(&metricsCertPath, "metrics-cert-path", "", "The directory that contains the metrics server certificate.")
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
pflag.StringVar(&metricsCertPath, "metrics-cert-path", "", "The directory that contains the metrics server certificate.")
pflag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
pflag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")

config.DefaultMutableFeatureGate.AddFlag(pflag.CommandLine)

opts := zap.Options{
Development: true,
TimeEncoder: zapcore.RFC3339NanoTimeEncoder,
}
opts.BindFlags(flag.CommandLine)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

if allGates := config.DefaultMutableFeatureGate.GetAll(); len(allGates) > 0 {
effectiveStates := make(map[string]bool, len(allGates))
for gate := range allGates {
effectiveStates[string(gate)] = config.DefaultMutableFeatureGate.Enabled(gate)
}
setupLog.Info("Feature gates initialized", "gates", effectiveStates)
}

// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
// More info:
Expand Down Expand Up @@ -147,16 +168,6 @@ func main() {
renewDeadline = time.Duration(renewDeadlineSecond) * time.Second
}

opts := zap.Options{
Development: true,
TimeEncoder: zapcore.RFC3339NanoTimeEncoder,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()

// Logging setup
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// Configure metrics certificate watcher if metrics certs are provided
var metricsCertWatcher *certwatcher.CertWatcher
if len(metricsCertPath) > 0 {
Expand Down Expand Up @@ -280,10 +291,11 @@ func main() {
os.Exit(1)
}

// Setup centralized validation webhook server (opt-in via ENABLE_VALIDATION_WEBHOOK env var, defaults to false)
enableWebhooks := os.Getenv("ENABLE_VALIDATION_WEBHOOK")
if enableWebhooks == "true" {
// Parse optional timeout configurations from environment
if _, ok := os.LookupEnv("ENABLE_VALIDATION_WEBHOOK"); ok {
setupLog.Info("DEPRECATED: ENABLE_VALIDATION_WEBHOOK env var is deprecated and will be removed in a future release; use --feature-gates=ValidationWebhook=true instead")
}

if config.DefaultMutableFeatureGate.Enabled(config.ValidationWebhook) {
readTimeout := 10 * time.Second
if val := os.Getenv("WEBHOOK_READ_TIMEOUT"); val != "" {
if d, err := time.ParseDuration(val); err == nil {
Expand All @@ -306,16 +318,15 @@ func main() {
Client: mgr.GetClient(),
})

// Add webhook server as a runnable to the manager
if err := mgr.Add(manager.RunnableFunc(func(ctx context.Context) error {
return webhookServer.Start(ctx)
})); err != nil {
setupLog.Error(err, "unable to add webhook server to manager")
os.Exit(1)
}
setupLog.Info("Validation webhook enabled via ENABLE_VALIDATION_WEBHOOK=true")
setupLog.Info("Validation webhook enabled")
} else {
setupLog.Info("Validation webhook disabled (set ENABLE_VALIDATION_WEBHOOK=true to enable)")
setupLog.Info("Validation webhook disabled (set --feature-gates=ValidationWebhook=true to enable)")
}
//+kubebuilder:scaffold:builder

Expand Down
9 changes: 5 additions & 4 deletions config/default-with-webhook/kustomization-cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Adds namespace to all resources.
# Cluster-scoped deployment WITH webhook enabled (opt-in)
# Requires cert-manager to be installed in the cluster
namespace: splunk-operator
namespace: splunk-operator

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
Expand Down Expand Up @@ -115,7 +115,7 @@ patches:
patch: |-
- op: add
path: /spec/template/spec/containers/0/env
value:
value:
- name: WATCH_NAMESPACE
value: WATCH_NAMESPACE_VALUE
- name: RELATED_IMAGE_SPLUNK_ENTERPRISE
Expand All @@ -124,12 +124,13 @@ patches:
value: splunk-operator
- name: SPLUNK_GENERAL_TERMS
value: SPLUNK_GENERAL_TERMS_VALUE
- name: ENABLE_VALIDATION_WEBHOOK
value: "true"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- op: add
path: /spec/template/spec/containers/0/args/-
value: --feature-gates=ValidationWebhook=true
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
# More info: https://book.kubebuilder.io/reference/metrics
- path: manager_metrics_patch.yaml
Expand Down
9 changes: 5 additions & 4 deletions config/default-with-webhook/kustomization-namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Adds namespace to all resources.
# Namespace-scoped deployment WITH webhook enabled (opt-in)
# Requires cert-manager to be installed in the cluster
namespace: splunk-operator
namespace: splunk-operator

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
Expand Down Expand Up @@ -115,7 +115,7 @@ patches:
patch: |-
- op: add
path: /spec/template/spec/containers/0/env
value:
value:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
Expand All @@ -126,12 +126,13 @@ patches:
value: splunk-operator
- name: SPLUNK_GENERAL_TERMS
value: SPLUNK_GENERAL_TERMS_VALUE
- name: ENABLE_VALIDATION_WEBHOOK
value: "true"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- op: add
path: /spec/template/spec/containers/0/args/-
value: --feature-gates=ValidationWebhook=true
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
# More info: https://book.kubebuilder.io/reference/metrics
- path: manager_metrics_patch.yaml
Expand Down
11 changes: 6 additions & 5 deletions config/default-with-webhook/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Adds namespace to all resources.
# Cluster-scoped deployment WITH webhook enabled (opt-in)
# Requires cert-manager to be installed in the cluster
namespace: splunk-operator
namespace: splunk-operator

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
Expand Down Expand Up @@ -115,21 +115,22 @@ patches:
patch: |-
- op: add
path: /spec/template/spec/containers/0/env
value:
value:
- name: WATCH_NAMESPACE
value: WATCH_NAMESPACE_VALUE
- name: RELATED_IMAGE_SPLUNK_ENTERPRISE
value: SPLUNK_ENTERPRISE_IMAGE
- name: OPERATOR_NAME
value: splunk-operator
- name: SPLUNK_GENERAL_TERMS
value: WATCH_NAMESPACE_VALUE
- name: ENABLE_VALIDATION_WEBHOOK
value: "true"
value: SPLUNK_GENERAL_TERMS_VALUE
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- op: add
path: /spec/template/spec/containers/0/args/-
value: --feature-gates=ValidationWebhook=true
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
# More info: https://book.kubebuilder.io/reference/metrics
- path: manager_metrics_patch.yaml
Expand Down
Loading
Loading