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 validation for instanceType and ami architecture #10747

Merged
merged 3 commits into from
Feb 18, 2021

Conversation

bharath-123
Copy link
Contributor

@bharath-123 bharath-123 commented Feb 6, 2021

When an ami and instanceType of different architectures are specified,kops update cluster does not fail even though its an invalid combination.

This can cause side effects like creation of unwanted versions of a launch template, failed cluster creations and so on.

This PR adds checks to validate the chosen instance type architecture against the ami architecture. This PR adds the validation for launch configuration, launch templates and mixed instance policies.

Open question: We are making a DescribeInstanceType call for each instance when validating for mixed instance policies. This can be expensive as more instances are added. Should we feature flag this validation?

UPDATE: I think the number of calls to DescribeInstanceType should be fine as this done only during spec validation and not during cluster creation.

Fixes: #10726

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 6, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @bharath-123. Thanks for your PR.

I'm waiting for a kubernetes 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.

@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/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 6, 2021
@k8s-ci-robot k8s-ci-robot added the area/provider/aws Issues or PRs related to aws provider label Feb 6, 2021
@hakman
Copy link
Member

hakman commented Feb 7, 2021

/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 Feb 7, 2021
@hakman
Copy link
Member

hakman commented Feb 8, 2021

Quick thought @bharath-123, when we debated validation of instance types, we decided to do it at config validation time:

func awsValidateInstanceType(fieldPath *field.Path, instanceType string, cloud awsup.AWSCloud) field.ErrorList {
allErrs := field.ErrorList{}
if instanceType != "" && cloud != nil {
for _, typ := range strings.Split(instanceType, ",") {
if _, err := cloud.DescribeInstanceType(typ); err != nil {
allErrs = append(allErrs, field.Invalid(fieldPath, typ, "machine type specified is invalid"))
}
}
}
return allErrs
}

Probably we should do the same for images and reduce the number of API calls later, when applying changes. I think the instance types are even cached to reduce the number of calls.

/cc @rifelpet

@bharath-123
Copy link
Contributor Author

bharath-123 commented Feb 8, 2021

I was not aware of this validation code. I ll work with this code. I think it makes sense to include during the deep validation phase.

Plus I think the instanceType caching is feature flagged as per https://github.com/kubernetes/kops/blob/master/pkg/featureflag/featureflag.go#L52 ?

@hakman
Copy link
Member

hakman commented Feb 8, 2021

Plus I think the instanceType caching is feature flagged as per https://github.com/kubernetes/kops/blob/master/pkg/featureflag/featureflag.go#L52 ?

Yes, this is the PR #9908. I think can be ignored for the initial implementation.

@bharath-123
Copy link
Contributor Author

@hakman I ll work on moving the validation logic to config validation time. I see the GetMachineTypeInfo

func GetMachineTypeInfo(c AWSCloud, machineType string) (*AWSMachineTypeInfo, error) {
which caches and returns instanceTypeInfo. If I can add a field to cache the architecture field, I think that should be useful over here, don't you think?

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/api and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 11, 2021
@bharath-123 bharath-123 force-pushed the task/arch-validation branch 3 times, most recently from 1f3c1e9 to 7fa96b1 Compare February 11, 2021 19:35
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 15, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 15, 2021
@bharath-123
Copy link
Contributor Author

@olemarkus @rifelpet @hakman Do have a look at this.

@@ -67,6 +67,8 @@ func awsValidateInstanceGroup(ig *kops.InstanceGroup, cloud awsup.AWSCloud) fiel

allErrs = append(allErrs, awsValidateInstanceType(field.NewPath(ig.GetName(), "spec", "machineType"), ig.Spec.MachineType, cloud)...)
Copy link
Member

Choose a reason for hiding this comment

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

Does this make sense anymore? No reason to check the instance type in 2 places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed we can push it to the arch instance type validation function. Will update this

Copy link
Member

@rifelpet rifelpet Feb 16, 2021

Choose a reason for hiding this comment

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

We should also check against all instance types in a mixed instance policy in addition to spec.machineType

EDIT: This is already being done

@bharath-123
Copy link
Contributor Author

I think this should be good for another round of review? @hakman @rifelpet

@rifelpet
Copy link
Member

I'm trying to find any validation that ensures InstanceGroup.Spec.Image is not empty but I don't see anything. I'm not sure if that is a valid case, but if the image were to be empty we would no longer be validating the instance type on its own.

@bharath-123
Copy link
Contributor Author

/retest

@rifelpet
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 18, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bharath-123, rifelpet

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 18, 2021
@k8s-ci-robot k8s-ci-robot merged commit 2407c37 into kubernetes:master Feb 18, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.20 milestone Feb 18, 2021
k8s-ci-robot added a commit that referenced this pull request Feb 19, 2021
…10884-upstream-release-1.20

Automated cherry pick of #10747: Add validation for ami arch to instance type arch #10884: Improve machine type and image validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/api area/provider/aws Issues or PRs related to aws provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure all instance types in mixedInstancesPolicy are the same architecture
4 participants