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
- func CompactJSON(v any) string
- func Labels(v any) map[string]string
- func Prunable(w Resource, sel Selector) bool
- func PruneWatches(cur Current, set *Set, sel Selector) []string
- type Change
- type Current
- type FieldDiff
- type KindInfo
- type Object
- type Report
- type Resource
- type Selector
- type Set
Constants ¶
const ( Sink = iota Watch Subscription NumKinds )
The kinds apply handles, in dependency order.
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 ¶
CompactJSON renders a value of the report; an absent one is "(none)".
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 ¶
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 FieldDiff ¶
FieldDiff is one changed write key, as a dotted path; null is absent.
func DiffWriteKeys ¶
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.
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 ¶
Report is the result of a run.
type Selector ¶
Selector is the label scope of --prune: every pair must match.
func ParseSelector ¶
ParseSelector parses -l values, each one key=value.
type Set ¶
Set is everything read from the files, per kind in file order.
func Read ¶
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 ¶
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) OutOfScope ¶
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 ¶
WatchesInScope counts the file's watches whose labels match sel.