0

I am building a spring boot java application with maven and fabric8-maven-plugin for openshift.

The command line I am running is:

mvn -Dfabric8.mode=openshift -Ddocker.skip=true clean install fabric8:resource fabric8:build fabric8:apply -Dfabric8.skipResourceValidation

and I have my openshift deploymentConfig in:

demo/src/main/fabric8/deployment.yml

As a result I would expect that the created deploymentConfig in the namespace my-namespace would have image triggers like:

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
...
spec:
....
  test: false
  triggers:
    - imageChangeParams:
        automatic: true
        containerNames:
          - demo
        from:
          kind: ImageStreamTag
          name: 'demo:latest'
          namespace: my-namespace
      type: ImageChange

But it does NOT. Any suggestions to why the image triggers are not created in the generated deployment config?

Some more details below:

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.1.8.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
  </parent> 

    <groupId>com.samples</groupId>
    <artifactId>demo</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <fabric8-maven-plugin.version>4.4.0</fabric8-maven-plugin.version>
        <!--
      <fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>true</fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>
      <fabric8.openshift.enrichAllWithImageChangeTrigger>true</fabric8.openshift.enrichAllWithImageChangeTrigger>
        -->
    </properties>


  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>4.10</version>
    </dependency>

  </dependencies>   


    <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>     


      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>fabric8-maven-plugin</artifactId>
        <version>${fabric8-maven-plugin.version}</version>
        <configuration>
          <images>
            <image>
              <name>${project.artifactId}</name>
              <build>
                <fromExt>
                  <name>openjdk18-openshift:1.6-16</name>
                  <namespace>internal</namespace>
                  <kind>ImageStreamTag</kind>
                </fromExt>                
                <assembly>
                  <basedir>/deployments</basedir>
                  <descriptorRef>rootWar</descriptorRef>
                </assembly>
                <env>
                  <JAVA_APP_DIR>/deployments</JAVA_APP_DIR>
                </env>
              </build>
            </image>
          </images>
        </configuration>
      </plugin>

        </plugins>
    </build>
</project>

demo/src/main/fabric8/deployment.yml

spec:
  replicas: 1
  strategy:
    activeDeadlineSeconds: 21600
    recreateParams:
      timeoutSeconds: 600
    type: Recreate
  template:
    metadata:
      labels:
        group: com.samples
        project: demo
        provider: fabric8
    spec:
      containers:
      - args:
         - /usr/local/s2i/run
        name: demo
        env:
          - name: JAVA_APP_JAR
            value: /deployments/ROOT.war        

src/main/java/com/samples/DemoApplication.java

package com.samples;

import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
  private static final org.slf4j.Logger log = LoggerFactory.getLogger(DemoApplication.class);

  private String name = "demoApplicationName";

  public String getName() {
    return name;
  }

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }
}
u123
  • 15,603
  • 58
  • 186
  • 303
  • Hi, I'm from Fabric8 team. Ideally ImageChange triggers are added by default for your main container. I tried it on https://github.com/rohanKanojia/fmp-demo-project demo project and I could see ImageChange triggers being generated – Rohan Kumar Feb 25 '20 at 06:45
  • There is one flag also to add ImageChange triggers for all containers: `fabric8.openshift.enrichAllWithImageChangeTrigger` Could you please check if it adds triggers in your case? – Rohan Kumar Feb 25 '20 at 06:46
  • Yes adding: true generates the triggers! Hm strange thought it would work out of the box. Also I did not find any documentation on fabric8.openshift.enrichAllWithImageChangeTrigger – u123 Feb 25 '20 at 09:27
  • Yes, ideally it should work out of the box. That's why I was asking for a reproducible sample so that I could debug why triggers are not getting added :-) – Rohan Kumar Feb 25 '20 at 09:43
  • See updated post. Should contain reproducible sample. Unless I enable true triggers will not be created. Could it be that something has been disabled on openshift platform level? – u123 Feb 26 '20 at 14:00
  • Hi, Sorry for late reply. I checked and I think there is a bug in FMP introduced during sidecar implementation. I've created a PR for this: https://github.com/fabric8io/fabric8-maven-plugin/pull/1794 Would appreciate you could try it out and share feedback. – Rohan Kumar Feb 28 '20 at 15:12

1 Answers1

0

This was a bug in Fabric8 Maven Plugin which has been fixed. It's available in v4.4.1. We are right now working towards rebranding Fabric8 Maven Plugin to Eclipse JKube. Would appreciate if you could try it out(It's the same as FMP, just without Fabric8 brand name). In future, Fabric8 Maven Plugin would be marked as deprecated in favor of Eclipse JKube. I've created a simple project with your provided code and Eclipse JKube in pom.xml:

https://github.com/r0haaaan/fmp-openshift-sample-with-fragments

After running oc:resource goal you can see that triggers are now being generated:

~/work/repos/fmp-samples/fmp-openshift-sample-with-fragments : $ mvn oc:resource
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.samples:demo >--------------------------
[INFO] Building demo 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- openshift-maven-plugin:1.0.0-alpha-2:resource (default-cli) @ demo ---
[INFO] oc: Using docker image name of namespace: rokumar
[INFO] oc: Running generator spring-boot
[INFO] oc: spring-boot: Using Docker image fabric8/java-centos-openjdk8-jdk:1.5.6 as base / builder
[INFO] oc: using resource templates from /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/src/main/jkube
[INFO] oc: jkube-service: Adding a default service 'demo' with ports [8080]
[INFO] oc: jkube-revision-history: Adding revision history limit to 2
[INFO] oc: validating /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/target/classes/META-INF/jkube/openshift/demo-service.yml resource
[INFO] oc: validating /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/target/classes/META-INF/jkube/openshift/demo-deploymentconfig.yml resource
[INFO] oc: validating /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/target/classes/META-INF/jkube/openshift/demo-route.yml resource
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.535 s
[INFO] Finished at: 2020-05-05T21:27:24+05:30
[INFO] ------------------------------------------------------------------------
~/work/repos/fmp-samples/fmp-openshift-sample-with-fragments : $ cat /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/target/classes/META-INF/jkube/openshift/demo-deploymentconfig.yml | tail -n10
  triggers:
  - type: ConfigChange
  - imageChangeParams:
      automatic: true
      containerNames:
      - demo
      from:
        kind: ImageStreamTag
        name: demo:latest
    type: ImageChange
~/work/repos/fmp-samples/fmp-openshift-sample-with-fragments : $ 
Rohan Kumar
  • 5,427
  • 8
  • 25
  • 40