resource

package
v0.8.3-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2020 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServiceInactive is a non-started service.
	ServiceInactive = "inactive"
	// ServiceActivating is a starting service.
	ServiceActivating = "activating"
	// ServiceActive is a started service.
	ServiceActive = "active"
	// ServiceFailed is a service that failed to start
	ServiceFailed = "failed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Deb

type Deb struct {
	Name string `structs:"name"`
	// Suffix is either "=" followed by the version, or "/" followed by the release stream (stable|testing|unstable).
	// Examples:
	//   Name: "busybox"
	//   Name: "busybox", Suffix: "/stable"
	//   Name: "busybox", Suffix: "=1:1.27.2-2ubuntu3.2"
	Suffix string `structs:"suffix"`
}

Deb represents a .deb package.

func DebResourceFromPackage

func DebResourceFromPackage(p debPkgInfo) *Deb

func (*Deb) Apply

func (d *Deb) Apply(runner plan.Runner, diff plan.Diff) (propagate bool, err error)

func (*Deb) QueryState

func (d *Deb) QueryState(runner plan.Runner) (plan.State, error)

func (*Deb) State

func (d *Deb) State() plan.State

func (*Deb) Undo

func (d *Deb) Undo(runner plan.Runner, current plan.State) error

func (*Deb) WouldChangeState

func (d *Deb) WouldChangeState(r plan.Runner) (bool, error)

WouldChangeState returns false if it's guaranteed that a call to Apply() wouldn't change the package installed, and true otherwise.

type Dir

type Dir struct {
	// Path at which to create directory
	Path fmt.Stringer `structs:"path,omitempty"`
	// RecursiveDelete makes the undo operation recursive
	RecursiveDelete bool
}

Dir represents a directory on the file system.

func (*Dir) Apply

func (d *Dir) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource.

func (*Dir) QueryState

func (d *Dir) QueryState(runner plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*Dir) State

func (d *Dir) State() plan.State

State implements plan.Resource.

func (*Dir) Undo

func (d *Dir) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type File

type File struct {
	// Source is a path to a local file. Only of of (Source, Content) can be
	// specified at once.
	Source string `structs:"source,omitempty"`
	// Content is the file content. Only of of (Source, Content) can be specified
	// at once.
	Content string `structs:"content,omitempty"`
	// Destination is the file destination path (required).
	Destination string `structs:"destination"`
	// File MD5 checksum. We use md5sum as it's part of coreutils and even part of
	// the default alpine image.
	Checksum string `structs:"checksum" plan:"hide"`
}

File represents a file on the file system.

func (*File) Apply

func (f *File) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource.

func (*File) QueryState

func (f *File) QueryState(runner plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*File) State

func (f *File) State() plan.State

State implements plan.Resource.

func (*File) Undo

func (f *File) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type GatherFactFunc

type GatherFactFunc func(o *OS, r plan.Runner) error

type KubeSecret

type KubeSecret struct {

	// SecretName is the name of the secret to read
	SecretName string `structs:"secretName"`
	// Checksum contains the sha256 checksum of the secret data
	Checksum [sha256.Size]byte `structs:"checksum"`
	// DestinationDirectory is the location in which to write stored file data
	DestinationDirectory string `structs:"destinationDirectory"`
	// SecretData holds the actual secret contents -- not serialized
	SecretData map[string][]byte `structs:"-" plan:"hide"`
	// FileNameTransform transforms a secret key into the file name for its contents
	FileNameTransform func(string) string
	// contains filtered or unexported fields
}

KubeSecret is a resource that reads a value out of a secret and writes it to the filesystem. It can only be created when running in code deployed within the cluster because we want to store the hash of the secret data in the Resource before the Plan is run so we can compare it against a later version of the Plan when the secret is updated.

func NewKubeSecretResource

func NewKubeSecretResource(secretName, destinationDirectory, ns string, fileNameTransform func(string) string) (*KubeSecret, error)

func (*KubeSecret) Apply

func (ks *KubeSecret) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource.

func (*KubeSecret) QueryState

func (ks *KubeSecret) QueryState(runner plan.Runner) (plan.State, error)

func (*KubeSecret) State

func (ks *KubeSecret) State() plan.State

State implements plan.Resource.

func (*KubeSecret) Undo

func (ks *KubeSecret) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type KubeadmInit

type KubeadmInit struct {

	// PublicIP is public IP of the master node we are trying to setup here.
	PublicIP string `structs:"publicIP"`
	// PrivateIP is private IP of the master node we are trying to setup here.
	PrivateIP string `structs:"privateIP"`
	// NodeName, if non-empty, will override the default node name guessed by kubeadm.
	NodeName string
	// KubeletConfig groups all options & flags which need to be passed to kubelet.
	KubeletConfig *config.KubeletConfig `structs:"kubeletConfig"`
	// ConntrackMax is the maximum number of NAT connections for kubeproxy to track (0 to leave as-is).
	ConntrackMax int32 `structs:"conntrackMax"`
	// UseIPTables controls whether the following command is called or not:
	//   sysctl net.bridge.bridge-nf-call-iptables=1
	// prior to running kubeadm init.
	UseIPTables bool `structs:"useIPTables"`
	// kubeadmInitScriptPath is the path to the "kubeadm init" script to use.
	KubeadmInitScriptPath string `structs:"kubeadmInitScriptPath"`
	// IgnorePreflightErrors is optionally used to skip kubeadm's preflight checks.
	IgnorePreflightErrors []string `structs:"ignorePreflightErrors"`
	// SSHKeyPath is the path to the private SSH key used by WKS to SSH into
	// nodes to add/remove them to/from the Kubernetes cluster.
	SSHKeyPath string `structs:"sshKeyPath"`
	// BootstrapToken is the token used by kubeadm init and kubeadm join to
	// safely form new clusters.
	BootstrapToken *kubeadmapi.BootstrapTokenString `structs:"bootstrapToken"`
	// The version of Kubernetes to install
	KubernetesVersion string `structs:"kubernetesVersion"`
	// ControlPlaneEndpoint is the IP:port of the control plane load balancer.
	// Default: localhost:6443
	// See also: https://kubernetes.io/docs/setup/independent/high-availability/#stacked-control-plane-and-etcd-nodes
	ControlPlaneEndpoint string `structs:"controlPlaneEndpoint"`
	// Cloud provider setting which is needed for kubeadm and kubelet
	CloudProvider string `structs:"cloudProvider"`
	// ImageRepository sets the container registry to pull images from. If empty,
	// `k8s.gcr.io` will be used by default.
	ImageRepository string `structs:"imageRepository"`
	// ExternalLoadBalancer is the name or IP of the external load balancer setup
	// in from the the API master nodes.
	ExternalLoadBalancer string
	// AdditionalSANs can hold additional SANs to add to the API server certificate.
	AdditionalSANs []string
	// The namespace in which to init kubeadm
	Namespace fmt.Stringer
	// Extra arguments to pass to the APIServer
	ExtraAPIServerArgs map[string]string
	// The IP range for service VIPs
	ServiceCIDRBlock string
	// PodCIDRBlock is the subnet used by pods.
	PodCIDRBlock string
	// contains filtered or unexported fields
}

KubeadmInit represents an attempt to init a Kubernetes node via kubeadm.

func (*KubeadmInit) Apply

func (ki *KubeadmInit) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource. TODO: find a way to make this idempotent. TODO: should such a resource be split into smaller resources?

func (*KubeadmInit) QueryState

func (b *KubeadmInit) QueryState(runner plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*KubeadmInit) State

func (ki *KubeadmInit) State() plan.State

State implements plan.Resource.

func (*KubeadmInit) Undo

func (ki *KubeadmInit) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type KubeadmJoin

type KubeadmJoin struct {

	// IsMaster should be true if this node should join as a master, or false otherwise.
	IsMaster bool `structs:"isMaster"`
	// NodeIP is the IP of the node trying to join the cluster.
	NodeIP string `structs:"nodeIP"`
	// NodeName, if non-empty, will override the default node name guessed by kubeadm.
	NodeName string
	// MasterIP is the IP of the master node to connect to in order to join the cluster --
	// hidden because the value can change in multi-master configurations but should not make the node plan
	// appear to have changed.
	MasterIP string `structs:"masterIP" plan:"hide"`
	// MasterPort is the port of the master node to connect to in order to join the cluster.
	MasterPort int `structs:"masterPort"`
	// Token is used to authenticate with the Kubernetes API server.
	Token string `structs:"token" plan:"hide"`
	// DiscoveryTokenCaCertHash is used to validate that the root CA public key of the cluster we are trying to join matches.
	DiscoveryTokenCaCertHash string `structs:"discoveryTokenCaCertHash" plan:"hide"`
	// CertificateKey is used to add master nodes to the cluster.
	CertificateKey string `structs:"certificateKey" plan:"hide"`
	// IgnorePreflightErrors is optionally used to skip kubeadm's preflight checks.
	IgnorePreflightErrors []string `structs:"ignorePreflightErrors"`
	// External Load Balancer name or IP address to be used instead of the master's IP
	ExternalLoadBalancer string `structs:"externalLoadBalancer"`
	// Kubernetes Version is used to prepare different parameters
	KubernetesVersion string `structs:"version"`
	// contains filtered or unexported fields
}

KubeadmJoin represents an attempt to join a Kubernetes node via kubeadm.

func (*KubeadmJoin) Apply

func (kj *KubeadmJoin) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource. TODO: find a way to make this idempotent. TODO: should such a resource be splitted in smaller resources?

func (*KubeadmJoin) QueryState

func (b *KubeadmJoin) QueryState(runner plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*KubeadmJoin) State

func (kj *KubeadmJoin) State() plan.State

State implements plan.Resource.

func (*KubeadmJoin) Undo

func (kj *KubeadmJoin) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type KubectlApply

type KubectlApply struct {

	// Filename is the remote manifest file name.
	// Only provide this if you do NOT provide ManifestPath or ManifestURL.
	Filename fmt.Stringer `structs:"filename"`
	// Manifest is the actual YAML/JSON content of the manifest to apply.
	// If this is provided, then there is no need to provide ManifestPath, but
	// Filename should be provided in order to name the remote manifest file.
	Manifest []byte `structs:"manifest"`
	// ManifestPath is the path to the manifest to apply.
	// If this is provided, then there is no need to provide Manifest.
	ManifestPath fmt.Stringer `structs:"manifestPath"`
	// ManifestURL is the URL of a remote manifest; if specified,
	// neither Filename, Manifest, nor ManifestPath should be specified.
	ManifestURL fmt.Stringer `structs:"manifestURL"`
	// WaitCondition, if not empty, makes Apply() perform "kubectl wait --for=<value>" on the resource.
	Namespace fmt.Stringer `structs:"namespace"`
	// OpaqueManifest is an alternative to Manifest for a resource to
	// apply whose content should not be exposed in a serialized plan.
	// If this is provided, then there is no need to provide
	// ManifestPath, but Filename should be provided in order to name
	// the remote manifest file.
	OpaqueManifest []byte `structs:"-" plan:"hide"`
	// ManifestPath is the path to the manifest to apply.
	// If this is provided, then there is no need to provide Manifest.
	// For example, waiting for "condition=established" is required after creating a CRD - see issue #530.
	WaitCondition string `structs:"afterApplyWaitsFor"`
	// contains filtered or unexported fields
}

KubectlApply is a resource applying the provided manifest. It doesn't realise any state, Apply will always apply the manifest.

func (*KubectlApply) Apply

func (ka *KubectlApply) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply performs a "kubectl apply" as specified in the receiver.

func (*KubectlApply) QueryState

func (b *KubectlApply) QueryState(runner plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*KubectlApply) State

func (ka *KubectlApply) State() plan.State

State implements plan.Resource.

func (*KubectlApply) Undo

func (b *KubectlApply) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type KubectlWait

type KubectlWait struct {

	// Namespace specifies the namespace in which to search for the object being waited on
	WaitNamespace string `structs:"namespace"`
	// WaitType specifies the object type to wait for
	WaitType string `structs:"typeWaitedFor"`
	// WaitSelector, if not empty, specifies which instances of the type to wait for
	WaitSelector string `structs:"itemsWaitedFor"`
	// WaitCondition specifies the condition to wait for
	WaitCondition string `structs:"waitFor"`
	// WaitTimeout, if specified, indicates how long to wait for the WaitCondition to become true before failing (default 30s)
	WaitTimeout string `structs:"waitTimeout"`
	// contains filtered or unexported fields
}

KubectlWait waits for an object to reach a required state

func (*KubectlWait) Apply

func (kw *KubectlWait) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply performs a "kubectl wait" as specified in the receiver.

func (*KubectlWait) QueryState

func (b *KubectlWait) QueryState(runner plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*KubectlWait) State

func (kw *KubectlWait) State() plan.State

State implements plan.Resource.

func (*KubectlWait) Undo

func (b *KubectlWait) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type OS

type OS struct {

	// Name is the OS name, eg. 'centos' or 'debian'. On systemd OSes, this is the ID
	// field of /etc/os-release. See:
	//   https://www.freedesktop.org/software/systemd/man/os-release.html
	Name string `structs:"Name"`

	// Version the OS version. On systemd OSes, this is the VERSION_ID field of
	// /etc/os-release. See:
	//   https://www.freedesktop.org/software/systemd/man/os-release.html
	Version    string `structs:"Version"`
	MachineID  string `structs:"MachineID"`
	SystemUUID string `structs:"SystemUUID"`
	// contains filtered or unexported fields
}

OS is a set of OS properties.

func NewOS

func NewOS(r plan.Runner) (*OS, error)

func (*OS) Apply

func (p *OS) Apply(r plan.Runner, _ plan.Diff) (bool, error)

Apply implements plan.Resource.

func (*OS) GetMachineID

func (p *OS) GetMachineID(r plan.Runner) (string, error)

func (*OS) GetSELinuxStatus

func (p *OS) GetSELinuxStatus() (SELinuxStatus, SELinuxMode, error)

func (*OS) GetSystemUUID

func (p *OS) GetSystemUUID(r plan.Runner) (string, error)

func (*OS) HasCommand

func (p *OS) HasCommand(cmd string) (bool, error)

func (*OS) IsOSInContainerVM

func (p *OS) IsOSInContainerVM() (bool, error)

func (*OS) IsSELinuxMode

func (p *OS) IsSELinuxMode(mode string) (bool, error)

func (*OS) QueryState

func (p *OS) QueryState(r plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*OS) State

func (p *OS) State() plan.State

State implements plan.Resource.

func (*OS) Undo

func (p *OS) Undo(r plan.Runner, current plan.State) error

type PkgType

type PkgType string
const (
	PkgTypeDeb  PkgType = "Deb"
	PkgTypeRPM  PkgType = "RPM"
	PkgTypeRHEL PkgType = "RHEL"
)

type RPM

type RPM struct {
	Name string `structs:"name"`
	// Version is optional
	Version         string `structs:"version,omitempty"`
	Release         string `structs:"release,omitempty"`
	DisableExcludes string `structs:"disableExcludes,omitempty"`
}

RPM represents an RPM package.

It isn't legal to provide a Release if no Version is specified. TODO: What about epoch?

func (*RPM) Apply

func (p *RPM) Apply(r plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource.

func (*RPM) QueryState

func (p *RPM) QueryState(r plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*RPM) State

func (p *RPM) State() plan.State

State implements plan.Resource.

func (*RPM) Undo

func (p *RPM) Undo(r plan.Runner, current plan.State) error

Undo implements plan.Resource

func (*RPM) WouldChangeState

func (p *RPM) WouldChangeState(r plan.Runner) (bool, error)

WouldChangeState returns false if a call to Apply() is guaranteed not to change the installed version of the package, and true otherwise.

type ReadFileCmdFunc

type ReadFileCmdFunc func(s ...string) string

type Run

type Run struct {
	Script       fmt.Stringer  `structs:"script"`
	UndoScript   fmt.Stringer  `structs:"undoScript,omitempty"`
	UndoResource plan.Resource `structs:"undoResource,omitempty"`
	Output       *string       // for later resources to use
	// contains filtered or unexported fields
}

Run is a resource running a script (which can be just a single command). Run doesn't realise any state, Apply will always run the given script.

func (*Run) Apply

func (r *Run) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource.

func (*Run) QueryState

func (b *Run) QueryState(runner plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*Run) State

func (r *Run) State() plan.State

State implements plan.Resource.

func (*Run) Undo

func (r *Run) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type RunScript

type RunScript struct {
	Path string      `structs:"path"`
	Args interface{} `structs:"args"`
	// contains filtered or unexported fields
}

RunScript is a resource running the script available at the provided path. Run doesn't realise any state, Apply will always run the given script.

func (*RunScript) Apply

func (r *RunScript) Apply(runner plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource.

func (*RunScript) QueryState

func (b *RunScript) QueryState(runner plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*RunScript) State

func (r *RunScript) State() plan.State

State implements plan.Resource.

func (*RunScript) Undo

func (b *RunScript) Undo(runner plan.Runner, current plan.State) error

Undo implements plan.Resource.

type SELinuxMode

type SELinuxMode int
const (
	SELinuxModeUnknown SELinuxMode = iota
	SELinuxEnforcing
	SELinuxPermissive
	SELinuxDisabled
)

func (SELinuxMode) IsDisabled

func (m SELinuxMode) IsDisabled() bool

func (SELinuxMode) IsEnforcing

func (m SELinuxMode) IsEnforcing() bool

func (SELinuxMode) IsPermissive

func (m SELinuxMode) IsPermissive() bool

func (SELinuxMode) IsUnknown

func (m SELinuxMode) IsUnknown() bool

type SELinuxStatus

type SELinuxStatus int
const (
	SELinuxUnknown SELinuxStatus = iota
	SELinuxNotInstalled
	SELinuxInstalled
)

func (SELinuxStatus) IsInstalled

func (s SELinuxStatus) IsInstalled() bool

func (SELinuxStatus) IsNotInstalled

func (s SELinuxStatus) IsNotInstalled() bool

func (SELinuxStatus) IsUnknown

func (s SELinuxStatus) IsUnknown() bool

type Service

type Service struct {
	// Name of the systemd unit.
	Name string `structs:"name"`
	// Status is the desired service status. Only "active" or "inactive" are valid
	// input.
	Status string `structs:"status"`
	// Whether the service is enabled (systemctl enable) or not.
	Enabled bool `structs:"enabled"`
}

Service represents a systemd service.

func (*Service) Apply

func (p *Service) Apply(r plan.Runner, diff plan.Diff) (bool, error)

Apply implements plan.Resource.

func (*Service) QueryState

func (p *Service) QueryState(r plan.Runner) (plan.State, error)

QueryState implements plan.Resource.

func (*Service) State

func (p *Service) State() plan.State

State implements plan.Resource.

func (*Service) Undo

func (p *Service) Undo(r plan.Runner, current plan.State) error

Undo implements plan.Resource

Jump to

Keyboard shortcuts

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