config

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package config validates configuration for different package format types.

How it works:

Each package format type (like registry+v1 or Helm) knows what configuration it accepts. When a user provides configuration, we validate it before creating a Config object. Once created, a Config is guaranteed to be valid - you never need to check it again.

The validation uses JSON Schema:

  1. Bundle provides its schema (what config is valid)
  2. We validate the user's config against that schema
  3. If valid, we create a Config object
  4. If invalid, we return a helpful error message

Design choices:

  • Validation happens once, when creating the Config. There's no Validate() method because once you have a Config, it's already been validated.

  • Config doesn't hold onto the schema. We only need the schema during validation, not after the Config is created.

  • You can't create a Config directly. You must go through UnmarshalConfig so that validation always happens.

Index

Constants

View Source
const (

	// FormatOwnNamespaceInstallMode defines the format check to ensure that
	// the watchNamespace must equal install namespace
	FormatOwnNamespaceInstallMode = "ownNamespaceInstallMode"
	// FormatSingleNamespaceInstallMode defines the format check to ensure that
	// the watchNamespace must differ from install namespace
	FormatSingleNamespaceInstallMode = "singleNamespaceInstallMode"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config map[string]any

Config holds validated configuration data from a ClusterExtension.

Different package format types have different configuration options, so we store the data in a flexible format and provide accessor methods to get values out.

Why there's no Validate() method: We validate configuration when creating a Config. If you have a Config object, it's already been validated - you don't need to check it again. You can't create a Config directly; you have to use UnmarshalConfig, which does the validation.

func UnmarshalConfig

func UnmarshalConfig(bytes []byte, schema map[string]any, installNamespace string) (*Config, error)

UnmarshalConfig takes user configuration, validates it, and creates a Config object. This is the only way to create a Config.

What it does:

  1. Checks the user's configuration against the schema (if provided)
  2. If valid, creates a Config object
  3. If invalid, returns an error explaining what's wrong

Parameters:

  • bytes: the user's configuration in YAML or JSON. If nil, we treat it as empty ({})
  • schema: describes what configuration is valid. If nil, we skip validation
  • installNamespace: the namespace where the operator will be installed. We use this to validate namespace constraints (e.g., OwnNamespace mode requires watchNamespace to equal installNamespace)

If the user doesn't provide any configuration but the package format type requires some fields (like watchNamespace), validation will fail with a helpful error.

func (*Config) GetWatchNamespace

func (c *Config) GetWatchNamespace() *string

GetWatchNamespace returns the watchNamespace value if present in the configuration. Returns nil if watchNamespace is not set or is explicitly set to null.

type SchemaProvider

type SchemaProvider interface {
	// GetConfigSchema returns a JSON Schema describing what configuration is valid.
	// Returns nil if this package format type doesn't need configuration validation.
	GetConfigSchema() (map[string]any, error)
}

SchemaProvider lets each package format type describe what configuration it accepts.

Different package format types provide schemas in different ways:

  • registry+v1: builds schema from the operator's install modes
  • Helm: reads schema from values.schema.json in the chart
  • registry+v2: (future) will have its own way

Jump to

Keyboard shortcuts

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