hope

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package utils -- Utility functions to be used throughout cmd. Kind of decided that this was a pretty decent way of doing shared logic for cmd. Basically the same as for pkg, so nothing too special there, but since cmd has a bit of nesting, it brings up some more questions. It seems like golang itself does a pattern like this for `base` cmd units, so this is probably not too shabby.

Index

Constants

This section is empty.

Variables

View Source
var DockerDaemonJson = `` /* 259-byte string literal not displayed */
View Source
var IpForward = `1
`
View Source
var K8SConf = `net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
`
View Source
var NginxConfig = `` /* 441-byte string literal not displayed */

Functions

func CopySSHKeyToAuthorizedKeys

func CopySSHKeyToAuthorizedKeys(log *logrus.Entry, node *Node) error

func CreateClusterMaster

func CreateClusterMaster(log *logrus.Entry, node *Node, podNetworkCidr string, loadBalancer *Node, loadBalancerHost string, masters *[]Node, force bool) error

func CreateClusterNode

func CreateClusterNode(log *logrus.Entry, node *Node, masters *[]Node, force bool) error

func DisableSelinuxOnRemote

func DisableSelinuxOnRemote(node *Node) error

func DisableSwapOnRemote

func DisableSwapOnRemote(node *Node) error

func EnsureSSHWithoutPassword

func EnsureSSHWithoutPassword(log *logrus.Entry, node *Node) error

func FetchKubeconfig

func FetchKubeconfig(log *logrus.Entry, node *Node, merge bool) error

func FollowLogsAndPollUntilJobComplete

func FollowLogsAndPollUntilJobComplete(log *logrus.Entry, kubectl *kubeutil.Kubectl, nsJob string, maxAttempts int, failedPollDelayMaxSeconds int) error

func FollowLogsIfContainersRunning

func FollowLogsIfContainersRunning(kubectl *kubeutil.Kubectl, namespace, job string) error

func GetPodsForJob

func GetPodsForJob(kubectl *kubeutil.Kubectl, namespace, job string) (*[]string, error)

func InitLoadBalancer added in v0.17.0

func InitLoadBalancer(log *logrus.Entry, node *Node) error

Just forwards to `SetLoadBalancerHosts`. There may be a time where this does more.

func KubeadmGetClusterCertificateKey added in v0.17.0

func KubeadmGetClusterCertificateKey(log *logrus.Entry, node *Node) (string, error)

func KubeadmGetClusterJoinCommandFromAnyMaster added in v0.25.1

func KubeadmGetClusterJoinCommandFromAnyMaster(masters *[]Node) (string, error)

Attempt to pull a token from a master within the list of masters. Accept the first one that succeeds.

func KubeadmResetRemote

func KubeadmResetRemote(log *logrus.Entry, kubectl *kubeutil.Kubectl, node *Node, deleteLocalData bool, force bool) error

func KubectlApplyF

func KubectlApplyF(kubectl *kubeutil.Kubectl, path string) error

func KubectlApplyStdIn

func KubectlApplyStdIn(kubectl *kubeutil.Kubectl, stdin string) error

func KubectlCreateStdIn

func KubectlCreateStdIn(kubectl *kubeutil.Kubectl, stdin string) error

func KubectlDeleteF added in v0.10.0

func KubectlDeleteF(kubectl *kubeutil.Kubectl, path string) error

func KubectlDeleteStdIn added in v0.10.0

func KubectlDeleteStdIn(kubectl *kubeutil.Kubectl, stdin string) error

func KubectlGetCreateStdIn

func KubectlGetCreateStdIn(kubectl *kubeutil.Kubectl, stdin string, args ...string) (string, error)

func ReplaceParametersInDirectoryCopy added in v0.21.0

func ReplaceParametersInDirectoryCopy(dir string, parameters []string) (string, error)

ReplaceParametersInDirectoryCopy - Copy the provided directory, and replace parameters in the files. Returns the temp path to the copied directory, and the caller must clean up that directory itself, unless an error occurs.

func ReplaceParametersInFile added in v0.21.0

func ReplaceParametersInFile(path string, parameters []string) (string, error)

func ReplaceParametersInString added in v0.21.0

func ReplaceParametersInString(str string, parameters []string) (string, error)

func ReplaceParametersWithSubstitutor added in v0.21.0

func ReplaceParametersWithSubstitutor(t *TextSubstitutor, parameters []string) (string, error)

func SetHostname

func SetHostname(log *logrus.Entry, node *Node, hostname string, force bool) error

func SetLoadBalancerHosts added in v0.17.0

func SetLoadBalancerHosts(log *logrus.Entry, node *Node, masters *[]Node) error

func TaintNodeByHost

func TaintNodeByHost(kubectl *kubeutil.Kubectl, node *Node, taint string) error

func TestCanSSHWithoutPassword

func TestCanSSHWithoutPassword(node *Node) error

Attempt to SSH into a machine without allowing password authentication. Also disables strict host checking to prevent the unattended nature of the execution from causing the script to fail.

func TryConfigureSSH

func TryConfigureSSH(log *logrus.Entry, node *Node) error

See what SSH key this host is trying to use, and try copying it over to the appropriate place using password auth.

Types

type BuildSpec added in v0.14.0

type BuildSpec struct {
	Path   string
	Source string
	Tag    string
	Pull   string
}

BuildSpec - Properties of a ResourceTypeDockerBuild

type ExecSpec added in v0.14.0

type ExecSpec struct {
	Selector string
	Timeout  string
	Command  []string
}

ExecSpec - Properties of a ResourceTypeExec

type Job added in v0.14.0

type Job struct {
	Name       string
	File       string
	Parameters []string
}

Job - Properties that can appear in any ephemeral job definition. TODO: Allow jobs to define max retry parameters, or accept them on the command line.

type JobStatus

type JobStatus int
const (
	JobStatusUnknown JobStatus = iota
	JobStatusRunning
	JobStatusComplete
	JobStatusFailed
)

func GetJobStatus

func GetJobStatus(log *logrus.Entry, kubectl *kubeutil.Kubectl, namespace, job string) (JobStatus, error)

Check to see if the provided job has completed, or is still running.

type Node added in v0.14.0

type Node struct {
	Name       string
	Role       string
	Host       string
	Hypervisor string
	Engine     string
	User       string
	Datastore  string
	Network    string
	Cpu        int
	Memory     int
}

Node - Defines a networked resource on which operations will typically be executed. Datastore is really only used for Hypervisors, but whatever; it's not incredibly intuitive how to have non-homogenous types in viper lists. If a more concrete type is eventually used, the Role property should become an enum/bitfield.

func (*Node) ConnectionString added in v0.14.0

func (node *Node) ConnectionString() string

ConnectionString - Get the node's connection string

func (*Node) IsHypervisor added in v0.15.0

func (node *Node) IsHypervisor() bool

IsHypervisor - Whether or not this node is a hypervisor node.

func (*Node) IsKubernetesNode added in v0.15.0

func (node *Node) IsKubernetesNode() bool

IsKubernetesNode - Whether or not this node has one of the Kubernetes roles.

func (*Node) IsLoadBalancer added in v0.17.0

func (node *Node) IsLoadBalancer() bool

IsLoadBalancer - Whether or not this node is a load-balancer node.

func (*Node) IsMaster added in v0.14.0

func (node *Node) IsMaster() bool

IsMaster - Whether or not this node is a control plane node.

func (*Node) IsMasterAndNode added in v0.14.0

func (node *Node) IsMasterAndNode() bool

IsMasterAndNode - Whether or not this node plays the roles of both control plane and worker node.

func (*Node) IsNode added in v0.14.0

func (node *Node) IsNode() bool

IsNode - Whether or not this node is a worker node.

func (*Node) IsRoleValid added in v0.14.0

func (node *Node) IsRoleValid() bool

IsRoleValid - Whether or not the node has a role that has been implemented.

type NodeRole added in v0.18.1

type NodeRole int
const (
	// NodeRoleHypervisor - Host that manages the other nodes listed.
	NodeRoleHypervisor NodeRole = iota

	// NodeRoleLoadBalancer - API Server load balancer VM that runs an
	//   instance of NGINX pointing at the Master nodes' API servers.
	NodeRoleLoadBalancer

	// NodeRoleMaster - Control plane nodes
	NodeRoleMaster

	// NodeRoleMasterAndNode - For small clusters, a machine that acts as both
	//   master and node.
	// Master node with the master:NoSchedule taint removed.
	NodeRoleMasterAndNode

	// NodeRoleNode - Plain Kubernetes node.
	NodeRoleNode
)

func (NodeRole) String added in v0.18.1

func (nr NodeRole) String() string

type NodeStatus added in v0.23.0

type NodeStatus int
const (
	// NodeStatusUnavailable - Something probably went wrong, and it couldn't
	//   be determined what the state of this node is.
	// Maybe the node exists, but it isn't serving properly, but in general,
	//   the node was found, but isn't but isn't doing what it's supposed to.
	NodeStatusUnavailable NodeStatus = iota

	// NodeStatusHealthy - Node is doing exactly what it should be doing.
	NodeStatusHealthy

	// NodeStatusDoesNotExist - Node is not available on Kubernetes, and not
	//   visible on its hypervisor.
	NodeStatusDoesNotExist
)

func (NodeStatus) String added in v0.23.0

func (ns NodeStatus) String() string

type Resource added in v0.14.0

type Resource struct {
	Name           string
	File           string
	Inline         string
	Parameters     []string
	FileParameters []string
	Build          BuildSpec
	Job            string
	Exec           ExecSpec
	Tags           []string
}

Resource - Properties that can appear in any resources. There may be a better way of doing this, but with a pretty generic list of items appearing in a yaml file, maybe not.

func (*Resource) GetType added in v0.14.0

func (resource *Resource) GetType() (ResourceType, error)

GetType - Scan through defined properties, and return the resource type that the resource appears to implement.

type ResourceType added in v0.14.0

type ResourceType int

ResourceType enum to differentiate the types of resource definitions that can appear in the hope yaml file.

const (
	// ResourceTypeUnknown - No resource type could be determined for the
	//   resource being evaluated.
	ResourceTypeUnknown ResourceType = iota

	// ResourceTypeFile - Provide a path to a local file/URL to a remote file
	//    to apply.
	ResourceTypeFile

	// ResourceTypeInline - Provide an inline yaml definition of resources to
	//   apply.
	ResourceTypeInline

	// ResourceTypeDockerBuild - Build a docker image with the given context
	//   path, and push it to the specified repository.
	ResourceTypeDockerBuild

	// ResourceTypeJob - Wait for a job with the given name to finish
	//   executing.
	ResourceTypeJob

	// ResourceTypeExec - Execute a script in a running pod/container.
	ResourceTypeExec
)

func (ResourceType) String added in v0.14.0

func (rt ResourceType) String() string

Not using stringer generation because of user-provided strings. Not using arrays to prevent ordering issues.

type TextSubstitutor

type TextSubstitutor struct {
	Bytes *[]byte
}

func NewTextSubstitutorFromBytes

func NewTextSubstitutorFromBytes(bytes []byte) *TextSubstitutor

func NewTextSubstitutorFromString

func NewTextSubstitutorFromString(str string) *TextSubstitutor

func TextSubstitutorFromFilepath

func TextSubstitutorFromFilepath(filepath string) (*TextSubstitutor, error)

func (*TextSubstitutor) SubstituteTextFromEnv

func (t *TextSubstitutor) SubstituteTextFromEnv(envVarsNames []string) error

func (*TextSubstitutor) SubstituteTextFromMap

func (t *TextSubstitutor) SubstituteTextFromMap(variables map[string]string) error

type VMImageSpec added in v0.15.0

type VMImageSpec struct {
	Name        string
	Hypervisors []string
	Parameters  []string
}

VMImageSpec - Defines the structure needed to populate a Packer job to build a VM Image.

type VMs added in v0.15.0

type VMs struct {
	Images []VMImageSpec
	Cache  string
	Output string
	Root   string
}

VMs - Object defining path information for building any VMs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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