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

Add support for configuration of credential helper with environment variables #3575

Merged
merged 3 commits into from
Feb 11, 2022

Conversation

tobiade
Copy link
Contributor

@tobiade tobiade commented Feb 10, 2022

Fixes #2814

@zhumin8
Copy link
Contributor

zhumin8 commented Feb 10, 2022

Thanks for your contribution!
I've triggered test runs and our team will review.

<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
Copy link
Member

Choose a reason for hiding this comment

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

We don't run integration tests on GitHub Actions but on a different CI. And we use Java 8 there.

<source>1.8</source>
<target>1.8</target>

<to>
<image>${_TARGET_IMAGE}</image>
<credHelper>
<helper>gcr</helper>
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we don't have an integration test using <credHelper>gcr</credHelper>, which should continue to work. Could you add that too? Thanks!

@@ -180,9 +226,14 @@ public FromConfiguration() {

@Nullable @Parameter private String image;
@Parameter private List<String> tags = Collections.emptyList();
@Nullable @Parameter private String credHelper;
@Parameter private CredHelperParameters credHelper;
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 we can just do

Suggested change
@Parameter private CredHelperParameters credHelper;
@Parameter private CredHelperParameters credHelper = new CredHelperParameters();

and remove the constructor you added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense - will refactor. Out of curiosity - are there any other benefits to the inline initialization you suggested apart from less code?

Copy link
Member

Choose a reason for hiding this comment

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

In this case, nothing other than that, IMO. But we kinda prefer, e.g.,

class Pool {
    private boolean resize = true;
    private Integer size = 10;
}

to

class Pool {
    private boolean resize;
    private Integer size;

    Pool() {
        this.resize = true;
        this.size = new Integer(10);
    }
}

and have been applying this style consistently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it

@Parameter private ToAuthConfiguration auth = new ToAuthConfiguration();

/** Constructor for defaults. */
public ToConfiguration() {
Copy link
Member

Choose a reason for hiding this comment

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

Can be removed by the above.

/** Configuration for {@code [from|to].credHelper} parameter. */
public static class CredHelperParameters implements CredHelperConfiguration {
@Nullable @Parameter private String helper;
@Parameter private Map<String, String> environment;
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Suggested change
@Parameter private Map<String, String> environment;
@Parameter private Map<String, String> environment = new HashMap<>();

and remove the constructor.

import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.Optional;

/** Object in {@link JibExtension} that configures the base image. */
public class BaseImageParameters {
public class BaseImageParameters extends ImageParameters {
Copy link
Member

Choose a reason for hiding this comment

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

We are not really a fan of inheritance for this kind of usage. I'd usually add ImageParameters as a field. But then, the parameter structure doesn't match the actual Jib configuration. (That is, AuthParameters should be a field as we have image.auth.) I think it's still fine to add the cred helper parameters as a field. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I think I get what you mean. I was trying to reduce the code duplication between BaseImageParameters and TargetImageParameters. I guess making ImageParameters a field would mean Jib configuration might have to change? e.g to configure auth we might need to do something like from.image.auth as opposed to from.auth?

If that's the case, I'm happy to revert and keep as it was before while making CredHelperParameters fields in both
BaseImageParameters and TargetImageParameters.

Copy link
Member

Choose a reason for hiding this comment

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

I guess making ImageParameters a field would mean Jib configuration might have to change? e.g to configure auth we might need to do something like from.image.auth as opposed to from.auth?

I think technically it is not impossible to have ImageParameters as a field while retaining the current Jib configuration structure. However, I don't really like doing that. I'd rather have the code structure in sync with Jib configuration.

So yeah, let's keep CredHelperParameters as a field.

@chanseokoh
Copy link
Member

I've triggered test runs and our team will review.

@zhumin8 just FYI, for external contributions, we need to add the kokoro:run label to trigger Kokoro.

@zhumin8
Copy link
Contributor

zhumin8 commented Feb 10, 2022

@chanseokoh Thanks for the reminder.

@tobiade
Copy link
Contributor Author

tobiade commented Feb 10, 2022

Thanks @chanseokoh. I've addressed comments in latest commit.

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

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

Thanks! I'll take another look later.

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

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

Overall, looks go to me. Just a few minor comments.

Also, could you update jib-maven-plugin/CHANGELOG.md and jib-gradle-plugin/CHANGELOG.md? (BTW, don't update other docs about the new configuration parameters in this PR, since we update them after making a release.)

@chanseokoh
Copy link
Member

And you can ignore the SonarCloud failure.

@tobiade
Copy link
Contributor Author

tobiade commented Feb 10, 2022

Thanks @chanseokoh. Updated as discussed.

@sonarcloud
Copy link

sonarcloud bot commented Feb 11, 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 4 Code Smells

85.9% 85.9% Coverage
3.6% 3.6% Duplication

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for your contribution.

@chanseokoh chanseokoh enabled auto-merge (squash) February 11, 2022 23:06
@chanseokoh chanseokoh merged commit 30301c4 into GoogleContainerTools:master Feb 11, 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.

Set environment variables for credHelper
4 participants