Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(maven-plugin): log informative message when maven jkube goals are skipped #1142 #1193

Conversation

sunix
Copy link
Member

@sunix sunix commented Jan 5, 2022

Description

Log informative message when maven jkube goals are skipped.

part of #1142

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

@sunix sunix force-pushed the maven-log-informative-message-if-skipped-goal branch 2 times, most recently from 0de8027 to b1f318d Compare January 5, 2022 15:14
@sunix sunix changed the title fix: log informative message when maven jkube goals are skipped #1142 feat: log informative message when maven jkube goals are skipped #1142 Jan 5, 2022
@sunix sunix force-pushed the maven-log-informative-message-if-skipped-goal branch from b1f318d to adb2b15 Compare January 5, 2022 15:19
@sunix sunix changed the title feat: log informative message when maven jkube goals are skipped #1142 feat(maven-plugin): log informative message when maven jkube goals are skipped #1142 Jan 5, 2022
@rohanKanojia
Copy link
Member

a test seems to be failing:

[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.83 s - in org.eclipse.jkube.maven.plugin.mojo.develop.DebugMojoTest
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   HelmPushMojoTest.execute_withSkip_shouldSkipExecution:197 » NullPointer
[INFO] 
[ERROR] Tests run: 36, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ---------------------------------------------------------------------

@sunix
Copy link
Member Author

sunix commented Jan 5, 2022

There is a failing test because I introduced mojoExecution that is null in one of the existing test. Trying to fix it.

@rohanKanojia
Copy link
Member

rohanKanojia commented Jan 5, 2022

Although the current log message is very good. While testing I had a feeling if we really need to do the extra effort of specifying goal name in skip message since the goal getting executed is specified by maven on a line above in logs.

Right now we're doing this:

$ mvn k8s:build k8s:resource k8s:apply -Djkube.version=1.6.0-SNAPSHOT -Djkube.skip=true -Pkubernetes
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------< org.eclipse.jkube.quickstarts.maven:spring-boot >-----------
[INFO] Building Eclipse JKube :: Quickstarts :: Maven :: Spring Boot Web 1.5.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.6.0-SNAPSHOT:build (default-cli) @ spring-boot ---
[INFO] k8s: `k8s:build` goal is skipped.
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.6.0-SNAPSHOT:resource (default-cli) @ spring-boot ---
[WARNING] k8s: Cannot access cluster for detecting mode: Unknown host kubernetes.default.svc: Name or service not known
[INFO] k8s: `k8s:resource` goal is skipped.
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.6.0-SNAPSHOT:apply (default-cli) @ spring-boot ---
[WARNING] k8s: Cannot access cluster for detecting mode: Unknown host kubernetes.default.svc
[INFO] k8s: `k8s:apply` goal is skipped.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.369 s
[INFO] Finished at: 2022-01-05T22:40:46+05:30
[INFO] ------------------------------------------------------------------------

Does it make sense to just keep a simple message like this? If not, we're good with current implementation as well.

$ mvn k8s:build k8s:resource k8s:apply -Djkube.version=1.6.0-SNAPSHOT -Djkube.skip=true -Pkubernetes
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------< org.eclipse.jkube.quickstarts.maven:spring-boot >-----------
[INFO] Building Eclipse JKube :: Quickstarts :: Maven :: Spring Boot Web 1.5.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.6.0-SNAPSHOT:build (default-cli) @ spring-boot ---
[INFO] k8s: Skipped.
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.6.0-SNAPSHOT:resource (default-cli) @ spring-boot ---
[WARNING] k8s: Cannot access cluster for detecting mode: Unknown host kubernetes.default.svc: Name or service not known
[INFO] k8s: Skipped
[INFO] 
[INFO] --- kubernetes-maven-plugin:1.6.0-SNAPSHOT:apply (default-cli) @ spring-boot ---
[WARNING] k8s: Cannot access cluster for detecting mode: Unknown host kubernetes.default.svc
[INFO] k8s: Skipped
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.410 s
[INFO] Finished at: 2022-01-05T22:42:35+05:30
[INFO] ------------------------------------------------------------------------

@sunix
Copy link
Member Author

sunix commented Jan 5, 2022

from the user perspective kubernetes-maven-plugin:1.6.0-SNAPSHOT:resource is not as straightforward as k8s:resource. I personally prefer mentioning the goal that is skipped rather than just Skipped.

@rohanKanojia
Copy link
Member

okay, let's keep it the way it is 👍

@sunix sunix force-pushed the maven-log-informative-message-if-skipped-goal branch from adb2b15 to f98a290 Compare January 6, 2022 13:23
@codecov
Copy link

codecov bot commented Jan 6, 2022

Codecov Report

Merging #1193 (a58d233) into master (d8825b7) will increase coverage by 0.02%.
The diff coverage is 31.70%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1193      +/-   ##
============================================
+ Coverage     49.57%   49.60%   +0.02%     
- Complexity     3656     3663       +7     
============================================
  Files           455      455              
  Lines         20625    20631       +6     
  Branches       2814     2814              
============================================
+ Hits          10225    10234       +9     
+ Misses         9315     9311       -4     
- Partials       1085     1086       +1     
Impacted Files Coverage Δ
...be/maven/plugin/mojo/build/AbstractDockerMojo.java 17.92% <18.75%> (+3.02%) ⬆️
...ube/maven/plugin/mojo/build/AbstractJKubeMojo.java 79.54% <77.77%> (+0.97%) ⬆️
...lipse/jkube/maven/plugin/mojo/build/BuildMojo.java 8.33% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8825b7...a58d233. Read the comment docs.

@sunix
Copy link
Member Author

sunix commented Jan 7, 2022

the codecov/patch error is caused by existing lines I have moved to a dedicated method ....

Comment on lines +410 to +425
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
init();
if (!canExecute()) {
log.info("`%s` goal is skipped.", mojoExecution.getMojoDescriptor().getFullGoalName());
return;
}
doExecute();
}
Copy link
Member

Choose a reason for hiding this comment

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

I understand that this reorganization is similar to what was discussed in #1198 (review)

However, there's already an issue to cover this (#147). Code reorganization at this point might make it harder to refactor later on. Especially since this class now has an execute, executeInternal, and doExecute methods with no clear separation of purposes (at least semantically speaking).

For the current PR I would rather not change (complicate) more the structure of the class (although I do agree the execute method is more readable now), end delay that effort until the whole refactor (+ maybe removal) of the class.

Copy link
Member Author

Choose a reason for hiding this comment

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

semantically:

  • execute is the public method
  • executeInternal is the execution implementation extended by subclasses -> should be abstract
  • I added doExecute which is the execution code from the abstract class. executed if not skipped

Basically at the end of the day after refactoring
execute()
should call doExecute
that should call executeInternal.

I am open to a better naming or suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

I understand what each does, but there's no clear separation of concerns. If all of the methods are executing stuff, why are you separating two of them... i.e. naming is fine, but separation isn't.

Anyway, this refactor right now introduces more burden if we want to tackle #147, which is the cleaner approach. The point here would be to add the simple log message and try to move on without changing too much what we already have. IMO it would be better to spend the time creating tests that would ensure a successful latter refactor.

Copy link
Member Author

Choose a reason for hiding this comment

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

I initially refactored because it was easier to test.
I refactored again. That should help to tackle #147 IMHO

Copy link
Member

Choose a reason for hiding this comment

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

I think I might not have explained myself clear.

If the refactor is required to improve or ease the test scenarios, then it's OK, period.

If the refactor or reorganization is to clean up, improve readability etc. what I was trying to say is that this effort will be wasted if we finally implement 147 (which we should). It might even complicate things further. Efforts should be pushed towards testing the current functionalities of the final Mojos so that the upcoming refactor can be done in a safe way.

Anyway, it's OK as it is. Let's move on.

@sunix sunix force-pushed the maven-log-informative-message-if-skipped-goal branch 4 times, most recently from 5a4634b to c82d91d Compare January 21, 2022 12:18
@sunix
Copy link
Member Author

sunix commented Jan 21, 2022

@manusa should be ok to merge ?

@manusa
Copy link
Member

manusa commented Jan 21, 2022

@manusa should be ok to merge ?

I'm not sure if this one can be removed:
https://sonarcloud.io/project/issues?id=jkubeio_jkube&pullRequest=1193&resolved=false&types=CODE_SMELL

@sunix
Copy link
Member Author

sunix commented Jan 21, 2022

@manusa should be ok to merge ?

I'm not sure if this one can be removed: https://sonarcloud.io/project/issues?id=jkubeio_jkube&pullRequest=1193&resolved=false&types=CODE_SMELL

let me give a try

…ractDockerMojo for readability

Signed-off-by: Sun Tan <sutan@redhat.com>
@sunix sunix force-pushed the maven-log-informative-message-if-skipped-goal branch from c82d91d to a58d233 Compare January 21, 2022 15:03
@sonarcloud
Copy link

sonarcloud bot commented Jan 21, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

89.5% 89.5% Coverage
0.0% 0.0% Duplication

@sunix
Copy link
Member Author

sunix commented Jan 21, 2022

@manusa should be ok to merge ?

I'm not sure if this one can be removed: https://sonarcloud.io/project/issues?id=jkubeio_jkube&pullRequest=1193&resolved=false&types=CODE_SMELL

fixed

@manusa manusa added this to the 1.6.0 milestone Jan 24, 2022
@manusa manusa merged commit 66fb1a6 into eclipse-jkube:master Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants