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

Refactor #802: Remove resource object post processing #1521

Merged
merged 5 commits into from
Feb 26, 2019

Conversation

rohanKanojia
Copy link
Member

Refactor #678 #802

@rohanKanojia rohanKanojia added the pr/wip Work in Progress, do not merge label Feb 13, 2019
@rohanKanojia rohanKanojia force-pushed the pr/issue802 branch 2 times, most recently from 5bee1ab to 3323f13 Compare February 15, 2019 08:02
@rohanKanojia rohanKanojia removed the pr/wip Work in Progress, do not merge label Feb 15, 2019
}

private Boolean isAutomaticTriggerEnabled(MavenEnricherContext enricherContext, Boolean defaultValue) {
if(enricherContext.getProperty("fabric8.openshift.enableAutomaticTrigger") != null) {
Copy link
Contributor

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.

* Detect automatically whether running on OpenShift or Kuberentes.
* This is done by contacting an API server
*/
auto(true, "Auto");
Copy link
Contributor

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;
Copy link
Contributor

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 ?

Copy link
Member Author

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):

platformMode = clusterAccess.resolvePlatformMode(mode, log);

Copy link
Member Author

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:

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")

Copy link
Contributor

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.

Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yeah, finally ;-)

@rohanKanojia rohanKanojia force-pushed the pr/issue802 branch 2 times, most recently from 6ae4cbe to 9ffd67f Compare February 20, 2019 12:19
@rohanKanojia rohanKanojia force-pushed the pr/issue802 branch 3 times, most recently from cdcb17f to e0df31d Compare February 20, 2019 12:39
Copy link
Contributor

@lordofthejars lordofthejars left a 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.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid star import.

Copy link
Contributor

@rhuss rhuss left a 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;
Copy link
Contributor

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);
Copy link
Contributor

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();
Copy link
Contributor

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();
Copy link
Contributor

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.

@rohanKanojia rohanKanojia force-pushed the pr/issue802 branch 2 times, most recently from f03d063 to 6db2ffa Compare February 22, 2019 08:40
@rohanKanojia rohanKanojia added the target/4.0 PR for targeted to 4.0.x label Feb 25, 2019
@rohanKanojia
Copy link
Member Author

@rhuss : I've filed an issue related to refactoring GeneratorContext out of ResourceMojo which can be done later: #1528

+ Remove of getLabels(), getAnnotations()
+ Remove getSelector(), addMetadata()
+ Rename enrich() -> create() and adapt() -> enrich() for better readability.
+ Removed RuntimeMode from ResourceMojo
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target/4.0 PR for targeted to 4.0.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants