cli

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Overview

Package cli holds the kubepkg commands. A distribution builds its own CLI from NewRootCommand: its own name and API group, plus commands of its own.

Example (Distribution)

A distribution's own CLI: its name and API group, and a command of its own next to the kubepkg ones.

package main

import (
	"github.com/spf13/cobra"

	"github.com/kuberoot-dev/kubepkg/pkg/cli"
)

func main() {
	opts := cli.DefaultOptions()
	opts.Name = "examplectl"
	opts.APIGroup = "packages.example.com"
	root := cli.NewRootCommand(opts)
	root.AddCommand(&cobra.Command{
		Use:   "upgrade-platform",
		Short: "Upgrade the whole platform to the next release",
		RunE:  func(*cobra.Command, []string) error { return nil },
	})
	_ = root.Execute()
}

Index

Examples

Constants

View Source
const AnnotationDependency = "kubepkg.dev/dependency"

AnnotationDependency marks a Package the CLI installed because another package required it, not because it was asked for.

Variables

View Source
var RenderFormats = []string{"flux", "argo", "helmfile"}

RenderFormats are the formats Render writes.

Functions

func Apply

func Apply(ctx context.Context, c client.Client, steps []Step) error

Apply creates or updates the Packages of a plan. Kept packages are left alone; the operator does the installing.

func NewRootCommand

func NewRootCommand(o Options) *cobra.Command

NewRootCommand returns the root command with every kubepkg command.

func Render

func Render(ctx context.Context, store *repo.Store, policy repo.Policy, reqs []resolve.Request, o RenderOptions) ([]byte, error)

Render resolves the requested packages and their requirements for an empty cluster and writes what another delivery tool needs to install them, in the order kubepkg would: Flux sources and HelmReleases with dependsOn, Argo CD Applications with sync waves, or a helmfile with needs. Requirements on APIs no package provides are assumed served.

func WritePlan

func WritePlan(w io.Writer, steps []Step) error

WritePlan prints a plan with what each change brings into the cluster.

Types

type AdoptComponent

type AdoptComponent struct {
	Name, Namespace, Release string
	// Overridden is true when the release is not where the package would
	// put it, so the Package must say where it is.
	Overridden bool
	Existing   *helm.ReleaseInfo
}

AdoptComponent is what adopting finds for one component.

type AdoptPlan

type AdoptPlan struct {
	Package    string
	Repository string
	Version    repo.Version
	Variant    string
	Components []AdoptComponent
	// Missing are required packages the cluster does not have.
	Missing []string
}

AdoptPlan is what adopting a package would do.

func PlanAdopt

func PlanAdopt(ctx context.Context, store *repo.Store, policy repo.Policy, releases ReleaseReader, installed map[string]bool, name, constraint, variant string, placements map[string]string) (*AdoptPlan, error)

PlanAdopt finds the release each component of the package's chosen version would be, existing or not. placements maps component names to namespace/release where the release is not where the package puts it.

func (*AdoptPlan) PackageObject

func (p *AdoptPlan) PackageObject(constraint string) (*v1.Package, error)

Package is the Package that adopts, carrying each release's values.

type Options

type Options struct {
	// Name is the binary name shown in help.
	Name string
	// Short is the one-line description.
	Short string
	// APIGroup is the default of --api-group.
	APIGroup string
	// IndexFetchers fetch repository indexes by URL scheme, as in the
	// operator; a distribution adds its transports.
	IndexFetchers repo.Fetchers
	// Policy admits versions, as in the operator, so plans offer only
	// what the operator will install.
	Policy repo.Policy
}

Options configure the root command.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions are the plain kubepkg CLI.

type ReleaseReader

type ReleaseReader interface {
	Release(namespace, name string) (*helm.ReleaseInfo, error)
}

ReleaseReader reads existing Helm releases.

type Removal

type Removal struct {
	Name   string
	Reason string
}

Removal is one package a remove deletes, and why.

func PlanRemove

func PlanRemove(ctx context.Context, c client.Client, names []string, autoremove bool) ([]Removal, error)

PlanRemove works out what removing names takes. It refuses while a package that stays requires one of them, directly or as the only provider of a capability. With autoremove it also removes packages that were installed as requirements and that nothing staying needs any more.

type RenderOptions

type RenderOptions struct {
	Format  string
	Variant string
	// ArgoNamespace and ArgoProject place Applications (argo format).
	ArgoNamespace, ArgoProject string
	// Insecure lets Flux pull from registries over plain HTTP.
	Insecure bool
}

RenderOptions tune the output of Render.

type ScanResult

type ScanResult struct {
	Package, Image string
	Counts         map[string]int
}

ScanResult is one image of one package.

func Scan

func Scan(ctx context.Context, pkgs []sbom.Package, scan Scanner, mirror string) (results []ScanResult, unpinned []string, err error)

Scan scans every image the packages pin, each once. Packages that pin no images are returned in unpinned.

type Scanner

type Scanner func(ctx context.Context, image string) (map[string]int, error)

Scanner reports the vulnerabilities of an image by severity.

func TrivyScanner

func TrivyScanner(binary string, extra []string) Scanner

TrivyScanner runs trivy image on each image.

type Step

type Step struct {
	resolve.Change
	// Repository and Entry are where the target version comes from.
	Repository string
	Entry      repo.Version
	// Constraint is what Package.spec.version is set to.
	Constraint string
	Dependency bool
	// Local means a hand-written PackageSource decides, not repositories.
	Local bool
	// SetVariant is the variant Package.spec.variant is set to, because a
	// package requiring this one needs it; empty leaves it as it is.
	SetVariant string
}

Step is one line of an install plan.

func Plan

func Plan(ctx context.Context, c client.Client, store *repo.Store, policy repo.Policy, apis controller.APIs, variant string, reqs []resolve.Request) ([]Step, error)

Plan works out what installing reqs takes: the requested packages and everything they require, from the cluster's repositories, as the operator would select them.

Jump to

Keyboard shortcuts

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