services

package
v0.0.0-...-921a65a Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package services contains logic related to HTTP and CLI clients.

Index

Constants

View Source
const GsutilExec = "gsutil"

Variables

This section is empty.

Functions

This section is empty.

Types

type Clients

type Clients struct {
	Gcloud  GcloudService
	Kubectl KubectlService
	OS      OSService
	Remote  RemoteService
	GCS     GcsService
}

Clients is a wrapper around HTTP clients and CLIs.

func NewClients

func NewClients(ctx context.Context, useGsutil, useGcloud, printCommands bool, serverDryRun bool) (*Clients, error)

NewClients returns a new Clients object with default services.

type Gcloud

type Gcloud struct {
	// contains filtered or unexported fields
}

Gcloud implements the GcloudService interface.

func NewGcloud

func NewGcloud(ctx context.Context, printCommands bool) (*Gcloud, error)

NewGcloud returns a new Gcloud object.

func NewGcloudGoClient

func NewGcloudGoClient(ctx context.Context, printCommands bool) *Gcloud

NewGcloudGoClient returns a new Gcloud object.

func (*Gcloud) ConfigGetValue

func (g *Gcloud) ConfigGetValue(ctx context.Context, property string) (string, error)

ConfigGetValue calls `gcloud config get-value <property>` and returns stdout.

func (*Gcloud) ContainerClustersGetCredentials

func (g *Gcloud) ContainerClustersGetCredentials(ctx context.Context, clusterName, clusterLocation, clusterProject string) error

func (*Gcloud) ContainerClustersGetCredentialsGoClient

func (g *Gcloud) ContainerClustersGetCredentialsGoClient(ctx context.Context, clusterName, clusterLocation, clusterProject string) error

ContainerClustersGetCredentialsGoClient uses the go client libraries to get cluster credentials and generate the kubeconfig file for kubectl. The kubectl authenticates using the accessToken instead of the google-gke-auth-plugin (which depends on gcloud).

type GcloudService

type GcloudService interface {
	ContainerClustersGetCredentials(ctx context.Context, clusterName, clusterLocation, clusterProject string) error
	ContainerClustersGetCredentialsGoClient(ctx context.Context, clusterName, clusterLocation, clusterProject string) error
	ConfigGetValue(ctx context.Context, property string) (string, error)
}

GcloudService is an interface for gcloud operations.

type GcsService

type GcsService interface {
	Copy(ctx context.Context, src, dst string, recursive bool) error
}

GcsService is an interface for interacting with Google Cloud Storage

type Gsutil

type Gsutil struct {
	// contains filtered or unexported fields
}

Gsutil implements the GcsService interface

func NewGsutil

func NewGsutil(ctx context.Context, printCommands bool) (*Gsutil, error)

NewGsutil returns a new Gsutil object

func (*Gsutil) Copy

func (g *Gsutil) Copy(ctx context.Context, src, dst string, recursive bool) error

Copy calls `gsutil cp -r <source_url> <destination_url>

type Kubectl

type Kubectl struct {
	// contains filtered or unexported fields
}

Kubectl implements the KubectlService interface. The service account that is calling this must have permission to access the cluster. e.g., to run on GCB: gcloud projects add-iam-policy-binding <project-id> --member=serviceAccount:<project-number>@cloudbuild.gserviceaccount.com --role=roles/container.admin

func NewKubectl

func NewKubectl(ctx context.Context, printCommands bool, serverDryRun bool) (*Kubectl, error)

NewKubectl returns a new Kubectl object.

func (*Kubectl) Apply

func (k *Kubectl) Apply(ctx context.Context, filename, namespace string) error

Apply calls `kubectl apply -f <filename> n <namespace>`.

func (*Kubectl) ApplyFromString

func (k *Kubectl) ApplyFromString(ctx context.Context, configString, namespace string) error

ApplyFromString calls `kubectl apply -f - -n <namespace> < ${configString}`.

func (*Kubectl) Get

func (k *Kubectl) Get(ctx context.Context, kind, name, namespace, format string, ignoreNotFound bool) (string, error)

Get calls `kubectl get <kind> <name> -n <namespace> --output=<format>`.

type KubectlService

type KubectlService interface {
	Apply(ctx context.Context, filename, namespace string) error
	ApplyFromString(ctx context.Context, configString, namespace string) error
	Get(ctx context.Context, kind, name, namespace, format string, ignoreNotFound bool) (string, error)
}

KubectlService is an interface for kubectl operations.

type OS

type OS struct{}

OS implements the OSService interface.

func NewOS

func NewOS(ctx context.Context) (*OS, error)

NewOS returns a new OS object.

func (*OS) MkdirAll

func (o *OS) MkdirAll(ctx context.Context, dirname string, perm os.FileMode) error

MkdirAll creates a directory dirname, including all parent directories if they do not exist.

func (*OS) ReadDir

func (o *OS) ReadDir(ctx context.Context, dirname string) ([]os.FileInfo, error)

ReadDir gets file descriptions for all files contained in a directory dirname.

func (*OS) ReadFile

func (o *OS) ReadFile(ctx context.Context, filename string) ([]byte, error)

ReadFile gets the entire contents of a file filename as bytes.

func (*OS) RemoveAll

func (o *OS) RemoveAll(ctx context.Context, path string) error

RemoveAll removes path and any children it contains.

func (*OS) Stat

func (o *OS) Stat(ctx context.Context, filename string) (os.FileInfo, error)

Stat gets a file description for a file filename.

func (*OS) TempDir

func (o *OS) TempDir(ctx context.Context, dir, pattern string) (string, error)

TempDir creates a new temporary directory in the directory dir.

func (*OS) WriteFile

func (o *OS) WriteFile(ctx context.Context, filename string, data []byte, perm os.FileMode) error

WriteFile writes data to a file.

type OSService

type OSService interface {
	Stat(ctx context.Context, filename string) (os.FileInfo, error)
	ReadDir(ctx context.Context, dirname string) ([]os.FileInfo, error)
	ReadFile(ctx context.Context, filename string) ([]byte, error)
	WriteFile(ctx context.Context, filename string, data []byte, perm os.FileMode) error
	MkdirAll(ctx context.Context, dirname string, perm os.FileMode) error
	RemoveAll(ctx context.Context, dir string) error
	TempDir(ctx context.Context, dir, pattern string) (string, error)
}

OSService is an interface for os operations.

type Remote

type Remote struct{}

Remote implements the RemoteService interface.

func NewRemote

func NewRemote(ctx context.Context) (*Remote, error)

NewRemote returns a new Remote object.

func (*Remote) Image

func (*Remote) Image(ctx context.Context, ref name.Reference) (v1.Image, error)

Image gets a remote image from a reference.

type RemoteService

type RemoteService interface {
	Image(ctx context.Context, ref name.Reference) (v1.Image, error)
}

RemoteService is an interface for github.com/google/go-containerregistry/pkg/v1/remote.

Jump to

Keyboard shortcuts

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