-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #978 from tejasparikh/support-storageclasses-869
- Loading branch information
Showing
12 changed files
with
510 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
...t/src/main/java/io/fabric8/kubernetes/client/dsl/internal/StorageClassOperationsImpl.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,42 @@ | ||
/** | ||
* 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.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<StorageClass, StorageClassList, DoneableStorageClass, Resource<StorageClass, DoneableStorageClass>> { | ||
public StorageClassOperationsImpl(OkHttpClient client, Config config) { | ||
this(client, config, null, null, null, true, null, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()); | ||
} | ||
|
||
public StorageClassOperationsImpl(OkHttpClient client, Config config, String apiVersion, String namespace, String name, Boolean cascading, StorageClass item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map<String, String> labels, Map<String, String> labelsNot, Map<String, String[]> labelsIn, Map<String, String[]> labelsNotIn, Map<String, String> 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; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...netes-client/src/main/java/io/fabric8/kubernetes/client/handlers/StorageClassHandler.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,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. | ||
*/ | ||
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<StorageClass, StorageClassBuilder> { | ||
@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<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).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<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).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<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).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<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).delete(item); | ||
} | ||
|
||
@Override | ||
public Watch watch(OkHttpClient client, Config config, String namespace, StorageClass item, Watcher<StorageClass> watcher) { | ||
return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).watch(watcher); | ||
} | ||
|
||
@Override | ||
public Watch watch(OkHttpClient client, Config config, String namespace, StorageClass item, String resourceVersion, Watcher<StorageClass> watcher) { | ||
return new StorageClassOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).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<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).waitUntilReady(amount, timeUnit); | ||
} | ||
|
||
} |
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
48 changes: 48 additions & 0 deletions
48
...rnetes-examples/src/main/java/io/fabric8/kubernetes/examples/ListStorageClassExample.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,48 @@ | ||
/** | ||
* 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.*; | ||
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); | ||
} | ||
|
||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/StorageClassExamples.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,97 @@ | ||
/** | ||
* 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; | ||
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 StorageClassExamples { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(StorageClassExamples.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 | ||
|
||
String name = UUID.randomUUID().toString(); | ||
ObjectMeta metadata = new ObjectMeta(); | ||
metadata.setName(name); | ||
|
||
Map<String, String> 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") | ||
.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 | ||
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); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.