fork

package
v0.0.0-...-1aef31a Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package fork implements a pattern for forking sub-processes as new Pods.

This can be used when some code that's part of the operator (usually an entire controller) needs to run under a different Pod context (e.g. different service account, volume mounts, etc.). The forked Pod runs the same container image as the parent Pod, so the code versions should stay synchronized as long as immutable image tags are used. This avoids the operational and maintenance burden of creating and publishing separate binaries and container images for each sub-process.

The forked Pod is given an additional environment variable telling it which forked code path it should run instead of the normal code path. The main() function should be written to take this into account by calling fork.Path() to determine which fork it should follow, if any.

The parent Pod must also give some environment variables to the operator's Container to let this package find the Pod in which it's currently running:

env:
- name: PS_OPERATOR_POD_NAME
  valueFrom:
    fieldRef:
      fieldPath: metadata.name
- name: PS_OPERATOR_POD_NAMESPACE
  valueFrom:
    fieldRef:
      fieldPath: metadata.namespace

The parent Pod uses its own Pod spec as a basis to build the child Pod spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPodSpec

func NewPodSpec(ctx context.Context, c client.Client, forkPath string) (*corev1.PodSpec, error)

NewPodSpec returns the specification for a child Pod to be forked off from the Pod in which you're currently running.

func Path

func Path() string

Path returns the name of the forked code path that this process should take. It returns "" if no fork should be taken (i.e. this is the root process).

Types

This section is empty.

Jump to

Keyboard shortcuts

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