Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 817b376

Browse files
authored
Merge branch 'master' into spring-boot/issue-880
2 parents 4bfc5e8 + 7733137 commit 817b376

File tree

52 files changed

+303
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+303
-80
lines changed

core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
<parent>
2323
<groupId>io.fabric8</groupId>
2424
<artifactId>fabric8-maven-parent</artifactId>
25-
<version>3.4-SNAPSHOT</version>
25+
<version>3.5-SNAPSHOT</version>
2626
<relativePath>../parent/pom.xml</relativePath>
2727
</parent>
2828

2929
<artifactId>fabric8-maven-core</artifactId>
30-
<version>3.4-SNAPSHOT</version>
30+
<version>3.5-SNAPSHOT</version>
3131

3232
<name>Fabric8 Maven :: Core</name>
3333

core/src/main/java/io/fabric8/maven/core/access/ClusterAccess.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.fabric8.maven.core.config.PlatformMode;
2424
import io.fabric8.maven.docker.util.Logger;
2525
import io.fabric8.openshift.client.DefaultOpenShiftClient;
26+
import io.fabric8.openshift.client.OpenShiftAPIGroups;
2627
import io.fabric8.openshift.client.OpenShiftClient;
2728
import io.fabric8.utils.Strings;
2829

@@ -72,6 +73,18 @@ public String getNamespace() {
7273
return namespace;
7374
}
7475

76+
/**
77+
* Returns true if this cluster is a traditional OpenShift cluster with the <code>/oapi</code> REST API
78+
* or supports the new <code>/apis/image.openshift.io</code> API Group
79+
*/
80+
public boolean isOpenShiftImageStream(Logger log) {
81+
if (isOpenShift(log)) {
82+
OpenShiftClient openShiftClient = createOpenShiftClient();
83+
return openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE);
84+
}
85+
return false;
86+
}
87+
7588
public boolean isOpenShift(Logger log) {
7689
try {
7790
return KubernetesHelper.isOpenShift(createKubernetesClient());
@@ -91,7 +104,7 @@ public PlatformMode resolvePlatformMode(PlatformMode mode, Logger log) {
91104
mode = PlatformMode.DEFAULT;
92105
}
93106
if (mode.isAuto()) {
94-
resolvedMode = isOpenShift(log) ? PlatformMode.openshift : PlatformMode.kubernetes;
107+
resolvedMode = isOpenShiftImageStream(log) ? PlatformMode.openshift : PlatformMode.kubernetes;
95108
} else {
96109
resolvedMode = mode;
97110
}

core/src/main/java/io/fabric8/maven/core/service/ClientToolsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public File getKubeCtlExecutable() {
5151
}
5252
if (file == null) {
5353
throw new IllegalStateException("Could not find " + missingCommandMessage +
54-
". Please try running `mvn fabric8:install` to install the necessary binaries and ensure they get added to your $PATH");
54+
". Please install the necessary binaries and ensure they get added to your $PATH");
5555
}
5656
return file;
5757
}

core/src/main/java/io/fabric8/maven/core/util/KubernetesResourceUtil.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.net.URL;
2525
import java.net.UnknownHostException;
2626
import java.nio.charset.Charset;
27+
import java.text.ParseException;
28+
import java.text.SimpleDateFormat;
2729
import java.util.ArrayList;
2830
import java.util.Arrays;
2931
import java.util.Collection;
@@ -95,9 +97,9 @@
9597
import org.apache.maven.plugin.MojoExecutionException;
9698
import org.apache.maven.project.MavenProject;
9799
import org.apache.maven.shared.utils.StringUtils;
100+
import org.slf4j.LoggerFactory;
98101

99102
import static io.fabric8.kubernetes.api.KubernetesHelper.getName;
100-
import static io.fabric8.kubernetes.api.KubernetesHelper.parseDate;
101103
import static io.fabric8.maven.core.util.Constants.RESOURCE_APP_CATALOG_ANNOTATION;
102104
import static io.fabric8.maven.core.util.Constants.RESOURCE_SOURCE_URL_ANNOTATION;
103105
import static io.fabric8.utils.Strings.isNullOrBlank;
@@ -110,6 +112,8 @@
110112
*/
111113
public class KubernetesResourceUtil {
112114

115+
private static final transient org.slf4j.Logger LOG = LoggerFactory.getLogger(KubernetesResourceUtil.class);
116+
113117
public static final String API_VERSION = "v1";
114118
public static final String API_EXTENSIONS_VERSION = "extensions/v1beta1";
115119
public static final String API_APPS_VERSION = "apps/v1beta1";
@@ -120,6 +124,8 @@ public class KubernetesResourceUtil {
120124

121125
public static final HashSet<Class<?>> SIMPLE_FIELD_TYPES = new HashSet<>();
122126

127+
protected static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";
128+
123129

124130
/**
125131
* Read all Kubernetes resource fragments from a directory and create a {@link KubernetesListBuilder} which
@@ -222,6 +228,7 @@ public boolean accept(File dir, String name) {
222228
"cr", "ClusterRole",
223229
"crole", "ClusterRole",
224230
"clusterrole", "ClusterRole",
231+
"crd", "CustomResourceDefinition",
225232
"crb", "ClusterRoleBinding",
226233
"clusterrb", "ClusterRoleBinding",
227234
"cj", "CronJob",
@@ -581,12 +588,21 @@ public static Date getCreationTimestamp(HasMetadata hasMetadata) {
581588
}
582589

583590
private static Date parseTimestamp(String text) {
584-
if (text == null) {
591+
if (Strings.isNullOrBlank(text)) {
585592
return null;
586593
}
587594
return parseDate(text);
588595
}
589596

597+
public static Date parseDate(String text) {
598+
try {
599+
return new SimpleDateFormat(DATE_TIME_FORMAT).parse(text);
600+
} catch (ParseException e) {
601+
LOG.warn("Unable to parse date: " + text, e);
602+
return null;
603+
}
604+
}
605+
590606
public static boolean podHasContainerImage(Pod pod, String imageName) {
591607
if (pod != null) {
592608
PodSpec spec = pod.getSpec();

doc/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
<parent>
2222
<groupId>io.fabric8</groupId>
2323
<artifactId>fabric8-maven-parent</artifactId>
24-
<version>3.4-SNAPSHOT</version>
24+
<version>3.5-SNAPSHOT</version>
2525
<relativePath>../parent/pom.xml</relativePath>
2626
</parent>
2727

2828
<artifactId>fabric8-maven-doc</artifactId>
29-
<version>3.4-SNAPSHOT</version>
29+
<version>3.5-SNAPSHOT</version>
3030
<packaging>jar</packaging>
3131

3232
<name>Fabric8 Maven :: Documentation</name>

doc/src/main/asciidoc/inc/goals/develop/_fabric8-watch.adoc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,35 @@
55
This goal is used to monitor the project workspace for changes and automatically trigger a redeploy of the application
66
running on Kubernetes.
77

8-
Before entering the watch mode, this goal generates the docker image and the Kubernetes resources
8+
Before entering the watch mode, this goal must generate the docker image and the Kubernetes resources
99
(optionally including some development libraries/configuration),
10-
and deploys the app on Kubernetes.
10+
and deploy the app on Kubernetes. Lifecycle bindings should be configured as follows to allow
11+
the generation of such resources.
1112

12-
[source, sh]
13+
.Lifecycle bindings for fabric8:watch
14+
[source, xml, indent=0]
15+
----
16+
<plugin>
17+
<groupId>io.fabric8</groupId>
18+
<artifactId>fabric8-maven-plugin</artifactId>
19+
20+
<!-- ... -->
21+
22+
<executions>
23+
<execution>
24+
<goals>
25+
<goal>resource</goal>
26+
<goal>build</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
----
32+
33+
For any application having `resource` and `build` goals bound to the lifecycle, the following
34+
command can be used to run the watch task.
35+
36+
[source, bash]
1337
----
1438
mvn fabric8:watch
1539
----

enricher/api/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
<parent>
2121
<groupId>io.fabric8</groupId>
2222
<artifactId>fabric8-maven-parent</artifactId>
23-
<version>3.4-SNAPSHOT</version>
23+
<version>3.5-SNAPSHOT</version>
2424
<relativePath>../../parent/pom.xml</relativePath>
2525
</parent>
2626

2727
<artifactId>fabric8-maven-enricher-api</artifactId>
28-
<version>3.4-SNAPSHOT</version>
28+
<version>3.5-SNAPSHOT</version>
2929

3030
<name>Fabric8 Maven :: Enricher :: API</name>
3131

enricher/api/src/main/java/io/fabric8/maven/enricher/api/EnricherContext.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ public OpenShiftDependencyResources getOpenshiftDependencyResources() {
8585
return openshiftDependencyResources;
8686
}
8787

88+
/**
89+
* Returns true if we are in watch mode
90+
*/
91+
public boolean isWatchMode() {
92+
try {
93+
return runningWithGoal("fabric8:watch-spring-boot", "fabric8:watch");
94+
} catch (MojoExecutionException e) {
95+
throw new IllegalStateException("Cannot determine maven goals", e);
96+
}
97+
}
98+
8899
/**
89100
* Returns true if maven is running with any of the given goals
90101
*/

enricher/fabric8/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
<parent>
2121
<groupId>io.fabric8</groupId>
2222
<artifactId>fabric8-maven-parent</artifactId>
23-
<version>3.4-SNAPSHOT</version>
23+
<version>3.5-SNAPSHOT</version>
2424
<relativePath>../../parent/pom.xml</relativePath>
2525
</parent>
2626

2727
<artifactId>fabric8-maven-enricher-fabric8</artifactId>
28-
<version>3.4-SNAPSHOT</version>
28+
<version>3.5-SNAPSHOT</version>
2929

3030
<name>Fabric8 Maven :: Enricher :: Fabric8</name>
3131

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2016 Red Hat, Inc.
3+
*
4+
* Red Hat licenses this file to you under the Apache License, version
5+
* 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
* implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
package io.fabric8.maven.enricher.fabric8;
18+
19+
import io.fabric8.kubernetes.api.builder.TypedVisitor;
20+
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
21+
import io.fabric8.kubernetes.api.model.ReplicationControllerBuilder;
22+
import io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder;
23+
import io.fabric8.kubernetes.api.model.extensions.ReplicaSetBuilder;
24+
import io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder;
25+
import io.fabric8.maven.enricher.api.BaseEnricher;
26+
import io.fabric8.maven.enricher.api.EnricherContext;
27+
import io.fabric8.openshift.api.model.DeploymentConfigBuilder;
28+
29+
/**
30+
* Enricher for customizing the deployment in fabric8:watch mode.
31+
*
32+
* @author nicola
33+
* @since 16/05/17
34+
*/
35+
public class WatchEnricher extends BaseEnricher {
36+
37+
public WatchEnricher(EnricherContext buildContext) {
38+
super(buildContext, "f8-watch");
39+
}
40+
41+
@Override
42+
public void adapt(KubernetesListBuilder builder) {
43+
if (getContext().isWatchMode()) {
44+
scaleDownToOnePod(builder);
45+
}
46+
}
47+
48+
private void scaleDownToOnePod(KubernetesListBuilder builder) {
49+
50+
builder.accept(new TypedVisitor<ReplicaSetBuilder>() {
51+
@Override
52+
public void visit(ReplicaSetBuilder b) {
53+
b.editOrNewSpec().withReplicas(1).endSpec();
54+
}
55+
});
56+
builder.accept(new TypedVisitor<ReplicationControllerBuilder>() {
57+
@Override
58+
public void visit(ReplicationControllerBuilder b) {
59+
b.editOrNewSpec().withReplicas(1).endSpec();
60+
}
61+
});
62+
builder.accept(new TypedVisitor<DeploymentBuilder>() {
63+
@Override
64+
public void visit(DeploymentBuilder b) {
65+
b.editOrNewSpec().withReplicas(1).endSpec();
66+
}
67+
});
68+
builder.accept(new TypedVisitor<DeploymentConfigBuilder>() {
69+
@Override
70+
public void visit(DeploymentConfigBuilder b) {
71+
b.editOrNewSpec().withReplicas(1).endSpec();
72+
}
73+
});
74+
builder.accept(new TypedVisitor<StatefulSetBuilder>() {
75+
@Override
76+
public void visit(StatefulSetBuilder b) {
77+
b.editOrNewSpec().withReplicas(1).endSpec();
78+
}
79+
});
80+
81+
}
82+
}

0 commit comments

Comments
 (0)