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
76 changes: 75 additions & 1 deletion cmd/local-storage-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ limitations under the License.
package main

import (
"context"
"crypto/tls"
"flag"
"os"
"runtime"
"time"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand All @@ -35,6 +38,7 @@ import (
lvdcontroller "github.com/openshift/local-storage-operator/pkg/controllers/localvolumediscovery"
lvscontroller "github.com/openshift/local-storage-operator/pkg/controllers/localvolumeset"
nodedaemoncontroller "github.com/openshift/local-storage-operator/pkg/controllers/nodedaemon"
lsotls "github.com/openshift/local-storage-operator/pkg/tls"
"github.com/openshift/local-storage-operator/pkg/utils"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
zaplog "go.uber.org/zap"
Expand All @@ -44,6 +48,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
Expand Down Expand Up @@ -102,12 +107,72 @@ func main() {
restConfig := ctrl.GetConfigOrDie()
le := utils.GetLeaderElectionConfig(restConfig, enableLeaderElection)

// Fetch TLS profile and adherence once at startup to ensure consistency
// Use a timeout to prevent indefinite stalls on API server outages
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

configClient, err := client.New(restConfig, client.Options{Scheme: scheme})
if err != nil {
klog.ErrorS(err, "unable to create config client for TLS profile")
os.Exit(1)
}

// Fetch TLS adherence policy first
adherence, err := lsotls.GetAdherencePolicyForLogging(ctx, configClient)
if err != nil {
klog.ErrorS(err, "failed to fetch TLS adherence policy")
os.Exit(1)
}

// Fetch TLS profile spec
tlsProfile, err := lsotls.FetchAPIServerTLSProfile(ctx, configClient)
if err != nil {
if adherence == configv1.TLSAdherencePolicyStrictAllComponents {
klog.ErrorS(err, "failed to fetch TLS profile in strict adherence mode")
os.Exit(1)
}
klog.Warningf("failed to fetch TLS profile, using controller-runtime defaults: %v", err)
tlsProfile = configv1.TLSProfileSpec{}
}

// Validate TLS configuration based on adherence policy
if adherence == configv1.TLSAdherencePolicyStrictAllComponents {
if tlsProfile.Ciphers == nil && tlsProfile.MinTLSVersion == "" {
klog.ErrorS(nil, "strict adherence mode requires explicit TLS profile configuration")
os.Exit(1)
}
}

// Get TLS configuration function for metrics server from the fetched profile
var tlsConfigFn func(*tls.Config)
if tlsProfile.Ciphers != nil || tlsProfile.MinTLSVersion != "" {
tlsConfigFn, err = lsotls.GetTLSConfigFromProfile(tlsProfile)
if err != nil {
if adherence == configv1.TLSAdherencePolicyStrictAllComponents {
klog.ErrorS(err, "failed to create TLS config in strict adherence mode")
os.Exit(1)
}
klog.Warningf("failed to create TLS config, using controller-runtime defaults: %v", err)
tlsConfigFn = nil
}
}

// Build metrics server options with TLS
metricsOpts := metricsserver.Options{
BindAddress: metricsAddr,
SecureServing: true,
}
if tlsConfigFn != nil {
metricsOpts.TLSOpts = []func(*tls.Config){tlsConfigFn}
}

mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{namespace: {}},
},
Scheme: scheme,
Metrics: metricsserver.Options{BindAddress: metricsAddr},
Metrics: metricsOpts,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
RenewDeadline: &le.RenewDeadline.Duration,
Expand Down Expand Up @@ -151,6 +216,15 @@ func main() {
klog.ErrorS(err, "unable to create NodeDaemon controller")
os.Exit(1)
}

// Setup TLS security profile watcher to restart operator on TLS profile/adherence changes
// Use the same profile and adherence values we fetched earlier to ensure consistency
tlsWatcher := lsotls.NewSecurityProfileWatcher(tlsProfile, adherence)
tlsWatcher.Client = mgr.GetClient()
if err = tlsWatcher.SetupWithManager(mgr); err != nil {
klog.ErrorS(err, "unable to create TLS security profile watcher")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.19.29
github.com/aws/aws-sdk-go-v2/service/ec2 v1.316.1
github.com/onsi/ginkgo/v2 v2.32.0
github.com/openshift/controller-runtime-common v0.0.0-20260722095319-fea68df23430
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ github.com/openshift/build-machinery-go v0.0.0-20250602125535-1b6d00b8c37c h1:gJ
github.com/openshift/build-machinery-go v0.0.0-20250602125535-1b6d00b8c37c/go.mod h1:8jcm8UPtg2mCAsxfqKil1xrmRMI3a+XU2TZ9fF8A7TE=
github.com/openshift/client-go v0.0.0-20260721124015-35d8f3c0e847 h1:i96ZYwZrCbqxsSrtO/qLJ7Olvu5M9xBU/yVz4Xg8LK4=
github.com/openshift/client-go v0.0.0-20260721124015-35d8f3c0e847/go.mod h1:il93009qOuWG58FeXsVnXD4Yurtm+RMtxIpJv231JdU=
github.com/openshift/controller-runtime-common v0.0.0-20260722095319-fea68df23430 h1:c068rCmMU/tUklmy5v3lH+hIAVIn2N56jDhiY5OX4rY=
github.com/openshift/controller-runtime-common v0.0.0-20260722095319-fea68df23430/go.mod h1:YVDrbC4muEYMejrIZkaQHhlH0bcBusL1UUBkPBxeVrI=
github.com/openshift/library-go v0.0.0-20260721103755-0c9fbc9f043a h1:86Mj1eP0RtYtwPRpdkGbzf6h1Tn+uuYiR6XKZXsWWn8=
github.com/openshift/library-go v0.0.0-20260721103755-0c9fbc9f043a/go.mod h1:iWcB6wgeOhsByZAZGhmzBtEnrLQzABL0s3aeou8AmSI=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
Expand Down
50 changes: 50 additions & 0 deletions pkg/tls/tlsprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package tls

import (
"context"
"crypto/tls"
"fmt"
"strings"

configv1 "github.com/openshift/api/config/v1"
configlistersv1 "github.com/openshift/client-go/config/listers/config/v1"
crcommon "github.com/openshift/controller-runtime-common/pkg/tls"
libapiserver "github.com/openshift/library-go/pkg/operator/configobserver/apiserver"
libevents "github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
Expand Down Expand Up @@ -93,3 +95,51 @@ func (a *apiServerListers) ResourceSyncer() resourcesynccontroller.ResourceSynce
func (a *apiServerListers) PreRunHasSynced() []cache.InformerSynced {
return nil
}

// GetTLSConfigFromProfile returns a function that configures a tls.Config based on
// the provided TLS profile spec. The returned function is suitable for use with
// controller-runtime's metricsserver.Options TLSOpts field.
// Returns an error if the profile contains unsupported cipher suites.
func GetTLSConfigFromProfile(profileSpec configv1.TLSProfileSpec) (func(*tls.Config), error) {
configFn, unsupportedCiphers := crcommon.NewTLSConfigFromProfile(profileSpec)
if len(unsupportedCiphers) > 0 {
return nil, fmt.Errorf("TLS profile contains unsupported cipher suites: %v", unsupportedCiphers)
Comment on lines +104 to +106

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== pkg/tls/tlsprofile.go ==\n'
wc -l pkg/tls/tlsprofile.go
sed -n '1,180p' pkg/tls/tlsprofile.go

printf '\n== search for NewTLSConfigFromProfile ==\n'
rg -n "NewTLSConfigFromProfile|unsupportedCiphers|TLS profile contains unsupported cipher suites" -S .

printf '\n== controller-runtime-common reference (if vendored or in go.mod) ==\n'
rg -n "controller-runtime-common|fea68df23430" -S go.mod go.sum vendor . 2>/dev/null || true

Repository: openshift/local-storage-operator

Length of output: 9060


🌐 Web query:

OpenShift controller-runtime-common NewTLSConfigFromProfile unsupportedCiphers omit unsupported cipher names profile contract retain supported entries rather than fail

💡 Result:

In OpenShift, the controller-runtime-common utility function NewTLSConfigFromProfile is designed to handle TLS configuration from a TLSProfileSpec while gracefully managing unsupported ciphers [1][2][3]. Its contract does not fail when encountering unsupported cipher names; instead, it adopts a policy of omission, retaining only the supported entries to ensure the application maintains a functional TLS configuration [1][3]. The function returns two values: the configured TLS settings (as a function or struct) and a slice of strings containing the names of any ciphers that were unsupported or could not be mapped [4][2][3]. Standard implementation patterns across OpenShift operators include checking if this unsupported cipher slice is non-empty and logging a warning or informational message to notify administrators that specific ciphers were ignored [1][4][2][3]. This approach prioritizes system availability by applying the valid subset of the requested security profile rather than causing the operator to crash or fail to start due to minor configuration mismatches [5][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '96,112p' pkg/tls/tlsprofile.go

Repository: openshift/local-storage-operator

Length of output: 1015


Don't fail GetTLSConfigFromProfile on unsupported ciphers. crcommon.NewTLSConfigFromProfile already drops ciphers this binary can't use and returns the supported config; returning an error here blocks metrics startup even when the profile still has usable entries. Keep the supported ciphers and log a warning for the rest.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/tls/tlsprofile.go` around lines 104 - 106, Update GetTLSConfigFromProfile
after crcommon.NewTLSConfigFromProfile so unsupportedCiphers no longer causes an
error return; retain the supported configFn and emit a warning listing the
unsupported cipher suites. Preserve normal configuration behavior when no
unsupported ciphers are returned.

Source: MCP tools

}
return configFn, nil
}

// ValidateMetricsAccess validates TLS configuration based on the cluster's adherence policy.
// In StrictAllComponents mode, returns an error if TLS profile cannot be fetched or is not configured.
// In LegacyAdheringComponentsOnly or NoOpinion mode, allows operation without TLS profile.
func ValidateMetricsAccess(ctx context.Context, c client.Client) error {
adherence, err := crcommon.FetchAPIServerTLSAdherencePolicy(ctx, c)
if err != nil {
return fmt.Errorf("failed to fetch TLS adherence policy: %w", err)
}

// Only enforce in StrictAllComponents mode
if adherence == configv1.TLSAdherencePolicyStrictAllComponents {
Comment on lines +120 to +121

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- pkg/tls/tlsprofile.go (relevant section) ---\n'
sed -n '1,220p' pkg/tls/tlsprofile.go | cat -n | sed -n '1,220p'

printf '\n--- search adherence policy usage ---\n'
rg -n "TLSAdherencePolicy|StrictAllComponents|adherence" -S .

printf '\n--- locate configv1 type definition in repo ---\n'
rg -n "type TLSAdherencePolicy|StrictAllComponents" -S pkg vendor api .

Repository: openshift/local-storage-operator

Length of output: 261


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Focus on the exact file and nearby code paths.
sed -n '1,220p' pkg/tls/tlsprofile.go | cat -n

Repository: openshift/local-storage-operator

Length of output: 7151


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Look up the upstream API docs and enum definition if not vendored locally.
python3 - <<'PY'
import sys, json, urllib.request
url = "https://pkg.go.dev/github.com/openshift/api/config/v1?tab=doc"
try:
    with urllib.request.urlopen(url, timeout=15) as r:
        data = r.read().decode('utf-8', 'replace')
    print("fetched", len(data))
    for needle in ["TLSAdherencePolicyStrictAllComponents", "TLSAdherencePolicy"]:
        print(needle, needle in data)
except Exception as e:
    print("ERR", repr(e))
PY

Repository: openshift/local-storage-operator

Length of output: 334


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search the repository for the TLS adherence policy enum and call sites.
rg -n "TLSAdherencePolicyStrictAllComponents|TLSAdherencePolicy" -S .

Repository: openshift/local-storage-operator

Length of output: 4787


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the file in question with line numbers.
cat -n pkg/tls/tlsprofile.go | sed -n '1,220p'

Repository: openshift/local-storage-operator

Length of output: 7151


🌐 Web query:

github.com/openshift/api config/v1 TLSAdherencePolicyStrictAllComponents enum unknown values validation

💡 Result:

In the OpenShift API (config/v1), the TLSAdherencePolicy field is validated using a Kubernetes custom resource validation enum [1][2][3]. The valid values for this field are restricted to "LegacyAdheringComponentsOnly" and "StrictAllComponents" [1][4]. To ensure forward compatibility, OpenShift components are designed to handle unknown values for the tlsAdherence field as follows [1][4]: 1. Defaulting Behavior: If a component encounters an unknown TLS adherence policy value, it must treat the setting as "StrictAllComponents" [1][4]. 2. Observability: Components are expected to log a warning when an unknown value is encountered, providing visibility into the configuration mismatch while defaulting to the more secure behavior [1][4][5]. This approach ensures that if new, stricter policies are added to the API in the future, existing components will default to the most secure state rather than falling back to potentially insecure legacy configurations [1][4]. Internal utility functions, such as those found in openshift/library-go, have been updated to support this pattern, including the addition of logging mechanisms for handling unrecognized enum values [5].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,220p' vendor/github.com/openshift/controller-runtime-common/pkg/tls/tls.go | cat -n
printf '\n---\n'
sed -n '1,220p' vendor/github.com/openshift/library-go/pkg/crypto/tls_adherence.go | cat -n
printf '\n---\n'
sed -n '270,320p' vendor/github.com/openshift/api/config/v1/types_apiserver.go | cat -n

Repository: openshift/local-storage-operator

Length of output: 11537


Treat unknown adherence policies as strict. ValidateMetricsAccess only handles StrictAllComponents explicitly, so any future enum value follows the permissive path. Use ShouldHonorClusterTLSProfile or add a default-to-strict branch here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/tls/tlsprofile.go` around lines 120 - 121, Update ValidateMetricsAccess
so unknown or future adherence policy values follow the strict enforcement path
instead of the permissive path. Reuse ShouldHonorClusterTLSProfile if it
provides the intended classification, or add a default-to-strict branch
alongside the existing StrictAllComponents check.

Sources: Path instructions, MCP tools

profileSpec, err := crcommon.FetchAPIServerTLSProfile(ctx, c)
if err != nil {
return fmt.Errorf("strict mode requires valid TLS profile: %w", err)
}
// Check if profile has any configuration
if profileSpec.Ciphers == nil && profileSpec.MinTLSVersion == "" {
return fmt.Errorf("strict mode requires explicit TLS profile")
Comment on lines +122 to +128

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Repo files of interest:\n'
git ls-files 'pkg/tls/*' 'pkg/**/tls*' | sed -n '1,120p'

printf '\nOutline for pkg/tls/tlsprofile.go:\n'
ast-grep outline pkg/tls/tlsprofile.go --view expanded || true

printf '\nRelevant lines from pkg/tls/tlsprofile.go:\n'
sed -n '1,220p' pkg/tls/tlsprofile.go

printf '\nSearch for FetchAPIServerTLSProfile definitions/usages:\n'
rg -n "FetchAPIServerTLSProfile|APIServerTLSProfile" -S .

printf '\nIf helper exists in vendored/internal path, show its file:\n'
fd -a "tls.go" . | sed -n '1,120p'

Repository: openshift/local-storage-operator

Length of output: 9164


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- pkg/tls/tlsprofile.go ---'
sed -n '1,220p' pkg/tls/tlsprofile.go

echo
echo '--- references in repo ---'
rg -n "FetchAPIServerTLSProfile|strict mode requires explicit TLS profile|explicit TLS profile|APIServerTLSProfile" pkg vendor . --glob '!**/node_modules/**' || true

echo
echo '--- attempt to inspect referenced upstream helper if network is available ---'
python3 - <<'PY'
import urllib.request
url = "https://raw.githubusercontent.com/openshift/controller-runtime-common/fea68df23430/pkg/tls/tls.go"
try:
    with urllib.request.urlopen(url, timeout=10) as r:
        data = r.read().decode("utf-8", "replace")
    for i, line in enumerate(data.splitlines(), 1):
        if "FetchAPIServerTLSProfile" in line or "TLSProfile" in line:
            start = max(1, i-25)
            end = min(len(data.splitlines()), i+80)
            for j in range(start, end + 1):
                print(f"{j:4d}: {data.splitlines()[j-1]}")
            break
except Exception as e:
    print(f"NETWORK_ERROR: {e}")
PY

Repository: openshift/local-storage-operator

Length of output: 8355


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- vendor/github.com/openshift/controller-runtime-common/pkg/tls/tls.go ---'
sed -n '1,220p' vendor/github.com/openshift/controller-runtime-common/pkg/tls/tls.go

echo
echo '--- cmd/local-storage-operator/main.go around the TLS logic ---'
sed -n '110,155p' cmd/local-storage-operator/main.go

Repository: openshift/local-storage-operator

Length of output: 8607


Check profile presence before defaulting. FetchAPIServerTLSProfile returns the intermediate default when spec.tlsSecurityProfile is unset, so this nil/empty check never rejects an absent profile. Strict mode still accepts the defaulted config instead of requiring an explicit APIServer TLS profile.

🧰 Tools
🪛 golangci-lint (2.12.2)

[error] 125-125: : # github.com/openshift/local-storage-operator/api/v1
api/v1/localvolume_types.go:125:25: cannot use &LocalVolume{} (value of type *LocalVolume) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to SchemeBuilder.Register: *LocalVolume does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)
api/v1/localvolume_types.go:125:41: cannot use &LocalVolumeList{} (value of type *LocalVolumeList) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to SchemeBuilder.Register: *LocalVolumeList does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)
api/v1/localvolumedevicelink_types.go:133:25: cannot use &LocalVolumeDeviceLink{} (value of type *LocalVolumeDeviceLink) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to SchemeBuilder.Register: *LocalVolumeDeviceLink does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)
api/v1/localvolumedevicelink_types.go:133:51: cannot use &LocalVolumeDeviceLinkList{} (value of type *LocalVolumeDeviceLinkList) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to SchemeBuilder.Register: *LocalVolumeDeviceLinkList does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)

(typecheck)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/tls/tlsprofile.go` around lines 122 - 128, Update the strict-mode logic
around FetchAPIServerTLSProfile to detect whether spec.tlsSecurityProfile is
explicitly present before using the returned profileSpec defaults. Reject an
absent profile with the existing explicit-profile error, while preserving
validation of an explicitly configured profile and propagation of fetch errors.

Source: MCP tools

}
}

return nil
}

// GetAdherencePolicyForLogging returns the current TLS adherence policy for logging purposes.
// Returns the policy and any error encountered.
func GetAdherencePolicyForLogging(ctx context.Context, c client.Client) (configv1.TLSAdherencePolicy, error) {
return crcommon.FetchAPIServerTLSAdherencePolicy(ctx, c)
}

// FetchAPIServerTLSProfile fetches the TLS profile spec from the cluster APIServer CR.
// This is a convenience wrapper around controller-runtime-common's function.
func FetchAPIServerTLSProfile(ctx context.Context, c client.Client) (configv1.TLSProfileSpec, error) {
return crcommon.FetchAPIServerTLSProfile(ctx, c)
}
50 changes: 50 additions & 0 deletions pkg/tls/watcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2021 The Local Storage Operator Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tls

import (
"context"
"os"

configv1 "github.com/openshift/api/config/v1"
crcommon "github.com/openshift/controller-runtime-common/pkg/tls"
"k8s.io/klog/v2"
)

// NewSecurityProfileWatcher creates a SecurityProfileWatcher that triggers operator
// restart when TLS profile or adherence policy changes.
// The initial TLS profile spec and adherence policy are passed in so the watcher
// knows the baseline configuration from operator startup.
func NewSecurityProfileWatcher(
initialProfile configv1.TLSProfileSpec,
initialAdherence configv1.TLSAdherencePolicy,
) *crcommon.SecurityProfileWatcher {
return &crcommon.SecurityProfileWatcher{
InitialTLSProfileSpec: initialProfile,
InitialTLSAdherencePolicy: initialAdherence,
OnProfileChange: func(ctx context.Context, oldProfile, newProfile configv1.TLSProfileSpec) {
klog.Infof("TLS profile changed, restarting operator to apply new configuration")
klog.V(2).Infof("Old profile: %+v, New profile: %+v", oldProfile, newProfile)
os.Exit(0) // Kubernetes will restart the pod
},
OnAdherencePolicyChange: func(ctx context.Context, oldPolicy, newPolicy configv1.TLSAdherencePolicy) {
klog.Infof("TLS adherence policy changed from %s to %s, restarting operator",
oldPolicy, newPolicy)
os.Exit(0)
},
}
}
Loading