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
- Loading branch information
1 parent
1b4a456
commit 4338099
Showing
6 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
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; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
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,6 @@ | ||
package io.fabric8.crd.bicycle; | ||
|
||
import io.fabric8.kubernetes.client.CustomResourceList; | ||
|
||
public class BicycleList extends CustomResourceList<Bicycle> { | ||
} |
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
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 + "}"; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
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,12 @@ | ||
package io.fabric8.crd.bicycle; | ||
|
||
public class BicycleStatus { | ||
private boolean isInUse; | ||
public boolean isInUse() { | ||
return isInUse; | ||
} | ||
|
||
public void setInUse(boolean inUse) { | ||
isInUse = inUse; | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...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,112 @@ | ||
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,64 @@ | ||
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 |