tools

package
v0.0.0-...-29c494f Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: Unlicense Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SubdomainRegexp = regexp.MustCompile(`[A-Za-z](?:[A-Za-z0-9\-]*[A-Za-z0-9])?`)

SubdomainRegexp is regular expression for dns subdomain name; used for k8s resource name. cf. https://tools.ietf.org/html/rfc1035

Functions

func ApplyTextTemplate

func ApplyTextTemplate(source io.Reader, config Config) (io.Reader, error)

ApplyTextTemplate applies template to source Reader with Config as data. Then returns Reader which reads result text.

func CreateOrGetTFBackendBucket

func CreateOrGetTFBackendBucket(ctx context.Context, client *storage.Client) (string, error)

CreateOrGetTFBackendBucket generates Cloud Storage bucket name for terraform backend and create new bucket with that name if it does not exists.

func GetGKECredentials

func GetGKECredentials(out io.Writer, clusterName string, clusterZone string) error

GetGKECredentials calls `gcloud containers clusters get-credentials`

func GetProjectBillingAccount

func GetProjectBillingAccount(ctx context.Context) (string, error)

GetProjectBillingAccount returns name of billing account for the project.

func GetProjectID

func GetProjectID(ctx context.Context) (string, error)

GetProjectID detects GCP project ID from instance metadata (for GCE, GCF, GAE, ...) or gcloud CLI.

func IsGrpcNotFound

func IsGrpcNotFound(e error) bool

IsGrpcNotFound returns true if the error is representing gRPC not found status code. false if not.

func IsValidK8sMetadataName

func IsValidK8sMetadataName(text string) bool

IsValidK8sMetadataName validates that text is valid subdomain name which can be used as Kubernates resource name.

func ReadFromStringOrPath

func ReadFromStringOrPath(strOrPath string) ([]byte, error)

ReadFromStringOrPath parses strOrPath and read payload, then return as sequence of bytes. If single hyphen is given, read remaining contents from stdin. If absolute path is given, read all contents from the file. Otherwise, just returns byte representation of the given string.

Types

type ClusterConfig

type ClusterConfig struct {
	Name             string `json:"name"`
	Location         string `json:"location"`
	VPCConnectorName string `json:"vpc_connector_name"`
}

ClusterConfig is schema of cluster block in config.yaml

type Config

type Config struct {
	Region  string        `json:"region"`
	Zone    string        `json:"zone"`
	Cluster ClusterConfig `json:"cluster"`
	Network NetworkConfig `json:"network"`
	Gate    GateConfig    `json:"gate"`
}

Config is schema of config.yaml

func (Config) IngressIP

func (config Config) IngressIP() (string, error)

func (Config) ProjectID

func (Config) ProjectID() (string, error)

func (Config) RegionID

func (config Config) RegionID() (string, error)

type GateConfig

type GateConfig struct {
	ServiceID string `json:"service_id"`
}

GateConfig is schema of gate block in config.yaml

type NetworkConfig

type NetworkConfig struct {
	PrimaryCidrRange      string `json:"primary_cidr_range"`
	PodCidrRange          string `json:"pod_cidr_range"`
	ServiceCidrRange      string `json:"service_cidr_range"`
	MasterCidrRange       string `json:"master_cidr_range"`
	VPCConnectorCidrRange string `json:"vpc_connector_cidr_range"`
	IngressIPResourceID   string `json:"ingress_ip_resource_id"`
}

NetworkConfig is schema of network block in config.yaml

type SecretHandle

type SecretHandle struct {
	MetadataName string
	Key          string
}

SecretHandle hols information that points to the secret data which managed by cloud secret manager.

func NewSecretHandles

func NewSecretHandles(secret corev1.Secret) []SecretHandle

NewSecretHandles builds SecretHandles from k8s Secret.

func (SecretHandle) Exists

func (handle SecretHandle) Exists(ctx context.Context) (bool, error)

Exists tests precense of the secret pointed by the SecretHandle.

func (SecretHandle) Set

func (handle SecretHandle) Set(ctx context.Context, payload []byte) error

Set stores payload to cloud for the secret pointed by the SecretHandle.

func (SecretHandle) String

func (handle SecretHandle) String() string

func (SecretHandle) Unvail

func (handle SecretHandle) Unvail(ctx context.Context) ([]byte, error)

Unvail retrieves secret version from cloud, and returns its payload.

type TFDocument

type TFDocument struct {
	Terraform TFTerraform           `json:"terraform"`
	Variable  map[string]TFVariable `json:"variable"`
}

TFDocument corresponds to terraform source file we are going to generate

type TFObject

type TFObject map[string]interface{}

TFObject is object in terraform json

type TFTerraform

type TFTerraform struct {
	Backend TFTerraformBackend `json:"backend"`
}

TFTerraform is "terraform" block in terraform source file.

type TFTerraformBackend

type TFTerraformBackend struct {
	GCS TFObject `json:"gcs"`
}

TFTerraformBackend is backend configuration using GCS.

type TFVariable

type TFVariable struct {
	Default interface{} `json:"default"`
}

TFVariable is "variable" block in terraform source file.

Jump to

Keyboard shortcuts

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