injector

package
v0.0.0-...-5461fec Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package injector deals with AdmissionReview requests and responses

Index

Constants

View Source
const (
	// affinity
	CreateAffinity              = "/spec/affinity"
	CreateNodeAffinity          = "/spec/affinity/nodeAffinity"
	AddRequiredDuringScheduling = "/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution"
	AddNodeSelectorTerms        = "/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms"
	AddToNodeSelectorTerms      = "/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/-"
	// tolerations
	CreateTolerations = "/spec/tolerations"
	AddTolerations    = "/spec/tolerations/-"
)

PatchPath values

Variables

View Source
var (
	ErrInvalidAdmissionReview        = errors.New("invalid admission review")
	ErrInvalidAdmissionReviewObj     = errors.New("invalid admission review object")
	ErrFailedToCreatePatch           = errors.New("failed to create patch")
	ErrFailedToReadNodeSelectorTerms = errors.New("failed to load node selector terms")
	ErrMissingConfiguration          = errors.New("missing configuration")
	ErrInvalidConfiguration          = errors.New("invalid configuration")
)

Errors returned by this package

Functions

This section is empty.

Types

type Injector

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

Injector handles AdmissionReview objects

func NewInjector

func NewInjector(k8sclient k8sclient.Interface, namespace string, configMapName string) *Injector

NewInjector returns *Injector with k8sclient and configMapName

func (*Injector) Mutate

func (m *Injector) Mutate(body []byte) ([]byte, error)

Mutate unmarshalls the AdmissionReview (body) and creates or updates the nodeAffinity and/or the tolerations of the k8s object in the admission review request, sets the AdmissionReview response and returns the marshalled AdmissionReview or an error

type JSONPatch

type JSONPatch struct {
	Op    string      `json:"op"`
	Path  PatchPath   `json:"path"`
	Value interface{} `json:"value"`
}

JSONPatch is the JSON patch (http://jsonpatch.com) for patching k8s object

type NamespaceConfig

type NamespaceConfig struct {
	NodeSelectorTerms []corev1.NodeSelectorTerm `json:"nodeSelectorTerms"`
	Tolerations       []corev1.Toleration       `json:"tolerations"`
	ExcludedLabels    map[string]string         `json:"excludedLabels"`
}

NamespaceConfig is the per-namespace configuration

type PatchPath

type PatchPath string

PatchPath is the path for the JSON patch

Jump to

Keyboard shortcuts

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