Skip to content

Commit be18f79

Browse files
committed
Update OperatorPolicy design to v1beta2
Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
1 parent 0335b24 commit be18f79

File tree

1 file changed

+84
-22
lines changed
  • enhancements/sig-policy/89-operator-policy-kind

1 file changed

+84
-22
lines changed

enhancements/sig-policy/89-operator-policy-kind/README.md

+84-22
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ difficult with current solutions.
6767

6868
### OperatorPolicy Syntax
6969

70+
Note: See Implementation Details for the previous `v1beta1` version.
71+
7072
```yaml
71-
apiVersion: policy.open-cluster-management.io/v1beta1
73+
apiVersion: policy.open-cluster-management.io/v1beta2
7274
kind: OperatorPolicy
7375
metadata:
7476
name: my-operator
@@ -141,7 +143,7 @@ fields based on specified defaults in the operator's PackageManifest. For exampl
141143
default channel to possibly be different on different clusters, reflecting the default channel in
142144
each cluster's catalog. It is not allowed to set `spec.subscription.installPlanApproval`; the policy
143145
will determine and set a value for that field based on the policy's `spec.versions` and
144-
`spec.updgradeApproval` settings.
146+
`spec.upgradeApproval` settings.
145147

146148
In "musthave" mode, the `spec.versions` list specifies what installed versions are considered
147149
Compliant when the policy is in `inform` mode, and which InstallPlans can be approved when in
@@ -154,14 +156,13 @@ The `spec.upgradeApproval` field specifies whether an enforced "musthave" policy
154156
upgrade InstallPlans for the operator. *It has no effect when the policy is in "mustnothave" mode*.
155157
This only affects InstallPlans for operators that are already installed on the cluster,
156158
which upgrade or replace the operator; initial InstallPlans for an operator can be approved
157-
regardless of this flag. Allowed values here include `Automatic` and `None`. If not set, the
158-
controller will behave as if it were set to `Automatic`.
159+
regardless of this flag. Allowed values here include `Automatic` and `None`.
159160

160-
Only when the policy is operating as if `spec.upgradeApproval` was set to `Automatic`, and the
161-
`spec.versions` field is empty (allowing all versions of the operator) will the subscription
162-
managed by this policy have its `installPlanApproval` field set to `Automatic`. Otherwise, the field
163-
will be set to `Manual`, but it should be noted that this controller will approve InstallPlans
164-
matching the desired versions automatically.
161+
Only when the policy's `spec.upgradeApproval` is set to `Automatic`, and the `spec.versions` field
162+
is empty (allowing all versions of the operator) will the subscription managed by this policy have
163+
its `installPlanApproval` field set to `Automatic`. Otherwise, the field will be set to `Manual`,
164+
but it should be noted that this controller will approve InstallPlans matching the desired versions
165+
automatically.
165166

166167
The `spec.removalBehavior` field allows configuration of what might be removed by the controller
167168
when the policy is in "mustnothave" mode. *It has no effect when the policy is in "musthave" mode.*
@@ -332,7 +333,7 @@ complete and all of Deployments listed in the operator's CSV are healthy.
332333

333334
Example yaml to apply (not including the Placement):
334335
```yaml
335-
apiVersion: policy.open-cluster-management.io/v1beta1
336+
apiVersion: policy.open-cluster-management.io/v1beta2
336337
kind: OperatorPolicy
337338
metadata:
338339
name: strimzi-policy
@@ -344,10 +345,10 @@ spec:
344345
channel: stable
345346
name: strimzi-kafka-operator
346347
namespace: openshift-operators
347-
installPlanApproval: Manual
348348
source: community-operators
349349
sourceNamespace: openshift-marketplace
350350
startingCSV: strimzi-cluster-operator.v0.35.0
351+
upgradeApproval: None
351352
versions:
352353
- strimzi-cluster-operator.v0.35.0
353354
```
@@ -361,7 +362,7 @@ progress to that version.
361362

362363
For example, to upgrade the operator, the policy from story 1 could be updated to match this:
363364
```yaml
364-
apiVersion: policy.open-cluster-management.io/v1beta1
365+
apiVersion: policy.open-cluster-management.io/v1beta2
365366
kind: OperatorPolicy
366367
metadata:
367368
name: strimzi-policy
@@ -373,10 +374,10 @@ spec:
373374
channel: stable
374375
name: strimzi-kafka-operator
375376
namespace: openshift-operators
376-
installPlanApproval: Manual
377377
source: community-operators
378378
sourceNamespace: openshift-marketplace
379379
startingCSV: strimzi-cluster-operator.v0.35.0
380+
upgradeApproval: Automatic
380381
versions:
381382
- strimzi-cluster-operator.v0.35.0
382383
- strimzi-cluster-operator.v0.35.1
@@ -389,7 +390,7 @@ available. The policy status should clearly indicate what new version is availab
389390

390391
The policy yaml would look like this, including some relevant fields from the status:
391392
```yaml
392-
apiVersion: policy.open-cluster-management.io/v1beta1
393+
apiVersion: policy.open-cluster-management.io/v1beta2
393394
kind: OperatorPolicy
394395
metadata:
395396
name: strimzi-policy
@@ -401,10 +402,10 @@ spec:
401402
channel: stable
402403
name: strimzi-kafka-operator
403404
namespace: openshift-operators
404-
installPlanApproval: Manual
405405
source: community-operators
406406
sourceNamespace: openshift-marketplace
407407
startingCSV: strimzi-cluster-operator.v0.35.0
408+
upgradeApproval: None
408409
versions:
409410
- strimzi-cluster-operator.v0.35.0
410411
statusConfig:
@@ -442,7 +443,7 @@ the operator is in the process of being upgraded (basically, whenever something
442443
the performance of the operator).
443444

444445
```yaml
445-
apiVersion: policy.open-cluster-management.io/v1beta1
446+
apiVersion: policy.open-cluster-management.io/v1beta2
446447
kind: OperatorPolicy
447448
metadata:
448449
name: strimzi-policy
@@ -454,9 +455,9 @@ spec:
454455
channel: stable
455456
name: strimzi-kafka-operator
456457
namespace: openshift-operators
457-
installPlanApproval: Automatic
458458
source: community-operators
459459
sourceNamespace: openshift-marketplace
460+
upgradeApproval: Automatic
460461
statusConfig:
461462
catalogSourceUnhealthy: NonCompliant
462463
deploymentsUnavailable: NonCompliant
@@ -474,7 +475,7 @@ As a policy user, I want to install an operator to a specific namespace via a po
474475
should become Compliant when the operator Deployments are fully available.
475476

476477
```yaml
477-
apiVersion: policy.open-cluster-management.io/v1beta1
478+
apiVersion: policy.open-cluster-management.io/v1beta2
478479
kind: OperatorPolicy
479480
metadata:
480481
name: strimzi-policy
@@ -492,9 +493,9 @@ spec:
492493
channel: stable
493494
name: strimzi-kafka-operator
494495
namespace: strimzi-app-one
495-
installPlanApproval: Automatic
496496
source: community-operators
497497
sourceNamespace: openshift-marketplace
498+
upgradeApproval: Automatic
498499
```
499500

500501
#### Story 6
@@ -503,7 +504,7 @@ As a policy user, I want to ensure a certain operator is not on the cluster. Whe
503504
should be deleted based on what I specify in `spec.removalBehavior`.
504505

505506
```yaml
506-
apiVersion: policy.open-cluster-management.io/v1beta1
507+
apiVersion: policy.open-cluster-management.io/v1beta2
507508
kind: OperatorPolicy
508509
metadata:
509510
name: strimzi-policy
@@ -515,9 +516,9 @@ spec:
515516
channel: stable
516517
name: strimzi-kafka-operator
517518
namespace: strimzi-app-one
518-
installPlanApproval: Automatic
519519
source: community-operators
520520
sourceNamespace: openshift-marketplace
521+
upgradeApproval: Automatic
521522
removalBehavior:
522523
operatorGroups: DeleteIfUnused
523524
subscriptions: Delete
@@ -547,9 +548,9 @@ spec:
547548
channel: stable
548549
name: strimzi-kafka-operator
549550
namespace: strimzi-app-one
550-
installPlanApproval: Automatic
551551
source: community-operators
552552
sourceNamespace: openshift-marketplace
553+
upgradeApproval: Automatic
553554
versions:
554555
- "strimzi-cluster-operator.v0.35.0"
555556
removalBehavior:
@@ -597,6 +598,67 @@ setting, then that InstallPlan will be approved. If an InstallPlan is created fo
597598
installations, it will not be approved by this controller, and it might cause an OperatorPolicy to
598599
become NonCompliant.
599600

601+
#### v1beta1 and v1beta2 Differences and Conversions
602+
603+
For reference, the `v1beta1` implementation used:
604+
```yaml
605+
apiVersion: policy.open-cluster-management.io/v1beta1
606+
kind: OperatorPolicy
607+
metadata:
608+
name: my-operator
609+
spec:
610+
remediationAction: enforce # or inform
611+
severity: medium
612+
complianceType: musthave
613+
operatorGroup: # optional
614+
name: my-operator-group
615+
namespace: own-namespace
616+
target:
617+
namespaces:
618+
- foo
619+
- bar
620+
# selector: # One of selector or namespaces is allowed.
621+
# matchLabels: # or matchExpressions
622+
# mydomain.io/prod: "true"
623+
serviceAccountName: my-og-account # optional
624+
subscription:
625+
config: {} # optional
626+
channel: stable
627+
name: my-operator
628+
namespace: own-namespace
629+
installPlanApproval: Automatic # or Manual, may be overridden by other settings.
630+
source: my-catalog
631+
sourceNamespace: my-catalog-namespace
632+
startingCSV: my-operator.v0.1.0 # optional
633+
versions:
634+
- my-operator.v0.1.1
635+
- my-operator.v0.2.0
636+
```
637+
638+
An initial implementation of this kind used `v1beta1` and focused on installation and upgrade
639+
scenarios. It *required* `spec.subscription.installPlanApproval` to be set to either `Automatic` or
640+
`Manual`, but that setting was believed to be confusing. When set to `Automatic`, the contoller
641+
needed to override that setting in the Subscription in order to restrict the possible upgrades, and
642+
approve any upgrades matching the `versions` specified in the policy. And when set to `Manual`, the
643+
controller would still approve those upgrades without user input, ie "automatically".
644+
645+
The breaking change in the `v1beta2` design is to *forbid* the user from setting the
646+
`spec.subscription.installPlanApproval` field in the subscription, while providing a similar setting
647+
via `spec.upgradeApproval`. The revised design provides more details on the interactions of this
648+
setting and the other fields.
649+
650+
The controller will expose a conversion webhook so that either version of the resource can be used.
651+
It will convert `installPlanApproval: Automatic` to `upgradeApproval: Automatic` and vice-versa, and
652+
`installPlanApproval: Manual` to `upgradeApproval: None` and vice-versa. This is effectively a
653+
change in behavior: as stated earlier, originally policies using `installPlanApproval: Manual` would
654+
approve some upgrades, but now those policies will *not approve any upgrades*. Since the original
655+
behavior was unclear in the design, and the new behavior results in fewer actions by the controller
656+
(and therefore, fewer possible surprises for the user), we believe this change is acceptable.
657+
658+
The policy framework does not need to "know" about this change. Thanks to the conversion webhook,
659+
it can apply whatever version is defined in the Policy: if that version is not registered on the
660+
managed cluster, it would have a `template-error` caused by the API call failing.
661+
600662
### Risks and Mitigation
601663

602664
### Open Questions [optional]

0 commit comments

Comments
 (0)