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

Update constructor to follow CasC best practices #406

Merged
merged 6 commits into from
Sep 21, 2023

Conversation

vineeth-bandi
Copy link
Collaborator

@vineeth-bandi vineeth-bandi commented Sep 11, 2023

Created a new constructor and getter and setter methods for non-required values as defined here. This is based on best practices for the CasC plugin as defined here. Added sanity check to ensure maxSize >= minSize. Created file CloudConstants.java to define default values for EC2FleetCloud and EC2FleetLabelCloud.

Updated Configuration-as-Code docs to reflect new default values, define min and max config examples, and fix typos and incorrect defaults in previous values.

Testing done

Defining new Clouds in UI and CasC is identical to previous behavior. This has no new tests added because the new functionality is covered by existing tests. Tested in UI and CasC that maxSize when set to be lower than minSize updates to minSize with a warning.

Updated CasC unit tests to handle new defaults. New CasC unit test that checks backwards compatibility with deprecated fieldcredentialsId.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@vineeth-bandi vineeth-bandi requested a review from pdk27 September 11, 2023 20:58
@vineeth-bandi vineeth-bandi marked this pull request as draft September 15, 2023 19:19
@vineeth-bandi vineeth-bandi force-pushed the constructor-best-practices branch 5 times, most recently from b4d73ca to fa8ec22 Compare September 19, 2023 14:08
@vineeth-bandi vineeth-bandi marked this pull request as ready for review September 19, 2023 15:03
@vineeth-bandi vineeth-bandi force-pushed the constructor-best-practices branch from fa8ec22 to 1e0efaa Compare September 19, 2023 17:17
@vineeth-bandi vineeth-bandi requested a review from pdk27 September 19, 2023 17:18
@vineeth-bandi vineeth-bandi force-pushed the constructor-best-practices branch 2 times, most recently from 627e2a4 to 9ad8ead Compare September 19, 2023 21:07

static final int DEFAULT_IDLE_MINUTES = 0;

static final int DEFAULT_MIN_SIZE = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will always leave 1 instance running unless maxTotalUses is set and met i.e. customer might pay for an idle instance due to this default. Was there a reason to change the default from 0 to 1?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Per our offline sync, I understand jelly has a defualt of 1. Can we just make the default 0 ? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, I'll also change the Jelly to reflect this default. I think it makes more sense to not have idle instances.

@@ -0,0 +1,33 @@
package com.amazon.jenkins.ec2fleet;

class CloudConstants {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 🌟


@DataBoundSetter
public void setIdleMinutes(Integer idleMinutes) {
this.idleMinutes = (idleMinutes != null) ? idleMinutes : 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

since the default is already set for this.idleMinutes

if (idleMinutes != null) {
    this.idleMinutes = idleMInutes;
} 

@DataBoundSetter
public void setMaxSize(int maxSize) {
if (maxSize < minSize) {
int newMaxSize = minSize > 0 ? minSize : 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

int newMaxSize = Math.max(1, minSize);?

public int getMaxTotalUses() {
return maxTotalUses;
}

@DataBoundSetter
public void setMaxTotalUses(String maxTotalUses) {
this.maxTotalUses = StringUtils.isBlank(maxTotalUses) ? DEFAULT_MAX_TOTAL_USES : Integer.parseInt(maxTotalUses);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the default is already set.

if (StringUtils.isNotBlank(maxtotalUses)) {
     this.maxTotalUses = Integer.parseInt(maxTotalUses);
}

@vineeth-bandi vineeth-bandi force-pushed the constructor-best-practices branch 6 times, most recently from 94b9d28 to 54c9ce4 Compare September 21, 2023 01:19
Copy link
Collaborator

@pdk27 pdk27 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for making the changes! 🚀

@vineeth-bandi vineeth-bandi force-pushed the constructor-best-practices branch from 54c9ce4 to 273a031 Compare September 21, 2023 14:34
@pdk27 pdk27 merged commit ae77bfa into jenkinsci:master Sep 21, 2023
@pdk27 pdk27 added bug documentation developer PR Label for automated release notes drafter internal and removed developer PR Label for automated release notes drafter labels Sep 25, 2023
vineeth-bandi added a commit that referenced this pull request Oct 31, 2023
vineeth-bandi added a commit that referenced this pull request Oct 31, 2023
@vineeth-bandi vineeth-bandi deleted the constructor-best-practices branch October 12, 2024 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants