✨ Warn about things that we strongly recommend avoiding#443
✨ Warn about things that we strongly recommend avoiding#443ksaritek wants to merge 3 commits intokubernetes-sigs:masterfrom ksaritek:434
Conversation
|
Welcome @ksaritek! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ksaritek The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/assign @DirectXMan12 |
|
First comment: the beginning of the commit should generally say "what" and "why". Having examples is fine, but it's generally go to snip to the relevant parts, and to used fenced code blocks. I'd expect something like: |
DirectXMan12
left a comment
There was a problem hiding this comment.
comments inline. Please remove the merge commits. Usually we prefer one "logical chunk" per commit, so in this case I'd expect to either see 1 commit for the whole thing, or one for the warning functionality and one to update the type error to a warning.
| // WarningRecorder knows how to record errors. It wraps the part of | ||
| // pkg/loader.Package that we need to record errors in places were it might not | ||
| // make sense to have a loader.Package |
There was a problem hiding this comment.
the second sentence here seems like it was copy-pasted verbatim, and doesn't make much sense any more.
I'd go with
| // WarningRecorder knows how to record errors. It wraps the part of | |
| // pkg/loader.Package that we need to record errors in places were it might not | |
| // make sense to have a loader.Package | |
| // WarningRecorder knows how to record warnings, which are effectively | |
| // non-fatal errors. It wraps the part of pkg/loader.Package that we need to | |
| // record warnings in places were it might not make sense to have a | |
| // loader.Package. |
| // pkg/loader.Package that we need to record errors in places were it might not | ||
| // make sense to have a loader.Package | ||
| type WarningRecorder interface { | ||
| // AddWarning records that the given error occurred. |
There was a problem hiding this comment.
| // AddWarning records that the given error occurred. | |
| // AddWarning records that the given warning (non-fatal error) occurred. |
| return &apiext.JSONSchemaProps{} | ||
| } | ||
| case *ast.StarExpr: | ||
| ctx.pkg.AddWarning(loader.ErrFromNode(fmt.Errorf("map values should be a named type, not %T", mapType.Value), mapType.Value)) |
There was a problem hiding this comment.
maybe tweak the message here a bit so it's obvious it's a warning. I'd do something like
as per the Kubernetes API conventions, map values *should* generally be primitives or named types that alias primitives, not %T. Consider using the "list as map" pattern here, except in cases where map is used for compatiblity/legacy purposes.
| return hadErrors | ||
| } | ||
|
|
||
| // PrintWarnings print errors associated with all packages |
There was a problem hiding this comment.
| // PrintWarnings print errors associated with all packages | |
| // PrintWarnings print warnings associated with all packages |
| // package's dependencies have been visited (postorder). | ||
| // The boolean result of pre(pkg) determines whether | ||
| // the imports of package pkg are visited. | ||
| func visit(pkgs []*Package, pre func(*Package) bool, post func(*Package)) { |
There was a problem hiding this comment.
do we ever use pre? If not, we can get rid of it.
| // Warnings contains any errors encountered querying the metadata | ||
| // of the package, or while parsing or type-checking its files. |
There was a problem hiding this comment.
| // Warnings contains any errors encountered querying the metadata | |
| // of the package, or while parsing or type-checking its files. | |
| // Warnings contains any warnings ("non-fatal" errors) encountered while type-checking or | |
| // generating output (OpenAPI, etc) from the given package. |
| } | ||
| } | ||
|
|
||
| // AddWarning adds an error to the warningss associated with the given package. |
There was a problem hiding this comment.
| // AddWarning adds an error to the warningss associated with the given package. | |
| // AddWarning adds a warning (represented as an error) to the warnings associated with the given package. | |
| // It functions nearly-identically to `AddError`, except that it adds to `Package.Warnings`. |
|
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
|
/remove-lifecycle stale |
|
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
|
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
|
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
|
@fejta-bot: Closed this PR. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
I created a guestbook kubebuilder init project and added a *ast.StarExpr to guestbook struct
type Env struct {
A int
json:"a"B string
json:"b"}
// Guestbook is the Schema for the guestbooks API
type Guestbook struct {
metav1.TypeMeta
json:",inline"metav1.ObjectMeta
json:"metadata,omitempty"}
my patch:
./controller-gen crd object:headerFile="hack/boilerplate.go.txt" paths="./..." output:crd:stdout
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
creationTimestamp: null
name: guestbooks.webapp.my.domain
spec:
group: webapp.my.domain
names:
kind: Guestbook
listKind: GuestbookList
plural: guestbooks
singular: guestbook
scope: Namespaced
validation:
openAPIV3Schema:
description: Guestbook is the Schema for the guestbooks API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
envs:
additionalProperties:
properties:
a:
type: integer
b:
type: string
required:
- a
- b
type: object
type: object
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: GuestbookSpec defines the desired state of Guestbook
properties:
foo:
description: Foo is an example field of Guestbook. Edit Guestbook_types.go
to remove/update
type: string
type: object
status:
description: GuestbookStatus defines the observed state of Guestbook
type: object
type: object
version: v1
versions:
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: null
storedVersions: null
/go/src/example/api/v1/guestbook_types.go:55:20: map values should be a named type, not *ast.StarExpr
controller-gen prints warning at the end like /go/src/example/api/v1/guestbook_types.go:55:20: map values should be a named type, not *ast.StarExpr.