Files
yxxhero 6e21671228 feat: kubedog integration with unified resource handling (#2383)
* feat: add kubedog-based resource tracking integration

Add kubedog tracking as an alternative to Helm's --wait flag with:
- Real-time deployment progress tracking
- Container log streaming
- Fine-grained resource filtering (trackKinds/skipKinds/trackResources)

Features:
- New pkg/resource package for unified manifest parsing and filtering
- New pkg/kubedog package wrapping kubedog library
- CLI flags: --track-mode, --track-timeout, --track-logs
- Helmfile YAML support for trackMode, trackTimeout, trackLogs, trackKinds, skipKinds, trackResources
- Case-insensitive kind matching for filtering
- Multi-context support with proper kubeconfig/kubeContext handling

Tracking supports: Deployment, StatefulSet, DaemonSet, Job

Resource filtering priority (highest to lowest):
1. trackResources - explicit resource whitelist
2. skipKinds - blacklist specific kinds
3. trackKinds - whitelist specific kinds

Integration:
- Disable Helm --wait when using kubedog tracking
- Track after successful Helm sync/apply
- Respect release.Namespace as fallback for resources without namespace
- Use getKubeContext() for correct cluster targeting

Tests:
- Unit tests for resource filtering and kubedog options
- Integration test with httpbin chart
- E2E snapshot tests for YAML serialization
- Documentation in docs/advanced-features.md

Signed-off-by: yxxhero <aiopsclub@163.com>

* fix: address PR #2383 review comments (round 4)

1. resource/filter.go: Skip empty whitelist entries in matchWhitelist
   - At least one field (kind/name/namespace) must be specified
   - Prevents matching all resources with empty TrackResources entries

2. config/apply.go: Add ValidateConfig for track-mode validation
   - Validate --track-mode must be 'helm' or 'kubedog'
   - Reject invalid values like --track-mode foo

3. config/sync.go: Add ValidateConfig for track-mode validation
   - Same validation as apply command
   - Ensures consistent behavior across commands

Signed-off-by: yxxhero <aiopsclub@163.com>

---------

Signed-off-by: yxxhero <aiopsclub@163.com>
2026-03-02 17:15:12 +08:00

55 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
test_start "kubedog-tracking - resource tracking with kubedog integration"
kubedog_case_dir="${cases_dir}/kubedog-tracking"
config_file="helmfile.yaml.gotmpl"
info "Testing kubedog integration with httpbin chart"
# Test 1: Basic sync with kubedog tracking
info "Syncing release with basic kubedog tracking"
${helmfile} -f "${kubedog_case_dir}/${config_file}" -l name=httpbin-basic sync
code=$?
[ "${code}" -eq 0 ] || fail "unexpected exit code returned by helmfile sync: ${code}"
wait_deploy_ready httpbin-basic-httpbin
info "Verifying httpbin-basic deployment is running"
${kubectl} get deployment httpbin-basic-httpbin -n "${test_ns}" || fail "httpbin-basic deployment not found"
# Test 2: Sync with whitelist filtering
info "Syncing release with whitelist filtering"
${helmfile} -f "${kubedog_case_dir}/${config_file}" -l name=httpbin-with-whitelist sync
code=$?
[ "${code}" -eq 0 ] || fail "unexpected exit code returned by helmfile sync with whitelist: ${code}"
wait_deploy_ready httpbin-with-whitelist-httpbin
info "Verifying httpbin-with-whitelist deployment is running"
${kubectl} get deployment httpbin-with-whitelist-httpbin -n "${test_ns}" || fail "httpbin-with-whitelist deployment not found"
# Test 3: Sync with specific resource tracking
info "Syncing release with specific resource tracking"
${helmfile} -f "${kubedog_case_dir}/${config_file}" -l name=httpbin-with-resources sync
code=$?
[ "${code}" -eq 0 ] || fail "unexpected exit code returned by helmfile sync with resource tracking: ${code}"
wait_deploy_ready httpbin-with-resources-httpbin
info "Verifying httpbin-with-resources deployment is running"
${kubectl} get deployment httpbin-with-resources-httpbin -n "${test_ns}" || fail "httpbin-with-resources deployment not found"
# Test 4: Apply all releases with kubedog via CLI flag
info "Testing apply with kubedog CLI flag"
${helmfile} -f "${kubedog_case_dir}/${config_file}" apply --track-mode kubedog --track-timeout 60
code=$?
[ "${code}" -eq 0 ] || fail "unexpected exit code returned by helmfile apply: ${code}"
# Test 5: Cleanup
info "Destroying all releases"
${helmfile} -f "${kubedog_case_dir}/${config_file}" destroy
code=$?
[ "${code}" -eq 0 ] || fail "unexpected exit code returned by helmfile destroy: ${code}"
info "kubedog integration test completed successfully"
test_pass "kubedog-tracking"