Documentation
¶
Overview ¶
Package gitopsdiff renders the charts a change touches on two revisions of a platform repository and reports what changed: the rendered manifests per chart and test case, the subcharts' default values, and the effective values with the file and line that set them. It replaces kubriX's create-pr-comment-file.sh and gitops-diff-comments.py.
Index ¶
- Constants
- func BaseCandidates(ctx context.Context, repo string) ([]string, error)
- func CaptureHelmWarnings(w io.Writer) func()
- func FailureLabel(s FailureStatus) string
- func FailureSubject(f Failure) string
- func Marker(name string) string
- func MarkerName(body string) (string, bool)
- func SyncComments(ctx context.Context, c CommentClient, pr PullRequest, comments []Comment, ...) error
- func WriteText(w io.Writer, r *Report)
- type Choices
- type Comment
- type CommentClient
- type DependencyBuilder
- type Failure
- type FailureStatus
- type FileDiff
- type Options
- type Progress
- type PullRequest
- type Report
- type Status
- type TestCase
- type ValueChange
Constants ¶
const ( // MaxCommentLength keeps some headroom below GitHub's 65536 characters per comment. MaxCommentLength = 60000 // MaxChartComments is how many charts get a comment of their own; with more, only the summary is posted. MaxChartComments = 10 )
const ChartsDir = "platform-apps/charts"
ChartsDir holds the application charts of a platform repository.
Variables ¶
This section is empty.
Functions ¶
func BaseCandidates ¶
BaseCandidates lists the revisions a change is usually compared against, the most likely first: the remote's default branch, then local branches and the other remote branches.
func CaptureHelmWarnings ¶
CaptureHelmWarnings routes the warnings helm prints through the standard logger (for example "cannot overwrite table with non table") to w, each distinct warning once and without a timestamp: a diff renders the same chart many times. It returns a function that restores the standard logger.
func FailureLabel ¶
func FailureLabel(s FailureStatus) string
FailureLabel describes a failure's status for people.
func FailureSubject ¶
FailureSubject names what failed: a chart with a test case, or a whole test case.
func Marker ¶
Marker starts every comment body, so a later run finds and updates or deletes its own comments.
func MarkerName ¶
MarkerName returns the comment name of a body that starts with a marker.
func SyncComments ¶
func SyncComments(ctx context.Context, c CommentClient, pr PullRequest, comments []Comment, dryRun bool, log io.Writer) error
SyncComments makes the pull request's diff comments match comments: a comment whose body changed is updated, an unchanged one is left alone, one that is no longer wanted is deleted, and new ones are created in order (the summary first). With dryRun it only prints what it would do.
Types ¶
type Choices ¶
Choices is what a diff of a change can render: the target types and charts of either revision, and the charts the change touches (all of them when it touches the target chart, a bootstrap Application or no chart).
type Comment ¶
Comment is one PR comment: Name identifies it across runs through its marker, Body is its Markdown.
type CommentClient ¶
type CommentClient interface {
IssueComments(ctx context.Context, owner, repo string, number int) ([]git.IssueComment, error)
CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) error
EditIssueComment(ctx context.Context, owner, repo string, id int64, body string) error
DeleteIssueComment(ctx context.Context, owner, repo string, id int64) error
}
CommentClient is the part of a git host's API that syncing PR comments needs.
type DependencyBuilder ¶
DependencyBuilder fetches the dependencies of the chart in dir into its charts/ directory.
func HelmDependencies ¶
func HelmDependencies(home string) DependencyBuilder
HelmDependencies builds dependencies like `helm dependency build`, falling back to `helm dependency update` when the chart has no Chart.lock or it is out of date. Repositories are used by URL; helm's own repository config and cache are not touched, so state lives in home.
type Failure ¶
type Failure struct {
Chart string `json:"chart,omitempty"`
TestCase string `json:"testCase"`
Status FailureStatus `json:"status"`
// Error is the head revision's error, or the base revision's for a failure the change fixes.
Error string `json:"error"`
}
Failure is a chart that could not be rendered with a test case on one or both revisions, or, with an empty Chart, a test case whose applications could not be resolved. Its rendered files are not compared.
type FailureStatus ¶
type FailureStatus string
FailureStatus says which revision a failure is on.
const ( // Broken fails on the change only: the change breaks rendering. Broken FailureStatus = "broken" // StillBroken fails on both revisions: the change neither caused nor fixed it. StillBroken FailureStatus = "still-broken" // Fixed fails on the base revision only: the change fixes it. Fixed FailureStatus = "fixed" )
type FileDiff ¶
type FileDiff struct {
Chart string `json:"chart"`
TestCase string `json:"testCase"`
Path string `json:"path"`
Status Status `json:"status"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
// Text is the unified diff, starting with a "diff -U 4 -rN" header line like diff -r prints.
Text string `json:"diff"`
}
FileDiff is the change of one rendered file of a chart in one test case.
type Options ¶
type Options struct {
// Repo is the platform repository; its git history provides Base and Head.
Repo string
Base string
// Head is the revision to compare; empty compares the working tree.
Head string
// TestCases default to every target type of either revision.
TestCases []TestCase
// Charts to compare; empty compares the charts the change touches, or all charts with AllCharts.
Charts []string
AllCharts bool
// CustomerConfig renders templates; empty uses each revision's bootstrap/customer-config.yaml.
CustomerConfig string
// Dependencies fetches chart dependencies; nil uses HelmDependencies.
Dependencies DependencyBuilder
// Parallel renders this many charts at once; 0 uses the number of CPUs.
Parallel int
// Progress, if set, is called after each rendering; calls are serialised.
Progress func(Progress)
}
Options of a diff.
type Progress ¶
Progress reports how many of the renderings a diff needs are done; Done is the last one finished.
type PullRequest ¶
type PullRequest struct {
Owner, Repo string
Number int
// Author is the login whose marked comments are this diff's; comments of anyone else are never touched.
Author string
}
PullRequest names the pull request to comment on and who the diff's own comments are written by.
type Report ¶
type Report struct {
Files []FileDiff `json:"files"`
DefaultValuesDiff string `json:"defaultValuesDiff"`
ValueChanges []ValueChange `json:"valueChanges"`
Failures []Failure `json:"failures"`
}
Report is everything that changed, sorted by chart, test case and path.
func Run ¶
Run checks out both revisions, renders the selected charts with every test case and reports what changed.
type TestCase ¶
type TestCase struct {
Name string
// TargetType resolves each chart's values through the target chart, as Argo CD would.
TargetType string
// Files are values files looked up in each chart's directory; missing ones are skipped.
Files []string
// Sets are helm --set expressions applied after Files.
Sets []engine.SetSource
}
TestCase is one set of values every changed chart is rendered with: the files and parameters a target type's Application passes to the chart, or chart-local values files and --set expressions given by hand.
type ValueChange ¶
type ValueChange struct {
Chart string `json:"chart"`
TestCase string `json:"testCase"`
Path string `json:"path"`
Kind Status `json:"kind"`
Before any `json:"before,omitempty"`
After any `json:"after,omitempty"`
// Source is where the head revision sets the value, or where the base revision set a removed one.
Source engine.SourceLocation `json:"source"`
}
ValueChange is an effective value of an application that differs between the revisions.