kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

How Can I Create ConfigMap From File

Open stupid-yu opened this issue 3 years ago • 3 comments
trafficstars

Hi, I want to create a configmap from file, is there any api implements the action kubectl create configmap [name] --from-flie=

stupid-yu avatar Jun 02 '22 08:06 stupid-yu

I think this could be a good addition. We do have same functionality in Eclipse JKube ConfigMapEnricher .

We should port this functionality to a static utility method (preferably KubernetesResourceUtil) in KubernetesClient.

Expected Behavior:

Method's expected behavior should be same as defined in Kubernetes Docs.

Creating From File

Given File game.properteis

enemies=aliens
lives=3
enemies.cheat=true
enemies.cheat.level=noGoodRotten
secret.code.passphrase=UUDDLRLRBABAS
secret.code.allowed=true
secret.code.lives=30

When upon running this command:

kubectl create configmap game-config --from-file=game.properties

then this ConfigMap is created:

apiVersion: v1
data:
  game.properties: |-
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
kind: ConfigMap
metadata:
  name: game-config

ConfigMap from directory

Given directory with files:

 $ ls configure-pod-container/configmap/
game.properties  ui.properties

When this command gets invoked:

$ kubectl create configmap game-config --from-file=configure-pod-container/configmap

Then this ConfigMap gets created:

apiVersion: v1
data:
  game.properties: |-
    enemies=aliens
    lives=3
    enemies.cheat=true
    enemies.cheat.level=noGoodRotten
    secret.code.passphrase=UUDDLRLRBABAS
    secret.code.allowed=true
    secret.code.lives=30
  ui.properties: |
    color.good=purple
    color.bad=yellow
    allow.textmode=true
    how.nice.to.look=fairlyNice
kind: ConfigMap
metadata:
  name: game-config
  namespace: default

rohanKanojia avatar Jun 06 '22 19:06 rohanKanojia

We should port this functionality to a static utility method (preferably KubernetesResourceUtil) in KubernetesClient.

Maybe also include it as part of the DSL for ConfigMaps

manusa avatar Jun 07 '22 05:06 manusa

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

stale[bot] avatar Sep 05 '22 06:09 stale[bot]

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

stale[bot] avatar Dec 08 '22 04:12 stale[bot]