|
| 1 | +/* |
| 2 | +Copyright 2024 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package apiwarnings |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "regexp" |
| 22 | + |
| 23 | + "github.com/go-logr/logr" |
| 24 | + |
| 25 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 26 | +) |
| 27 | + |
| 28 | +// DomainQualifiedFinalizerWarning is a regular expression that matches a |
| 29 | +// warning that the API server returns when a finalizer is not domain-qualified. |
| 30 | +func DomainQualifiedFinalizerWarning(domain string) *regexp.Regexp { |
| 31 | + return regexp.MustCompile( |
| 32 | + fmt.Sprintf("^metadata.finalizers:.*%s.*prefer a domain-qualified finalizer name to avoid accidental conflicts with other finalizer writers$", domain), |
| 33 | + ) |
| 34 | +} |
| 35 | + |
| 36 | +// DefaultHandler is a handler that discards warnings that are the result of |
| 37 | +// decisions made by the Cluster API project, but cannot be immediately |
| 38 | +// addressed, and are therefore not helpful to the user. |
| 39 | +func DefaultHandler(l logr.Logger) *DiscardMatchingHandler { |
| 40 | + return NewDiscardMatchingHandler( |
| 41 | + l, |
| 42 | + DiscardMatchingHandlerOptions{ |
| 43 | + Deduplicate: true, |
| 44 | + Expressions: []regexp.Regexp{ |
| 45 | + *DomainQualifiedFinalizerWarning(clusterv1.GroupVersion.Group), |
| 46 | + }, |
| 47 | + }, |
| 48 | + ) |
| 49 | +} |
0 commit comments