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

Use dependency injection in tasks #3897

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Sineaggi
Copy link
Contributor

@Sineaggi Sineaggi commented Dec 16, 2022

Replaces setters with constructor injection. Allows us to remove nullable annotation, make the private JibExtension fields final, and remove null checks.

Unfortunately there's no TaskContainer#register overload that takes a name, type, constructor args and a configuration action, we work around that by using TaskContainer#register first then calling TaskProvider#configure

@sonarcloud
Copy link

sonarcloud bot commented Dec 16, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

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

57.7% 57.7% Coverage
0.0% 0.0% Duplication

@Sineaggi
Copy link
Contributor Author

Also, I noticed that the JibTask interface had a setJibExtension function, but it wasn't implemented by all tasks registered by the jib plugin, so there was a bit of duplication for other tasks. Not sure if that was by design or a bug. Perhaps JibTask was only meant to be implemented by the main 3 tasks? Regardless, JibTask is now empty.

@Sineaggi Sineaggi force-pushed the use-dependency-injection-in-tasks branch from 2ba8524 to 8203305 Compare January 20, 2023 16:27
@Sineaggi
Copy link
Contributor Author

Sineaggi commented Feb 4, 2023

Bump

@Sineaggi Sineaggi force-pushed the use-dependency-injection-in-tasks branch from 8203305 to 31997f7 Compare February 8, 2023 21:13
@sonarcloud
Copy link

sonarcloud bot commented Feb 8, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

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

57.7% 57.7% Coverage
0.0% 0.0% Duplication

@Sineaggi
Copy link
Contributor Author

Sineaggi commented Feb 8, 2023

@emmileaf Thanks for merging #3890, can you check a look at this as well?

@emmileaf
Copy link
Contributor

emmileaf commented Feb 8, 2023

Will be reviewing this along with #3892 - thanks again for your patience!

@emmileaf
Copy link
Contributor

@Sineaggi Is there any way we could keep the public setJibExtension along with introducing the constructor injection, or are these mutually exclusive?

I'm mainly concerned this might be a breaking change for users, given the context that the JibTask interface was introduced in #926 to expose the public setJibExtension. Though the original workaround that prompted this is no longer relevant, I’m not sure if there may be other use scenarios similar to this comment that we would be breaking here with this removal.

Also, I noticed that the JibTask interface had a setJibExtension function, but it wasn't implemented by all tasks registered by the jib plugin, so there was a bit of duplication for other tasks.

Hmm yeah, I'm not entirely sure why the skaffold tasks didn’t implement the JibTask interface either. But since they don’t have any custom setJibExtension logic, I don’t see an issue with adding implements JibTask to these as well, to reduce the duplication.

@Sineaggi
Copy link
Contributor Author

Is there any way we could keep the public setJibExtension along with introducing the constructor injection, or are these mutually exclusive?

We could keep the public setter for backwards compatibility.

Perhaps we could require the extension to be non-null in the setter, but still have it initialized via the constructor?

Copy link
Contributor

@emmileaf emmileaf left a comment

Choose a reason for hiding this comment

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

We could keep the public setter for backwards compatibility.
Perhaps we could require the extension to be non-null in the setter, but still have it initialized via the constructor?

I think that would be a good idea. Could we update this implementation so that the extension is required to be non-null in the private field and getter, gets initialized via the constructor, but has the public setter available? Thanks!

Copy link
Contributor

@mpeddada1 mpeddada1 left a comment

Choose a reason for hiding this comment

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

Thanks for opening this PR and helping us improve our code @Sineaggi! One quick question from the UI perspective - Will these changes affect how the jib gradle plugin is defined in a build.gradle file?

Comment on lines 190 to 195

@Override
public BuildImageTask setJibExtension(JibExtension jibExtension) {
this.jibExtension = jibExtension;
return this;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep this public method. I think this was orginally made public to allow BuildImageTask to be further customized: #612 (comment). Removing the method may be a breaking change for folks who are going this route.

* @param jibExtension the {@link JibExtension}
* @return this
*/
Task setJibExtension(JibExtension jibExtension);
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in the previous comment, let's keep this method to maintain backwards compatibility.

@Sineaggi Sineaggi force-pushed the use-dependency-injection-in-tasks branch from 31997f7 to 7276c95 Compare January 23, 2024 01:00
@Sineaggi Sineaggi force-pushed the use-dependency-injection-in-tasks branch from bab01b5 to f325370 Compare January 23, 2024 01:19
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