Skip to content

Disable ec2 mirror for non aws instances#390

Merged
blackboxsw merged 5 commits into
canonical:masterfrom
lucasmoura:ec2-mirror
Jun 30, 2020
Merged

Disable ec2 mirror for non aws instances#390
blackboxsw merged 5 commits into
canonical:masterfrom
lucasmoura:ec2-mirror

Conversation

@lucasmoura
Copy link
Copy Markdown
Contributor

@lucasmoura lucasmoura commented May 25, 2020

For versions before 20.2, we allowed the use of ec2 mirrors if the datasource availability_zone matches one of the ec2 regions. We are now updating that behavior to allow allow the use of ec2 mirrors on ec2 instances or if the user directly passes an an ec2 mirror url through #cloud-config apt directives.

LP: #1456277

@blackboxsw blackboxsw self-assigned this May 26, 2020
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

I think we may need to revisit this and have a discussion.

I'm actually not certain that this bug is valid anymore.

the %(ec2_region)s mirror lines should have failed to be included on any cloud platform unless their region names happened to be something like eu-west-[0-9][a-z]

because we would have raised a KeyError (and continued instead of appending)

That said, I think we can still cleanup the platform_type matching using your platform_type == "ec2" and then provide such ec2_region and region keys.
One other thing I'm thinking about is that ubuntu cloudimage for azure adds the following custom config
primary:
- http://azure.archive.ubuntu.com/ubuntu/

so I wonder if it's worth considering adding a %(platform)s.archive.ubuntu.com as well as adapting the original %(ec2_region)s.%(platform)s.archive.ubuntu,com

Comment thread cloudinit/config/cc_apt_configure.py Outdated
# list of mirrors to try to resolve
mirror = util.search_for_mirror(mcfg.get("search", None))
search_mirrors = None
params = {'REGION': cloud.datasource.region}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think I'd like to reject this 'feature' to provide REGION magic template string in user cloud-config. I'd like to support one-way to do things, and that's with jinja templates which already provide this feature. We should instead add a documentation example to this json schema definition that shows how to do this

Without a magic REGION template string , a user can override this on their instance by providing the following cloud-config:

#template: jinja
#cloud-config 
apt:
  primary:
    - arches: [default]
      search:
        - http://{{ region }}.ec2.archive.ubuntu.com/ubuntu/

Comment thread cloudinit/distros/__init__.py Outdated
if (ALLOW_EC2_MIRRORS_ON_NON_AWS_INSTANCE_TYPES
and data_source.platform_type == "ec2"):
subst['ec2_region'] = "%s" % ec2_region
elif not ALLOW_EC2_MIRRORS_ON_NON_AWS_INSTANCE_TYPES:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This elif is incorrect isn't it? We only want to set subst[ec2_region'] if any([ data_source.platform_type == "ec2", ALLOW_EC2_MIRRORS_ON_NON_AWS_INSTANCE_TYPES] ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is incorrect 🤦 I will update the logic to fix this

@@ -845,7 +848,13 @@ def _get_package_mirror_info(mirror_info, data_source=None,
# ec2 availability zones are named cc-direction-[0-9][a-d] (us-east-1b)
# the region is us-east-1. so region = az[0:-1]
if _EC2_AZ_RE.match(data_source.availability_zone):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think maybe we can just drop this re.match and instead just specificall check data_source.platform_type == "ec2".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But wouldn't that interfere with past release ? We would like to have past releases still being able to user ec2 mirrors, right ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You are right, darn backward compatibility.

@github-actions
Copy link
Copy Markdown

Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close.

If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging powersj, and he will ensure that someone takes a look soon.

(If the pull request is closed, please do feel free to reopen it if you wish to continue working on it.)

@github-actions github-actions Bot added the stale-pr Pull request is stale; will be auto-closed soon label Jun 23, 2020
@lucasmoura lucasmoura force-pushed the ec2-mirror branch 2 times, most recently from 6d59994 to 0cf79cd Compare June 26, 2020 18:10
@lucasmoura
Copy link
Copy Markdown
Contributor Author

@blackboxsw I have update the PR with the suggested changes. There is just some things that I have some doubts about:

  1. I have verified that when we use a jinja template file as you stated, we get the parsed version on the apt_configure module when we start evaluating the mirrors. But where do you think we should put an example of this change ? Maybe we can add it as an example on the apt_configure module schema ?
  2. I know this is not related to this PR, but just to make sure, we we call this method do we parse the user-data and apply it at the same time or am I missing something ?
  3. I have not yet addressed the distro url in this update, but I do think this is a good idea. Shall I add this to this PR or another one ?

@blackboxsw blackboxsw removed the stale-pr Pull request is stale; will be auto-closed soon label Jun 30, 2020
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Thank @lucasmoura minor text update request (or something similar to the suggestion). Also can you please update the description of the PR to the commit message you would like to see when we squash merge this branch?

@@ -845,7 +848,13 @@ def _get_package_mirror_info(mirror_info, data_source=None,
# ec2 availability zones are named cc-direction-[0-9][a-d] (us-east-1b)
# the region is us-east-1. so region = az[0:-1]
if _EC2_AZ_RE.match(data_source.availability_zone):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You are right, darn backward compatibility.

Comment thread cloudinit/features.py Outdated
Comment on lines +33 to +36
the use of ec2 mirrors if the user region matches one
of the possible aws regions. We are now updating that to only
the use of ec2 mirror for aws instances, unless the user specifically
sets that on the userdata config.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
the use of ec2 mirrors if the user region matches one
of the possible aws regions. We are now updating that to only
the use of ec2 mirror for aws instances, unless the user specifically
sets that on the userdata config.
the use of ec2 mirrors if the datasource availability_zone format
matches one of the possible aws ec2 regions. After the 20.2 release, we
no longer publish ec2 region mirror urls on non-AWS cloud platforms.
Besides feature_overrides.py, users can override this by providing
#cloud-config apt directives.

@lucasmoura
Copy link
Copy Markdown
Contributor Author

@blackboxsw Done, I have updated both descriptions

@lucasmoura lucasmoura requested a review from blackboxsw June 30, 2020 19:21
Copy link
Copy Markdown
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Thanks @lucasmoura

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.

2 participants