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

✨ Feat/allow skipping ami in launch template when EKS managed nodegroup #4388

Conversation

Julian-Chu
Copy link

What type of PR is this?

/kind feature

What this PR does / why we need it:

EKS managed node group can have empty AMI id in launch template. It allows EKS manage AMI for us with custom launch template like user data or storage

Which issue(s) this PR fixes :
Fixes #4377

Special notes for your reviewer:

Checklist:

  • squashed commits
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

Release note:


@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority labels Jul 10, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @Julian-Chu!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-aws 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api-provider-aws has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 10, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @Julian-Chu. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@richardcase
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 11, 2023
@@ -32,6 +32,8 @@ type Service struct {

// SSMClient is used to look up the official EKS AMI ID
SSMClient ssmiface.SSMAPI
// isMock is used to return current mock service instead of creating new one, for testing
isMock bool
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this. Could you take a look at other tests which create this service? :) You can see that we are mocking the scope, which is then, in turn, used to set up these services.

Copy link
Author

Choose a reason for hiding this comment

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

hey @Skarlso
thanks for comment. I saw servicefactory pattern in controller like

// https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/exp/controllers/awsmachinepool_controller.go#L74
func (r *AWSMachinePoolReconciler) getEC2Service(scope scope.EC2Scope) services.EC2Interface {
	if r.ec2ServiceFactory != nil {
		return r.ec2ServiceFactory(scope)
	}

	return ec2.NewService(scope)
}

the issue here is that EC2Service has to create new EC2Service inside the ReconcileLaunchTemplate method, so I can't apply serviceFactory to it. Can we reuse EC2Service instead of creating new one? Any suggestion? 🙏

// https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/pkg/cloud/services/ec2/launchtemplate.go#L64
func (s *Service) ReconcileLaunchTemplate(
	scope scope.LaunchTemplateScope,
	canUpdateLaunchTemplate func() (bool, error),
	runPostLaunchTemplateUpdateOperation func() error,
) error {
        ...
	ec2svc := NewService(scope.GetEC2Scope())
        ...
}


type Service struct {
	scope     scope.EC2Scope
	EC2Client ec2iface.EC2API

	// SSMClient is used to look up the official EKS AMI ID
	SSMClient ssmiface.SSMAPI
}

// NewService returns a new service given the ec2 api client.
func NewService(clusterScope scope.EC2Scope) *Service {
	return &Service{
		scope:     clusterScope,
		EC2Client: scope.NewEC2Client(clusterScope, clusterScope, clusterScope, clusterScope.InfraCluster()),
		SSMClient: scope.NewSSMClient(clusterScope, clusterScope, clusterScope, clusterScope.InfraCluster()),
	}
}

Copy link
Author

Choose a reason for hiding this comment

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

another idea is to create factory in EC2Service, but we still need new fields.

func (s *Service) new(clusterScope scope.EC2Scope) *Service {
	var ec2Client ec2iface.EC2API
	if s.ec2ClientFactory != nil {
		ec2Client = s.ec2ClientFactory()
	} else {
		ec2Client = scope.NewEC2Client(clusterScope, clusterScope, clusterScope, clusterScope.InfraCluster())
	}
	var ssmClient ssmiface.SSMAPI
	if s.ssmClientFactory != nil {
		ssmClient = s.ssmClientFactory()
	} else {
		ssmClient = scope.NewSSMClient(clusterScope, clusterScope, clusterScope, clusterScope.InfraCluster())
	}

	return &Service{
		scope:     clusterScope,
		EC2Client: ec2Client,
		SSMClient: ssmClient,
	}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm so sorry, I will reply to this either this night or tomorrow morning.

@Skarlso PING

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, so you don't need any of that because you have the scope and the ec2Mock EXPECTs. And the scope is mocked and you can control the ec2 service responses from there. From example, GetEC2Scope will return InfraCluster from the MachinePool scope.

So when you set things up here:

		InfraCluster:       mcps,

you should be able to return something canned. I can take a look at that later if you don't find anything. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah crap, I see what you mean. And I see now that we do that with the Service Factory pattern:

			ec2ServiceFactory: func(scope.EC2Scope) services.EC2Interface {
				return ec2Svc
			},

Okay. Would you mind please switching this isMock to that then please? Cheers!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, and sorry it took so long to reply. Eventually, I'll rework this into using proper injection pattern. But that's not gonna happen in this PR. :) Cheers.

Copy link
Author

Choose a reason for hiding this comment

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

hi @Skarlso ,

sorry for late reply, I refactored it in refactor to service factory pattern. If you have time, please take a look.

if you have already done rework in another PR, I would be happy to follow that. 😄

@Julian-Chu
Copy link
Author

/retest

1 similar comment
@Julian-Chu
Copy link
Author

/retest

@Julian-Chu Julian-Chu marked this pull request as ready for review July 12, 2023 15:34
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 12, 2023
@k8s-ci-robot k8s-ci-robot requested a review from richardcase July 12, 2023 15:34
@Julian-Chu Julian-Chu requested a review from Skarlso July 12, 2023 19:59
@Ankitasw
Copy link
Member

Ankitasw commented Sep 5, 2023

@Julian-Chu do you require any help here to proceed with the PR?

@Julian-Chu
Copy link
Author

@Julian-Chu do you require any help here to proceed with the PR?

thanks @Ankitasw . got new comments, I will push new commit when available.

@Julian-Chu
Copy link
Author

/retest

@richardcase
Copy link
Member

/milestone v2.4.0

@k8s-ci-robot k8s-ci-robot added this to the v2.4.0 milestone Oct 16, 2023
@Julian-Chu
Copy link
Author

/retest

@Julian-Chu
Copy link
Author

/retest

@Julian-Chu
Copy link
Author

/retest

@Julian-Chu Julian-Chu requested a review from Skarlso November 28, 2023 07:56
@Julian-Chu
Copy link
Author

hi @Ankitasw, may I have your help? regarding to this error message in PR verify step failed: No matching PR type indicator found in title.
What should I add into the title?

@Skarlso Skarlso removed their request for review November 28, 2023 08:51
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 20, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@richardcase
Copy link
Member

/milestone clear

@k8s-ci-robot k8s-ci-robot removed this from the v2.4.0 milestone Jan 23, 2024
@Ankitasw Ankitasw changed the title Feat/allow skipping ami in launch template when EKS managed nodegroup ✨ Feat/allow skipping ami in launch template when EKS managed nodegroup Jan 25, 2024
@Ankitasw
Copy link
Member

hi @Ankitasw, may I have your help? regarding to this error message in PR verify step failed: No matching PR type indicator found in title. What should I add into the title?

Sorry for late reply, added the PR type for you.

@k8s-ci-robot
Copy link
Contributor

@Julian-Chu: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-aws-build-docker 35d21a5 link true /test pull-cluster-api-provider-aws-build-docker

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 29, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 28, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closed this PR.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Reopen this PR with /reopen
  • Mark this PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-priority needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow empty AMI ID, Instance type in launch template of AWSManagedMachinePool
6 participants