Skip to content

Commit

Permalink
fix : Spring Boot actuator endpoints don't generate if `deployment.ym…
Browse files Browse the repository at this point in the history
…l` fragment is used (eclipse-jkube#1295)

Right now with DeploymentConfigBuilder, TypedVisitor<ContainerBuilder>
is visiting ContainerBuilder twice instead of visiting it once. This is
generating list with duplicate ContainerBuilder elements.

Move DeploymentConfigEnricher lower than Health Check enrichers in order
to do conversion after health checks have been added to Deployment.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia committed Mar 2, 2022
1 parent 9568ece commit 8dad8c4
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Usage:
./scripts/extract-changelog-for-version.sh 1.3.37 5
```
### 1.8.0-SNAPSHOT
* Fix #1295: Spring Boot actuator endpoints failed to generate automatically if `deployment.yml` resource fragment is used

### 1.7.0 (2022-02-25)
* Fix #1315: Pod Log Service works for Jobs with no selector
Expand Down
26 changes: 26 additions & 0 deletions gradle-plugin/it/src/it/spring-boot-with-fragment/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
id 'org.eclipse.jkube.kubernetes' version "${jKubeVersion}"
id 'org.eclipse.jkube.openshift' version "${jKubeVersion}"
id 'org.springframework.boot' version '2.5.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}

group = 'org.eclipse.jkube.integration.tests.gradle'
version = '0.0.1-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

kubernetes {
offline = true
}
openshift {
offline = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/path: /metrics
jkube.io/git-branch: "@ignore@"
prometheus.io/port: "@ignore@"
prometheus.io/scrape: "@ignore@"
jkube.io/git-url: "@ignore@"
jkube.io/git-commit: "@ignore@"
labels:
expose: "true"
app: spring-boot-with-fragment
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: spring-boot-with-fragment
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: spring-boot-with-fragment
provider: jkube
group: org.eclipse.jkube.integration.tests.gradle
- apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
jkube.io/git-url: "@ignore@"
jkube.io/git-commit: "@ignore@"
jkube.io/git-branch: "@ignore@"
labels:
app: spring-boot-with-fragment
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: spring-boot-with-fragment
spec:
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
app: spring-boot-with-fragment
provider: jkube
group: org.eclipse.jkube.integration.tests.gradle
template:
metadata:
annotations:
jkube.io/git-url: "@ignore@"
jkube.io/git-commit: "@ignore@"
jkube.io/git-branch: "@ignore@"
labels:
app: spring-boot-with-fragment
provider: jkube
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
spec:
containers:
- env:
- name: ABC
value: dummy
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: gradle/spring-boot-with-fragment:latest
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /actuator/health
port: 8080
scheme: HTTP
initialDelaySeconds: 180
successThreshold: 1
name: spring-boot
ports:
- containerPort: 8080
name: http
protocol: TCP
- containerPort: 9779
name: prometheus
protocol: TCP
- containerPort: 8778
name: jolokia
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /actuator/health
port: 8080
scheme: HTTP
initialDelaySeconds: 10
successThreshold: 1
securityContext:
privileged: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at:
#
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

---
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: Service
metadata:
name: spring-boot-with-fragment
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: spring-boot-with-fragment
provider: jkube
group: org.eclipse.jkube.integration.tests.gradle
- apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
labels:
provider: jkube
app: spring-boot-with-fragment
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
name: spring-boot-with-fragment
spec:
replicas: 1
selector:
app: spring-boot-with-fragment
provider: jkube
group: org.eclipse.jkube.integration.tests.gradle
template:
metadata:
labels:
provider: jkube
app: spring-boot-with-fragment
version: "@ignore@"
group: org.eclipse.jkube.integration.tests.gradle
spec:
containers:
- env:
- name: ABC
value: dummy
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: spring-boot-with-fragment:latest
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /actuator/health
port: 8080
scheme: HTTP
initialDelaySeconds: 180
name: spring-boot
ports:
- containerPort: 8080
name: http
protocol: TCP
- containerPort: 9779
name: prometheus
protocol: TCP
- containerPort: 8778
name: jolokia
protocol: TCP
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
scheme: HTTP
initialDelaySeconds: 10
securityContext:
privileged: false
triggers:
- type: ConfigChange
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.it.gradle.spring.boot;

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

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at:
#
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

spec:
template:
spec:
containers:
- env:
- name: ABC
value: dummy
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.gradle.plugin.tests;

import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;

import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class SpringBootWithFragmentIT {
@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();

@Test
public void k8sResource_whenRun_generatesK8sManifests() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("spring-boot-with-fragment")
.withArguments("build", "k8sResource", "--stacktrace")
.build();
// Then
ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultKubernetesResourceFile(),
gradleRunner.resolveFile("expected", "kubernetes.yml"));
assertThat(result).extracting(BuildResult::getOutput).asString()
.contains("Running in Kubernetes mode")
.contains("Running generator spring-boot")
.contains("jkube-service: Adding a default service")
.contains("jkube-healthcheck-spring-boot: Adding readiness probe on port 8080")
.contains("jkube-healthcheck-spring-boot: Adding liveness probe on port 8080")
.contains("jkube-service-discovery: Using first mentioned service port '8080' ")
.contains("jkube-revision-history: Adding revision history limit to 2");
}

@Test
public void ocResource_whenRun_generatesOpenShiftManifests() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("spring-boot-with-fragment")
.withArguments("build", "ocResource", "--stacktrace")
.build();
// Then
ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultOpenShiftResourceFile(),
gradleRunner.resolveFile("expected", "openshift.yml"));
assertThat(result).extracting(BuildResult::getOutput).asString()
.contains("Running in OpenShift mode")
.contains("Running generator spring-boot")
.contains("jkube-service: Adding a default service")
.contains("jkube-openshift-deploymentconfig: Converting Deployment to DeploymentConfig")
.contains("jkube-healthcheck-spring-boot: Adding readiness probe on port 8080")
.contains("jkube-healthcheck-spring-boot: Adding liveness probe on port 8080")
.contains("jkube-service-discovery: Using first mentioned service port '8080' ")
.contains("jkube-revision-history: Adding revision history limit to 2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
# Route exposure
- jkube-openshift-service-expose
- jkube-openshift-route
- jkube-openshift-deploymentconfig
- jkube-openshift-project

# Ingress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
# Route exposure
- jkube-openshift-service-expose
- jkube-openshift-route
- jkube-openshift-deploymentconfig
- jkube-openshift-project

# -----------------------------------------
Expand All @@ -66,6 +65,9 @@
# Value merge enrichers
- jkube-container-env-java-options

# DeploymentConfigEnricher converts Deployment into DeploymentConfig
- jkube-openshift-deploymentconfig

# Dependencies shouldn't be enriched anymore, therefore it's last in the list
- jkube-dependency
- jkube-revision-history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public void visit(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder i
.endSpec();
}
});
} else {
}

if (platformMode == PlatformMode.openshift) {
builder.accept(new TypedVisitor<DeploymentConfigBuilder>() {
@Override
public void visit(DeploymentConfigBuilder item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
# Route exposure
- jkube-openshift-service-expose
- jkube-openshift-route
- jkube-openshift-deploymentconfig
- jkube-openshift-project

# Ingress
Expand Down

0 comments on commit 8dad8c4

Please sign in to comment.