Skip to content

Conversation

@balasubramanian-s
Copy link

@balasubramanian-s balasubramanian-s commented Nov 11, 2025

Description

Enhanced kubeconfig error handling to provide clear, user-friendly error messages when users provide missing or invalid kubeconfig files. The plugin now validates kubeconfig options before attempting to load them and provides actionable feedback to help users resolve configuration issues quickly.

This work was completed with AI assistance following Progress AI policies.

Related Issue

Jira Ticket: CHEF-27550

Changes

  • Enhanced lib/train-kubernetes/connection.rb with comprehensive kubeconfig validation:

    • Added validation to ensure kubeconfig option is provided
    • Added file existence check with path expansion support
    • Added error handling for YAML syntax errors (Psych::SyntaxError)
    • Added error handling for Kubernetes configuration errors (K8s::Error)
    • Added generic error handling for unexpected errors
    • All errors raise Train::UserError with clear, actionable messages
  • Added comprehensive RDoc documentation with examples

  • Added 3 negative test scenarios in test/unit/connection_test.rb:

    • test_parse_kubeconfig_missing_option - Validates error when kubeconfig not provided
    • test_parse_kubeconfig_file_not_found - Validates error for non-existent file paths
    • test_parse_kubeconfig_invalid_yaml - Validates error for malformed YAML syntax

Test Results

  • ✅ All 29 tests passing (26 existing + 3 new)
  • ✅ Code coverage: 86.19% (exceeds 80% requirement)
  • ✅ RuboCop: 0 violations in modified files

Types of changes

  • New content (non-breaking change)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

Files Changed

  • lib/train-kubernetes/connection.rb - Enhanced parse_kubeconfig method with validation and error handling
  • test/unit/connection_test.rb - Added 3 comprehensive negative test scenarios

Signed-off-by: balasubramanian-s <[email protected]>
- Enhanced parse_kubeconfig method with comprehensive error handling
  - Validates kubeconfig option is provided
  - Checks file existence before parsing
  - Catches Psych::SyntaxError for invalid YAML
  - Catches K8s::Error for invalid Kubernetes configuration
  - Catches StandardError for unexpected errors
  - All errors raised as Train::UserError with clear messages

- Added 4 comprehensive negative test scenarios
  - test_parse_kubeconfig_missing_option
  - test_parse_kubeconfig_file_not_found
  - test_parse_kubeconfig_invalid_yaml
  - test_parse_kubeconfig_invalid_k8s_config

All tests passing: 30 runs, 76 assertions, 0 failures, 0 errors

Signed-off-by: balasubramanian-s <[email protected]>
@balasubramanian-s balasubramanian-s added the ai-assisted ai-assisted label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted ai-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants