util

package
v0.0.0-...-23d9192 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CertFileMode = os.FileMode(0644)
	KeyFileMode  = os.FileMode(0600)
)

Variables

This section is empty.

Functions

func CreateOrUpdate

func CreateOrUpdate(ctx context.Context, client *k8s.Client, req k8s.Resource, options ...k8s.Option) error

CreateOrUpdate creates or updates a given resource.

func EnvVarSourceFieldRef

func EnvVarSourceFieldRef(fieldPath string) *corev1.EnvVarSource

EnvVarSourceFieldRef creates a new envvar source with field reference to given field path.

func IntOrStringI

func IntOrStringI(i int32) *intstr.IntOrString

IntOrStringI returns an IntOrString filled with an int.

func IntOrStringS

func IntOrStringS(s string) *intstr.IntOrString

IntOrStringS returns an IntOrString filled with a string.

func IsK8sAlreadyExists

func IsK8sAlreadyExists(err error) bool

IsK8sAlreadyExists returns true if the given error is or is caused by a kubernetes not-found error.

func IsK8sConflict

func IsK8sConflict(err error) bool

IsK8sConflict returns true if the given error is or is caused by a kubernetes conflict error.

func IsK8sNotFound

func IsK8sNotFound(err error) bool

IsK8sNotFound returns true if the given error is or is caused by a kubernetes not-found error.

func NewServiceAccountCertificate

func NewServiceAccountCertificate(saPubPath, saKeyPath string) (string, string, error)

NewServiceAccountCertificate tries to create a service account certificate pair. Returns cert, key, error

func RenderToString

func RenderToString(log zerolog.Logger, templateData string, options interface{}, config ...TemplateConfigurator) (string, error)

RenderToString renders the given template data using given options to string.

Types

type CA

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

CA is a Certificate Authority.

func NewCA

func NewCA(commonName string, caCertPath, caKeyPath string) (CA, error)

NewCA tries to load a CA from given path, if not found, creates a new one.

func (*CA) Cert

func (ca *CA) Cert() string

Cert returns the CA certificate, as PEM encoded

func (*CA) CreateTLSClientAuthCertificate

func (ca *CA) CreateTLSClientAuthCertificate(commonName, orgName string, client SSHClient, additionalHosts ...string) (string, string, error)

CreateTLSClientAuthCertificate creates a TLS client authentication for the given client. Returns certificate, key, error.

func (*CA) CreateTLSServerCertificate

func (ca *CA) CreateTLSServerCertificate(commonName, orgName string, client SSHClient, additionalHosts ...string) (string, string, error)

CreateTLSServerCertificate creates a server certificates for the given client. Returns certificate, key, error.

func (*CA) Key

func (ca *CA) Key() string

Key returns the CA private key, as PEM encoded

type SSHClient

type SSHClient interface {
	io.Closer
	GetAddress() string
	GetHostName() string
	Run(log zerolog.Logger, command, stdin string, quiet bool) (string, error)

	// EnsureDirectoryOf checks if the directory of the given file path exists and if not creates it.
	// If such a path does exist, it checks if it is a directory, if not an error is returned.
	EnsureDirectoryOf(log zerolog.Logger, filePath string, perm os.FileMode) error
	// EnsureDirectory checks if a directory with given path exists and if not creates it.
	// If such a path does exist, it checks if it is a directory, if not an error is returned.
	EnsureDirectory(log zerolog.Logger, dirPath string, perm os.FileMode) error
	// UpdateFile compares the given content with the context of the file at the given filePath and
	// if the content is different, the file is updated.
	// If the file does not exist, it is created.
	UpdateFile(log zerolog.Logger, filePath string, content []byte, perm os.FileMode) error
	// RemoveFile removes the given file.
	// If no such file exists, the request is ignored.
	RemoveFile(log zerolog.Logger, filePath string) error
	// RemoveDirectory removes the given directory with its content.
	// If no such directory exists, the request is ignored.
	RemoveDirectory(log zerolog.Logger, dirPath string) error
	// Render updates the given destinationPath according to the given template and options.
	Render(log zerolog.Logger, templateData, destinationPath string, options interface{}, destinationFileMode os.FileMode, config ...TemplateConfigurator) error
}

func DialSSH

func DialSSH(userName, hostName, address string, dryRun bool) (SSHClient, error)

DialSSH creates a new SSH connection to the given user on the given host.

type TemplateConfigurator

type TemplateConfigurator func(*template.Template)

Jump to

Keyboard shortcuts

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