ccpatch

package
v0.3.12-test Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

CCPatch

CCPatch is a tool for patching cloud-config files. It is designed to be used in conjunction with cloud-init, but can be used with any tool that reads cloud-config files in YAML format.

Is supports a few edge cases for our ionos-cloudinit, like environment keys and substitutions.

Substitutions

You must save the globalState object either in the state of your controller or in a global configmap. The globalState stores Key-Value pairs for each identifier and is used to replace the substitutions in the cloud-config file.

Substitutions with unknown handlers will be ignored.

Usage
raw := []byte(`#cloud-config ...`)
// or load state
gs := substitution.NewGlobalState()

substitutions = []substitution.Substitution{
		{
			Type:   "ipv6Address",
			Key:    "$ipv6Address",
			Unique: true,
			AdditionalProperties: map[string]string{
				"cidr": "fc00:1::1/64",
			},
		},
		{
			Type:   "ipv4Address",
			Key:    "$ipv4",
			Unique: true,
			AdditionalProperties: map[string]string{
				"cidr": "192.0.2.0/24",
			},
		},
	}

patcher, err := ccpatch.NewCloudInitPatcherWithSubstitutions(raw, identifier, substitutions, gs)

// ... do as usual with the patcher

// save State in crd status

Take a look at func TestSubstitutionManager(t *testing.T) {

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDecodeFailed is returned when base64 decoding fails
	ErrDecodeFailed = errors.New("failed to decode base64")
	// ErrNoCloudConfig is returned when no cloud-config header is found
	ErrNoCloudConfig = errors.New("no cloud-config header found")
	// ErrMalformedData is returned when the cloud-init data is malformed
	ErrMalformedData = errors.New("malformed cloud-init data")
)

Functions

func IsCloudConfig

func IsCloudConfig(userdata string) bool

IsCloudConfig checks if the given userdata is a cloud-config

Types

type CloudInitPatcher

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

CloudInitPatcher is a helper to patch cloud-init userdata

func NewCloudInitPatcher

func NewCloudInitPatcher(rawUserData string) (*CloudInitPatcher, error)

NewCloudInitPatcher returns a new CloudInitPatcher instance from a base64 encoded string

func NewCloudInitPatcherWithSubstitutions

func NewCloudInitPatcherWithSubstitutions(rawUserData string, identifier substitution.Identifier, substitutions []substitution.Substitution, globalState *substitution.GlobalState) (*CloudInitPatcher, error)

NewCloudInitPatcherWithSubstitutions returns a new CloudInitPatcher instance with a list of substitutions

func (*CloudInitPatcher) Encode

func (c *CloudInitPatcher) Encode() string

Encode returns the base64 encoded cloud-init data

func (*CloudInitPatcher) Get

func (c *CloudInitPatcher) Get(key string) any

Get returns the value of a key in the cloud-init data

func (*CloudInitPatcher) GetEnv

func (c *CloudInitPatcher) GetEnv(key string) string

GetEnv returns the value of an environment variable in the cloud-init data

func (*CloudInitPatcher) Patch

func (c *CloudInitPatcher) Patch(key string, value any) *CloudInitPatcher

Patch adds or modifies a key-value pair in the cloud-init data

func (*CloudInitPatcher) SetEnv

func (c *CloudInitPatcher) SetEnv(key string, value string) *CloudInitPatcher

SetEnv sets an environment variable in the cloud-init data within the "environment" key

func (*CloudInitPatcher) String

func (c *CloudInitPatcher) String() string

String returns the cloud-init data as a string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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