Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/preview/previewctl/pkg/gcloud/config.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package gcloud
6
7
import (
8
"context"
9
10
"google.golang.org/api/container/v1"
11
"google.golang.org/api/option"
12
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
13
)
14
15
var _ Client = (*Config)(nil)
16
17
type Client interface {
18
GetCluster(ctx context.Context, name, projectID, zone string) (*container.Cluster, error)
19
}
20
21
type Config struct {
22
gkeService *container.Service
23
}
24
25
func New(ctx context.Context, serviceAccountPath string) (*Config, error) {
26
var opts []option.ClientOption
27
if serviceAccountPath != "" {
28
opts = append(opts, option.WithCredentialsFile(serviceAccountPath))
29
}
30
31
client, err := container.NewService(ctx, opts...)
32
if err != nil {
33
return nil, err
34
}
35
36
return &Config{
37
gkeService: client,
38
}, err
39
}
40
41
func (c *Config) GetCluster(ctx context.Context, name, projectID, zone string) (*container.Cluster, error) {
42
return c.gkeService.Projects.Zones.Clusters.Get(projectID, zone, name).Context(ctx).Do()
43
}
44
45