Skip to content

Commit e892dfa

Browse files
jpbetzthockinaaron-prindleyongruilin
committed
Add validators: opaque
Skips validation of a type's tags. Co-authored-by: Tim Hockin <[email protected]> Co-authored-by: Aaron Prindle <[email protected]> Co-authored-by: Yongrui Lin <[email protected]>
1 parent c1f9e6b commit e892dfa

File tree

1 file changed

+56
-0
lines changed
  • staging/src/k8s.io/code-generator/cmd/validation-gen/validators

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2025 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 validators
18+
19+
import "k8s.io/apimachinery/pkg/util/sets"
20+
21+
const (
22+
opaqueTypeTagName = "k8s:opaqueType"
23+
)
24+
25+
type opaqueTypeTagValidator struct{}
26+
27+
func init() {
28+
RegisterTagValidator(opaqueTypeTagValidator{})
29+
}
30+
31+
func (opaqueTypeTagValidator) Init(Config) {}
32+
33+
func (opaqueTypeTagValidator) TagName() string {
34+
return opaqueTypeTagName
35+
}
36+
37+
func (opaqueTypeTagValidator) ValidScopes() sets.Set[Scope] {
38+
return sets.New(ScopeAny)
39+
}
40+
41+
func (opaqueTypeTagValidator) GetValidations(context Context, _ []string, _ string) (Validations, error) {
42+
return Validations{OpaqueType: true}, nil
43+
}
44+
45+
func (opaqueTypeTagValidator) Docs() TagDoc {
46+
doc := TagDoc{
47+
Tag: opaqueTypeTagName,
48+
Scopes: []Scope{ScopeField},
49+
Description: "Indicates that any validations declared on the referenced type will be ignored. " +
50+
"If a referenced type's package is not included in the generator's current " +
51+
"flags, this tag must be set, or code generation will fail (preventing silent " +
52+
"mistakes). If the validations should not be ignored, add the type's package " +
53+
"to the generator using the --extra-pkg flag.",
54+
}
55+
return doc
56+
}

0 commit comments

Comments
 (0)