gitopsdiff

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 37 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 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

View Source
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
)
View Source
const ChartsDir = "platform-apps/charts"

ChartsDir holds the application charts of a platform repository.

Variables

This section is empty.

Functions

func BaseCandidates

func BaseCandidates(ctx context.Context, repo string) ([]string, error)

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

func CaptureHelmWarnings(w io.Writer) func()

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

func FailureSubject(f Failure) string

FailureSubject names what failed: a chart with a test case, or a whole test case.

func Marker

func Marker(name string) string

Marker starts every comment body, so a later run finds and updates or deletes its own comments.

func MarkerName

func MarkerName(body string) (string, bool)

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.

func WriteText

func WriteText(w io.Writer, r *Report)

WriteText prints the report for a terminal: what changed per chart and test case, the changed values with the file that sets them, and the diffs.

Types

type Choices

type Choices struct {
	TargetTypes []string
	Charts      []string
	Changed     []string
}

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).

func ListChoices

func ListChoices(ctx context.Context, repo, base, head string) (Choices, error)

ListChoices finds the choices of comparing head (empty: the working tree) against base, reading git trees and the working tree without checking anything out.

type Comment

type Comment struct {
	Name string
	Body string
}

Comment is one PR comment: Name identifies it across runs through its marker, Body is its Markdown.

func Comments

func Comments(r *Report, runURL string) []Comment

Comments renders the report as PR comments: the summary first, then one comment per changed chart unless more than MaxChartComments charts changed. runURL links the full diffs.

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

type DependencyBuilder func(ctx context.Context, dir string) error

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

type Progress struct {
	Done, Total int
	Last        string
}

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

func Run(ctx context.Context, opts Options) (*Report, error)

Run checks out both revisions, renders the selected charts with every test case and reports what changed.

func (*Report) Broken

func (r *Report) Broken() []Failure

Broken are the failures the change introduces.

func (*Report) Charts

func (r *Report) Charts() []string

Charts are the charts with rendered changes, sorted.

func (*Report) Empty

func (r *Report) Empty() bool

Empty reports whether nothing changed.

type Status

type Status string

Status of a file or value between the two revisions.

const (
	Added    Status = "added"
	Removed  Status = "removed"
	Modified Status = "modified"
)

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.

Jump to

Keyboard shortcuts

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