-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 crdgen: compare metav1 pkg by ID (#686)
* crdgen: compare metav1 pkg by ID & fsp loader This patch updates the way the CRD generator compares an imported metav1 package. Previously the comparison occurred using a Golang equality operator, !=, against two, in-memory data structures. However, this fails when multiple root paths are loaded. Their metav1 packages are identical, just not identical objects in memory. This patch updates the comparison to compare the package IDs, not the instance of the object. This patch also introduces a filesystem-path specific loader for each unique filesystem path provided as a root. This ensures the AST is loaded correctly and the kubebuilder markers are parsed as intended. * Reproduce the issue This patch adds tests to reproduce the issue of the markers not being discovered when multiple paths are used. The issue is not markers missing from a type, but markers missing from a *referenced* type. For example, the new Job type imports the unserved.CronJobSpec as the field Job.Spec.CronJob. The markers are not generated for Job.Spec.CronJob as it is referenced from another package. Co-authored-by: akutz <[email protected]> Co-authored-by: akutz <[email protected]>
- Loading branch information
1 parent
a260f13
commit 3c8b410
Showing
8 changed files
with
363 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// +groupName=testdata.kubebuilder.io | ||
// +versionName=v1beta1 | ||
package job | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"testdata.kubebuilder.io/cronjob/unserved" | ||
) | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:subresource:status | ||
// +kubebuilder:resource:singular=job | ||
|
||
// JobSpec is the spec for the jobs API. | ||
type JobSpec struct { | ||
// FriendlyName is the friendly name for the job. | ||
// | ||
// +kubebuilder:validation:MinLength=5 | ||
FriendlyName string `json:"friendlyName"` | ||
|
||
// Count is the number of times a job may be executed. | ||
// | ||
// +kubebuilder:validation:Minimum=0 | ||
// +kubebuilder:validation:Maximum=10 | ||
Count int32 `json:"count"` | ||
|
||
// CronJob is the spec for the related CrongJob. | ||
CronnJob unserved.CronJobSpec `json:"crongJob"` | ||
} | ||
|
||
// Job is the Schema for the jobs API | ||
type Job struct { | ||
/* | ||
*/ | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec JobSpec `json:"spec"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// JobList contains a list of Job | ||
type JobList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []Job `json:"items"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: (devel) | ||
creationTimestamp: null | ||
name: jobs.testdata.kubebuilder.io | ||
spec: | ||
group: testdata.kubebuilder.io | ||
names: | ||
kind: Job | ||
listKind: JobList | ||
plural: jobs | ||
singular: job | ||
scope: Namespaced | ||
versions: | ||
- name: v1beta1 | ||
schema: | ||
openAPIV3Schema: | ||
description: Job is the Schema for the jobs 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 | ||
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: JobSpec is the spec for the jobs API. | ||
properties: | ||
count: | ||
description: Count is the number of times a job may be executed. | ||
format: int32 | ||
maximum: 10 | ||
minimum: 0 | ||
type: integer | ||
crongJob: | ||
description: CronJob is the spec for the related CrongJob. | ||
properties: | ||
int32WithValidations: | ||
format: int32 | ||
maximum: 2 | ||
minimum: -2 | ||
multipleOf: 2 | ||
type: integer | ||
twoOfAKindPart0: | ||
description: This tests that markers that are allowed on both | ||
fields and types are applied to fields | ||
minLength: 4 | ||
type: string | ||
required: | ||
- int32WithValidations | ||
- twoOfAKindPart0 | ||
type: object | ||
friendlyName: | ||
description: FriendlyName is the friendly name for the job. | ||
minLength: 5 | ||
type: string | ||
required: | ||
- count | ||
- crongJob | ||
- friendlyName | ||
type: object | ||
required: | ||
- spec | ||
type: object | ||
served: true | ||
storage: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.