util

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceVersionAnnotation = "internal.kpt.dev/resource-version"
)

Variables

This section is empty.

Functions

func AddRevisionMetadata

func AddRevisionMetadata(prr *porchapi.PackageRevisionResources) error

func CreateScheme added in v1.6.0

func CreateScheme() (*runtime.Scheme, error)

CreateScheme returns a runtime.Scheme registered with the type sets that rpkg subcommands operate on: porchapi (PackageRevision and friends), the porchconfig API (Repository), corev1 (ConfigMap and other core kinds), and metav1 (Status, WatchEvent and other meta types required for list/watch decoding). The set mirrors the scheme used by cliutils.CreateClientWithFlags so that commands which build their own client see the same kinds.

func GetResourceFileKubeObject

func GetResourceFileKubeObject(prr *porchapi.PackageRevisionResources, file, kind, name string) (*fnsdk.KubeObject, error)

func GetResourceVersion

func GetResourceVersion(prr *porchapi.PackageRevisionResources) (string, error)

func InitClient added in v1.6.0

func InitClient(cmd *cobra.Command, cfg *genericclioptions.ConfigFlags) (client.Client, error)

InitClient creates a controller-runtime client and validates the namespace flag. If --namespace is specified without a value, it returns an error immediately. A nil cfg is rejected up front so callers (and tests) cannot trigger a panic inside cliutils.CreateClientWithFlags -> ConfigFlags.ToRESTConfig.

func MakePreRunE added in v1.6.0

func MakePreRunE(op errors.Op, cfg *genericclioptions.ConfigFlags, clientPtr *client.Client) func(*cobra.Command, []string) error

MakePreRunE returns a cobra PreRunE function that validates the namespace flag and creates a controller-runtime client, storing it in *clientPtr. Pass the command's op constant for error context (e.g. command + ".preRunE").

func NewV1Alpha2PackageRevision added in v1.6.0

func NewV1Alpha2PackageRevision(ns, name string) *porchv1alpha2.PackageRevision

NewV1Alpha2PackageRevision builds a v1alpha2 PackageRevision with the TypeMeta pre-filled. Callers set Spec/Status/ObjectMeta fields on the returned object as needed.

func PackageAlreadyExistsV1Alpha2 added in v1.6.0

func PackageAlreadyExistsV1Alpha2(ctx context.Context, c client.Client, repository, packageName, namespace string) (bool, error)

func RemoveRevisionMetadata

func RemoveRevisionMetadata(prr *porchapi.PackageRevisionResources) error

func RunForEachPackage added in v1.6.0

func RunForEachPackage(
	ctx context.Context,
	c client.Client,
	cmd *cobra.Command,
	namespace string,
	args []string,
	opts RunForEachOpts,
	action PackageAction,
) error

RunForEachPackage loops over package names, fetches each PackageRevision, optionally runs a readiness pre-check, then runs the action. Errors are collected and reported. When opts.WithRetry is true, each iteration is retried on conflict. When opts.CheckReadiness is true, readiness gates are verified before the action runs.

func V1Alpha2Scheme added in v1.6.0

func V1Alpha2Scheme(t *testing.T) *runtime.Scheme

V1Alpha2Scheme returns a runtime.Scheme with the v1alpha2 API registered. It calls t.Fatal on error.

func WriteTempKubeconfig added in v1.6.0

func WriteTempKubeconfig(t *testing.T) string

WriteTempKubeconfig writes a minimal kubeconfig pointing at an unreachable host into t.TempDir() and returns the path. It is sufficient to exercise cfg.ToRESTConfig() and a lazy client.New() without requiring a live cluster, and is intended for use by rpkg sub-command preRunE tests that need a real configuration path on disk.

Types

type PackageAction added in v1.6.0

type PackageAction func(ctx context.Context, client client.Client, pr *porchapi.PackageRevision) (string, error)

PackageAction processes a single PackageRevision and returns a success message. Return ("", nil) to skip the standard success print. Callbacks that have already written their own informational output to the command's output stream take this path, for example propose and propose-delete printing "already proposed" before returning.

type RunForEachOpts added in v1.6.0

type RunForEachOpts struct {
	CmdName        string
	WithRetry      bool
	CheckReadiness bool
}

RunForEachOpts groups the behavioural flags accepted by RunForEachPackage so that call sites read as `WithRetry: true, CheckReadiness: true` instead of two anonymous booleans.

CmdName is the per-subcommand identifier (e.g. "cmdrpkgapprove") used to build the errors.Op tag suffixed with ".runE". It is required; passing an empty string is rejected up front by RunForEachPackage rather than producing a malformed ".runE" op tag.

type Runner added in v1.6.0

type Runner struct {
	Ctx     context.Context
	Cfg     *genericclioptions.ConfigFlags
	Client  client.Client
	Command *cobra.Command
}

Runner holds the common fields used by rpkg lifecycle commands.

Ctx is intentionally stored on the struct rather than passed per-method. Each rpkg subcommand is a short-lived CLI runner whose lifetime equals one command invocation; the context is captured at construction time from the outer cobra command and used by the embedded methods (preRunE/runE) that cobra invokes through a fixed signature. This mirrors the per-command `runner` struct convention that already exists across rpkg subpackages. See SonarQube rule godre:S8242 for the general guidance against contexts in structs; this exception is documented rather than refactored to avoid fanning a behavioural change out across every rpkg subcommand.

func NewTestRunner added in v1.6.0

func NewTestRunner(ns string, c client.Client, cmd *cobra.Command) Runner

NewTestRunner returns a Runner pre-wired for table-driven CLI tests in the rpkg sub-packages. It accepts a namespace string (heap-escaped via &ns), a fake client, and the cobra command under test.

Jump to

Keyboard shortcuts

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