-
Notifications
You must be signed in to change notification settings - Fork 4
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-2193: Support setting the owner of ElfCluster and virtual machines #162
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import ( | |
|
||
infrav1 "github.com/smartxworks/cluster-api-provider-elf/api/v1beta1" | ||
"github.com/smartxworks/cluster-api-provider-elf/pkg/config" | ||
typesutil "github.com/smartxworks/cluster-api-provider-elf/pkg/util/types" | ||
) | ||
|
||
// GetUpdatedVMRestrictedFields returns the updated restricted fields of the VM compared to ElfMachine. | ||
|
@@ -309,3 +310,27 @@ func calGPUAvailableVgpusNum(vgpuInstanceNum, assignedVGPUsNum int32) int32 { | |
|
||
return count | ||
} | ||
|
||
// parseOwnerFromCreatedBy parse owner from createdBy annotation. | ||
// | ||
// The owner can be in one of the following two formats: | ||
// 1. ${Tower username}_${Tower auth_config_id}, e.g. caas.smartx_7e98ecbb-779e-43f6-8330-1bc1d29fffc7. | ||
// 2. ${Tower username}, e.g. root. If auth_config_id is not set, it means it is a LOCAL user. | ||
func parseOwnerFromCreatedBy(createdBy string) string { | ||
lastIndex := strings.LastIndex(createdBy, "@") | ||
if len(createdBy) <= 1 || lastIndex <= 0 || lastIndex == len(createdBy) { | ||
return createdBy | ||
} | ||
|
||
username := createdBy[0:lastIndex] | ||
authConfigID := createdBy[lastIndex+1:] | ||
|
||
// If authConfigID is not in UUID format, it means username contains the last `@` character, | ||
// return createdBy directly. | ||
if !typesutil.IsUUID(authConfigID) { | ||
return createdBy | ||
} | ||
|
||
// last `@` replaced with `_`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个替换补充下原因 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. func 已经有说明使用 ${Tower username}_${Tower auth_config_id} 这种格式。Annotation 也有说明使用 @ 间隔。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // last There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 或者你在Func comment中补充下 createdBy string是什么格式 |
||
return fmt.Sprintf("%s_%s", username, authConfigID) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2023. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package types | ||
|
||
import "regexp" | ||
|
||
const ( | ||
// UUIDPattern is a regex pattern and is used by ConvertUUIDToProviderID | ||
// to convert a UUID into a providerID string. | ||
UUIDPattern = `(?i)^[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}$` | ||
) | ||
|
||
func IsUUID(uuid string) bool { | ||
if uuid == "" { | ||
return false | ||
} | ||
|
||
pattern := regexp.MustCompile(UUIDPattern) | ||
|
||
return pattern.MatchString(uuid) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改个名称:parseOwnerFromCreatedByAnnotation()