Skip to content

Commit

Permalink
Merge pull request #660 from fluxcd/fix-cel-immutable
Browse files Browse the repository at this point in the history
ssa: Extend CEL immutable error detection
  • Loading branch information
stefanprodan authored Oct 6, 2023
2 parents 6dc2f17 + 8b6f39b commit bf2de60
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ssa/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ func IsKustomization(object *unstructured.Unstructured) bool {
return false
}

var matchImmutableFieldErr = regexp.MustCompile(`.*is\simmutable.*`)
// Match CEL immutable error variants.
var matchImmutableFieldErrors = []*regexp.Regexp{
regexp.MustCompile(`.*is\simmutable.*`),
regexp.MustCompile(`.*immutable\sfield.*`),
}

// IsImmutableError checks if the given error is an immutable error.
func IsImmutableError(err error) bool {
Expand All @@ -297,8 +301,10 @@ func IsImmutableError(err error) bool {

// Detect immutable errors returned by custom admission webhooks and Kubernetes CEL
// https://kubernetes.io/blog/2022/09/29/enforce-immutability-using-cel/#immutablility-after-first-modification
if matchImmutableFieldErr.MatchString(err.Error()) {
return true
for _, fieldError := range matchImmutableFieldErrors {
if fieldError.MatchString(err.Error()) {
return true
}
}

return false
Expand Down

0 comments on commit bf2de60

Please sign in to comment.