gke

package
v2.1.155 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const KmsLocation = "global"

KmsLocation indicates the location used by the Google KMS service

Variables

View Source
var (
	// RequiredServiceAccountRoles the roles required to create a cluster with terraform
	RequiredServiceAccountRoles = []string{"roles/owner"}

	// KanikoServiceAccountRoles the roles required to run kaniko with GCS
	KanikoServiceAccountRoles = []string{"roles/storage.admin",
		"roles/storage.objectAdmin",
		"roles/storage.objectCreator"}

	// VeleroServiceAccountRoles the roles required to run velero with GCS
	VeleroServiceAccountRoles = []string{

		"roles/storage.admin",
		"roles/storage.objectAdmin",
		"roles/storage.objectCreator"}
)
View Source
var PROJECT_LIST_HEADER = "PROJECT_ID"

Functions

func BucketName

func BucketName(serviceName string) string

BucketName creates a Bucket name for a given service name

func FindLatestImageTag

func FindLatestImageTag(output string) (string, error)

FindLatestImageTag returns the latest image tag from the JSON output of the command ` gcloud container images list-tags gcr.io/jenkinsxio/builder-maven --format jsonhig`

func GcpServiceAccountSecretName

func GcpServiceAccountSecretName(serviceName string) string

GcpServiceAccountSecretName builds the secret name where the GCP service account is stored

func GetCurrentProject

func GetCurrentProject() (string, error)

func GetGoogleMachineTypes

func GetGoogleMachineTypes() []string

func GetGoogleProjects

func GetGoogleProjects() ([]string, error)

func GetGoogleRegions

func GetGoogleRegions(project string) ([]string, error)

func GetGoogleZones

func GetGoogleZones(project string) ([]string, error)

func GetRegionFromZone

func GetRegionFromZone(zone string) string

GetRegionFromZone parses the region from a GCP zone name. TODO: Return an error if the format of the zone is not correct

func KeyName

func KeyName(serviceName string) string

KeyName creates a key name for a given service and cluster name

func KeyringName

func KeyringName(serviceName string) string

KeyringName creates a keyring name for a given service and cluster name

func ParseContext

func ParseContext(context string) (string, string, string, error)

ParseContext parses the context string for GKE and gets the GKE project, GKE zone and cluster name

func ServiceAccountName

func ServiceAccountName(clusterName, serviceAbbreviation string) string

ServiceAccountName creates a service account name for a given service and cluster name

func StreamTransferFileFromBucket

func StreamTransferFileFromBucket(fullBucketURL string) (io.ReadCloser, error)

StreamTransferFileFromBucket will perform a stream transfer from the GCS bucket to stdout and return a scanner with the piped result

Types

type Cluster

type Cluster struct {
	Name           string            `json:"name,omitempty"`
	ResourceLabels map[string]string `json:"resourceLabels,omitempty"`
	Status         string            `json:"status,omitempty"`
	Location       string            `json:"location,omitempty"`
}

Cluster struct to represent a cluster on gcloud

type GCloud

type GCloud struct {
}

GCloud real implementation of the gcloud helper

func (*GCloud) AddBucketLabel

func (g *GCloud) AddBucketLabel(bucketName string, label string)

AddBucketLabel adds a label to a Google Storage bucket

func (*GCloud) BucketExists

func (g *GCloud) BucketExists(projectID string, bucketName string) (bool, error)

BucketExists checks if a Google Storage bucket exists

func (*GCloud) CheckPermission

func (g *GCloud) CheckPermission(perm string, projectID string) (bool, error)

CheckPermission checks permission on the given project

func (*GCloud) CleanupServiceAccountKeys

func (g *GCloud) CleanupServiceAccountKeys(serviceAccount string, projectID string) error

CleanupServiceAccountKeys remove all keys from given service account

func (*GCloud) ClusterZone

func (g *GCloud) ClusterZone(cluster string) (string, error)

ClusterZone retrives the zone of GKE cluster description

func (*GCloud) ConfigureBucketRoles

func (g *GCloud) ConfigureBucketRoles(projectID string, serviceAccount string, bucketURL string, roles []string) error

ConfigureBucketRoles gives the given roles to the given service account

func (*GCloud) ConnectToCluster

func (g *GCloud) ConnectToCluster(projectID, zone, clusterName string) error

ConnectToCluster connects to the specified cluster

func (*GCloud) ConnectToRegionCluster

func (g *GCloud) ConnectToRegionCluster(projectID, region, clusterName string) error

ConnectToRegionCluster connects to the specified regional cluster

func (*GCloud) CreateBucket

func (g *GCloud) CreateBucket(projectID string, bucketName string, location string) error

CreateBucket creates a new Google Storage bucket

func (*GCloud) CreateDNSZone

func (g *GCloud) CreateDNSZone(projectID string, domain string) (string, []string, error)

CreateDNSZone creates the DNS zone if it doesn't exist and returns the list of name servers for the given domain and project

func (*GCloud) CreateGCPServiceAccount

func (g *GCloud) CreateGCPServiceAccount(kubeClient kubernetes.Interface, serviceName, serviceAbbreviation, namespace, clusterName, projectID string, serviceAccountRoles []string, serviceAccountSecretKey string) (string, error)

CreateGCPServiceAccount creates a service account in GCP for a service using the account roles specified

func (*GCloud) CreateKmsKey

func (g *GCloud) CreateKmsKey(keyName string, keyringName string, projectID string) error

CreateKmsKey creates a new KMS key in the given keyring

func (*GCloud) CreateKmsKeyring

func (g *GCloud) CreateKmsKeyring(keyringName string, projectID string) error

CreateKmsKeyring creates a new KMS keyring

func (*GCloud) CreateManagedZone

func (g *GCloud) CreateManagedZone(projectID string, domain string) error

CreateManagedZone creates a managed zone for the given domain in the specified project

func (*GCloud) CreateServiceAccountKey

func (g *GCloud) CreateServiceAccountKey(serviceAccount string, projectID string, keyPath string) error

CreateServiceAccountKey creates a new service account key and downloads into the given file

func (*GCloud) CurrentProject

func (g *GCloud) CurrentProject() (string, error)

CurrentProject returns the current GKE project name if it can be detected

func (*GCloud) DeleteAllObjectsInBucket

func (g *GCloud) DeleteAllObjectsInBucket(bucketName string) error

DeleteAllObjectsInBucket deletes all objects in a Google Storage bucket

func (*GCloud) DeleteBucket

func (g *GCloud) DeleteBucket(bucketName string) error

DeleteBucket deletes a Google storage bucket

func (*GCloud) DeleteServiceAccount

func (g *GCloud) DeleteServiceAccount(serviceAccount string, projectID string, roles []string) error

DeleteServiceAccount deletes a service account and its role bindings

func (*GCloud) DeleteServiceAccountKey

func (g *GCloud) DeleteServiceAccountKey(serviceAccount string, projectID string, key string) error

DeleteServiceAccountKey deletes a service account key

func (*GCloud) EnableAPIs

func (g *GCloud) EnableAPIs(projectID string, apis ...string) error

EnableAPIs enables APIs for the given services

func (*GCloud) FindBucket

func (g *GCloud) FindBucket(bucketName string) bool

FindBucket finds a Google Storage bucket

func (*GCloud) FindServiceAccount

func (g *GCloud) FindServiceAccount(serviceAccount string, projectID string) bool

FindServiceAccount checks if a service account exists

func (*GCloud) GetEnabledApis

func (g *GCloud) GetEnabledApis(projectID string) ([]string, error)

GetEnabledApis returns which services have the API enabled

func (*GCloud) GetManagedZoneNameServers

func (g *GCloud) GetManagedZoneNameServers(projectID string, domain string) (string, []string, error)

GetManagedZoneNameServers retrieves a list of name servers associated with a zone

func (*GCloud) GetOrCreateServiceAccount

func (g *GCloud) GetOrCreateServiceAccount(serviceAccount string, projectID string, clusterConfigDir string, roles []string) (string, error)

GetOrCreateServiceAccount retrieves or creates a GCP service account. It will return the path to the file where the service account token is stored

func (*GCloud) GetProjectNumber

func (g *GCloud) GetProjectNumber(projectID string) (string, error)

func (*GCloud) GetServiceAccountKeys

func (g *GCloud) GetServiceAccountKeys(serviceAccount string, projectID string) ([]string, error)

GetServiceAccountKeys returns all keys of a service account

func (*GCloud) IsGCSWriteRoleEnabled

func (g *GCloud) IsGCSWriteRoleEnabled(cluster string, zone string) (bool, error)

IsGCSWriteRoleEnabled will check if the devstorage.full_control scope is enabled in the cluster in order to use GCS

func (*GCloud) IsKmsKeyAvailable

func (g *GCloud) IsKmsKeyAvailable(keyName string, keyringName string, projectID string) bool

IsKmsKeyAvailable checks if the KMS key is already available

func (*GCloud) IsKmsKeyringAvailable

func (g *GCloud) IsKmsKeyringAvailable(keyringName string, projectID string) bool

IsKmsKeyringAvailable checks if the KMS keyring is already available

func (*GCloud) ListClusters

func (g *GCloud) ListClusters(region string, projectID string) ([]Cluster, error)

ListClusters returns the clusters in a GKE project

func (*GCloud) ListObjects

func (g *GCloud) ListObjects(bucketName string, path string) ([]string, error)

ListObjects checks if a Google Storage bucket exists

func (*GCloud) LoadGkeCluster

func (g *GCloud) LoadGkeCluster(region string, projectID string, clusterName string) (*Cluster, error)

LoadGkeCluster load a gke cluster from a GKE project

func (*GCloud) Login

func (g *GCloud) Login(serviceAccountKeyPath string, skipLogin bool) error

Login login an user into Google account. It skips the interactive login using the browser when the skipLogin flag is active

func (*GCloud) UpdateGkeClusterLabels

func (g *GCloud) UpdateGkeClusterLabels(region string, projectID string, clusterName string, labels []string) error

UpdateGkeClusterLabels updates labesl for a gke cluster

func (*GCloud) UserLabel

func (g *GCloud) UserLabel() string

UserLabel returns a string identifying current user that can be used as a label

type GClouder

type GClouder interface {
	CreateManagedZone(projectID string, domain string) error
	CreateDNSZone(projectID string, domain string) (string, []string, error)
	GetManagedZoneNameServers(projectID string, domain string) (string, []string, error)
	ClusterZone(cluster string) (string, error)
	BucketExists(projectID string, bucketName string) (bool, error)
	CreateBucket(projectID string, bucketName string, location string) error
	AddBucketLabel(bucketName string, label string)
	FindBucket(bucketName string) bool
	DeleteAllObjectsInBucket(bucketName string) error
	DeleteBucket(bucketName string) error
	FindServiceAccount(serviceAccount string, projectID string) bool
	GetOrCreateServiceAccount(serviceAccount string, projectID string, clusterConfigDir string, roles []string) (string, error)
	CreateServiceAccountKey(serviceAccount string, projectID string, keyPath string) error
	GetServiceAccountKeys(serviceAccount string, projectID string) ([]string, error)
	ListClusters(region string, projectID string) ([]Cluster, error)
	LoadGkeCluster(region string, projectID string, clusterName string) (*Cluster, error)
	UpdateGkeClusterLabels(region string, projectID string, clusterName string, labels []string) error
	DeleteServiceAccountKey(serviceAccount string, projectID string, key string) error
	CleanupServiceAccountKeys(serviceAccount string, projectID string) error
	DeleteServiceAccount(serviceAccount string, projectID string, roles []string) error
	GetEnabledApis(projectID string) ([]string, error)
	EnableAPIs(projectID string, apis ...string) error
	Login(serviceAccountKeyPath string, skipLogin bool) error
	CheckPermission(perm string, projectID string) (bool, error)
	CreateKmsKeyring(keyringName string, projectID string) error
	IsKmsKeyringAvailable(keyringName string, projectID string) bool
	CreateKmsKey(keyName string, keyringName string, projectID string) error
	IsKmsKeyAvailable(keyName string, keyringName string, projectID string) bool
	IsGCSWriteRoleEnabled(cluster string, zone string) (bool, error)
	UserLabel() string
	CreateGCPServiceAccount(kubeClient kubernetes.Interface, serviceName, serviceAbbreviation, namespace, clusterName, projectID string, serviceAccountRoles []string, serviceAccountSecretKey string) (string, error)
	ConnectToCluster(projectID, zone, clusterName string) error
	ConnectToRegionCluster(projectID, region, clusterName string) error
	ConfigureBucketRoles(projectID string, serviceAccount string, bucketURL string, roles []string) error
	GetProjectNumber(projectID string) (string, error)
}

GClouder interface to define interactions with the gcloud command

type ImageTagInfo

type ImageTagInfo struct {
	Digest string   `json: "digest"`
	Tags   []string `json: "tags"`
}

ImageTagInfo contains tag information for container images

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL