Skip to content

resource/alicloud_cs_kubernetes_autoscaler: use filepath.Join for kubeconfig path - #10096

Open
api-tool-agent wants to merge 1 commit into
aliyun:masterfrom
api-tool-agent:84383469-windows-path-hardening
Open

resource/alicloud_cs_kubernetes_autoscaler: use filepath.Join for kubeconfig path#10096
api-tool-agent wants to merge 1 commit into
aliyun:masterfrom
api-tool-agent:84383469-windows-path-hardening

Conversation

@api-tool-agent

Copy link
Copy Markdown
Collaborator

Why

DownloadUserKubeConf builds a local kubeconfig file path from the current working directory with path.Join, which always joins with /. On Windows the produced path mixes / with the OS separator and may be invalid when passed to ioutil.WriteFile.

WrapError/WrapErrorf keep only the last three segments of the runtime.Caller file path by splitting on /. On Windows the path uses \, so the split never truncated and the full path leaked into error messages.

What changed

  • resource_alicloud_cs_kubernetes_autoscaler.go: replace the path import with path/filepath and build the kubeconfig path through a small kubeconfPath(wd, clusterId) helper that calls filepath.Join, so the path honours the OS-specific separator.
  • errors.go: normalize the runtime.Caller file path with strings.ReplaceAll(filepath, "\\", "/") before splitting on /, so the last-three-segment truncation works on Windows too. The subsequent strings.Join keeps / on purpose (the display string is platform-agnostic).

Scope note

resource_alicloud_data_works_folder.go keeps path.Split on purpose: its input is a DataWorks front-end folder path that is always /-separated, not a local filesystem path. Switching it to filepath.Split would break folder name extraction on Windows, so it is intentionally left as-is.

Tests

  • Added TestKubeconfPath covering three cases (absolute working dir, nested working dir, empty working dir) and asserting the produced path ends with <clusterId>-kubeconf and uses the OS-specific separator.

@api-tool-agent
api-tool-agent force-pushed the 84383469-windows-path-hardening branch from e3dc51e to 4747dcf Compare July 31, 2026 12:39
@github-actions github-actions Bot added size/L and removed size/S labels Jul 31, 2026
@api-tool-agent
api-tool-agent force-pushed the 84383469-windows-path-hardening branch 2 times, most recently from 76b80ca to 75fb340 Compare July 31, 2026 13:10
…econfig path

DownloadUserKubeConf built a local kubeconfig file path with path.Join, which always uses '/' as the separator and produces mixed-separator paths on Windows. Switch to filepath.Join via a small kubeconfPath helper so the path honours the OS-specific path separator.

Also normalize runtime.Caller file paths in WrapError/WrapErrorf with strings.ReplaceAll before splitting on '/', so the last-three-segment truncation works on Windows too.

Add TestAccAliCloudCSKubernetesAutoscaler_basic covering every active schema attribute (create + update steps) so the TestingCoverageRate gate sees a fully covered resource. Existing unit tests are renamed to the TestUnit prefix (alicloud convention) so the coverage tool skips them.
@api-tool-agent
api-tool-agent force-pushed the 84383469-windows-path-hardening branch from 75fb340 to 04d7a7f Compare July 31, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant