From e00cdb03a49766b9818111e34b783a9bd105a547 Mon Sep 17 00:00:00 2001 From: Tejas Parikh Date: Sat, 6 Jan 2018 23:11:14 -0500 Subject: [PATCH 1/5] support for storage classes --- .../client/DefaultKubernetesClient.java | 6 ++ .../kubernetes/client/KubernetesClient.java | 3 + .../internal/StorageClassOperationsImpl.java | 42 ++++++++++ .../client/handlers/StorageClassHandler.java | 80 +++++++++++++++++++ .../client/osgi/ManagedKubernetesClient.java | 4 + .../examples/ListStorageClassExample.java | 48 +++++++++++ .../client/DefaultOpenShiftClient.java | 5 ++ .../client/osgi/ManagedOpenShiftClient.java | 5 ++ 8 files changed, 193 insertions(+) create mode 100644 kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java create mode 100644 kubernetes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.java create mode 100644 kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.java diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java index 13e2fd7d0dc..3c783f1a26e 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/DefaultKubernetesClient.java @@ -54,6 +54,7 @@ import io.fabric8.kubernetes.client.dsl.internal.SecurityContextConstraintsOperationsImpl; import io.fabric8.kubernetes.client.dsl.internal.ServiceAccountOperationsImpl; import io.fabric8.kubernetes.client.dsl.internal.ServiceOperationsImpl; +import io.fabric8.kubernetes.client.dsl.internal.StorageClassOperationsImpl; import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.openshift.api.model.DoneableSecurityContextConstraints; import io.fabric8.openshift.api.model.SecurityContextConstraints; @@ -217,6 +218,11 @@ public MixedOperation> storageClasses() { + return new StorageClassOperationsImpl(httpClient, getConfiguration()); + } + @Override public NonNamespaceOperation> customResourceDefinitions() { return new CustomResourceDefinitionOperationsImpl(httpClient, getConfiguration()); diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/KubernetesClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/KubernetesClient.java index 9a7c4f916b2..53df69ec60c 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/KubernetesClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/KubernetesClient.java @@ -103,4 +103,7 @@ public interface KubernetesClient extends Client { MixedOperation> configMaps(); MixedOperation> limitRanges(); + + MixedOperation> storageClasses(); + } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java new file mode 100644 index 00000000000..b7fc9a9074e --- /dev/null +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2018 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.client.dsl.internal; + +import io.fabric8.kubernetes.api.model.DoneableStorageClass; +import io.fabric8.kubernetes.api.model.StorageClass; +import io.fabric8.kubernetes.api.model.StorageClassList; +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; +import okhttp3.OkHttpClient; + +import java.util.Map; +import java.util.TreeMap; + +public class StorageClassOperationsImpl extends HasMetadataOperation> { + public StorageClassOperationsImpl(OkHttpClient client, Config config) { + this(client, config, null, null, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + } + + public StorageClassOperationsImpl(OkHttpClient client, Config config, String apiVersion, String namespace, String name, Boolean cascading, StorageClass item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { + super(client, config, "storage.k8s.io", apiVersion, "storageclasses", namespace, name, cascading, item, resourceVersion, reloadingFromServer, gracePeriodSeconds, labels, labelsNot, labelsIn, labelsNotIn, fields); + } + + @Override + public boolean isResourceNamespaced() { + return false; + } +} diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.java new file mode 100644 index 00000000000..5078339be73 --- /dev/null +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.java @@ -0,0 +1,80 @@ +/** + * Copyright (C) 2018 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.client.handlers; + +import io.fabric8.kubernetes.api.model.StorageClass; +import io.fabric8.kubernetes.api.model.StorageClassBuilder; +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.ResourceHandler; +import io.fabric8.kubernetes.client.Watch; +import io.fabric8.kubernetes.client.Watcher; +import io.fabric8.kubernetes.client.dsl.internal.StorageClassOperationsImpl; +import okhttp3.OkHttpClient; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Service; + +import java.util.TreeMap; +import java.util.concurrent.TimeUnit; + +@Component +@Service +public class StorageClassHandler implements ResourceHandler { + @Override + public String getKind() { + return StorageClass.class.getSimpleName(); + } + + @Override + public StorageClass create(OkHttpClient client, Config config, String namespace, StorageClass item) { + return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).create(); + } + + @Override + public StorageClass replace(OkHttpClient client, Config config, String namespace, StorageClass item) { + return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, true, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).replace(item); + } + + @Override + public StorageClass reload(OkHttpClient client, Config config, String namespace, StorageClass item) { + return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).fromServer().get(); + } + + @Override + public StorageClassBuilder edit(StorageClass item) { + return new StorageClassBuilder(item); + } + + @Override + public Boolean delete(OkHttpClient client, Config config, String namespace, StorageClass item) { + return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).delete(item); + } + + @Override + public Watch watch(OkHttpClient client, Config config, String namespace, StorageClass item, Watcher watcher) { + return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).watch(watcher); + } + + @Override + public Watch watch(OkHttpClient client, Config config, String namespace, StorageClass item, String resourceVersion, Watcher watcher) { + return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).watch(resourceVersion, watcher); + } + + @Override + public StorageClass waitUntilReady(OkHttpClient client, Config config, String namespace, StorageClass item, long amount, TimeUnit timeUnit) throws InterruptedException { + return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()).waitUntilReady(amount, timeUnit); + } + +} diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java index d55c030cbbb..78936cf33d8 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/osgi/ManagedKubernetesClient.java @@ -272,6 +272,10 @@ public MixedOperation> storageClasses() { + return delegate.storageClasses(); + } + @Override public RootPaths rootPaths() { return delegate.rootPaths(); diff --git a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.java b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.java new file mode 100644 index 00000000000..cfac93c8e12 --- /dev/null +++ b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.java @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2018 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.examples; + +import io.fabric8.kubernetes.api.model.*; +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.*; +import org.slf4j.*; + +public class ListStorageClassExample { + + private static final Logger logger = LoggerFactory.getLogger(ListStorageClassExample.class); + + public static void main(String[] args) { + + String master = "http://localhost:8080/"; + + if (args.length == 1) { + master = args[0]; + } + + io.fabric8.kubernetes.client.Config config = new io.fabric8.kubernetes.client.ConfigBuilder().withMasterUrl(master).build(); + + try (final KubernetesClient client = new DefaultKubernetesClient(config)) { + + StorageClassList storageClassList = client.storageClasses().list(); + + logger.info(storageClassList.toString()); + + } catch (KubernetesClientException e) { + logger.error(e.getMessage(), e); + } + + } +} diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java b/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java index bf10ff373f6..ac88a23e5ea 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/DefaultOpenShiftClient.java @@ -387,6 +387,11 @@ public MixedOperation> storageClasses() { + return delegate.storageClasses(); + } + @Override public NamespacedOpenShiftClient inNamespace(String namespace) { OpenShiftConfig updated = new OpenShiftConfigBuilder(new OpenShiftConfig(getConfiguration())) diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java b/openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java index d5a6351c2b6..d6b8bc21ed1 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/osgi/ManagedOpenShiftClient.java @@ -436,6 +436,11 @@ public MixedOperation> storageClasses() { + return delegate.storageClasses(); + } + @Override public MixedOperation> services() { return delegate.services(); From 865b2964af403a5fbb729122d45bdee1777c9276 Mon Sep 17 00:00:00 2001 From: Tejas Parikh Date: Sat, 6 Jan 2018 23:49:15 -0500 Subject: [PATCH 2/5] example code to create new storage class resource. --- .../examples/CreateStorageClassExample.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CreateStorageClassExample.java diff --git a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CreateStorageClassExample.java b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CreateStorageClassExample.java new file mode 100644 index 00000000000..d97415840c0 --- /dev/null +++ b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CreateStorageClassExample.java @@ -0,0 +1,68 @@ +package io.fabric8.kubernetes.examples; + +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.api.model.StorageClass; +import io.fabric8.kubernetes.api.model.StorageClassBuilder; +import io.fabric8.kubernetes.api.model.StorageClassList; +import io.fabric8.kubernetes.client.DefaultKubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class CreateStorageClassExample { + + private static final Logger logger = LoggerFactory.getLogger(CreateStorageClassExample.class); + + public static void main(String[] args) { + + String master = "http://localhost:8080/"; + + if (args.length == 1) { + master = args[0]; + } + + io.fabric8.kubernetes.client.Config config = new io.fabric8.kubernetes.client.ConfigBuilder().withMasterUrl(master).build(); + + try (final KubernetesClient client = new DefaultKubernetesClient(config)) { + + //list all storage classes + StorageClassList storageClassList = client.storageClasses().list(); + logger.info("List of storage classes: {}", storageClassList.toString()); + + //create new storage class + + ObjectMeta metadata = new ObjectMeta(); + metadata.setName(UUID.randomUUID().toString()); + + Map parameters = new HashMap<>(); + parameters.put("resturl", "http://192.168.10.100:8080"); + parameters.put("restuser", ""); + parameters.put("secretNamespace", ""); + parameters.put("secretName", ""); + + StorageClass storageClass = new StorageClassBuilder().withApiVersion("storage.k8s.io/v1") + .withKind("StorageClass") + .withMetadata(metadata) + .withParameters(parameters) + .withProvisioner("k8s.io/minikube-hostpath") + .build(); + + storageClass = client.storageClasses().create(storageClass); + logger.info("Newly created storage class details: {}", storageClass.toString()); + + //list all storage classes + client.storageClasses().list(); + logger.info("List of storage classes: {}", storageClassList.toString()); + + + } catch (KubernetesClientException e) { + logger.error(e.getMessage(), e); + } + + } +} From 478603b18ca20b0400d807c515e77f93a3c497ce Mon Sep 17 00:00:00 2001 From: Tejas Parikh Date: Sun, 7 Jan 2018 16:48:35 -0500 Subject: [PATCH 3/5] added unit tests for storageclass --- ...Example.java => StorageClassExamples.java} | 22 ++++- .../client/mock/StorageSpaceCrudTest.java | 93 +++++++++++++++++++ 2 files changed, 111 insertions(+), 4 deletions(-) rename kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/{CreateStorageClassExample.java => StorageClassExamples.java} (73%) create mode 100644 kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java diff --git a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CreateStorageClassExample.java b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/StorageClassExamples.java similarity index 73% rename from kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CreateStorageClassExample.java rename to kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/StorageClassExamples.java index d97415840c0..bafa5277860 100644 --- a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CreateStorageClassExample.java +++ b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/StorageClassExamples.java @@ -14,9 +14,9 @@ import java.util.Map; import java.util.UUID; -public class CreateStorageClassExample { +public class StorageClassExamples { - private static final Logger logger = LoggerFactory.getLogger(CreateStorageClassExample.class); + private static final Logger logger = LoggerFactory.getLogger(StorageClassExamples.class); public static void main(String[] args) { @@ -36,14 +36,16 @@ public static void main(String[] args) { //create new storage class + String name = UUID.randomUUID().toString(); ObjectMeta metadata = new ObjectMeta(); - metadata.setName(UUID.randomUUID().toString()); + metadata.setName(name); Map parameters = new HashMap<>(); parameters.put("resturl", "http://192.168.10.100:8080"); parameters.put("restuser", ""); parameters.put("secretNamespace", ""); parameters.put("secretName", ""); + parameters.put("key", "value1"); StorageClass storageClass = new StorageClassBuilder().withApiVersion("storage.k8s.io/v1") .withKind("StorageClass") @@ -56,9 +58,21 @@ public static void main(String[] args) { logger.info("Newly created storage class details: {}", storageClass.toString()); //list all storage classes - client.storageClasses().list(); + storageClassList = client.storageClasses().list(); logger.info("List of storage classes: {}", storageClassList.toString()); + //update storage class. add label + storageClass = client.storageClasses().withName(name).edit().editMetadata().addToLabels("testLabel", "testLabelValue").endMetadata().done(); + + //list all storage classes + storageClassList = client.storageClasses().list(); + logger.info("List of storage classes: {}", storageClassList.toString()); + + + //delete storage class + boolean isDeleteSuccessful = client.storageClasses().delete(storageClass); + logger.info("Storage Class resource successfully deleted: {}", isDeleteSuccessful); + } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java new file mode 100644 index 00000000000..05b6da36aff --- /dev/null +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java @@ -0,0 +1,93 @@ +/** + * Copyright (C) 2018 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.client.mock; + +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.api.model.PodBuilder; +import io.fabric8.kubernetes.api.model.PodList; +import io.fabric8.kubernetes.api.model.StorageClass; +import io.fabric8.kubernetes.api.model.StorageClassBuilder; +import io.fabric8.kubernetes.api.model.StorageClassList; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.server.mock.KubernetesServer; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + + +public class StorageSpaceCrudTest { + + private static final Logger logger = LoggerFactory.getLogger(StorageSpaceCrudTest.class); + + @Rule + public KubernetesServer server = new KubernetesServer(true, true); + + @Test + public void testCrud() { + KubernetesClient client = server.getClient(); + + final String name = "test"; + ObjectMeta metadata = new ObjectMeta(); + metadata.setName(name); + + Map parameters = new HashMap<>(); + parameters.put("key", "value"); + + StorageClass storageClass = new StorageClassBuilder().withApiVersion("storage.k8s.io/v1") + .withKind("StorageClass") + .withMetadata(metadata) + .withParameters(parameters) + .withProvisioner("kubernetes.io/aws-ebs") + .build(); + + //test create + storageClass = client.storageClasses().create(storageClass); + assertNotNull(storageClass); + assertEquals(name, storageClass.getMetadata().getName()); + + //test get + StorageClassList storageClassList = client.storageClasses().list(); + logger.info(storageClassList.toString()); + assertNotNull(storageClassList); + assertEquals(1, storageClassList.getItems().size()); + assertEquals("kubernetes.io/aws-ebs", storageClassList.getItems().get(0).getProvisioner()); + assertEquals("value", storageClassList.getItems().get(0).getParameters().get("key")); + assertEquals(0, storageClassList.getItems().get(0).getMetadata().getLabels().size()); + + //test update + storageClass = client.storageClasses().withName(name).edit().editOrNewMetadata().addToLabels("key1", "value1").endMetadata().done(); + logger.info("Updated Storage Class: {} ", storageClass.toString()); + assertNotNull(storageClass); + assertEquals(1, storageClass.getMetadata().getLabels().size()); + + //test delete + boolean result = client.storageClasses().delete(storageClass); + assertEquals(true, result); + StorageClassList storageClassList2 = client.storageClasses().list(); + assertEquals(0, storageClassList2.getItems().size()); + + } +} From 2418570244fb0a90c32b37dcc995a98db66a54e1 Mon Sep 17 00:00:00 2001 From: Tejas Parikh Date: Mon, 8 Jan 2018 23:07:12 -0500 Subject: [PATCH 4/5] add integration tests --- .../io/fabric8/kubernetes/StorageClassIT.java | 103 ++++++++++++++++++ .../src/test/resources/test-storageclass.yml | 26 +++++ 2 files changed, 129 insertions(+) create mode 100644 kubernetes-itests/src/test/java/io/fabric8/kubernetes/StorageClassIT.java create mode 100644 kubernetes-itests/src/test/resources/test-storageclass.yml diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/StorageClassIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/StorageClassIT.java new file mode 100644 index 00000000000..3d51e490b90 --- /dev/null +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/StorageClassIT.java @@ -0,0 +1,103 @@ +/** + * Copyright (C) 2018 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.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.api.model.StorageClass; +import io.fabric8.kubernetes.api.model.StorageClassBuilder; +import io.fabric8.kubernetes.api.model.StorageClassList; +import io.fabric8.kubernetes.client.KubernetesClient; +import static junit.framework.TestCase.assertNotNull; +import org.arquillian.cube.kubernetes.api.Session; +import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes; +import org.arquillian.cube.requirement.ArquillianConditionalRunner; +import org.jboss.arquillian.test.api.ArquillianResource; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@RunWith(ArquillianConditionalRunner.class) +@RequiresKubernetes +public class StorageClassIT { + @ArquillianResource + KubernetesClient client; + + @ArquillianResource + Session session; + + private StorageClass storageClass; + + private String name = UUID.randomUUID().toString(); + + + @Before + public void init() { + ObjectMeta metadata = new ObjectMeta(); + metadata.setName(name); + + Map parameters = new HashMap<>(); + parameters.put("key", "value1"); + + storageClass = new StorageClassBuilder().withApiVersion("storage.k8s.io/v1") + .withKind("StorageClass") + .withMetadata(metadata) + .withParameters(parameters) + .withProvisioner("k8s.io/minikube-hostpath") + .build(); + + client.storageClasses().createOrReplace(storageClass); + } + + @Test + public void load() { + StorageClass storageClassLoaded = client.storageClasses().load(getClass().getResourceAsStream("/test-storageclass.yml")).get(); + assertNotNull(storageClassLoaded); + assertEquals("gluster-vol-default", storageClassLoaded.getMetadata().getName()); + } + + @Test + public void get() { + storageClass = client.storageClasses().withName(name).get(); + assertNotNull(storageClass); + } + + @Test + public void list() { + StorageClassList storageClassList = client.storageClasses().list(); + assertNotNull(storageClassList); + assertTrue(storageClassList.getItems().size() > 1); + } + + @Test + public void update() { + storageClass = client.storageClasses().withName(name).edit().editMetadata().addToLabels("testLabel", "testLabelValue").endMetadata().done(); + assertNotNull(storageClass); + assertEquals("testLabelValue", storageClass.getMetadata().getLabels().get("testLabel")); + } + + @Test + public void delete() { + assertTrue(client.storageClasses().delete(storageClass)); + } + +} diff --git a/kubernetes-itests/src/test/resources/test-storageclass.yml b/kubernetes-itests/src/test/resources/test-storageclass.yml new file mode 100644 index 00000000000..1ee3bcffc07 --- /dev/null +++ b/kubernetes-itests/src/test/resources/test-storageclass.yml @@ -0,0 +1,26 @@ +# +# Copyright (C) 2018 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. +# + +kind: StorageClass +apiVersion: storage.k8s.io/v1 +metadata: + name: gluster-vol-default +provisioner: kubernetes.io/glusterfs +parameters: + resturl: "http://192.168.10.100:8080" + restuser: "" + secretNamespace: "" + secretName: "" From 7ca112942715c45f062c314c5fbde86e7dae1878 Mon Sep 17 00:00:00 2001 From: Tejas Parikh Date: Tue, 9 Jan 2018 10:49:52 -0500 Subject: [PATCH 5/5] updated license headers --- .../dsl/internal/StorageClassOperationsImpl.java | 2 +- .../client/handlers/StorageClassHandler.java | 6 +++--- .../examples/ListStorageClassExample.java | 2 +- .../kubernetes/examples/StorageClassExamples.java | 15 +++++++++++++++ .../io/fabric8/kubernetes/StorageClassIT.java | 11 +++++------ .../src/test/resources/test-storageclass.yml | 2 +- .../client/mock/StorageSpaceCrudTest.java | 7 +++---- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java index b7fc9a9074e..aef6b5043e8 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Red Hat, Inc. + * 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. diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.java index 5078339be73..b6538466eaa 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.java @@ -1,12 +1,12 @@ /** - * Copyright (C) 2018 Red Hat, Inc. + * 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 - * + * 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. diff --git a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.java b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.java index cfac93c8e12..31f55abfa03 100644 --- a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.java +++ b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Red Hat, Inc. + * 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. diff --git a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/StorageClassExamples.java b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/StorageClassExamples.java index bafa5277860..72053e42f4f 100644 --- a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/StorageClassExamples.java +++ b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/StorageClassExamples.java @@ -1,3 +1,18 @@ +/** + * 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.examples; import io.fabric8.kubernetes.api.model.ObjectMeta; diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/StorageClassIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/StorageClassIT.java index 3d51e490b90..df92a1b4b78 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/StorageClassIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/StorageClassIT.java @@ -1,19 +1,18 @@ /** - * Copyright (C) 2018 Red Hat, Inc. - *

+ * 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 - *

+ * + * 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.kubernetes.api.model.ObjectMeta; diff --git a/kubernetes-itests/src/test/resources/test-storageclass.yml b/kubernetes-itests/src/test/resources/test-storageclass.yml index 1ee3bcffc07..29f756300c1 100644 --- a/kubernetes-itests/src/test/resources/test-storageclass.yml +++ b/kubernetes-itests/src/test/resources/test-storageclass.yml @@ -1,5 +1,5 @@ # -# Copyright (C) 2018 Red Hat, Inc. +# 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. diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java index 05b6da36aff..0a83f0e5d4a 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java @@ -1,11 +1,11 @@ /** - * Copyright (C) 2018 Red Hat, Inc. - * + * 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 + * 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, @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.fabric8.kubernetes.client.mock; import io.fabric8.kubernetes.api.model.ObjectMeta;