resolved

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package resolved answers what configuration a container actually received.

Kubernetes spreads that answer across env, envFrom, valueFrom, the downward API, and mounted volumes, with precedence rules between them. Reading it back means opening the pod spec, then every ConfigMap it references, and applying the same precedence the kubelet did. That is the work this package does once so nobody has to do it by hand at two in the morning.

Secret values are masked by never being fetched. Masking a value you already hold is a rendering decision; masking a value you never read is a property.

Index

Constants

View Source
const (
	// ClassUnknown means no comparison was possible, usually a secret nobody
	// may read on one side.
	ClassUnknown = ""
	// ClassMatch is identical and unremarkable.
	ClassMatch = "match"
	// ClassExpected differs for a reason the values themselves explain.
	ClassExpected = "expected"
	// ClassDrift differs with no explanation.
	ClassDrift = "drift"
	// ClassSuspicious matches where matching is the problem.
	ClassSuspicious = "suspicious"
	// ClassMissing is present on one side only.
	ClassMissing = "missing"
)

Classifications.

View Source
const (
	// DiffUnknown means no comparison was possible: there is no previous
	// revision, or this container did not exist in it.
	DiffUnknown = ""
	// DiffUnchanged is only ever set for values the template fully determines.
	DiffUnchanged      = "unchanged"
	DiffChanged        = "changed"
	DiffAdded          = "added"
	DiffRemoved        = "removed"
	DiffSourceChanged  = "source-changed"
	DiffNotRecoverable = "not-recoverable"
	// DiffRuntime marks values resolved at container start, which belong to the
	// run rather than to the revision.
	DiffRuntime = "runtime"
)

Diff states.

View Source
const (
	SourceInline    = "inline"
	SourceConfigMap = "configMap"
	SourceSecret    = "secret"
	SourceDownward  = "downwardAPI"
	SourceResource  = "resourceField"
)

Where a value came from.

Variables

This section is empty.

Functions

func Compare

func Compare(cfg *Config, prev Snapshot, revision string)

Compare annotates a resolved config against the previous revision.

An empty snapshot leaves every row uncompared rather than marking everything added, because a screen full of "added" is noise dressed as information.

func Digest

func Digest(value []byte) string

Digest fingerprints a secret value for comparison.

The digest exists so two environments' credentials can be compared without either being read onto a screen. It is truncated because nobody needs 64 characters to see that two fingerprints differ.

Types

type Config

type Config struct {
	Pod        string      `json:"pod"`
	Containers []Container `json:"containers"`
	// Caveat states what this reading cannot promise.
	Caveat string `json:"caveat,omitempty"`
	// ComparedTo names the revision the diff column is against, empty when no
	// comparison was possible.
	ComparedTo string `json:"comparedTo,omitempty"`
}

Config is a pod's configuration, one table per container.

func Resolve

func Resolve(ctx context.Context, client kubernetes.Interface, pod *corev1.Pod) Config

Resolve reads one pod's configuration.

Every ConfigMap is fetched at most once however many keys reference it, and no Secret is fetched at all.

func ResolveWith

func ResolveWith(ctx context.Context, client kubernetes.Interface, pod *corev1.Pod, permit Permit) Config

ResolveWith adds a permission probe, so every masked row knows whether its reveal would work before anybody clicks it.

type Container

type Container struct {
	Name   string  `json:"name"`
	Init   bool    `json:"init,omitempty"`
	Image  string  `json:"image,omitempty"`
	Values []Value `json:"values"`
	Mounts []Mount `json:"mounts,omitempty"`
}

Container is one container's resolved configuration.

type CrossRow

type CrossRow struct {
	Key   string `json:"key"`
	Left  string `json:"left,omitempty"`
	Right string `json:"right,omitempty"`
	// LeftUnset and RightUnset distinguish a key that is not set from one set
	// to the empty string, which are different configurations.
	LeftUnset  bool `json:"leftUnset,omitempty"`
	RightUnset bool `json:"rightUnset,omitempty"`
	// Masked marks a secret-sourced row. Its values never appear; only digests
	// are compared, so production credentials never sit beside staging ones on
	// a screen.
	Masked      bool   `json:"masked,omitempty"`
	LeftDigest  string `json:"leftDigest,omitempty"`
	RightDigest string `json:"rightDigest,omitempty"`
	Class       string `json:"class"`
	Reason      string `json:"reason,omitempty"`
	LeftSource  Source `json:"leftSource,omitzero"`
	RightSource Source `json:"rightSource,omitzero"`
}

CrossRow is one key compared across two environments.

func CrossDiff

func CrossDiff(left, right Container, leftEnv, rightEnv Env) []CrossRow

CrossDiff compares two containers' resolved configuration.

type Declared

type Declared struct {
	Key    string
	Value  string
	Source Source
}

Declared is one env entry as the pod template declares it. Declared, not resolved: a template holds references, never their contents.

type Diff

type Diff struct {
	State string `json:"state,omitempty"`
	// Previous is the old value, or the old reference when only that survives.
	Previous string `json:"previous,omitempty"`
	Reason   string `json:"reason,omitempty"`
}

Diff is how one value compares with the previous revision.

type Env

type Env struct {
	Name string `json:"name"`
	Risk string `json:"risk"` // low, medium, high
}

Env is the side of a comparison: its name and how dangerous it is.

type Mount

type Mount struct {
	Path     string `json:"path"`
	Source   Source `json:"source"`
	Masked   bool   `json:"masked,omitempty"`
	ReadOnly bool   `json:"readOnly,omitempty"`
}

Mount is file-based configuration. A tool that shows only environment variables sends people back to kubectl for half of their config.

type Permit

type Permit func(secret string) (allowed bool, reason string)

Permit reports whether this reader may read one Secret, and what they need when they may not.

type Snapshot

type Snapshot struct {
	Containers map[string][]Declared
	// EnvFrom records the bulk references a container declared. Their keys
	// cannot be listed from the template, since the keys live in the object
	// being referenced, but knowing the reference existed is enough to tell a
	// genuinely new key from one whose old content is simply gone.
	EnvFrom map[string][]Source
}

Snapshot is a revision's declared environment, by container.

func FromTemplate

func FromTemplate(containers, initContainers []corev1.Container) Snapshot

FromTemplate reads a revision's pod template. No cluster reads happen here: everything it returns was preserved inside the ReplicaSet.

type Source

type Source struct {
	Kind string `json:"kind"`
	Ref  string `json:"ref,omitempty"`
	Key  string `json:"key,omitempty"`
}

Source is one value's provenance. Without it a config table is a list of strings nobody can act on: knowing MAX_CONNECTIONS is 25 matters far less than knowing which ConfigMap to edit.

type Summary

type Summary struct {
	Drift      int `json:"drift"`
	Suspicious int `json:"suspicious"`
	Missing    int `json:"missing"`
	Expected   int `json:"expected"`
	Match      int `json:"match"`
	Unknown    int `json:"unknown"`
}

Summary counts each class, which is what the topbar reports.

func Summarize

func Summarize(rows []CrossRow) Summary

Summarize counts rows by class.

type Value

type Value struct {
	Key    string `json:"key"`
	Value  string `json:"value"`
	Source Source `json:"source"`
	// Masked marks a value that was never read, because it comes from a Secret.
	Masked bool `json:"masked,omitempty"`
	// Missing marks a reference that could not be resolved. A key that is not
	// there is frequently why a container is crashing, so it renders as missing
	// rather than as blank.
	Missing bool `json:"missing,omitempty"`
	// Overrides marks a value that shadowed another source, which is where
	// "but the ConfigMap says something else" comes from.
	Overrides bool   `json:"overrides,omitempty"`
	Reason    string `json:"reason,omitempty"`
	// CanReveal reports whether this reader may fetch the masked value.
	// RevealReason names what is missing when they may not, because a control
	// is disabled and explained, never hidden.
	CanReveal    bool   `json:"canReveal,omitempty"`
	RevealReason string `json:"revealReason,omitempty"`
	// Diff is how this value compares with the previous revision, scoped to
	// what the cluster actually preserved.
	Diff Diff `json:"diff,omitzero"`
	// Digest is a hash of a masked value, computed for comparison only. It
	// exists so two environments' credentials can be compared without either
	// one being read onto a screen.
	Digest string `json:"digest,omitempty"`
}

Value is one resolved environment entry.

Jump to

Keyboard shortcuts

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