forked from fabric8io/kubernetes-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(crd-generator): Add support for selectable fields (fabric8io#6392)
- Loading branch information
Showing
10 changed files
with
256 additions
and
3 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
27 changes: 27 additions & 0 deletions
27
...src/test/java/io/fabric8/crd/generator/approvaltests/selectablefield/SelectableField.java
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,27 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.crd.generator.approvaltests.selectablefield; | ||
|
||
import io.fabric8.crd.generator.annotation.AdditionalSelectableField; | ||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.fabric8.kubernetes.model.annotation.Group; | ||
import io.fabric8.kubernetes.model.annotation.Version; | ||
|
||
@Version("v1alpha1") | ||
@Group("sample.fabric8.io") | ||
@AdditionalSelectableField(jsonPath = ".spec.deepLevel1.name") | ||
public class SelectableField extends CustomResource<SelectableFieldSpec, Void> { | ||
} |
46 changes: 46 additions & 0 deletions
46
...test/java/io/fabric8/crd/generator/approvaltests/selectablefield/SelectableFieldSpec.java
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,46 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.crd.generator.approvaltests.selectablefield; | ||
|
||
import io.fabric8.crd.generator.annotation.SelectableField; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class SelectableFieldSpec { | ||
|
||
@SelectableField | ||
private String id; | ||
|
||
private DeepLevel1 deepLevel1; | ||
|
||
@Data | ||
static class DeepLevel1 { | ||
// targeted from @AdditionalSelectableField | ||
private String name; | ||
|
||
@SelectableField | ||
private Integer fromLevel1; | ||
|
||
private DeepLevel2 deepLevel2; | ||
} | ||
|
||
@Data | ||
static class DeepLevel2 { | ||
@SelectableField | ||
private Boolean fromLevel2; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
.../CRDGeneratorApprovalTest.approvalTest.selectablefields.sample.fabric8.io.v1.approved.yml
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,44 @@ | ||
# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! | ||
apiVersion: "apiextensions.k8s.io/v1" | ||
kind: "CustomResourceDefinition" | ||
metadata: | ||
name: "selectablefields.sample.fabric8.io" | ||
spec: | ||
group: "sample.fabric8.io" | ||
names: | ||
kind: "SelectableField" | ||
plural: "selectablefields" | ||
singular: "selectablefield" | ||
scope: "Cluster" | ||
versions: | ||
- name: "v1alpha1" | ||
schema: | ||
openAPIV3Schema: | ||
properties: | ||
spec: | ||
properties: | ||
deepLevel1: | ||
properties: | ||
deepLevel2: | ||
properties: | ||
fromLevel2: | ||
type: "boolean" | ||
type: "object" | ||
fromLevel1: | ||
type: "integer" | ||
name: | ||
type: "string" | ||
type: "object" | ||
id: | ||
type: "string" | ||
type: "object" | ||
status: | ||
type: "object" | ||
type: "object" | ||
selectableFields: | ||
- jsonPath: ".spec.deepLevel1.deepLevel2.fromLevel2" | ||
- jsonPath: ".spec.deepLevel1.fromLevel1" | ||
- jsonPath: ".spec.deepLevel1.name" | ||
- jsonPath: ".spec.id" | ||
served: true | ||
storage: true |
44 changes: 44 additions & 0 deletions
44
...otations/src/main/java/io/fabric8/crd/generator/annotation/AdditionalSelectableField.java
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,44 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.crd.generator.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Defines a selectable field. Must be placed at the root of the | ||
* custom resource. | ||
* | ||
* @see <a href= | ||
* "https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-selectors">Kubernetes | ||
* Docs - Field Selectors</a> | ||
*/ | ||
@Target({ ElementType.TYPE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Repeatable(AdditionalSelectableFields.class) | ||
public @interface AdditionalSelectableField { | ||
|
||
/** | ||
* The JSON Path to the field. | ||
* | ||
* @return the JSON path | ||
*/ | ||
String jsonPath(); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...tations/src/main/java/io/fabric8/crd/generator/annotation/AdditionalSelectableFields.java
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,27 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.crd.generator.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface AdditionalSelectableFields { | ||
AdditionalSelectableField[] value(); | ||
} |
33 changes: 33 additions & 0 deletions
33
generator-annotations/src/main/java/io/fabric8/crd/generator/annotation/SelectableField.java
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,33 @@ | ||
/* | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.crd.generator.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marks a field as selectable. | ||
* | ||
* @see <a href= | ||
* "https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-selectors">Kubernetes | ||
* Docs - Field Selectors</a> | ||
*/ | ||
@Target({ ElementType.FIELD, ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface SelectableField { | ||
} |