apply

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 11 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 apply holds the plan logic of `angelia apply` (story #73): reading watch files (docs/watch-file.md, unchanged), the label scope of --prune and the diff of the report. It does no I/O on the network: cmd/angelia sends the requests and prints the report.

Index

Constants

View Source
const (
	Sink = iota
	Watch
	Subscription
	NumKinds
)

The kinds apply handles, in dependency order.

View Source
const (
	ChangeCreated   = "created"
	ChangeUpdated   = "updated"
	ChangeUnchanged = "unchanged"
	ChangeDeleted   = "deleted"
	ChangeGone      = "gone"    // a prune candidate someone else deleted first
	ChangeKept      = "kept"    // a prune candidate left alone
	ChangeSkipped   = "skipped" // not deleted because the prune stopped
	ChangeFailed    = "failed"
)

Changes in the report.

Variables

This section is empty.

Functions

func CompactJSON

func CompactJSON(v any) string

CompactJSON renders a value of the report; an absent one is "(none)".

func Labels

func Labels(v any) map[string]string

Labels returns the string values of a decoded labels object.

func Prunable

func Prunable(w Resource, sel Selector) bool

Prunable reports whether a watch may be pruned: managed by the API and in the scope. Objects managed by the watch file are never pruned.

func PruneWatches

func PruneWatches(cur Current, set *Set, sel Selector) []string

PruneWatches returns the sorted names of the watches --prune deletes: in the scope (Prunable) and not in the files. Only watches carry labels in API v1, so only watches are pruned.

Types

type Change

type Change struct {
	Kind   string      `json:"kind"`
	Name   string      `json:"name"`
	Change string      `json:"change"`
	Diff   []FieldDiff `json:"diff,omitempty"`
	Note   string      `json:"note,omitempty"`
	Error  string      `json:"error,omitempty"`
}

Change is one line of the report.

func Kept

func Kept(cur Current, set *Set, sel Selector) []Change

Kept lists the subscriptions and sinks a prune leaves alone although they may be left over, each with a note on how to delete it by hand:

  • an API subscription not in the files whose filter.labels match the scope (filter.labels select events; they do not say who owns it);
  • an API sink not in the files that no subscription uses after the apply and that an API subscription in the scope used before it (a sink the files' subscriptions moved away from). Unused sinks of other teams are not listed.

type Current

type Current [NumKinds]map[string]Resource

Current is what the server has, per kind: name -> resource.

type FieldDiff

type FieldDiff struct {
	Path string `json:"path"`
	Old  any    `json:"old"`
	New  any    `json:"new"`
}

FieldDiff is one changed write key, as a dotted path; null is absent.

func DiffWriteKeys

func DiffWriteKeys(old, cur Resource, keys []string) []FieldDiff

DiffWriteKeys compares the write keys of two resources, flattened to dotted paths and sorted.

type KindInfo

type KindInfo struct {
	Name    string // in the report: sink, watch, subscription
	Section string // the key of the watch file
	// WriteKeys are the keys of the *Write schema: the ones a diff compares.
	WriteKeys []string
}

KindInfo describes a resource type.

func Kinds

func Kinds() [NumKinds]KindInfo

Kinds returns the resource types, indexed by Sink, Watch and Subscription.

type Object

type Object struct {
	Name   string
	Body   []byte // the object as JSON: the PUT body
	Origin string // file and position, for messages
	// Labels are a watch's labels, or a subscription's filter.labels.
	Labels map[string]string
	Sink   string // a subscription's sink
}

Object is one sink, watch or subscription read from a file.

type Report

type Report struct {
	DryRun  bool     `json:"dry_run"`
	Changes []Change `json:"changes"`
}

Report is the result of a run.

func (*Report) Count

func (r *Report) Count(change string) int

Count returns the number of changes of one kind.

func (*Report) Summary

func (r *Report) Summary() string

Summary is the count line: created, updated, unchanged and deleted always, the others when they occur.

type Resource

type Resource = map[string]any

Resource is a sink, watch or subscription as the API returned it.

type Selector

type Selector map[string]string

Selector is the label scope of --prune: every pair must match.

func ParseSelector

func ParseSelector(vals []string) (Selector, error)

ParseSelector parses -l values, each one key=value.

func (Selector) Matches

func (s Selector) Matches(labels map[string]string) bool

Matches reports whether labels carry every pair of the selector.

func (Selector) String

func (s Selector) String() string

String formats the selector as sorted key=value pairs.

type Set

type Set struct {
	Objects [NumKinds][]Object
	// contains filtered or unexported fields
}

Set is everything read from the files, per kind in file order.

func NewSet

func NewSet() *Set

NewSet returns an empty set.

func Read

func Read(stdin io.Reader, paths []string) (*Set, error)

Read reads every path: a watch file, a directory of .yaml, .yml and .json watch files, or "-" for stdin. Each file holds one YAML document, as internal/watchfile requires. Every problem is reported.

func (*Set) AddDocument

func (s *Set) AddDocument(doc any, origin string) []error

AddDocument adds the objects of one watch file document (docs/watch-file.md section 2). Only the structure, names and label types are checked here; the server validates each object by the rules of the watch file.

func (*Set) Has

func (s *Set) Has(k int, name string) bool

Has reports whether the files hold an object of kind k named name.

func (*Set) OutOfScope

func (s *Set) OutOfScope(sel Selector) []string

OutOfScope returns a warning for every watch in the files that lacks the scope's labels: it is applied, but a prune with this scope never deletes it.

func (*Set) WatchesInScope

func (s *Set) WatchesInScope(sel Selector) int

WatchesInScope counts the file's watches whose labels match sel.

Jump to

Keyboard shortcuts

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