Skip to content

Commit 00be0af

Browse files
committed
added ExactlyOneOf to markers package and included it in init function
1 parent 7b1857d commit 00be0af

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkg/analysis/arrayofstruct/analyzer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"sigs.k8s.io/kube-api-linter/pkg/analysis/helpers/inspector"
2727
markershelper "sigs.k8s.io/kube-api-linter/pkg/analysis/helpers/markers"
2828
"sigs.k8s.io/kube-api-linter/pkg/analysis/utils"
29+
"sigs.k8s.io/kube-api-linter/pkg/markers"
2930
)
3031

3132
const name = "arrayofstruct"
@@ -39,6 +40,10 @@ var Analyzer = &analysis.Analyzer{
3940
Requires: []*analysis.Analyzer{inspector.Analyzer},
4041
}
4142

43+
func init() {
44+
markershelper.DefaultRegistry().Register(markers.KubebuilderValidationExactlyOneOf)
45+
}
46+
4247
func run(pass *analysis.Pass) (any, error) {
4348
inspect, ok := pass.ResultOf[inspector.Analyzer].(inspector.Inspector)
4449
if !ok {
@@ -227,5 +232,5 @@ func hasExactlyOneOfMarker(structType *ast.StructType, markersAccess markershelp
227232
// Use StructMarkers to get the set of markers on the struct
228233
markerSet := markersAccess.StructMarkers(structType)
229234

230-
return markerSet.Has("kubebuilder:validation:ExactlyOneOf")
235+
return markerSet.Has(markers.KubebuilderValidationExactlyOneOf)
231236
}

pkg/markers/markers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const (
9393
// KubebuilderRequiredMarker is the marker that indicates that a field is required in kubebuilder.
9494
KubebuilderRequiredMarker = "kubebuilder:validation:Required"
9595

96+
// KubebuilderValidationExactlyOneOf is the marker that indicates that a field has an exactly one of in kubebuilder.
97+
KubebuilderValidationExactlyOneOf = "kubebuilder:validation:ExactlyOneOf"
98+
9699
// KubebuilderItemsMaxLengthMarker is the marker that indicates that a field has a maximum length in kubebuilder.
97100
KubebuilderItemsMaxLengthMarker = "kubebuilder:validation:items:MaxLength"
98101

0 commit comments

Comments
 (0)