Skip to content

Replace gcloud and gsutil shell invocations with client libraries in tools/kops #1033

@hdp617

Description

@hdp617

The tools/kops utility currently relies on executing external CLI commands (gcloud and gsutil) for various GCP operations in pkg/kops/gcp.go. This approach introduces external dependencies, makes error handling brittle, and is less efficient than direct API calls.
We should refactor these methods to use the GCP go client libraries.

Current Usage (pkg/kops/gcp.go)

  1. Account Discovery:
    saCmd := exec.Command("gcloud", "config", "list", "--format", "value(core.account)")
  2. SSH Configuration:
    cmd := exec.Command("gcloud", "compute", "--project="+c.GCPProject, "config-ssh", "--ssh-key-file="+c.SSHPrivateKey)
  3. GCS Bucket Management (gsutil):
    • gsutil ls to check if the bucket exists.
    • gsutil mb to create the bucket.
    • gsutil ubla set off to disable uniform bucket-level access.
    • gsutil iam ch to set IAM permissions.

Proposed Changes

Refactor pkg/kops/gcp.go to use the client libraries.

  1. Replace gcloud config list:
    • Use cloud.google.com/go/compute/metadata.
  2. Replace gcloud compute config-ssh:
    • Use cloud.google.com/go/compute/apiv1.
  3. Replace gsutil:
    • Use cloud.google.com/go/storage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/cleanupCategorizes issue or PR as related to cleaning up code, process, or technical debt.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions