Skip to content

Enable selective resource registration via option parameter#2274

Merged
cb-github-robot merged 9 commits intocloud-barista:mainfrom
leehyeoklee:improve-registration
Jan 15, 2026
Merged

Enable selective resource registration via option parameter#2274
cb-github-robot merged 9 commits intocloud-barista:mainfrom
leehyeoklee:improve-registration

Conversation

@leehyeoklee
Copy link
Copy Markdown
Contributor

@leehyeoklee leehyeoklee commented Jan 15, 2026

close #2273

📝 Description

This PR enhances the resource registration process by introducing granular control over resource types via the option parameter. It also implements an early validation mechanism to enforce logical dependencies between resources, ensuring a "Fail-Fast" behavior for invalid requests.

🔍 Key Changes

1. Granular Resource Option Selection

  • Users can specify exactly which resource types to register via the option parameter.
  • Default Behavior: If the option parameter is omitted or empty, all resource types are registered by default.
  • Supported types: vNet, securityGroup, sshKey, vm, dataDisk, customImage.
Granular Options

2. Early Logical Dependency Validation (Fail-Fast)

  • Enforced strict dependency checks at the start of the flow (e.g., securityGroup requires vNet).
Validation Error Example
  • Invalid combinations are rejected immediately to prevent unnecessary processing.

3. Best Effort Execution & Error Handling

Once the initial validation passes, the registration process proceeds with a Best Effort strategy to handle various valid resource combinations.

For runtime failures caused by external factors rather than logical dependencies, the existing error handling logic is preserved:
e.g., If VM registration fails, the result is handled according to the specified MCI policy (continue, rollback, refine).

Copy link
Copy Markdown
Member

@seokho-son seokho-son left a comment

Choose a reason for hiding this comment

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

Thanks @leehyeoklee
LGTM in general!

I have a minor suggestion. :)

}

fmt.Printf("\n\n%s [Elapsed]Total %d \n\n", connConfig, int(math.Round(time.Now().Sub(startTime).Seconds())))
if doMap["securityGroup"] && !doMap["vNet"] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about using model.StrVNet instead of using the text directly? (applicable to the other resource types)

FYI: I think we need to refactor source code later for key stings for resource types in perspective of code maintenance. (currently, overall source code use both model.StrVNet and "vNet".)
I think we can make a package similar to CSP https://github.com/cloud-barista/cb-tumblebug/blob/main/src/core/model/csp/csp.go. and apply it to the existing codes.

No need to update it in this PR ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went ahead and updated the code to use constants like model.StrVNet as suggested!
I totally agree that creating a dedicated package is the way to go for better maintenance.
I'll try to implement that structure in a future refactoring. Thanks! 😊

@seokho-son seokho-son self-assigned this Jan 15, 2026
@seokho-son
Copy link
Copy Markdown
Member

@leehyeoklee Also, please evaluate the effect from these changes (RegisterCspNativeResources) to other functions and API documentation referencing RegisterCspNativeResources.

for instance, RestRegisterCspNativeResources, RestPostScheduleRegisterCspResources (+ CreateScheduledJob) and so on. :)

@leehyeoklee
Copy link
Copy Markdown
Contributor Author

I completely missed checking those parts. 😅
Fortunately, it seems the legacy options were only remaining in the documentation and comments.
I've checked and updated them all to match the changes!

Also, it appears that resources are successfully registered when running the scheduled job.

Copy link
Copy Markdown
Member

@seokho-son seokho-son left a comment

Choose a reason for hiding this comment

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

@leehyeoklee I guess we can apply the following suggestions.

result.RegisterationOverview.SshKey--
result.RegisterationOverview.Failed++
// [3] SecurityGroup
if doMap["securityGroup"] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how about

Suggested change
if doMap["securityGroup"] {
if doMap[model.StrSecurityGroup] {

result.RegisterationOverview.SecurityGroup--
result.RegisterationOverview.Failed++
// [2] VNet
if doMap["vNet"] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how about

Suggested change
if doMap["vNet"] {
if doMap[model.StrVNet] {

result.RegisterationOverview.DataDisk--
result.RegisterationOverview.Failed++
// [4] SSHKey
if doMap["sshKey"] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if doMap["sshKey"] {
if doMap[model.StrSSHKey] {

ConnectionName: connConfig,
CspResourceId: r.CspResourceId,
// [5] VM
if doMap["vm"] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if doMap["vm"] {
if doMap[model.StrVM] {

result.RegisterationOverview.CustomImage--
result.RegisterationOverview.Failed++
// [6] DataDisk
if doMap["dataDisk"] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if doMap["dataDisk"] {
if doMap[model.StrDataDisk] {

Copy link
Copy Markdown
Member

@seokho-son seokho-son left a comment

Choose a reason for hiding this comment

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

I have additional suggestions. :)

Comment on lines +952 to +972
if doMap[model.StrDataDisk] && !doMap[model.StrVM] {
valErrs = append(valErrs, "'dataDisk' requires 'vm'")
}

fmt.Printf("\n\n%s [Elapsed]%s %d \n\n", connConfig, model.StrVM, int(math.Round(time.Now().Sub(startTime06).Seconds()))) //tmp
if doMap[model.StrVM] {
if !doMap[model.StrSecurityGroup] {
valErrs = append(valErrs, "'vm' requires 'securityGroup'")
}
if !doMap[model.StrSSHKey] {
valErrs = append(valErrs, "'vm' requires 'sshKey'")
}
}

fmt.Printf("\n\n%s [Elapsed]Total %d \n\n", connConfig, int(math.Round(time.Now().Sub(startTime).Seconds())))
if doMap[model.StrSecurityGroup] && !doMap[model.StrVNet] {
valErrs = append(valErrs, "'securityGroup' requires 'vNet'")
}

return result, err
if len(valErrs) > 0 {
return fmt.Errorf("Validation Failed: %s", strings.Join(valErrs, ", "))
}
return nil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how about the following style. (to minimize redundant codes)

we can centralize required resource dependency rules in one section.

Suggested change
if doMap[model.StrDataDisk] && !doMap[model.StrVM] {
valErrs = append(valErrs, "'dataDisk' requires 'vm'")
}
fmt.Printf("\n\n%s [Elapsed]%s %d \n\n", connConfig, model.StrVM, int(math.Round(time.Now().Sub(startTime06).Seconds()))) //tmp
if doMap[model.StrVM] {
if !doMap[model.StrSecurityGroup] {
valErrs = append(valErrs, "'vm' requires 'securityGroup'")
}
if !doMap[model.StrSSHKey] {
valErrs = append(valErrs, "'vm' requires 'sshKey'")
}
}
fmt.Printf("\n\n%s [Elapsed]Total %d \n\n", connConfig, int(math.Round(time.Now().Sub(startTime).Seconds())))
if doMap[model.StrSecurityGroup] && !doMap[model.StrVNet] {
valErrs = append(valErrs, "'securityGroup' requires 'vNet'")
}
return result, err
if len(valErrs) > 0 {
return fmt.Errorf("Validation Failed: %s", strings.Join(valErrs, ", "))
}
return nil
requiredDeps := map[string][]string{
model.StrDataDisk: {model.StrVM},
model.StrVM: {model.StrSecurityGroup, model.StrSSHKey},
model.StrSecurityGroup: {model.StrVNet},
}
valErrs := []string{}
for key, required := range requiredDeps {
if !doMap[key] {
continue
}
for _, dep := range required {
if !doMap[dep] {
valErrs = append(valErrs, fmt.Sprintf("'%s' requires '%s'", key, dep))
}
}
}
if len(valErrs) > 0 {
return fmt.Errorf("Validation Failed: %s", strings.Join(valErrs, ", "))
}
return nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This map-based approach makes the dependency logic much clearer and easier to maintain.
Thanks for the improvement!

Copy link
Copy Markdown
Member

@seokho-son seokho-son left a comment

Choose a reason for hiding this comment

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

LGTM! :)

@seokho-son
Copy link
Copy Markdown
Member

/approve

@github-actions github-actions bot added the approved This PR is approved and will be merged soon. label Jan 15, 2026
@cb-github-robot cb-github-robot merged commit 137c375 into cloud-barista:main Jan 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved This PR is approved and will be merged soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance registration options to resolve dependency failures

3 participants