etcd

package
v0.0.0-...-bfebeee Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

Etcd Configuration Function

Creates Resource configs to deploy Etcd on Kubernetes.

Function Features

Function settings are documented in the Options Go type. Metadata and other data is documented in the ConfigFunction type.

Getting Started

In the following example we create Resource configs for an Etcd server. These configs are meant to be checked into version control, so Secrets are not included. Optionally, all necessary Secrets can be created in-cluster via Jobs -- check out the production demo.

Set up a workspace and define a function configuration.

DEMO=$(mktemp -d)
mkdir $DEMO/functions

cat <<EOF >$DEMO/functions/configmap_my-etcd.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-etcd
  namespace: example
  annotations:
    config.kubernetes.io/function: |
      container:
        image: gcr.io/config-functions/etcd:v0.0.1
EOF

Generate Resources.

config run $DEMO

Generated Resources

The function generates the following resources.

EXPECTED='.
├── [Resource]  ConfigMap example/my-etcd-server
├── [Resource]  ConfigMap example/my-etcd
├── [Resource]  Service example/my-etcd-server
└── [Resource]  StatefulSet example/my-etcd-server'

TEST="$(config tree $DEMO --graph-structure=owners)"
[ "$TEST" = "$EXPECTED" ]

Configuration

Default Function Configuration

The function adds any missing configuration fields to the function ConfigMap we created above, populating their values with defaults.

EXPECTED='apiVersion: v1
kind: ConfigMap
metadata:
  name: my-etcd
  namespace: "example"
  labels:
    app.kubernetes.io/instance: my-etcd
    app.kubernetes.io/name: etcd-server
  annotations:
    config.kubernetes.io/function: |
      container:
        image: gcr.io/config-functions/etcd:v0.0.1
data:
  tls_ca_secret_name: "my-etcd-example-tls-ca"
  tls_generator_job_enabled: "false"
  tls_root_client_secret_name: "my-etcd-example-tls-client-root"
  tls_server_secret_name: "my-etcd-example-tls-server"'

TEST="$(cat $DEMO/functions/configmap_my-etcd.yaml)"
[ "$TEST" = "$EXPECTED" ]
Replicas

If you change the number of replicas for the Etcd StatefulSet and re-run the config function, it can update the TLS generator job, ETCD_INITIAL_CLUSTER config, and other configs for you.

For illustration, let's set spec.replicas to 3 in the previously generated StatefulSet, and remove the old ETCD_INITIAL_CLUSTER setting.

sed -i '/^spec:/a\  replicas: 3' $DEMO/example/statefulset_my-etcd-server.yaml
sed -i '/^  ETCD_INITIAL_CLUSTER:/d' $DEMO/example/configmap_my-etcd-server.yaml
config run $DEMO

The initial cluster settings should be updated.

EXPECTED='.
└── [Resource]  ConfigMap example/my-etcd-server
    └── data.ETCD_INITIAL_CLUSTER: my-etcd-server-0=https://my-etcd-server-0.my-etcd-server:2380,my-etcd-server-1=https://my-etcd-server-1.my-etcd-server:2380,my-etcd-server-2=https://my-etcd-server-2.my-etcd-server:2380'

TEST="$(config tree \
  --field="data.ETCD_INITIAL_CLUSTER" \
  --graph-structure=owners \
  $DEMO/example/configmap_my-etcd-server.yaml)"
[ "$TEST" = "$EXPECTED" ]

Cleanup the demo workspace.

rm -rf $DEMO

Documentation

Index

Constants

View Source
const DefaultAppNameAnnotationValue = "etcd-server"

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigFunction

type ConfigFunction struct {
	cfunc.ConfigFunction `yaml:",inline"`

	// Data contains various options specific to this config function.
	Data Options

	// InitialCluster is used to configure etcd's `initial-cluster`
	// setting. By default the function detects the number of StatefulSet
	// replicas from an existing Resource config to generate this value.
	//
	// InitialCluster is exposed in the server ConfigMap as
	// `ETCD_INITIAL_CLUSTER` rather than the function ConfigMap.
	//
	// https://github.com/etcd-io/etcd/blob/master/Documentation/op-guide/configuration.md#--initial-cluster
	InitialCluster string

	// Hostnames are the names of the pods that will be created by the
	// StatefulSet. It is updated when the StatefulSet's `spec.replicas`
	// changes.
	Hostnames []string
}

ConfigFunction implements kio.Filter and holds information used in Resource templates.

func (*ConfigFunction) Filter

func (f *ConfigFunction) Filter(in []*yaml.RNode) ([]*yaml.RNode, error)

Filter generates Resources.

type Options

type Options struct {
	// TLSGeneratorJobEnabled creates Jobs which generate TLS assets for
	// communication with Etcd.
	TLSGeneratorJobEnabled bool `yaml:"tls_generator_job_enabled"`

	// TLSServerSecretName is the name of the Secret used to hold Etcd
	// server TLS assets.
	TLSServerSecretName string `yaml:"tls_server_secret_name"`

	// TLSCASecretName is the name of the Secret used to hold Etcd CA TLS
	// assets.
	TLSCASecretName string `yaml:"tls_ca_secret_name"`

	// TLSRootClientSecretName is the name of the Secret used to hold Etcd
	// root user TLS assets.
	TLSRootClientSecretName string `yaml:"tls_root_client_secret_name"`
}

Options holds settings used in the config function.

func (*Options) UnmarshalYAML

func (d *Options) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler. It ensures all values from a ConfigMap's KV data can be converted into relevant Go types.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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