Skip to content
This repository was archived by the owner on Jan 24, 2026. It is now read-only.

Conversation

@nmn3m
Copy link
Contributor

@nmn3m nmn3m commented Jun 7, 2025

Add Automatic Host Resource Validation to Cluster Creation

Summary

This PR implements automatic resource validation during the playground create cluster workflow. It checks the host machine for minimum CPU, memory, disk space, and port availability before proceeding with cluster provisioning. If validation fails, cluster creation is halted with clear, actionable feedback.

Key Changes

  • Added internal validation logic before cluster creation begins
  • Implemented resource checks: CPU, memory, disk, ports, container runtime
  • Introduced --skip-host-validation and --force flags to override default behavior
  • Ensured cross-platform support (macOS, Linux, Windows)
  • Improved user feedback on resource shortfalls and recommendations

Linked Issue

status.Error = err
} else {
status.IsOpen = true
listener.Close()

Check warning

Code scanning / gosec

Errors unhandled Warning

Errors unhandled
Copy link
Owner

@mrgb7 mrgb7 left a comment

Choose a reason for hiding this comment

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

CI is failing , try the following before open a pull request
make test
make build

@nmn3m
Copy link
Contributor Author

nmn3m commented Jun 7, 2025

@mrgb7 I got the error now, it failed when it try to build-all, i will work on it.
Thanks

return fmt.Errorf("failed to validate host resources: %w", err)
}

portStatus, err := validator.ValidatePorts()
Copy link
Owner

Choose a reason for hiding this comment

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

Could you explain what is the problem on Ports, is not multipass ensure dedicated IP address for each node ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you mention in issue feature file, you want to validate if port is available? , if not -> fail fast.
That's what i tried to achieve, I don't know where multipass check for port in code for sure.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, please keep in mind that when I outline a new issue or feature, it's not necessarily the finalized design. Some assumptions may be inaccurate or incomplete, so it's important that you validate and critically evaluate the requirements before proceeding

}

func getAvailableMemoryImpl() (float64, error) {
var m runtime.MemStats
Copy link
Owner

Choose a reason for hiding this comment

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

The runtime memStats it reflects go runtime managed memory allocated only.
read this
https://cs.opensource.google/go/go/+/refs/tags/go1.24.4:src/runtime/mstats.go;l=347

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got it. i will fix it.

return runtime.NumCPU(), nil
}

func getAvailableMemoryImpl() (float64, error) {
Copy link
Owner

Choose a reason for hiding this comment

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

What Impl suffix means ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found that , This is a common pattern in Go for making code more testable and flexible, especially when dealing with system-level operations that might need to be mocked in tests. so i do it in this way.

Copy link
Owner

Choose a reason for hiding this comment

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

@nmn3m Could you refer to the docs I am interested to learn more about this convention in go ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mrgb7 ,

To be honest, there isn’t an official Go documentation link that defines the Implsuffix as a convention.

In this case, I used the Impl suffix to clearly separate the default implementation from the function variable, which can then be overridden in tests. This allows us to inject mocks without using interfaces.

Is there any alternative, I can use instead of that suffix?.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, this isn't considered best practice in Go. Golang is designed to be straightforward. so It doesn't require interfaces solely for testing purposes. It's not an object-oriented language, but rather one that emphasizes simplicity and package-based structuring. You can effectively write unit tests without unnecessary abstraction layers. I'd recommend checking out this article for a clear explanation on writing tests in Go using the built-in testing package: How to Write Unit Tests in Go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mrgb7 Noticed, I fixed.

removing Impl suffix | handling testing
@mrgb7 mrgb7 changed the title Feat/host resource validation Add host resource validation before creating VMs Jun 15, 2025
}

if !skipValidation {
requirements, err := validator.CalculateResourceRequirements(
Copy link
Owner

Choose a reason for hiding this comment

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

I see an issue on calculating disk it returns 0GB free

./bin/playground cluster create --name obs-test --size 1 \
--master-cpus 8 --master-memory 20G
Resource validation failed:
❌ Disk: 0.0 GB available (20.0 GB required)

Recommendations:
- Free up at least 20.0 GB of disk space to meet minimum requirements
- Consider cleaning up disk space for optimal performance

To bypass this check, use: playground create cluster --skip-host-validation
Failed to create cluster: insufficient resources for cluster creation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants