Skip to content

Commit

Permalink
Merge pull request #1839 from deads2k/by-gate-31-cel-enfroce
Browse files Browse the repository at this point in the history
use CEL to enforce immutable featureset
  • Loading branch information
openshift-merge-bot[bot] committed Mar 30, 2024
2 parents 8bef56a + f74db6f commit f28a8dc
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
80 changes: 80 additions & 0 deletions config/v1/tests/featuregates.config.openshift.io/AAA_ungated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,83 @@ tests:
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec: {}
- name: Can create TechPreview
initial: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: TechPreviewNoUpgrade
expected: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: TechPreviewNoUpgrade
onUpdate:
- name: Default to TechPreview
initial: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: ""
updated: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: TechPreviewNoUpgrade
expected: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: TechPreviewNoUpgrade
- name: TechPreview to Default
initial: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: TechPreviewNoUpgrade
updated: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: ""
expectedError: "TechPreviewNoUpgrade may not be changed"
- name: TechPreview to Custom
initial: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: TechPreviewNoUpgrade
updated: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: CustomNoUpgrade
expectedError: "TechPreviewNoUpgrade may not be changed"
- name: Default to Custom
initial: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: ""
updated: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: CustomNoUpgrade
expected: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: CustomNoUpgrade
- name: Custom to Default
initial: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: CustomNoUpgrade
updated: |
apiVersion: config.openshift.io/v1
kind: FeatureGate
spec:
featureSet: ""
expectedError: "CustomNoUpgrade may not be changed"
2 changes: 2 additions & 0 deletions config/v1/types_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type FeatureGateSelection struct {
// Turning on or off features may cause irreversible changes in your cluster which cannot be undone.
// +unionDiscriminator
// +optional
// +kubebuilder:validation:XValidation:rule="oldSelf == 'CustomNoUpgrade' ? self == 'CustomNoUpgrade' : true",message="CustomNoUpgrade may not be changed"
// +kubebuilder:validation:XValidation:rule="oldSelf == 'TechPreviewNoUpgrade' ? self == 'TechPreviewNoUpgrade' : true",message="TechPreviewNoUpgrade may not be changed"
FeatureSet FeatureSet `json:"featureSet,omitempty"`

// customNoUpgrade allows the enabling or disabling of any feature. Turning this feature set on IS NOT SUPPORTED, CANNOT BE UNDONE, and PREVENTS UPGRADES.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ spec:
on or off features may cause irreversible changes in your cluster
which cannot be undone.
type: string
x-kubernetes-validations:
- message: CustomNoUpgrade may not be changed
rule: 'oldSelf == ''CustomNoUpgrade'' ? self == ''CustomNoUpgrade''
: true'
- message: TechPreviewNoUpgrade may not be changed
rule: 'oldSelf == ''TechPreviewNoUpgrade'' ? self == ''TechPreviewNoUpgrade''
: true'
type: object
status:
description: status holds observed values from the cluster. They may not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ spec:
on or off features may cause irreversible changes in your cluster
which cannot be undone.
type: string
x-kubernetes-validations:
- message: CustomNoUpgrade may not be changed
rule: 'oldSelf == ''CustomNoUpgrade'' ? self == ''CustomNoUpgrade''
: true'
- message: TechPreviewNoUpgrade may not be changed
rule: 'oldSelf == ''TechPreviewNoUpgrade'' ? self == ''TechPreviewNoUpgrade''
: true'
type: object
status:
description: status holds observed values from the cluster. They may not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ spec:
on or off features may cause irreversible changes in your cluster
which cannot be undone.
type: string
x-kubernetes-validations:
- message: CustomNoUpgrade may not be changed
rule: 'oldSelf == ''CustomNoUpgrade'' ? self == ''CustomNoUpgrade''
: true'
- message: TechPreviewNoUpgrade may not be changed
rule: 'oldSelf == ''TechPreviewNoUpgrade'' ? self == ''TechPreviewNoUpgrade''
: true'
type: object
status:
description: status holds observed values from the cluster. They may not
Expand Down

0 comments on commit f28a8dc

Please sign in to comment.