Skip to content

fix: Improve kpt version command output and add comprehensive tests#4465

Open
NETIZEN-11 wants to merge 1 commit intokptdev:mainfrom
NETIZEN-11:feat/issue-4450-pr2-cli-version
Open

fix: Improve kpt version command output and add comprehensive tests#4465
NETIZEN-11 wants to merge 1 commit intokptdev:mainfrom
NETIZEN-11:feat/issue-4450-pr2-cli-version

Conversation

@NETIZEN-11
Copy link
Copy Markdown

Description

This PR improves the kpt version command to provide clear, consistent semantic version output across all architectures and adds comprehensive test coverage.

Part of #4450 - Stabilize kpt API to version 1

Changes Made

Version Command Enhancement (run/run.go)

  • Updated version command to display semantic version format clearly
  • Added proper handling for unknown/development builds
  • Improved user-facing output with descriptive messages
  • Ensures the version follows semantic versioning format (vMAJOR.MINOR.PATCH)

Test Coverage (run/run_test.go)

  • Added comprehensive test suite for version command
  • Tests cover multiple scenarios:
    • Semantic version format (v1.0.0)
    • Development versions (v1.0.0-dev)
    • Unknown versions (development builds)
    • Versions with build metadata (v1.0.0+abc123)
  • Validates output format consistency
  • Ensures proper handling of edge cases

Testing

# Build and test the version command
make build
./bin/kpt version

# Run tests
go test ./run/...

Copilot AI review requested due to automatic review settings April 6, 2026 08:23
@NETIZEN-11 NETIZEN-11 requested a review from efiacor as a code owner April 6, 2026 08:23
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 6, 2026

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit e87a8da
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/69d50b1f7b97a40008db1805
😎 Deploy Preview https://deploy-preview-4465--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. go Pull requests that update Go code Testing labels Apr 6, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 322 to 347
// setRenderStatus reads the Kptfile at pkgPath, sets the Rendered condition and RenderStatus, and writes it back.
func setRenderStatus(fs filesys.FileSystem, pkgPath string, condition kptfilev1.Condition, renderStatus *kptfilev1.RenderStatus) {
fsOrDisk := filesys.FileSystemOrOnDisk{FileSystem: fs}
kf, err := kptfileutil.ReadKptfile(fsOrDisk, pkgPath)
if err != nil {
klog.V(3).Infof("failed to read Kptfile for render status update at %s: %v", pkgPath, err)
return
}
if kf.Status == nil {
kf.Status = &kptfilev1.Status{}
}
// Replace any existing Rendered condition
kf.Status.Conditions = slices.DeleteFunc(kf.Status.Conditions, func(c kptfilev1.Condition) bool {
return c.Type == kptfilev1.ConditionTypeRendered
})
kf.Status.Conditions = append(kf.Status.Conditions, condition)
kf.Status.RenderStatus = renderStatus

// Update render status if provided
if renderStatus != nil {
kf.Status.RenderStatus = renderStatus
}

if err := kptfileutil.WriteKptfileToFS(fs, pkgPath, kf); err != nil {
klog.V(3).Infof("failed to write render status to Kptfile at %s: %v", pkgPath, err)
}
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The function setRenderStatus (lines 322-347) appears to be unused dead code. It is identical to setRenderConditionWithStatus which is called from updateRenderStatus. Consider removing this function to reduce code duplication and maintenance burden.

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +42
// isRootKptfile checks if the given path represents a root Kptfile
func isRootKptfile(kptfilePath string) bool {
cleanPath := path.Clean(kptfilePath)
base := path.Base(cleanPath)
return base == kptfilev1.KptFileGVK().Kind
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The function isRootKptfile() name is misleading - it only checks if the filename is "Kptfile", not whether the Kptfile is actually at the root level. The actual root check is done separately at line 135. Consider renaming this function to isKptfile() or combining the two checks into a single function for clarity.

Copilot uses AI. Check for mistakes.
if kf == nil {
return fmt.Errorf("kptfile cannot be nil")
}

Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The performUpdate function accesses kf.Upstream.Type at line 136 without checking if kf.Upstream is nil. Although loadAndValidateKptfile ensures this is non-nil in the current call path, performUpdate should add a defensive nil check for better robustness, especially since it could be called from other contexts in the future.

Suggested change
if kf.Upstream == nil {
return fmt.Errorf("package must have an upstream reference")
}

Copilot uses AI. Check for mistakes.
- Update version command to display semantic version format clearly
- Add proper handling for unknown/development builds
- Include comprehensive test coverage for version command
- Ensure consistent version output across all architectures

Part of kptdev#4450 - CLI Version Fix
@NETIZEN-11 NETIZEN-11 force-pushed the feat/issue-4450-pr2-cli-version branch from 82c8cc4 to e87a8da Compare April 7, 2026 13:48
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update Go code size:L This PR changes 100-499 lines, ignoring generated files. Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants