importer

package
v1.0.0-rc07 Latest Latest
Warning

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

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

Index

Constants

View Source
const (
	TerraformOutputNetworkID = "opencenter_network_id"
	TerraformOutputSubnetID  = "opencenter_subnet_id"
)

TerraformOutputNames are the OpenTofu outputs `cluster observe` promotes into the cluster config. They are emitted by the generated infrastructure tree at lifecycle contract v3; a contract v2 module exposes none of them, which is an empty observation rather than an error.

Variables

This section is empty.

Functions

func ApplyClusterWritePlan

func ApplyClusterWritePlan(plan *ClusterWritePlan) error

func IsProtectedField

func IsProtectedField(path string) bool

func ObserveTerraform

func ObserveTerraform(ctx context.Context, cfg *v2.Config, clusterDir string, tofuPath string) ([]FieldInferenceResult, []FieldConflict, error)

ObserveTerraform reads the post-apply OpenTofu outputs for a cluster and returns the config fields whose stored value differs from what the infrastructure actually created.

The point of this is the tofu-managed network: `cluster provider openstack` clears network_id/subnet_id so OpenTofu can create them, and until now nothing ever wrote the created IDs back. The CCM renders its [LoadBalancer] subnet-id from networking.subnet_id, so a tofu-managed cluster shipped a blank one.

A field that already holds a value is reported as a conflict, never as an automatic promotion: a populated subnet_id may be an operator selection made with --create-internal-network=false, and silently rewriting it would repoint a running cluster's addressing.

clusterDir is the generated infrastructure directory (the `tofu` working directory). An absent directory or a module that predates contract v3 yields no observations and no error, so observe stays usable on Kind, Magnum, baremetal, and VMware clusters.

func ObserveTerraformFromConfig

func ObserveTerraformFromConfig(ctx context.Context, cfg *v2.Config, tofuPath string) ([]FieldInferenceResult, []FieldConflict, error)

ObserveTerraformFromConfig resolves the infrastructure directory from the cluster config and observes it. It mirrors the path the deploy path renders into, so observe and deploy never look at different directories.

func ObserveTerraformOutputs

func ObserveTerraformOutputs(cfg *v2.Config, clusterDir string, outputs tofuoutput.Outputs) ([]FieldInferenceResult, []FieldConflict, error)

ObserveTerraformOutputs evaluates already-parsed OpenTofu outputs against the cluster config, returning inferred fields and conflicts. This allows callers using their own command runners (e.g. bootstrap lifecycle runners) to process outputs without directly spawning an OS process.

func RenderScanResult

func RenderScanResult(result *ImportScanResult, format string) ([]byte, error)

func RepoHash

func RepoHash(repoPath string) string

func SelectApprovedFields

func SelectApprovedFields(cluster ClusterImportResult) ([]FieldInferenceResult, []SkippedField)

func SetYAMLPath

func SetYAMLPath(root *yaml.Node, path string, value any) error

SetYAMLPath writes value at the dotted path (for example "opencenter.infrastructure.cloud.openstack.subnet_id"), creating the intermediate mappings. It is the repo's generic config-path writer: the import write plan, `cluster promote`, and the deploy network-binding all patch through it so a config field has exactly one write mechanism.

Types

type ArtifactStore

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

func NewArtifactStore

func NewArtifactStore() (*ArtifactStore, error)

func (*ArtifactStore) LoadLatest

func (s *ArtifactStore) LoadLatest(repoPath string) (*SavedArtifact, error)

func (*ArtifactStore) Save

func (s *ArtifactStore) Save(repoPath string, result *ImportScanResult, savedAt time.Time) (*SavedArtifact, error)

type ClusterImportResult

type ClusterImportResult struct {
	ClusterName    string                   `json:"cluster_name"`
	Organization   string                   `json:"organization,omitempty"`
	Sources        ClusterSources           `json:"sources"`
	ProposedConfig *v2.Config               `json:"proposed_config,omitempty"`
	FieldResults   []FieldInferenceResult   `json:"field_results,omitempty"`
	ServiceResults []ServiceInferenceResult `json:"service_results,omitempty"`
	Conflicts      []FieldConflict          `json:"conflicts,omitempty"`
	SkippedFields  []SkippedField           `json:"skipped_fields,omitempty"`
	ExistingConfig string                   `json:"existing_config,omitempty"`
	ProposedPatch  string                   `json:"proposed_patch,omitempty"`
	Warnings       []string                 `json:"warnings,omitempty"`
	Errors         []string                 `json:"errors,omitempty"`
}

func BuildLiveImportResult

func BuildLiveImportResult(ctx context.Context, cfg *v2.Config, kubeconfigPath string) (ClusterImportResult, error)

type ClusterSources

type ClusterSources struct {
	RepoPath         string   `json:"repo_path"`
	ClusterName      string   `json:"cluster_name"`
	ClusterDir       string   `json:"cluster_dir,omitempty"`
	OverlayDir       string   `json:"overlay_dir,omitempty"`
	LegacyConfigPath string   `json:"legacy_config_path,omitempty"`
	ReadmePath       string   `json:"readme_path,omitempty"`
	KubeconfigPaths  []string `json:"kubeconfig_paths,omitempty"`
}

type ClusterWritePlan

type ClusterWritePlan struct {
	ClusterName     string
	Organization    string
	ConfigPath      string
	Create          bool
	ApprovedFields  []FieldInferenceResult
	SkippedFields   []SkippedField
	RenderedContent []byte
	Diff            string
}

func PrepareClusterWritePlan

func PrepareClusterWritePlan(ctx context.Context, cluster ClusterImportResult) (*ClusterWritePlan, error)

type ConfidenceLevel

type ConfidenceLevel string
const (
	ConfidenceHigh     ConfidenceLevel = "high"
	ConfidenceMedium   ConfidenceLevel = "medium"
	ConfidenceLow      ConfidenceLevel = "low"
	ConfidenceConflict ConfidenceLevel = "conflict"
)

type DetectorRegistry

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

func NewDetectorRegistry

func NewDetectorRegistry() *DetectorRegistry

func (*DetectorRegistry) Detector

func (r *DetectorRegistry) Detector(name string) ServiceDetector

func (*DetectorRegistry) Names

func (r *DetectorRegistry) Names() []string

type EvidenceRef

type EvidenceRef struct {
	Source string `json:"source,omitempty"`
	Path   string `json:"path,omitempty"`
	Detail string `json:"detail,omitempty"`
}

type FieldConflict

type FieldConflict struct {
	Path           string        `json:"path"`
	GitOpsValue    any           `json:"gitops_value,omitempty"`
	LiveValue      any           `json:"live_value,omitempty"`
	Recommended    string        `json:"recommended,omitempty"`
	Evidence       []EvidenceRef `json:"evidence,omitempty"`
	ProtectedField bool          `json:"protected_field,omitempty"`
}

type FieldInferenceResult

type FieldInferenceResult struct {
	Path       string          `json:"path"`
	Value      any             `json:"value,omitempty"`
	Confidence ConfidenceLevel `json:"confidence"`
	Origin     FieldOrigin     `json:"origin"`
	Evidence   []EvidenceRef   `json:"evidence,omitempty"`
}

type FieldOrigin

type FieldOrigin string
const (
	FieldOriginGitOps  FieldOrigin = "gitops"
	FieldOriginLive    FieldOrigin = "live"
	FieldOriginDefault FieldOrigin = "default"
	FieldOriginManual  FieldOrigin = "manual"
	// FieldOriginTerraform marks a value read from the applied OpenTofu state,
	// i.e. infrastructure that exists because the CLI provisioned it.
	FieldOriginTerraform FieldOrigin = "terraform"
)

type ImportScanResult

type ImportScanResult struct {
	RepoPath  string                `json:"repo_path"`
	ScannedAt time.Time             `json:"scanned_at"`
	Clusters  []ClusterImportResult `json:"clusters"`
	Summary   ImportSummary         `json:"summary"`
	Warnings  []string              `json:"warnings,omitempty"`
}

type ImportSummary

type ImportSummary struct {
	ClustersDiscovered int `json:"clusters_discovered"`
	ClustersWithErrors int `json:"clusters_with_errors,omitempty"`
	ConflictCount      int `json:"conflict_count,omitempty"`
	SkippedFieldCount  int `json:"skipped_field_count,omitempty"`
}

type LiveSnapshot

type LiveSnapshot struct {
	KubernetesVersion string
	MasterCount       int
	WorkerCount       int
	Namespaces        map[string]struct{}
}

func CollectLiveSnapshot

func CollectLiveSnapshot(ctx context.Context, kubeconfigPath string) (*LiveSnapshot, error)

type NamespaceRegistry

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

func NewNamespaceRegistry

func NewNamespaceRegistry() *NamespaceRegistry

func (*NamespaceRegistry) ApplyOverrides

func (r *NamespaceRegistry) ApplyOverrides(overrides []string) error

func (*NamespaceRegistry) NamespacesFor

func (r *NamespaceRegistry) NamespacesFor(serviceName string) []string

type PatchResult

type PatchResult struct {
	Path    string
	Content []byte
	Diff    string
}

func PatchYAMLFile

func PatchYAMLFile(path string, updates []FieldInferenceResult) (*PatchResult, error)

type SavedArtifact

type SavedArtifact struct {
	RepoHash string            `json:"repo_hash"`
	Path     string            `json:"path"`
	SavedAt  time.Time         `json:"saved_at"`
	Result   *ImportScanResult `json:"result,omitempty"`
}

type Scanner

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

func NewScanner

func NewScanner() *Scanner

func (*Scanner) ApplyNamespaceOverrides

func (s *Scanner) ApplyNamespaceOverrides(overrides []string) error

func (*Scanner) ScanRepo

func (s *Scanner) ScanRepo(ctx context.Context, repoPath string) (*ImportScanResult, error)

type ServiceDetector

type ServiceDetector interface {
	ServiceName() string
	Detect(context.Context, *detectContext) ServiceInferenceResult
}

type ServiceInferenceResult

type ServiceInferenceResult struct {
	ServiceName  string                       `json:"service_name"`
	Namespaces   []string                     `json:"namespaces,omitempty"`
	Enabled      *bool                        `json:"enabled,omitempty"`
	AdoptionMode *configservices.AdoptionMode `json:"adoption_mode,omitempty"`
	Fields       []FieldInferenceResult       `json:"fields,omitempty"`
	Conflicts    []FieldConflict              `json:"conflicts,omitempty"`
	Skipped      []SkippedField               `json:"skipped,omitempty"`
}

type SkippedField

type SkippedField struct {
	Path       string          `json:"path"`
	Reason     string          `json:"reason"`
	Confidence ConfidenceLevel `json:"confidence,omitempty"`
}

Jump to

Keyboard shortcuts

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