From d7a1ac229127029db92a383d59e9e8d1eb352859 Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Thu, 29 Jan 2026 17:54:22 +0200 Subject: [PATCH] support custom markers with values --- config/config.go | 5 +++-- processor/processor.go | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index b1c792e..3b9b68f 100644 --- a/config/config.go +++ b/config/config.go @@ -39,8 +39,9 @@ type ProcessorConfig struct { } type Marker struct { - Name string - Target TargetType + Name string + Target TargetType + HasValue bool `json:"hasValue"` } type TargetType string diff --git a/processor/processor.go b/processor/processor.go index 3c2d056..0d6cecb 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -527,9 +527,19 @@ func mkRegistry(customMarkers []config.Marker) (*markers.Registry, error) { continue } - if err := registry.Define(marker.Name, t, struct{}{}); err != nil { + var d *markers.Definition + var err error + if marker.HasValue { + d, err = markers.MakeAnyTypeDefinition(marker.Name, t, crdmarkers.Default{}) + } else { + d, err = markers.MakeDefinition(marker.Name, t, struct{}{}) + } + if err != nil { return nil, fmt.Errorf("failed to define custom marker %s: %w", marker.Name, err) } + if err := registry.Register(d); err != nil { + return nil, fmt.Errorf("failed to register custom marker %s: %w", marker.Name, err) + } } return registry, nil @@ -547,7 +557,6 @@ func parseMarkers(markers markers.MarkerValues) (string, []string) { for _, name := range markerNames { value := markers[name][len(markers[name])-1] - if strings.HasPrefix(name, "kubebuilder:validation:") { name := strings.TrimPrefix(name, "kubebuilder:validation:") @@ -569,7 +578,7 @@ func parseMarkers(markers markers.MarkerValues) (string, []string) { defaultValue = fmt.Sprintf("%v", v.Value) } - // Handle standalone +required and +k8s:required marker + // Handle standalone +required and +k8s:required marker // This is equivalent to +kubebuilder:validation:Required if name == "required" || name == "k8s:required" { validation = append(validation, "Required: {}")