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.
feat (kubernetes-client) : Add DSL support for creating ConfigMap fro…
…m file (fabric8io#4184) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
1bcf0ed
commit 3cff070
Showing
13 changed files
with
273 additions
and
13 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
7 changes: 7 additions & 0 deletions
7
kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/ConfigMapResource.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,7 @@ | ||
package io.fabric8.kubernetes.client.dsl; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
|
||
public interface ConfigMapResource extends Resource<ConfigMap>, | ||
FromFileCreatable<Resource<ConfigMap>> { | ||
} |
11 changes: 11 additions & 0 deletions
11
kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/FromFileCreatable.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,11 @@ | ||
package io.fabric8.kubernetes.client.dsl; | ||
|
||
public interface FromFileCreatable<T> { | ||
/** | ||
* Create new ConfigMap from a directory or file contents. | ||
* | ||
* @param dirOrFilePath a file or directory path | ||
* @return {@link Resource<T> for operations to do with this ConfigMap | ||
*/ | ||
T fromFile(String dirOrFilePath); | ||
} |
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
54 changes: 54 additions & 0 deletions
54
.../main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/ConfigMapOperationsImpl.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,54 @@ | ||
package io.fabric8.kubernetes.client.dsl.internal.core.v1; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.fabric8.kubernetes.api.model.ConfigMapList; | ||
import io.fabric8.kubernetes.client.Client; | ||
import io.fabric8.kubernetes.client.KubernetesClientException; | ||
import io.fabric8.kubernetes.client.dsl.ConfigMapResource; | ||
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperation; | ||
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl; | ||
import io.fabric8.kubernetes.client.dsl.internal.OperationContext; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
|
||
import static io.fabric8.kubernetes.client.utils.KubernetesResourceUtil.createNewConfigMapFromDirOrFile; | ||
|
||
public class ConfigMapOperationsImpl extends HasMetadataOperation<ConfigMap, ConfigMapList, ConfigMapResource> | ||
implements ConfigMapResource { | ||
|
||
public ConfigMapOperationsImpl(Client client) { | ||
this(HasMetadataOperationsImpl.defaultContext(client)); | ||
} | ||
|
||
public ConfigMapOperationsImpl(OperationContext context) { | ||
super(context.withPlural("configmaps"), ConfigMap.class, ConfigMapList.class); | ||
} | ||
|
||
@Override | ||
public ConfigMapOperationsImpl newInstance(OperationContext context) { | ||
return new ConfigMapOperationsImpl(context); | ||
} | ||
|
||
@Override | ||
public ConfigMapResource fromFile(String dirOrFilePath) { | ||
if (dirOrFilePath == null || dirOrFilePath.isEmpty()) { | ||
throw new IllegalArgumentException("invalid file path provided"); | ||
} | ||
File file = Paths.get(dirOrFilePath).toFile(); | ||
if (!file.exists()) { | ||
throw new IllegalArgumentException(String.format("File %s doesn't exist", dirOrFilePath)); | ||
} | ||
|
||
return resource(createNewConfigMap(file.getName(), dirOrFilePath)); | ||
} | ||
|
||
private ConfigMap createNewConfigMap(String fileName, String dirOrFilePath) { | ||
try { | ||
return createNewConfigMapFromDirOrFile(name, fileName, dirOrFilePath); | ||
} catch (IOException ioException) { | ||
throw new KubernetesClientException("Unable to create ConfigMap " + name, ioException); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.