Skip to content

Commit 8c14e2d

Browse files
committed
🐛 Don't generate schema with Any in it, its not supported
This reverts commit e0d7c9d.
1 parent 57250aa commit 8c14e2d

File tree

3 files changed

+0
-115
lines changed

3 files changed

+0
-115
lines changed

Diff for: pkg/crd/schema.go

-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package crd
1919
import (
2020
"fmt"
2121
"go/ast"
22-
"go/token"
2322
"go/types"
2423
"strings"
2524

@@ -109,11 +108,6 @@ func (c *schemaContext) requestSchema(pkgPath, typeName string) {
109108

110109
// infoToSchema creates a schema for the type in the given set of type information.
111110
func infoToSchema(ctx *schemaContext) *apiext.JSONSchemaProps {
112-
if obj := ctx.pkg.Types.Scope().Lookup(ctx.info.Name); obj != nil && implementsJSONMarshaler(obj.Type()) {
113-
schema := &apiext.JSONSchemaProps{Type: "Any"}
114-
applyMarkers(ctx, ctx.info.Markers, schema, ctx.info.RawSpec.Type)
115-
return schema
116-
}
117111
return typeToSchema(ctx, ctx.info.RawSpec.Type)
118112
}
119113

@@ -431,16 +425,3 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo
431425

432426
return typ, format, nil
433427
}
434-
435-
// Open coded go/types representation of encoding/json.Marshaller
436-
var jsonMarshaler = types.NewInterfaceType([]*types.Func{
437-
types.NewFunc(token.NoPos, nil, "MarshalJSON",
438-
types.NewSignature(nil, nil,
439-
types.NewTuple(
440-
types.NewVar(token.NoPos, nil, "", types.NewSlice(types.Universe.Lookup("byte").Type())),
441-
types.NewVar(token.NoPos, nil, "", types.Universe.Lookup("error").Type())), false)),
442-
}, nil).Complete()
443-
444-
func implementsJSONMarshaler(typ types.Type) bool {
445-
return types.Implements(typ, jsonMarshaler) || types.Implements(types.NewPointer(typ), jsonMarshaler)
446-
}

Diff for: pkg/crd/testdata/cronjob_types.go

-88
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ limitations under the License.
2323
package cronjob
2424

2525
import (
26-
"encoding/json"
2726
"fmt"
28-
"net/url"
2927

3028
batchv1beta1 "k8s.io/api/batch/v1beta1"
3129
corev1 "k8s.io/api/core/v1"
@@ -209,84 +207,6 @@ func (t *TotallyABool) UnmarshalJSON(in []byte) error {
209207
return nil
210208
}
211209

212-
// +kubebuilder:validation:Type=string
213-
// URL wraps url.URL.
214-
// It has custom json marshal methods that enable it to be used in K8s CRDs
215-
// such that the CRD resource will have the URL but operator code can can work with url.URL struct
216-
type URL struct {
217-
url.URL
218-
}
219-
220-
func (u *URL) MarshalJSON() ([]byte, error) {
221-
return []byte(fmt.Sprintf("%q", u.String())), nil
222-
}
223-
224-
func (u *URL) UnmarshalJSON(b []byte) error {
225-
var ref string
226-
if err := json.Unmarshal(b, &ref); err != nil {
227-
return err
228-
}
229-
if ref == "" {
230-
*u = URL{}
231-
return nil
232-
}
233-
234-
r, err := url.Parse(ref)
235-
if err != nil {
236-
return err
237-
} else if r != nil {
238-
*u = URL{*r}
239-
} else {
240-
*u = URL{}
241-
}
242-
return nil
243-
}
244-
245-
func (u *URL) String() string {
246-
if u == nil {
247-
return ""
248-
}
249-
return u.URL.String()
250-
}
251-
252-
// +kubebuilder:validation:Type=string
253-
// URL2 is an alias of url.URL.
254-
// It has custom json marshal methods that enable it to be used in K8s CRDs
255-
// such that the CRD resource will have the URL but operator code can can work with url.URL struct
256-
type URL2 url.URL
257-
258-
func (u *URL2) MarshalJSON() ([]byte, error) {
259-
return []byte(fmt.Sprintf("%q", u.String())), nil
260-
}
261-
262-
func (u *URL2) UnmarshalJSON(b []byte) error {
263-
var ref string
264-
if err := json.Unmarshal(b, &ref); err != nil {
265-
return err
266-
}
267-
if ref == "" {
268-
*u = URL2{}
269-
return nil
270-
}
271-
272-
r, err := url.Parse(ref)
273-
if err != nil {
274-
return err
275-
} else if r != nil {
276-
*u = *(*URL2)(r)
277-
} else {
278-
*u = URL2{}
279-
}
280-
return nil
281-
}
282-
283-
func (u *URL2) String() string {
284-
if u == nil {
285-
return ""
286-
}
287-
return (*url.URL)(u).String()
288-
}
289-
290210
// ConcurrencyPolicy describes how the job will be handled.
291211
// Only one of the following concurrent policies may be specified.
292212
// If none of the following policies is specified, the default one
@@ -323,14 +243,6 @@ type CronJobStatus struct {
323243
// with microsecond precision.
324244
// +optional
325245
LastScheduleMicroTime *metav1.MicroTime `json:"lastScheduleMicroTime,omitempty"`
326-
327-
// LastActiveLogURL specifies the logging url for the last started job
328-
// +optional
329-
LastActiveLogURL *URL `json:"lastActiveLogURL,omitempty"`
330-
331-
// LastActiveLogURL2 specifies the logging url for the last started job
332-
// +optional
333-
LastActiveLogURL2 *URL2 `json:"lastActiveLogURL2,omitempty"`
334246
}
335247

336248
// +kubebuilder:object:root=true

Diff for: pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -5192,14 +5192,6 @@ spec:
51925192
type: string
51935193
type: object
51945194
type: array
5195-
lastActiveLogURL:
5196-
description: LastActiveLogURL specifies the logging url for the last
5197-
started job
5198-
type: string
5199-
lastActiveLogURL2:
5200-
description: LastActiveLogURL2 specifies the logging url for the last
5201-
started job
5202-
type: string
52035195
lastScheduleMicroTime:
52045196
description: Information about the last time the job was successfully
52055197
scheduled, with microsecond precision.

0 commit comments

Comments
 (0)