fabric8: Add a configmap

866 Views Asked by At

I've been able to build and deploy my spring boot service image into openshift using fabric8 plugin.

I need to add some configmap.

I've tried to add an striaghtforward configmap.yml into src/main/fabric8.

Currently, I'm getting this message:

[INFO] --- fabric8-maven-plugin:4.4.1:resource (default-cli) @ connector ---
[INFO] F8: Using Container image name of namespace: arxius-linia
[INFO] F8: Running generator spring-boot
[INFO] F8: spring-boot: Using Container image fabric8/java-centos-openjdk11-jdk:1.6.3 as base / builder
[INFO] F8: using resource templates from /home/jeusdi/projects/arxius-linia/connector/src/main/fabric8
[INFO] F8: fmp-controller: Adding a default Deployment
[INFO] F8: fmp-service: Adding a default service 'connector' with ports [8080]
[WARNING] F8: fmp-git: Could not detect any git remote
[WARNING] F8: fmp-git: Could not detect any git remote
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  20.839 s
[INFO] Finished at: 2020-11-25T14:08:29+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:fabric8-maven-plugin:4.4.1:resource (default-cli) on project connector: Execution default-cli of goal io.fabric8:fabric8-maven-plugin:4.4.1:resource failed.: NullPointerException -> [Help 1]

My configmap.yml is:

data:
  application.properties: |
    spring.profiles.active=dev

My current related pom.xml configuration is:

<build>
    <plugins>
        <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <version>4.4.1</version>
        </plugin>
   </plugins>
</build>

It's zero configuration based.

Any ideas about how to add my configmap.yml?

1

There are 1 best solutions below

0
On BEST ANSWER

I'm from Fabric8/Eclipse JKube team.

As I've mentioned in the comment, you should try switching to Eclipse JKube since it's going to be supported in future. Migrating to Eclipse JKube is as simple as running this goal:

$ mvn org.eclipse.jkube:kubernetes-maven-plugin:migrate

I tried out your ConfigMap resource fragment with this version of kubernetes-maven-plugin in one of my demo projects:

      <plugin>
        <groupId>org.eclipse.jkube</groupId>
        <artifactId>kubernetes-maven-plugin</artifactId>
        <version>1.1.0</version>
        <executions>
          <execution>
            <goals>
              <goal>resource</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

I added your ConfigMap to my src/main/jkube directory:

eclipse-jkube-sample-with-resource-fragments : $ cat src/main/jkube/second-configmap.yaml 
data:
  application.properties: |
    spring.profiles.active=dev

When I did mvn k8s:resource k8s:apply, I was able to see ConfigMap being created:

eclipse-jkube-sample-with-resource-fragments : $ mvn k8s:resource k8s:apply
[INFO] Scanning for projects... 
[INFO] 
[INFO] -------< org.eclipse.jkube.quickstarts.maven:external-resources >-------
[INFO] Building Eclipse JKube :: Quickstarts :: Maven :: External Resources 1.1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.1.0:resource (default-cli) @ external-resources ---
[INFO] k8s: Running generator spring-boot
[INFO] k8s: spring-boot: Using Docker image quay.io/jkube/jkube-java-binary-s2i:0.0.9 as base / builder
[INFO] k8s: Using resource templates from /home/rohaan/work/repos/eclipse-jkube-sample-with-resource-fragments/src/main/jkube                                                                                                 
[INFO] k8s: jkube-controller: Adding a default Deployment
[INFO] k8s: jkube-healthcheck-spring-boot: Adding readiness probe on port 8080, path='/health', scheme='HTTP', with initial delay 10 seconds                                                                                  
[INFO] k8s: jkube-healthcheck-spring-boot: Adding liveness probe on port 8080, path='/health', scheme='HTTP', with initial delay 180 seconds                                                                                  
[INFO] k8s: jkube-service-discovery: Using first mentioned service port '80' 
[INFO] k8s: jkube-revision-history: Adding revision history limit to 2
[INFO] k8s: validating /home/rohaan/work/repos/eclipse-jkube-sample-with-resource-fragments/target/classes/META-INF/jkube/kubernetes/ribbon-serviceaccount.yml resource                                                       
[INFO] k8s: validating /home/rohaan/work/repos/eclipse-jkube-sample-with-resource-fragments/target/classes/META-INF/jkube/kubernetes/external-resources-service.yml resource                                                  
[INFO] k8s: validating /home/rohaan/work/repos/eclipse-jkube-sample-with-resource-fragments/target/classes/META-INF/jkube/kubernetes/game-config-env-file-configmap.yml resource                                              
[INFO] k8s: validating /home/rohaan/work/repos/eclipse-jkube-sample-with-resource-fragments/target/classes/META-INF/jkube/kubernetes/second-configmap.yml resource                                                            
[INFO] k8s: validating /home/rohaan/work/repos/eclipse-jkube-sample-with-resource-fragments/target/classes/META-INF/jkube/kubernetes/external-resources-deployment.yml resource
[INFO] k8s: validating /home/rohaan/work/repos/eclipse-jkube-sample-with-resource-fragments/target/classes/META-INF/jkube/kubernetes/my-ingress-ingress.yml resource
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.1.0:apply (default-cli) @ external-resources ---
[INFO] k8s: Using Kubernetes at https://192.168.39.102:8443/ in namespace default with manifest /home/rohaan/work/repos/eclipse-jkube-sample-with-resource-fragments/target/classes/META-INF/jkube/kubernetes.yml 
[INFO] k8s: Creating a ServiceAccount from kubernetes.yml namespace default name ribbon
[INFO] k8s: Created ServiceAccount: target/jkube/applyJson/default/serviceaccount-ribbon-1.json
[INFO] k8s: Creating a Service from kubernetes.yml namespace default name external-resources
[INFO] k8s: Created Service: target/jkube/applyJson/default/service-external-resources-1.json
[INFO] k8s: Creating a ConfigMap from kubernetes.yml namespace default name game-config-env-file
[INFO] k8s: Created ConfigMap: target/jkube/applyJson/default/configmap-game-config-env-file-1.json
[INFO] k8s: Creating a ConfigMap from kubernetes.yml namespace default name second
[INFO] k8s: Created ConfigMap: target/jkube/applyJson/default/configmap-second-1.json
[INFO] k8s: Creating a Deployment from kubernetes.yml namespace default name external-resources
[INFO] k8s: Created Deployment: target/jkube/applyJson/default/deployment-external-resources-1.json
[INFO] k8s: Applying Ingress my-ingress from kubernetes.yml
[INFO] k8s: HINT: Use the command `kubectl get pods -w` to watch your pods start up
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.821 s
[INFO] Finished at: 2021-02-09T12:37:38+05:30
[INFO] ------------------------------------------------------------------------

When I checked, I was able to see ConfigMap created in default namespace:

eclipse-jkube-sample-with-resource-fragments : $ kubectl get configmap second -o yaml
apiVersion: v1
data:
  application.properties: |
    spring.profiles.active=dev
kind: ConfigMap
metadata:
  creationTimestamp: "2021-02-09T07:07:37Z"
...