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: same-name conflict check specified by multus.spidernet.io/cr-name #4168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ty-dc
Copy link
Collaborator

@ty-dc ty-dc commented Oct 14, 2024

Thanks for contributing!

Notice:

What issue(s) does this PR fix:

Fixes #4167
Fixed #4183
Special notes for your reviewer:

@ty-dc ty-dc added release/bug cherrypick-release-v0.8 Cherry-pick the PR to branch release-v0.8. cherrypick-release-v0.9 cherrypick-release-v1.0 Cherry-pick the PR to branch release-v1.0. labels Oct 14, 2024
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.39%. Comparing base (50dcb53) to head (ae327b9).
Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4168      +/-   ##
==========================================
- Coverage   80.85%   80.39%   -0.47%     
==========================================
  Files          51       51              
  Lines        4519     5637    +1118     
==========================================
+ Hits         3654     4532     +878     
- Misses        699      939     +240     
  Partials      166      166              
Flag Coverage Δ
unittests 80.39% <ø> (-0.47%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 49 files with indirect coverage changes

weizhoublue
weizhoublue previously approved these changes Oct 15, 2024
if ok && customMultusName == "" {
func (mcw *MultusConfigWebhook) validateAnnotation(ctx context.Context, multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *field.Error {
// Validate the annotation 'multus.spidernet.io/cr-name' to customize the net-attach-def resource name.
customMultusName, hasCustomMultusName := multusConfig.Annotations[constant.AnnoNetAttachConfName]
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个annotations 可能是 nil

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

为 nil 的场景在后面判断了

case !hasCustomMultusName &&

Copy link
Collaborator

Choose a reason for hiding this comment

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

我的意思是 multus.Annotations 可能是 nil,L266 可能panic

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

已沟通,不会 panic

return field.Invalid(annotationField, multusConfig.Annotations, "invalid custom net-attach-def resource empty name")
}
if len(customMultusName) > k8svalidation.DNS1123SubdomainMaxLength {
return field.Invalid(annotationField, multusConfig.Annotations,
fmt.Sprintf("the custom net-attach-def resource name must be no more than %d characters", k8svalidation.DNS1123SubdomainMaxLength))
}

// validate the custom net-attach-def CNI version
var spiderMultusConfigList spiderpoolv2beta1.SpiderMultusConfigList
if err := mcw.APIReader.List(ctx, &spiderMultusConfigList); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里感觉需要有一个 listOptions 之类的过滤 mulutsname ?如果list 不为空说明当前已经有同名冲突的 multusConfig 了

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

是通过 multus.spidernet.io/cr-name 指定的别名,出现冲突。listOptions 并不能去过滤注解?

Copy link
Collaborator

Choose a reason for hiding this comment

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

是通过 multus.spidernet.io/cr-name 指定的别名,

我知道,我的意思就是直接去 Get 通过 multus.spidernet.io/cr-name 指定的别名,如果成功则有冲突,避免每次创建 webhhok 都需要向 apiServer 全量 List

Copy link
Collaborator Author

@ty-dc ty-dc Oct 17, 2024

Choose a reason for hiding this comment

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

默认 spiderMultusConfig 同步 nad 需要一分钟,如果 nad 删除了,这需要一分钟才会同步出来。此时有同名创建, 通过指定 multus.spidernet.io/cr-name 的别名,去查可能就查不到,仍会导致同名 nad 创建成功。

对于 spidernet,或则开始使用 multus 并未使用 spidermultusConfig 的场景。开始存在 nad,然后安装了 spidermultusConfig ,此时需要通过 spidermultusConfig 去纳管 nad ,如果 list multus.spidernet.io/cr-name 指定的别名,有可能纳管失败。

所以全部通过比对 spidermultusconfig 自身不存在冲突,如上是出于这样的目。cc

Copy link
Collaborator

@cyclinder cyclinder Oct 17, 2024

Choose a reason for hiding this comment

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

默认 spiderMultusConfig 同步 nad 需要一分钟,如果 nad 删除了,这需要一分钟才会同步出来。此时有同名创建, 通过指定 multus.spidernet.io/cr-name 的别名,去查可能就查不到,仍会导致同名 nad 创建成功。

所以这里直接去Get Multus NAD?我感觉这里只需要去检查 当前创建的 smc 指定的 annotationCR name 是否存在同名的 multus Nad就可以了,理论上每一个 spiderMultusConfig 都会得到webhook 验证

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

场景是如果直接去 Get Multus NAD,此时 Multus NAD 被删除,但 spiderMultusConfig 还没有完成同步 Multus NAD(同步时间很长),新建的 spiderMultusConfig 指定了被删除的别名,将能够创建出来。仍会导致同名冲突。故就对 spiderMultusConfig 做检查。

Copy link
Collaborator

Choose a reason for hiding this comment

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

应该 Multus NAD 事件触发 spiderMultusConfig 同步

Signed-off-by: tao.yang <tao.yang@daocloud.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherrypick-release-v0.8 Cherry-pick the PR to branch release-v0.8. cherrypick-release-v0.9 cherrypick-release-v1.0 Cherry-pick the PR to branch release-v1.0. release/bug
Projects
None yet
3 participants