diff --git a/apis/trivy/openapi_generated.go b/apis/trivy/openapi_generated.go index 6c108f1c9..8740e6a36 100755 --- a/apis/trivy/openapi_generated.go +++ b/apis/trivy/openapi_generated.go @@ -20887,16 +20887,8 @@ func schema_kubeopsdev_scanner_apis_trivy_Time(ref common.ReferenceCallback) com return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "Time": { - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "date-time", - }, - }, - }, - Required: []string{"Time"}, + Type: Time{}.OpenAPISchemaType(), + Format: Time{}.OpenAPISchemaFormat(), }, }, } diff --git a/apis/trivy/time.go b/apis/trivy/time.go index 6e7a290da..691f03191 100644 --- a/apis/trivy/time.go +++ b/apis/trivy/time.go @@ -79,6 +79,14 @@ func (t Time) MarshalJSON() ([]byte, error) { return buf, nil } +// OpenAPISchemaType and OpenAPISchemaFormat mirror metav1.Time so openapi-gen +// emits a scalar date-time string. Without them, defining Time as a new named +// type strips metav1.Time's methods and the generated schema becomes an object, +// breaking the server-side-apply type converter. +func (Time) OpenAPISchemaType() []string { return []string{"string"} } + +func (Time) OpenAPISchemaFormat() string { return "date-time" } + func init() { utilruntime.Must( apiequality.Semantic.AddFunc(func(a, b Time) bool { diff --git a/pkg/cmds/server/start.go b/pkg/cmds/server/start.go index 24fc4be24..cb161877b 100644 --- a/pkg/cmds/server/start.go +++ b/pkg/cmds/server/start.go @@ -117,7 +117,11 @@ func (o *ScannerServerOptions) Config() (*apiserver.Config, error) { openapi.NewDefinitionNamer(apiserver.Scheme)) serverConfig.OpenAPIV3Config.Info.Title = "scanner" serverConfig.OpenAPIV3Config.Info.Version = api.SchemeGroupVersion.Version - serverConfig.OpenAPIV3Config.IgnorePrefixes = ignore + // Do NOT reuse `ignore` here: the v3 config feeds the server-side-apply + // managed-fields type converter (getOpenAPIModels), and ignoring the scanner + // group prefix drops its resources from the converter, causing + // "no corresponding type for scanner.appscode.com/v1alpha1" on every write. + serverConfig.OpenAPIV3Config.IgnorePrefixes = []string{"/swaggerapi"} extraConfig := apiserver.ExtraConfig{ ClientConfig: serverConfig.ClientConfig,