diff --git a/go.mod b/go.mod index 13ffd0209..4d629d0ac 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 mvdan.cc/sh/v3 v3.10.0 sigs.k8s.io/controller-runtime v0.19.1 - sigs.k8s.io/controller-tools v0.16.4 + sigs.k8s.io/controller-tools v0.16.5 sigs.k8s.io/yaml v1.4.0 ) diff --git a/go.sum b/go.sum index 2e1a706f2..5be93c798 100644 --- a/go.sum +++ b/go.sum @@ -1886,8 +1886,8 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/controller-runtime v0.19.1 h1:Son+Q40+Be3QWb+niBXAg2vFiYWolDjjRfO8hn/cxOk= sigs.k8s.io/controller-runtime v0.19.1/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= -sigs.k8s.io/controller-tools v0.16.4 h1:VXmar78eDXbx1by/H09ikEq1hiq3bqInxuV3lMr3GmQ= -sigs.k8s.io/controller-tools v0.16.4/go.mod h1:kcsZyYMXiOFuBhofSPtkB90zTSxVRxVVyvtKQcx3q1A= +sigs.k8s.io/controller-tools v0.16.5 h1:5k9FNRqziBPwqr17AMEPPV/En39ZBplLAdOwwQHruP4= +sigs.k8s.io/controller-tools v0.16.5/go.mod h1:8vztuRVzs8IuuJqKqbXCSlXcw+lkAv/M2sTpg55qjMY= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/kustomize/api v0.17.2 h1:E7/Fjk7V5fboiuijoZHgs4aHuexi5Y2loXlVOAVAG5g= diff --git a/vendor/modules.txt b/vendor/modules.txt index d611d452f..65b4e549e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2303,7 +2303,7 @@ sigs.k8s.io/controller-runtime/pkg/webhook/admission sigs.k8s.io/controller-runtime/pkg/webhook/admission/metrics sigs.k8s.io/controller-runtime/pkg/webhook/conversion sigs.k8s.io/controller-runtime/pkg/webhook/internal/metrics -# sigs.k8s.io/controller-tools v0.16.4 +# sigs.k8s.io/controller-tools v0.16.5 ## explicit; go 1.22.0 sigs.k8s.io/controller-tools/cmd/controller-gen sigs.k8s.io/controller-tools/pkg/crd diff --git a/vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go b/vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go index d2955c510..219d0dbb6 100644 --- a/vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go +++ b/vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go @@ -125,29 +125,38 @@ func infoToSchema(ctx *schemaContext) *apiext.JSONSchemaProps { return typeToSchema(ctx, ctx.info.RawSpec.Type) } +type schemaMarkerWithName struct { + SchemaMarker SchemaMarker + Name string +} + // applyMarkers applies schema markers given their priority to the given schema func applyMarkers(ctx *schemaContext, markerSet markers.MarkerValues, props *apiext.JSONSchemaProps, node ast.Node) { - markers := make([]SchemaMarker, 0, len(markerSet)) - itemsMarkers := make([]SchemaMarker, 0, len(markerSet)) - itemsMarkerNames := make(map[SchemaMarker]string) + markers := make([]schemaMarkerWithName, 0, len(markerSet)) + itemsMarkers := make([]schemaMarkerWithName, 0, len(markerSet)) for markerName, markerValues := range markerSet { for _, markerValue := range markerValues { if schemaMarker, isSchemaMarker := markerValue.(SchemaMarker); isSchemaMarker { if strings.HasPrefix(markerName, crdmarkers.ValidationItemsPrefix) { - itemsMarkers = append(itemsMarkers, schemaMarker) - itemsMarkerNames[schemaMarker] = markerName + itemsMarkers = append(itemsMarkers, schemaMarkerWithName{ + SchemaMarker: schemaMarker, + Name: markerName, + }) } else { - markers = append(markers, schemaMarker) + markers = append(markers, schemaMarkerWithName{ + SchemaMarker: schemaMarker, + Name: markerName, + }) } } } } - cmpPriority := func(markers []SchemaMarker, i, j int) bool { + cmpPriority := func(markers []schemaMarkerWithName, i, j int) bool { var iPriority, jPriority crdmarkers.ApplyPriority - switch m := markers[i].(type) { + switch m := markers[i].SchemaMarker.(type) { case crdmarkers.ApplyPriorityMarker: iPriority = m.ApplyPriority() case applyFirstMarker: @@ -156,7 +165,7 @@ func applyMarkers(ctx *schemaContext, markerSet markers.MarkerValues, props *api iPriority = crdmarkers.ApplyPriorityDefault } - switch m := markers[j].(type) { + switch m := markers[j].SchemaMarker.(type) { case crdmarkers.ApplyPriorityMarker: jPriority = m.ApplyPriority() case applyFirstMarker: @@ -171,18 +180,18 @@ func applyMarkers(ctx *schemaContext, markerSet markers.MarkerValues, props *api sort.Slice(itemsMarkers, func(i, j int) bool { return cmpPriority(itemsMarkers, i, j) }) for _, schemaMarker := range markers { - if err := schemaMarker.ApplyToSchema(props); err != nil { + if err := schemaMarker.SchemaMarker.ApplyToSchema(props); err != nil { ctx.pkg.AddError(loader.ErrFromNode(err /* an okay guess */, node)) } } for _, schemaMarker := range itemsMarkers { if props.Type != "array" || props.Items == nil || props.Items.Schema == nil { - err := fmt.Errorf("must apply %s to an array value, found %s", itemsMarkerNames[schemaMarker], props.Type) + err := fmt.Errorf("must apply %s to an array value, found %s", schemaMarker.Name, props.Type) ctx.pkg.AddError(loader.ErrFromNode(err, node)) } else { itemsSchema := props.Items.Schema - if err := schemaMarker.ApplyToSchema(itemsSchema); err != nil { + if err := schemaMarker.SchemaMarker.ApplyToSchema(itemsSchema); err != nil { ctx.pkg.AddError(loader.ErrFromNode(err /* an okay guess */, node)) } } @@ -242,11 +251,30 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("unknown type %s", ident.Name), ident)) return &apiext.JSONSchemaProps{} } + // This reproduces the behavior we had pre gotypesalias=1 (needed if this + // project is compiled with default settings and Go >= 1.23). + if aliasInfo, isAlias := typeInfo.(*types.Alias); isAlias { + typeInfo = aliasInfo.Underlying() + } if basicInfo, isBasic := typeInfo.(*types.Basic); isBasic { typ, fmt, err := builtinToType(basicInfo, ctx.allowDangerousTypes) if err != nil { ctx.pkg.AddError(loader.ErrFromNode(err, ident)) } + // Check for type aliasing to a basic type for gotypesalias=0. See more + // in documentation https://pkg.go.dev/go/types#Alias: + // > For gotypesalias=1, alias declarations produce an Alias type. + // > Otherwise, the alias information is only in the type name, which + // > points directly to the actual (aliased) type. + if basicInfo.Name() != ident.Name { + ctx.requestSchema("", ident.Name) + link := TypeRefLink("", ident.Name) + return &apiext.JSONSchemaProps{ + Type: typ, + Format: fmt, + Ref: &link, + } + } return &apiext.JSONSchemaProps{ Type: typ, Format: fmt, @@ -274,7 +302,7 @@ func namedToSchema(ctx *schemaContext, named *ast.SelectorExpr) *apiext.JSONSche ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("unknown type %v.%s", named.X, named.Sel.Name), named)) return &apiext.JSONSchemaProps{} } - typeInfo := typeInfoRaw.(*types.Named) + typeInfo := typeInfoRaw.(interface{ Obj() *types.TypeName }) typeNameInfo := typeInfo.Obj() nonVendorPath := loader.NonVendorPath(typeNameInfo.Pkg().Path()) ctx.requestSchema(nonVendorPath, typeNameInfo.Name())