-
Notifications
You must be signed in to change notification settings - Fork 202
Refactor #802: Remove resource object post processing #1521
Conversation
d290284
to
7bd668c
Compare
5bee1ab
to
3323f13
Compare
3323f13
to
259c7cb
Compare
core/src/main/java/io/fabric8/maven/core/util/kubernetes/KubernetesResourceUtil.java
Outdated
Show resolved
Hide resolved
...her/standard/src/main/java/io/fabric8/maven/enricher/standard/DefaultControllerEnricher.java
Outdated
Show resolved
Hide resolved
...her/standard/src/main/java/io/fabric8/maven/enricher/standard/DefaultControllerEnricher.java
Outdated
Show resolved
Hide resolved
enricher/standard/src/main/java/io/fabric8/maven/enricher/standard/PodAnnotationEnricher.java
Outdated
Show resolved
Hide resolved
enricher/standard/src/main/java/io/fabric8/maven/enricher/standard/PodAnnotationEnricher.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
private Boolean isAutomaticTriggerEnabled(MavenEnricherContext enricherContext, Boolean defaultValue) { | ||
if(enricherContext.getProperty("fabric8.openshift.enableAutomaticTrigger") != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If getProperty
can be called without casting then we will not have a Maven dependency anymore.
enricher/api/src/main/java/io/fabric8/maven/enricher/api/Enricher.java
Outdated
Show resolved
Hide resolved
* Detect automatically whether running on OpenShift or Kuberentes. | ||
* This is done by contacting an API server | ||
*/ | ||
auto(true, "Auto"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iiur then "PlatformMode" is used for creating the resources (i.e. for doing the two passes through the enricher chain), and "RuntimeMode" is for deployment (i.e. to select which client to use for applying resources).
What does then "auto" mean here ? I would also recommend to adapt the documentation to better reflect this distinction.
@@ -293,10 +278,8 @@ | |||
// Access for creating OpenShift binary builds | |||
private ClusterAccess clusterAccess; | |||
|
|||
private PlatformMode platformMode; | |||
private RuntimeMode runtimeMode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be no reference to the runtimeMode in ResourceMojo. Do you know why this is needed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used to find out which runtime we're using here and setting some properties(Maybe they were relevant in fabric8 context):
fabric8-maven-plugin/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java
Line 489 in 19c3689
platformMode = clusterAccess.resolvePlatformMode(mode, log); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus we add ImageChange triggers in deployment config based on runtime mode:
Lines 117 to 127 in 19c3689
if (mode.equals(PlatformMode.openshift)) { | |
for (Map.Entry<String, String> entry : containerToImageMap.entrySet()) { | |
String containerName = entry.getKey(); | |
ImageName image = new ImageName(entry.getValue()); | |
String tag = image.getTag() != null ? image.getTag() : "latest"; | |
specBuilder.addNewTrigger() | |
.withType("ImageChange") | |
.withNewImageChangeParams() | |
.withAutomatic(enableAutomaticTrigger) | |
.withNewFrom() | |
.withKind("ImageStreamTag") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really try hard to get rid of this. I.e. we should check who is using this property and seek for a solution which doesn't involve this runtime mode.
The reason why I'm arguing so hard for removing it is that it can't be that the resources are created differently depending on whether you are connected to a Kuberntes or OpenShift cluster. This totally defeats repeatable builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the DeploymentOpenShiftConverter should either use the new PlatformMode or we should question why it adds the image trigger here. If this is because e.g. needed for 'fabric8:build' triggering a redeployment, then this functionality should go to 'fabric8:build' to patch existing deployment configs, or even trigger a redeployment on their own.
plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java
Show resolved
Hide resolved
@@ -416,18 +399,17 @@ public void executeInternal() throws MojoExecutionException, MojoFailureExceptio | |||
resolvedImages = getResolvedImages(images, log); | |||
if (!skip && (!isPomProject() || hasFabric8Dir())) { | |||
// Extract and generate resources which can be a mix of Kubernetes and OpenShift resources | |||
KubernetesList resources = generateResources(resolvedImages, remoteResources); | |||
// Adapt list to use OpenShift specific resource objects | |||
KubernetesList openShiftResources = convertToOpenShiftResources(resources); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 yeah, finally ;-)
plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java
Outdated
Show resolved
Hide resolved
plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java
Outdated
Show resolved
Hide resolved
6ae4cbe
to
9ffd67f
Compare
cdcb17f
to
e0df31d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment
import io.fabric8.maven.core.util.kubernetes.KubernetesHelper; | ||
import io.fabric8.maven.docker.config.ImageConfiguration; | ||
import io.fabric8.maven.docker.util.ImageName; | ||
import io.fabric8.openshift.api.model.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid star import.
e0df31d
to
334d1f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work, really love it.
I did some sanity checks on ResourceMojo and the Enricher API, see my comments.
The only thing which we really should fix is the usage of the RuntimeMode during resource creation. IMO we should get rid of this by checking where it is used and either find a different way to implement that behaviour or, in the worst case, remove that functionality then (and maybe implement it differently).
@rohanKanojia it would be awesome if you could identify the remaining use cases of the RuntimeMode in ResourceMojo.
@@ -293,10 +278,8 @@ | |||
// Access for creating OpenShift binary builds | |||
private ClusterAccess clusterAccess; | |||
|
|||
private PlatformMode platformMode; | |||
private RuntimeMode runtimeMode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really try hard to get rid of this. I.e. we should check who is using this property and seek for a solution which doesn't involve this runtime mode.
The reason why I'm arguing so hard for removing it is that it can't be that the resources are created differently depending on whether you are connected to a Kuberntes or OpenShift cluster. This totally defeats repeatable builds.
@@ -63,14 +37,12 @@ | |||
* | |||
* @param builder the build to examine and add to | |||
*/ | |||
void addMissingResources(KubernetesListBuilder builder); | |||
void enrich(PlatformMode platformMode, KubernetesListBuilder builder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice now ! It has now the two inner passes from the initial suggestion.
Wdyt about renaming these two methods to "create" (was "enrich") and to "enrich" (was "adapt") as suggested in #678 ?
That way we can clearly indicate the intension of this API, too.
OpenShiftDependencyResources getOpenshiftDependencyResources(); | ||
PlatformMode getPlatformMode(); | ||
|
||
RuntimeMode getRuntimeMode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must not be there. (see other comments)
|
||
Object getProperty(String key); | ||
|
||
Properties getProperties(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's about having only one of these methods to keep the API slim?
Alternatively, you could make getProperty()
a "default" interface method, too.
And don't forget to add JavaDoc. While I wouldn't insist on having docs everywhere, for public API which are used e.g. for implementing Enrichers, good documentation is mandatory.
f03d063
to
6db2ffa
Compare
6db2ffa
to
653c95e
Compare
+ Remove of getLabels(), getAnnotations() + Remove getSelector(), addMetadata() + Rename enrich() -> create() and adapt() -> enrich() for better readability. + Removed RuntimeMode from ResourceMojo
653c95e
to
a456ac4
Compare
Refactor #678 #802