Skip to content

Commit 736dc85

Browse files
Fix: make OperatorPolicy history length configurable
Signed-off-by: yiraeChristineKim <[email protected]>
1 parent f94a7ca commit 736dc85

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

controllers/operatorpolicy_controller.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ var (
112112
// OperatorPolicyReconciler reconciles a OperatorPolicy object
113113
type OperatorPolicyReconciler struct {
114114
client.Client
115-
DynamicClient dynamic.Interface
116-
DynamicWatcher depclient.DynamicWatcher
117-
InstanceName string
118-
DefaultNamespace string
115+
DynamicClient dynamic.Interface
116+
DynamicWatcher depclient.DynamicWatcher
117+
InstanceName string
118+
DefaultNamespace string
119+
// MaxHistoryLength controls how many compliance history entries are stored in status.history.
120+
// If set to < 1, it will default to 10.
121+
MaxHistoryLength int
119122
TargetClient client.Client
120123
HubDynamicWatcher depclient.DynamicWatcher
121124
HubClient *kubernetes.Clientset
@@ -323,7 +326,11 @@ func (r *OperatorPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Reque
323326

324327
policy.Status.History = append([]policyv1.HistoryEvent{newEvent}, policy.Status.History...)
325328

326-
maxHistoryLength := 10 // At some point, we may make this length configurable
329+
maxHistoryLength := r.MaxHistoryLength
330+
if maxHistoryLength < 1 {
331+
maxHistoryLength = 10
332+
}
333+
327334
if len(policy.Status.History) > maxHistoryLength {
328335
policy.Status.History = policy.Status.History[:maxHistoryLength]
329336
}

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type ctrlOpts struct {
8787
secureMetrics bool
8888
probeAddr string
8989
operatorPolDefaultNS string
90+
operatorPolHistoryLength uint16
9091
clientQPS float32
9192
clientBurst uint16
9293
evalBackoffSeconds uint32
@@ -583,6 +584,7 @@ func main() {
583584
DynamicWatcher: watcher,
584585
InstanceName: instanceName,
585586
DefaultNamespace: opts.operatorPolDefaultNS,
587+
MaxHistoryLength: int(opts.operatorPolHistoryLength),
586588
TargetClient: targetClient,
587589
HubDynamicWatcher: opPolHubDynamicWatcher,
588590
HubClient: hubClient,
@@ -910,6 +912,13 @@ func parseOpts(flags *pflag.FlagSet, args []string) *ctrlOpts {
910912
"The default namespace to be used by an OperatorPolicy if not specified in the policy.",
911913
)
912914

915+
flags.Uint16Var(
916+
&opts.operatorPolHistoryLength,
917+
"operator-policy-status-history-length",
918+
10,
919+
"The maximum number of compliance history entries stored on the OperatorPolicy status.",
920+
)
921+
913922
flags.BoolVar(
914923
&opts.enableOcmPolicyNamespace,
915924
"enable-ocm-policy-namespace",

0 commit comments

Comments
 (0)