Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CEL rule to validate field immutability for direct Compute resources #3193

Closed
wants to merge 1 commit into from
Closed
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: 2 additions & 0 deletions apis/compute/v1beta1/firewallpolicyrule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ type ComputeFirewallPolicyRuleSpec struct {
// +optional
EnableLogging *bool `json:"enableLogging,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="the field is immutable"
Copy link
Collaborator

Choose a reason for hiding this comment

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

These fields are related to identity. We do not need the immutable check, but set this as required.

Copy link
Collaborator Author

@gemmahou gemmahou Nov 19, 2024

Choose a reason for hiding this comment

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

They are required fields now. If no immutable check is needed, we can close this PR.

/* Immutable. */
FirewallPolicyRef *refs.ComputeFirewallPolicyRef `json:"firewallPolicyRef"`

/* A match condition that incoming traffic is evaluated against. If it evaluates to true, the corresponding 'action' is enforced. */
Match *FirewallPolicyRuleMatch `json:"match"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="the field is immutable"
/* Immutable. An integer indicating the priority of a rule in the list. The priority must be a positive value between 0 and 2147483647. Rules are evaluated from highest to lowest priority where 0 is the highest priority and 2147483647 is the lowest prority. */
Priority int64 `json:"priority"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ spec:
resource.
type: string
type: object
x-kubernetes-validations:
- message: the field is immutable
rule: self == oldSelf
match:
description: A match condition that incoming traffic is evaluated
against. If it evaluates to true, the corresponding 'action' is
Expand Down Expand Up @@ -217,6 +220,9 @@ spec:
where 0 is the highest priority and 2147483647 is the lowest prority.
format: int64
type: integer
x-kubernetes-validations:
- message: the field is immutable
rule: self == oldSelf
targetResources:
items:
oneOf:
Expand Down
Loading