diff --git a/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/Bicycle.java b/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/Bicycle.java new file mode 100644 index 00000000000..bba3ea409ca --- /dev/null +++ b/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/Bicycle.java @@ -0,0 +1,36 @@ +/** + * 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.bicycle; + +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Version("v1") +@Group("demos.fabric8.io") +public class Bicycle extends CustomResource { + private String apiVersion; + + @Override + public void setApiVersion(String version) { + this.apiVersion = version; + } + + @Override + public String getApiVersion() { + return this.apiVersion; + } +} diff --git a/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleList.java b/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleList.java new file mode 100644 index 00000000000..c2bc1b13a82 --- /dev/null +++ b/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleList.java @@ -0,0 +1,21 @@ +/** + * 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.bicycle; + +import io.fabric8.kubernetes.client.CustomResourceList; + +public class BicycleList extends CustomResourceList { +} diff --git a/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleSpec.java b/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleSpec.java new file mode 100644 index 00000000000..c0ef58f223b --- /dev/null +++ b/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleSpec.java @@ -0,0 +1,64 @@ +/** + * 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.bicycle; + +public class BicycleSpec { + private int cadence; + private int gear; + private int speed; + private String modelName; + + public int getCadence() { + return cadence; + } + + public void setCadence(int cadence) { + this.cadence = cadence; + } + + public int getGear() { + return gear; + } + + public void setGear(int gear) { + this.gear = gear; + } + + public int getSpeed() { + return speed; + } + + public void setSpeed(int speed) { + this.speed = speed; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + @Override + public String toString() { + return "BicycleSpec{" + + "modelName=" + this.modelName + + "gear=" + this.gear + + "speed=" + this.speed + + "cadence=" + this.cadence + "}"; + } +} diff --git a/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleStatus.java b/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleStatus.java new file mode 100644 index 00000000000..35b8cd6205b --- /dev/null +++ b/kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleStatus.java @@ -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.bicycle; + +public class BicycleStatus { + private boolean isInUse; + public boolean isInUse() { + return isInUse; + } + + public void setInUse(boolean inUse) { + isInUse = inUse; + } +} diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CustomResourceDefinitionMultipleVersionsSamePojoTest.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CustomResourceDefinitionMultipleVersionsSamePojoTest.java new file mode 100644 index 00000000000..5425fc24327 --- /dev/null +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CustomResourceDefinitionMultipleVersionsSamePojoTest.java @@ -0,0 +1,127 @@ +/** + * 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.kubernetes; + +import io.fabric8.commons.AssumingK8sVersionAtLeast; +import io.fabric8.commons.ClusterEntity; +import io.fabric8.crd.bicycle.Bicycle; +import io.fabric8.crd.bicycle.BicycleList; +import io.fabric8.crd.bicycle.BicycleSpec; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext; +import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes; +import org.arquillian.cube.requirement.ArquillianConditionalRunner; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(ArquillianConditionalRunner.class) +@RequiresKubernetes +public class CustomResourceDefinitionMultipleVersionsSamePojoTest { + private MixedOperation> v1BicycleClient; + private MixedOperation> v1beta1BicycleClient; + + @ArquillianResource + KubernetesClient client; + + @ClassRule + public static final AssumingK8sVersionAtLeast assumingK8sVersion = new AssumingK8sVersionAtLeast("1", "16"); + + @BeforeClass + public static void init() { + ClusterEntity.apply(CustomResourceDefinitionMultipleVersionsSamePojoTest.class.getResourceAsStream("/bicycle-crd.yml")); + } + + @Before + public void initBicycleClients() { + v1BicycleClient = client.customResources(new CustomResourceDefinitionContext.Builder() + .withGroup("demos.fabric8.io") + .withPlural("bicycles") + .withVersion("v1") + .withScope("Cluster") + .build(), Bicycle.class, BicycleList.class); + v1beta1BicycleClient = client.customResources(new CustomResourceDefinitionContext.Builder() + .withGroup("demos.fabric8.io") + .withPlural("bicycles") + .withVersion("v1beta1") + .withScope("Cluster") + .build(), Bicycle.class, BicycleList.class); + } + + @Test + public void v1CreateListDelete() { + // Create + String name = "santa-cruz-heckler-mx-carbon"; + Bicycle bicycle = createBicycle("v1", name, 60, 8, 20, "Heckler"); + Bicycle createdBicycle = v1BicycleClient.create(bicycle); + assertThat(createdBicycle).isNotNull(); + + // List + BicycleList bicycleList = v1BicycleClient.list(); + assertThat(bicycleList).isNotNull(); + assertThat(bicycleList.getItems()).hasSizeGreaterThanOrEqualTo(1); + + // Delete + Boolean isDeleted = v1BicycleClient.withName(name).delete(); + assertThat(isDeleted).isTrue(); + } + + @Test + public void v1beta1CreateListDelete() { + // Create + String name = "pinarello-grevil-grx-gravel"; + Bicycle bicycle = createBicycle("v1beta1", name, 68, 4, 18, "GRX 1x 650b Gravel"); + Bicycle createdBicycle = v1beta1BicycleClient.create(bicycle); + assertThat(createdBicycle).isNotNull(); + + // List + BicycleList bicycleList = v1beta1BicycleClient.list(); + assertThat(bicycleList).isNotNull(); + assertThat(bicycleList.getItems()).hasSizeGreaterThanOrEqualTo(1); + + // Delete + Boolean isDeleted = v1beta1BicycleClient.withName(name).delete(); + assertThat(isDeleted).isTrue(); + } + + @AfterClass + public static void cleanup() { + ClusterEntity.remove(CustomResourceDefinitionMultipleVersionsSamePojoTest.class.getResourceAsStream("/bicycle-crd.yml")); + } + + private Bicycle createBicycle(String version, String name, int cadence, int gear, int speed, String modelName) { + Bicycle bicycle = new Bicycle(); + bicycle.setApiVersion(bicycle.getGroup() + "/" + version); + bicycle.setMetadata(new ObjectMetaBuilder().withName(name).build()); + BicycleSpec bicycleSpec = new BicycleSpec(); + + bicycleSpec.setCadence(cadence); + bicycleSpec.setGear(gear); + bicycleSpec.setSpeed(speed); + bicycleSpec.setModelName(modelName); + + return bicycle; + } +} diff --git a/kubernetes-itests/src/test/resources/bicycle-crd.yml b/kubernetes-itests/src/test/resources/bicycle-crd.yml new file mode 100644 index 00000000000..7c34cba59a2 --- /dev/null +++ b/kubernetes-itests/src/test/resources/bicycle-crd.yml @@ -0,0 +1,80 @@ +# +# 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. +# + +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: bicycles.demos.fabric8.io +spec: + group: demos.fabric8.io + versions: + - name: v1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + cadence: + type: integer + gear: + type: integer + speed: + type: integer + modelName: + type: string + status: + type: object + properties: + isInUse: + type: boolean + subresources: + status: {} + - name: v1beta1 + served: true + storage: false + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + cadence: + type: integer + gear: + type: integer + speed: + type: integer + modelName: + type: string + status: + type: object + properties: + isInUse: + type: boolean + subresources: + status: {} + scope: Cluster + names: + plural: bicycles + singular: bicycle + kind: Bicycle + shortNames: + - bicycle