chartinspector

package
v1.86.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package chartinspector is the client for chart-inspector, the service that renders a composition's helm chart for one composition and reports the Kubernetes resources the render contains (group, version, resource, namespace, and the verbs helm needs on each).

It is the input to compositionrbac: chart-inspector answers "what would this composition's chart create", and compositionrbac turns that into the RBAC a controller needs to install it. Moved from the composition-dynamic-controller's internal/chartinspector so the same client serves every caller that derives that RBAC.

Index

Constants

View Source
const ReasonValuesSchemaViolation = "ValuesSchemaViolation"

ReasonValuesSchemaViolation is the Status reason chart-inspector puts on a values-schema 400 (#325). A CONTRACT: chart-inspector's internal/handlers/resources/get declares the same value, and the two modules cannot share a declaration, so each pins the literal in a test.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChartInspector

type ChartInspector struct {
	// contains filtered or unexported fields
}

func NewChartInspector

func NewChartInspector(server string) ChartInspector

func (*ChartInspector) Resources

func (c *ChartInspector) Resources(ctx context.Context, params Parameters) ([]Resource, error)

func (*ChartInspector) Validate

func (c *ChartInspector) Validate(params Parameters) error

Validate refuses, before it is sent, every request chart-inspector's parameter checks would refuse.

The set is chart-inspector's own: its /resources handler answers 400 when any of the first six is empty ("missing required query parameters") and, separately, when releaseName is (#329). ReleaseName was documented REQUIRED on Parameters and was not checked here, so an empty one went over the wire and came back as a 400.

An incomplete request is a cdc defect, and refusing it here reports it as one (a *MissingParameterError, classified by type and not as "could not reach") instead of a round trip that comes back as an anonymous 400. The schema 400 is told apart by its own Status reason (StatusError.ValuesSchemaViolation, #325), not by this check.

func (*ChartInspector) WithHTTPClient

func (c *ChartInspector) WithHTTPClient(httpClient *http.Client)

func (*ChartInspector) WithServer

func (c *ChartInspector) WithServer(server string)

type ChartInspectorInterface

type ChartInspectorInterface interface {
	Resources(ctx context.Context, params Parameters) ([]Resource, error)
}

type MissingParameterError

type MissingParameterError struct {
	// Name is the query parameter, spelled as chart-inspector reads it.
	Name string
}

MissingParameterError is Validate refusing a request chart-inspector would refuse. No request was sent, so a caller must not report it as chart-inspector being unreachable.

func (*MissingParameterError) Error

func (e *MissingParameterError) Error() string

type Parameters

type Parameters struct {
	CompositionName                string `json:"compositionName"`                // The name of the composition. Required.
	CompositionNamespace           string `json:"compositionNamespace"`           // The namespace of the composition. Required.
	CompositionGroup               string `json:"compositionGroup"`               // The group of the composition. Optional, defaults to "composition.krateo.io"
	CompositionVersion             string `json:"compositionVersion"`             // The version of the composition. Required.
	CompositionResource            string `json:"compositionResource"`            // The resource name of the composition. Required.
	CompositionDefinitionName      string `json:"compositionDefinitionName"`      // The name of the composition definition. Required.
	CompositionDefinitionNamespace string `json:"compositionDefinitionNamespace"` // The namespace of the composition definition. Required.
	CompositionDefinitionGroup     string `json:"compositionDefinitionGroup"`     // The group of the composition definition. Optional, defaults to "core.krateo.io"
	CompositionDefinitionVersion   string `json:"compositionDefinitionVersion"`   // The version of the composition definition. Optional, defaults to "v1alpha1"
	CompositionDefinitionResource  string `json:"compositionDefinitionResource"`  // The resource name of the composition definition. Optional, defaults to "compositiondefinitions"

	// ReleaseName is the helm release name the CALLER has resolved for this composition. REQUIRED.
	//
	// It is sent because chart-inspector used to re-derive it from the composition's
	// krateo.io/release-name LABEL, read off the live object it fetches itself — and the caller's
	// value is not always on the live object yet. #303's adoption path is exactly that case: a
	// recreated CR has no label (its absence is what triggers adoption), the cdc resolves the
	// adopted name in memory, and Observe is a pure read that must not persist it (#110, #130). So
	// chart-inspector dry-ran an install with release name "" and helm answered "no name provided",
	// which failed Observe, which meant the runtime never reached Update — the only phase that
	// would have written the label. A deadlock, retried forever (#329).
	//
	// Found by the openstack-ironic-operator-kog session, who constructed the precondition on a
	// throwaway chart and then confirmed the cause by setting the label by hand and changing
	// nothing else: the composition went from a permanent retry loop to Synced=True at revision 3.
	//
	// THE CALLER KNOWS THE NAME. A callee that re-derives what the caller already computed is
	// coupled to the caller's persistence schedule, which is not a thing a callee can see.
	ReleaseName string `json:"releaseName"`
}

type Resource

type Resource struct {
	Group     string `json:"group"`
	Version   string `json:"version"`
	Resource  string `json:"resource"`
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
	// Verbs to grant on this resource. Set by chart-inspector's tracer: [get,list,watch] for a
	// collection read (Helm `lookup` of a set), ["*"] for a named observation. Absent (older
	// inspector) is treated as ["*"] by rbacgen — backward-compatible.
	Verbs []string `json:"verbs,omitempty"`
}

type StatusError

type StatusError struct {
	Code int
	Body string
}

StatusError carries chart-inspector's HTTP status so a caller can tell WHOSE fault a failure is.

Before this, every non-200 collapsed into a formatted string and a 422 was indistinguishable from a 500 — so the cdc could not act on the distinction chart-inspector had just started making (core-provider#265).

func AsStatusError

func AsStatusError(err error) (*StatusError, bool)

AsStatusError unwraps to a *StatusError if the chain carries one.

func (*StatusError) ClientSide

func (e *StatusError) ClientSide() bool

ClientSide reports any 4xx, including the two above.

func (*StatusError) Detail

func (e *StatusError) Detail() string

Detail is what chart-inspector SAID, in the form a person reads it.

chart-inspector answers every failure with plumbing's response.Status, a JSON object whose `message` is the sentence (for a values-schema 400, helm's own explanation). Quoting Body verbatim put that sentence inside a JSON string, escaped quotes and all, which is the burying #325 is about. So the message is extracted when the body is a Status that carries one.

DEFENSIVE, AND IT NEVER DROPS THE BODY. Anything else in front of chart-inspector can answer too (net/http's ServeMux answers a wrong path with the text "404 page not found"), and an older or newer chart-inspector may shape its body differently. A body that is not a JSON object, or is one without a string `message`, comes back verbatim: an unparsed sentence is less readable, a dropped one is lost.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Reason

func (e *StatusError) Reason() string

Reason is the Status reason chart-inspector sent, or "" when the body is not a Status that has one.

func (*StatusError) ServerSide

func (e *StatusError) ServerSide() bool

ServerSide reports a 5xx: chart-inspector itself failed and the caller's blueprint is not implicated.

func (*StatusError) Unprocessable

func (e *StatusError) Unprocessable() bool

Unprocessable reports a 422: the request was well-formed and chart-inspector cannot render it AS THINGS STAND. The canonical cause is a chart referencing an API kind the cluster does not serve.

"AS THINGS STAND" IS THE WHOLE CONTRACT AND A CALLER MUST NOT LATCH ON IT. chart-inspector classifies on a REST-mapping miss, which cannot distinguish a kind that will never exist from one whose CRD was created moments ago and has not yet reached its RESTMapper. Treating a 422 as permanent would freeze a composition on a transient window — the same defect as a condition computed once from state nobody refreshes (#261, #273).

func (*StatusError) ValuesSchemaViolation

func (e *StatusError) ValuesSchemaViolation() bool

ValuesSchemaViolation reports a 400 that chart-inspector MARKED as a values-schema violation.

BY WHAT THE RESPONSE SAYS, NOT BY ELIMINATION. chart-inspector answers 400 for missing query parameters and a missing releaseName too, all with reason BadRequest. Classifying "any 400 this client could not have caused" as a schema violation would hold only while Validate and the server agree on every parameter, and would mislabel the next 400 cause anyone adds. A 400 without the reason is a refusal, and is reported as one.

Jump to

Keyboard shortcuts

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