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

Fix/autoscaling #301

Merged
merged 2 commits into from
Feb 25, 2021
Merged

Fix/autoscaling #301

merged 2 commits into from
Feb 25, 2021

Conversation

skeith45
Copy link
Contributor

Description

The pull request is to fix the auto-scaling configuration using object variable rather than individual variables.

Two variables had wrong typing so they were being put in config.toml even if set to -1 which should have resulted in those to return empty strings but they were filled with the values has -1 each.

${runners_off_peak_idle_count}
${runners_off_peak_idle_time}

The 3 spaces for the object-based auto-scaling config was shifted from "template/runner-config.tpl" to "template/runners_machine_autoscaling.tpl" since that particular space placement made it so only the first set of
"[[runners.machine.autoscaling]]" were preceded by 3 spaces

Finally, line 3 of "template/runners_machine_autoscaling.tpl" was missing surrounding double-quotes that would also yield invalid configuration.

Migrations required

NO (Shouldn't be at least seeing as setting up auto-scaling using the object variable is currently not working)

Verification

None of the examples currently use the object configuration method rather than the method marked as deprecated.

The parameter used to test was :

runners_machine_autoscaling = [
    {
      timezone   = var.timezone
      idle_count = 0
      idle_time  = 60
      periods = ["* * 0-7,18-23 * * mon-fri *"]
    },
    {
      timezone   = var.timezone
      idle_count = 0
      idle_time  = 60
      periods = ["* * * * * sat,sun *"]
    }
  ]

Documentation

pre-commit script were run and passed

@npalm
Copy link
Collaborator

npalm commented Feb 18, 2021

@skeith45 thanks for your contribution. I put it on my backlog to check the PR in the next days.

Copy link
Collaborator

@npalm npalm left a comment

Choose a reason for hiding this comment

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

First of al thanks for the contribution! I just checked your change, A few questions and remarks

  • I have deployed the deafult example, with the change in this PR the runner agent was not starting. I think the problem is introduced via the formatting of the toml for auto scaling group. Please can you check once again?
  • The PR needs to rebased, due to conflicts with other merged pr's
  • Just wondering which version of tf docs are you using. Since resources are added to the readme.

@skeith45
Copy link
Contributor Author

I'll recheck for the toml. A bit odd that its not working cause I use the same changes that are in this PR in a repo that is used to deploy runners that are currently in-use. Curious if there could be differences due to terraform version? I'm currently using the latest 0.12 version of terraform.

Regarding the conflict, I followed the contributing doc and used master as the starting point but I see that the other pull request got merged into develop and master has yet to change. Is it safe to assume I should using develop as a base? If so it might be pertinent to update the contributing documentation.

Regarding the tf docs version. I'm using tf docs version 0.11.0 (Windows version to be precise, don't know if it makes any difference). Installed it via chocolatey; I see that there is a version 0.11.2 available however.

@npalm
Copy link
Collaborator

npalm commented Feb 24, 2021

I'll recheck for the toml. A bit odd that its not working cause I use the same changes that are in this PR in a repo that is used to deploy runners that are currently in-use. Curious if there could be differences due to terraform version? I'm currently using the latest 0.12 version of terraform.

Did specify in your cae the following variable? runners_machine_autoscaling as is done in the default example?

  # Deprecated, replaced by runners_machine_autoscaling
  # runners_off_peak_periods    = "[\"* * 0-9,17-23 * * mon-fri *\", \"* * * * * sat,sun *\"]"
  # runners_off_peak_timezone   = var.timezone
  # runners_off_peak_idle_count = 0
  # runners_off_peak_idle_time  = 60
  runners_machine_autoscaling = [
    {
      periods    = ["\"* * 0-9,17-23 * * mon-fri *\"", "\"* * * * * sat,sun *\""]
      idle_count = 0
      idle_time  = 60
      timezone   = var.timezone
    }
  ]

see https://github.com/npalm/terraform-aws-gitlab-runner/blob/532eb0b3ecc20502693ad87747274d32aaa8869e/examples/runner-default/main.tf#L81

Regarding the conflict, I followed the contributing doc and used master as the starting point but I see that the other pull request got merged into develop and master has yet to change. Is it safe to assume I should using develop as a base? If so it might be pertinent to update the contributing documentation.

Sorry for the confusion, and I wil upate the contribution guide. Please use the default branch develop.

Regarding the tf docs version. I'm using tf docs version 0.11.0 (Windows version to be precise, don't know if it makes any difference). Installed it via chocolatey; I see that there is a version 0.11.2 available however.

My mistake, it seems my link to the terraform-dcos installation wasn't correct. Generation of the resources was added to version 11. So that is all good.

@skeith45
Copy link
Contributor Author

skeith45 commented Feb 24, 2021

I put in the content of the variable inside the PR main post (changed the value to 9 to 5 in the comment here however) :

runners_machine_autoscaling = [
    {
      timezone   = var.timezone
      idle_count = 0
      idle_time  = 60
      periods = ["* *0-9,17-23 * * mon-fri *"]
    },
    {
      timezone   = var.timezone
      idle_count = 0
      idle_time  = 60
      periods = ["* * * * * sat,sun *"]
    }
  ]

This makes the template file generate two [[runners.machine.autoscaling]] blocks which is how its done in the gitlab runner documentation : Autoscaling Documentation

I guess I should probably remove the join call in the template cause that doesn't work with this method of configuring autoscaling as far as I'm aware.

@skeith45
Copy link
Contributor Author

skeith45 commented Feb 24, 2021

My bad, the period is an array of strings, so I guess it should work if you put multiple periods in it.
But the current code didn't surround the periods with double quotes.
And didn't allow for multiple autoscaling blocks.

I'll try to make sure the multiple period string within same object still work at least. Maybe I broke that.

@npalm
Copy link
Collaborator

npalm commented Feb 24, 2021

I think you aprroach is actually better. This avoid the user has to avoid escaping the double quotes. I just checked the defaullt example and set thre periods to:

periods    = ["* * 0-9,17-23 * * mon-fri *", "* * * * * sat,sun *"]

This is working, drawback is that is breaking backwards compatiblity. But we could add a clear direction for migration. Do you see any good option to remain backwards compatible.

@skeith45
Copy link
Contributor Author

skeith45 commented Feb 24, 2021

I added backward compatibility. It makes the period handling of the template a bit harder to read but it makes it compatible with both methods of writing the autoscaling object.

I didn't test it in an actual runner but I did test the output of the template using the variable below which tests both old and new version of the period. The output is the same for both old and new. (whether you add escaped double quotes or not you'll get the same output)

runners_machine_autoscaling = [
  {
    periods    = ["\"* * 0-9,17-23 * * mon-fri *\"", "\"* * * * * sat,sun *\""]
    idle_count = 0
    idle_time  = 60
    timezone   = "Europe/Amsterdam"
  },
  {
    periods    = ["\"* * * * * sat,sun *\""]
    idle_count = 0
    idle_time  = 60
    timezone   = "Europe/Amsterdam"
  },
  {
    periods    = ["* * 0-9,17-23 * * mon-fri *","* * * * * sat,sun *"]
    idle_count = 0
    idle_time  = 60
    timezone   = "Europe/Amsterdam"
  },
  {
    periods    = ["* * * * * sat,sun *"]
    idle_count = 0
    idle_time  = 60
    timezone   = "Europe/Amsterdam"
  }
]

Copy link
Collaborator

@npalm npalm 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 all the work!

@npalm npalm merged commit 6b35a10 into cattle-ops:develop Feb 25, 2021
github-actions bot pushed a commit that referenced this pull request Feb 28, 2021
## [4.23.0](4.22.0...4.23.0) (2021-02-28)

### Features

* additional config parameter asg_delete_timeout to configure the timeout when trying to delete the ASG ([#305](#305)) ([f60c9d5](f60c9d5))
* allow multilines build scripts ([#282](#282)) ([7000c07](7000c07)), closes [#250](#250)

### Bug Fixes

* autoscaling configuraton ([#301](#301)) ([6b35a10](6b35a10))
* respect create_cache_bucket variable and avoid concurrent changes to cache bucket ([#296](#296)) ([c3629f6](c3629f6))
@semantic-releaser
Copy link
Contributor

🎉 This PR is included in version 4.23.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants