forked from fabric8io/kubernetes-client
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Integration test for CustomResource with multiple versions
+ Added IT for a CustomResource with two different versions v1 and v1beta1 using the same POJO by providing different CustomResourceDefinitionContexts Related to fabric8io#2738 . This test demonstrates that it's still supported. However we need to discuss this whether this method should be marked as deprecatd or not
- Loading branch information
1 parent
fced0b7
commit 27b9c8e
Showing
8 changed files
with
361 additions
and
1 deletion.
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
36 changes: 36 additions & 0 deletions
36
kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/Bicycle.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,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<BicycleSpec, BicycleStatus> { | ||
private String apiVersion; | ||
|
||
@Override | ||
public void setApiVersion(String version) { | ||
this.apiVersion = version; | ||
} | ||
|
||
@Override | ||
public String getApiVersion() { | ||
return this.apiVersion; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleList.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,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<Bicycle> { | ||
} |
64 changes: 64 additions & 0 deletions
64
kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleSpec.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,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 + "}"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
kubernetes-itests/src/test/java/io/fabric8/crd/bicycle/BicycleStatus.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.bicycle; | ||
|
||
public class BicycleStatus { | ||
private boolean isInUse; | ||
public boolean isInUse() { | ||
return isInUse; | ||
} | ||
|
||
public void setInUse(boolean inUse) { | ||
isInUse = inUse; | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
...test/java/io/fabric8/kubernetes/CustomResourceDefinitionMultipleVersionsSamePojoTest.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,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<Bicycle, BicycleList, Resource<Bicycle>> v1BicycleClient; | ||
private MixedOperation<Bicycle, BicycleList, Resource<Bicycle>> 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 initPetClientAndCurrentNamespace() { | ||
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; | ||
} | ||
} |
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,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 |
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