Path: blob/main/dev/preview/previewctl/pkg/gcloud/config.go
2501 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package gcloud56import (7"context"89"google.golang.org/api/container/v1"10"google.golang.org/api/option"11_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"12)1314var _ Client = (*Config)(nil)1516type Client interface {17GetCluster(ctx context.Context, name, projectID, zone string) (*container.Cluster, error)18}1920type Config struct {21gkeService *container.Service22}2324func New(ctx context.Context, serviceAccountPath string) (*Config, error) {25var opts []option.ClientOption26if serviceAccountPath != "" {27opts = append(opts, option.WithCredentialsFile(serviceAccountPath))28}2930client, err := container.NewService(ctx, opts...)31if err != nil {32return nil, err33}3435return &Config{36gkeService: client,37}, err38}3940func (c *Config) GetCluster(ctx context.Context, name, projectID, zone string) (*container.Cluster, error) {41return c.gkeService.Projects.Zones.Clusters.Get(projectID, zone, name).Context(ctx).Do()42}434445