Skip to content

Conversation

Atoms
Copy link

@Atoms Atoms commented Mar 25, 2025

Issue #, if available:
fixes #451

  • Adjusted order of how scheduling happens

    • First we determine if we have usable template (fail fast if not)
  • If we have usable template, determine how we need to schedule

    • if Target is provided schedule on that node if template is there
    • if Target and allowedNodes missing assume we want all nodes to use in scheduling (discover all nodes)
    • if templates are on more nodes then is in allowedNodes schedule only on allowedNodes
    • if templates missing on some allowedNodes still continue to schedule on nodes where template exists.

LocalStorage:

  • If localstorage (we have no easy way to determine if template is no localstorage):
    • multiple templates can be found
    • assign options.Node same as options.Target as we will use template from same node.
    • templateID and SourceNode cannot be used in this scenario
  • If !localstorage
    • only 1 template can be found, if multiple found fail
    • schedule vm on any allowedNode (either Target or allowedNodes or discovered nodes)
    • templateID and SourceNode only can be used in this scenario

Fixed existing tests to reflect multiple scenarios (moving out templateID and SourceNode from setupReconcilerTest

  • fixed yamlfmt

createVM had became too complex (gocyclo) as i've written in code for now it should be function to revisit and get into smaller chunks.

Copy link

Tests

Please note that running unit and e2e tests requires manual approval from a team member.

e2e tests

We use labels to control which e2e tests contexts are run:

Label Behaviour
none Run Generic tests only
e2e/none skip all e2e tests (documentation etc) - overrides all e2e/* labels Do not run any e2e tests
e2e/flatcar run Flatcar e2e tests Add Flatcar tests

ℹ️ Ask a team member to add the requested labels if you don't have enough permissions.

@Atoms
Copy link
Author

Atoms commented Mar 27, 2025

did more intensive testing, not all cases now work, so will be making some changes there.

@Atoms
Copy link
Author

Atoms commented Apr 14, 2025

fully reworked logic is now pushed, also updated description.

Copy link
Collaborator

@wikkyk wikkyk left a comment

Choose a reason for hiding this comment

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

Please make better use of validation rules instead of the overriding logic or erroring out. Early failure is better UX.

Make sure the examples are still correct.

This feature deserves documentation :)

This is close. I like the overall idea and implementation but it can be simplified. Please avoid just reformatting unrelated files as that makes the PR larger and thus harder to review plus it can mess up rebasing/reverting/... .

@Atoms
Copy link
Author

Atoms commented May 21, 2025

rebased on main

@Atoms
Copy link
Author

Atoms commented May 29, 2025

any comments?

@stibi
Copy link

stibi commented Jun 9, 2025

Hello guys, anything I can help with here? For now, I'll at least try to make a build and test this. I'm quite looking forward to this feature. Thanks a lot @Atoms.

@RomRider
Copy link

Looking forward to it too and happy to test.

@Atoms Atoms requested a review from wikkyk June 16, 2025 19:44
Comment on lines +58 to +59
warnings = append(warnings, "localStorage is mutually exclusive with templateID/sourceNode")
return warnings, apierrors.NewBadRequest("localStorage is mutually exclusive with templateID/sourceNode")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you can't see the sonarqube report (sorry about that): it's complaining about this string constant being repeated 5 times. Personally, I don't really see the point in setting warnings here at all only to return the same warning again as an error. This also applies to ValidateUpdate below. validateLocalStorage should return an error that can be returned by ValidateCreate and ValidateUpdate directly.

Comment on lines +89 to +90
warnings = append(warnings, "localStorage is mutually exclusive with templateID/sourceNode")
return warnings, apierrors.NewBadRequest("localStorage is mutually exclusive with templateID/sourceNode")
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

func (c *APIClient) FindVMTemplateByTags(ctx context.Context, templateTags []string) (string, int32, error) {
vmTemplates := make([]*proxmox.ClusterResource, 0)
// FindVMTemplatesByTags finds VM templates by tags across the whole cluster.
func (c *APIClient) FindVMTemplatesByTags(ctx context.Context, templateTags []string, allowedNodes []string, localStorage bool) (map[string]int32, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, since you can't see the sonarqube report: It finds this function too complex ("Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed"). While indeed there are many branches here, they're all fairly straightforward and there isn't really a better place to put them.

func (c *APIClient) FindVMTemplatesByTags(ctx context.Context, templateTags []string, allowedNodes []string, localStorage bool) (map[string]int32, error) {
templates := make(map[string]int32)

// if for some reason there is not tags, we fail early and return error
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// if for some reason there is not tags, we fail early and return error
// if for some reason there are no tags, fail early and return error

vmTags := strings.Split(vm.Tags, ";")
slices.Sort(vmTags)

// if localstorage - template should be on all allowed nodes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// if localstorage - template should be on all allowed nodes
// if localstorage, the template should be on all allowed nodes

@wikkyk
Copy link
Collaborator

wikkyk commented Jul 4, 2025

We are focusing on releasing v0.8/v1alpha2 and aren't planning to add any new features to the v0.7 branch, so I think .spec.Target can get removed, after all. We'll just merge this PR into v0.8.0 if it's ready. I don't want to set any expectations here but we should be ready in August.

Copy link

sonarqubecloud bot commented Jul 4, 2025

@Atoms
Copy link
Author

Atoms commented Jul 7, 2025

Should i rebase on v1alpha2 branch then ?

@wikkyk
Copy link
Collaborator

wikkyk commented Jul 28, 2025

No, that branch is not ready yet. We'll rebase this PR once it's ready. Please hold on tight :)

chrodriguez added a commit to Mikroways/cluster-api-helm that referenced this pull request Aug 14, 2025
@mikhailkobik
Copy link

Hi guys, any news for this PR? This is most useful feature for homelab usage

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.

Local storage templates per Proxmox Node

5 participants