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

kubeadm: skip validating pod subnet against node-cidr-mask when allocate-node-cidrs is set to be false #98984

Merged
merged 1 commit into from Mar 3, 2021

Conversation

SataQiu
Copy link
Member

@SataQiu SataQiu commented Feb 11, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

kubeadm: skip validating pod subnet against node-cidr-mask when allocate-node-cidrs is set to be false

Which issue(s) this PR fixes:

Ref kubernetes/kubeadm#2391

Special notes for your reviewer:

Does this PR introduce a user-facing change?

kubeadm: skip validating pod subnet against node-cidr-mask when allocate-node-cidrs is set to be false

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 11, 2021
@k8s-ci-robot k8s-ci-robot added area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 11, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SataQiu

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 11, 2021
@SataQiu
Copy link
Member Author

SataQiu commented Feb 11, 2021

/cc @aojea

If allocate-node-cidrs is already set to be false, the node IPAM controller will not be enabled.
So is it possible to skip the validation when allocate-node-cidrs is set to be false?

@SataQiu SataQiu changed the title kubeadm: validate pod subnet against node-cidr-mask only when allocate-node-cidrs is set to be true kubeadm: skip validating pod subnet against node-cidr-mask when allocate-node-cidrs is set to be false Feb 11, 2021
@@ -501,8 +501,10 @@ func ValidateNetworking(c *kubeadm.ClusterConfiguration, fldPath *field.Path) fi
}
if len(c.Networking.PodSubnet) != 0 {
allErrs = append(allErrs, ValidateIPNetFromString(c.Networking.PodSubnet, constants.MinimumAddressesInPodSubnet, isDualStack, field.NewPath("podSubnet"))...)
// Pod subnet was already validated, we need to validate now against the node-mask
allErrs = append(allErrs, ValidatePodSubnetNodeMask(c.Networking.PodSubnet, c, field.NewPath("podSubnet"))...)
if c.ControllerManager.ExtraArgs["allocate-node-cidrs"] != "false" {
Copy link
Member

Choose a reason for hiding this comment

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

we need unit tests cmd/kubeadm/app/phases/controlplane/manifests_test.go

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @aojea !
I'm sorry for the delay.
Could you please have a look?

Copy link
Member Author

Choose a reason for hiding this comment

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

If allocation-node-cidrs is not explicitly configured, it will be defaulted as true by kubeadm.
So we should validate the Pod subnet against the node-mask when c.ControllerManager.ExtraArgs["allocate-node-cidrs"] != "false".

Copy link
Member

Choose a reason for hiding this comment

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

I think is correct but let's double check with @neolit123 ^^^

Copy link
Member

Choose a reason for hiding this comment

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

the KCM flag allocate-node-cidrs is false by default, so it makes sense to validate in kubeadm only if the the user has set the flag to true.

Copy link
Member Author

Choose a reason for hiding this comment

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

If the PodSubnet is set and the ExtraArgs["allocate-node-cidrs"] is not set, kubeadm will add allocate-node-cidrs=true flag for KCM automatically.
In this case, can we skip this validation?
Or should we not add the allocate-node-cidrs flag for KCM automatically?

if cfg.Networking.PodSubnet != "" {
defaultArguments["allocate-node-cidrs"] = "true"

Copy link
Member

Choose a reason for hiding this comment

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

the KCM docs say that cluster-cidr requires allocate-node-cidrs, so we should be setting it to true in the default args. adding the flag by default seems correct to me. this make it easier for the user and not require them to pass flags when they wish to set a pod subnet.

extraArgs are merged over default args.
so if the user was explicit about allocate-node-cidrs==false, we should respect it and skip validation in ValidateNetworking.

so the diff here seems valid to me.

@aojea
Copy link
Member

aojea commented Feb 11, 2021

If allocate-node-cidrs is already set to be false, the node IPAM controller will not be enabled.
So is it possible to skip the validation when allocate-node-cidrs is set to be false?

right

@SataQiu
Copy link
Member Author

SataQiu commented Feb 11, 2021

/test pull-kubernetes-e2e-kind

@neolit123
Copy link
Member

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 21, 2021
@neolit123
Copy link
Member

@SataQiu @aojea can we proceed with this PR for 1.21?

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 26, 2021
@aojea
Copy link
Member

aojea commented Feb 26, 2021

this lgtm , defer to @neolit123 to double check this logic #98984 (comment)

@@ -423,7 +423,7 @@ func ValidateServiceSubnetSize(subnetStr string, fldPath *field.Path) field.Erro
}

// ValidatePodSubnetNodeMask validates that the relation between podSubnet and node-masks is correct
func ValidatePodSubnetNodeMask(subnetStr string, c *kubeadm.ClusterConfiguration, fldPath *field.Path) field.ErrorList {
func ValidatePodSubnetNodeMask(subnetStr string, c *kubeadm.ClusterConfiguration, isDualStack bool, fldPath *field.Path) field.ErrorList {
Copy link
Member

@neolit123 neolit123 Feb 26, 2021

Choose a reason for hiding this comment

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

i think we should leave the signature of ValidatePodSubnetNodeMask the way it is.

"dual stack" is a feature gate, and functions like getClusterNodeMask can continue extracting the value from the ClusterConfiguration:
isDualStack := features.Enabled(c.FeatureGates, features.IPv6DualStack)

isIPv6 is not a feature gate, it is a condition that matters to getClusterNodeMask

with this i also means that we don't have to do the vadation._test.go changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Emm, just found isDualStack is already calculated in parent function and a similar function ValidateIPNetFromString has already done like this. 😅

isDualStack := features.Enabled(c.FeatureGates, features.IPv6DualStack)
if len(c.Networking.ServiceSubnet) != 0 {
allErrs = append(allErrs, ValidateIPNetFromString(c.Networking.ServiceSubnet, constants.MinimumAddressesInServiceSubnet, isDualStack, field.NewPath("serviceSubnet"))...)
// Service subnet was already validated, we need to validate now the subnet size
allErrs = append(allErrs, ValidateServiceSubnetSize(c.Networking.ServiceSubnet, field.NewPath("serviceSubnet"))...)
}
if len(c.Networking.PodSubnet) != 0 {
allErrs = append(allErrs, ValidateIPNetFromString(c.Networking.PodSubnet, constants.MinimumAddressesInPodSubnet, isDualStack, field.NewPath("podSubnet"))...)
// Pod subnet was already validated, we need to validate now against the node-mask
allErrs = append(allErrs, ValidatePodSubnetNodeMask(c.Networking.PodSubnet, c, field.NewPath("podSubnet"))...)
}

Copy link
Member

Choose a reason for hiding this comment

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

ok, this seems like a separate refactor that can be done in the future.

@neolit123
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 3, 2021
@pacoxu
Copy link
Member

pacoxu commented Mar 3, 2021

/retest
for subpath flake

@k8s-ci-robot k8s-ci-robot merged commit b0ba6c0 into kubernetes:master Mar 3, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Mar 3, 2021
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/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants