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

SKS-2194: Fix labeling virtual machines #163

Merged
merged 2 commits into from
Dec 8, 2023

Conversation

haijianyang
Copy link
Contributor

@haijianyang haijianyang commented Dec 8, 2023

Issue SKS-2194

#162 给虚拟机增加虚拟机后,Tower 会自动给虚拟机添加系统标签导致 CAPE 不能给虚拟机添加预期的标签。

// 已经有了系统标签,导致没有进入 if 执行。
	if len(vm.Labels) == 0 {
		if ok, err := r.reconcileLabels(ctx, vm); !ok {
			return reconcile.Result{}, errors.Wrapf(err, "failed to reconcile labels")
		}
        }

Change

如果虚拟机打上了 managed 标签就认为所有的标签就有了,就可以跳过给虚拟机加标签的逻辑。

考虑每次 Reconcile 都要从 Tower 获取 managed 标签,且 managed 标签除非被人为删除,否则不会变动。为了减少 Tower 接口访问,managed 会缓存 30m。

Test

创建 1CP + 3Workers 集群,在 ElfCluster 指定 haijian.yang@d8dc20fc-e197-41da-83b6-c903c88663fd。

观察到虚拟机指定了 owner
image

虚拟机也打上了预期的标签
image

image

Copy link

codecov bot commented Dec 8, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (b2fb22f) 59.59% compared to head (3cdd60d) 59.92%.

Files Patch % Lines
controllers/elfmachine_controller.go 72.22% 3 Missing and 2 partials ⚠️
controllers/tower_cache.go 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #163      +/-   ##
==========================================
+ Coverage   59.59%   59.92%   +0.32%     
==========================================
  Files          20       20              
  Lines        3579     3603      +24     
==========================================
+ Hits         2133     2159      +26     
+ Misses       1297     1296       -1     
+ Partials      149      148       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return false, errors.Wrapf(err, "failed to upsert label "+towerresources.GetVMLabelManaged())
}

setLabelCache(managedLabel)
Copy link
Collaborator

Choose a reason for hiding this comment

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

setLabelCache 改名为 setLabelInCache, 与 getLabelFromCache 名称对应。

controllers/elfmachine_controller.go Outdated Show resolved Hide resolved
controllers/tower_cache.go Outdated Show resolved Hide resolved
@haijianyang haijianyang merged commit a30b311 into smartxworks:master Dec 8, 2023
3 checks passed
@haijianyang haijianyang deleted the cahce-label branch December 12, 2023 08:29
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