1

I am writing sample program to deploy into Openshift with configmap. I have the following configmap yaml in the source code folder so when devops is setup, Jenkins should pick up this yaml and create/update the configs.

 apiVersion: v1
 kind: ConfigMap
 metadata:
  name: sampleapp
 data:  
  username: usernameTest
  password: passwordTest

However, I could not find the command that would create/update if the config already exist (similar to kubectl apply command). Can you help with the correct command which would create the Resource if the job is run for the first time and update if otherwise.

I also want to create/update the Services,Routes from the yaml files in the src repository.

Thanks.

jack
  • 803
  • 3
  • 15
  • 26
  • 1
    Use ‘oc apply’. The oc command has same sub commands as kubectl still, in addition to its extra options. – Graham Dumpleton May 12 '18 at 18:19
  • I need to create an application using the template, so I used "oc new-app -f sampletemplate.yaml". But when the same command is run again, it gives "resource already exists" error while creating resource. This makes sense, but not sure which command to use in CI/CD which will create the app if new and update the app and resources if already exist. oc apply command does not work with new-app. – jack May 12 '18 at 18:57
  • Use ``oc process`` piped to ``oc apply``. – Graham Dumpleton May 13 '18 at 03:26

2 Answers2

3

you can use "oc apply" command to update the resources already exists.

Like below Example:

#oc process -f openjdk-basic-template.yml  -p APPLICATION_NAME=spring-rest -p SOURCE_REPOSITORY_URL=https://github.com/rest.git -p CONTEXT_DIR='' | oc apply -f-

service "spring-rest" configured
route "spring-rest" created
imagestream "spring-rest" configured
buildconfig "spring-rest" configured
deploymentconfig "spring-rest" configured
Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
3

If you have configmap in yaml file or you store in some place you can do replace it.

oc replace --force -f config-map.yaml this will update the existing configmap (it actually deletes and creates a new one)

After this - I executed: oc set env --from=configmap/example-cm dc/example-dc

Esdras Xavier
  • 867
  • 1
  • 7
  • 18
Springhills
  • 360
  • 1
  • 5
  • 12