overrides

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

Overrides Package

The overrides package provides functionality for extracting configuration overrides by comparing configured values against default values from Helm charts.

Overview

This package contains the core logic for identifying differences between configured values and default values, producing a minimal set of overrides that represent only the meaningful differences.

Usage

import "github.com/cloudzero/cloudzero-agent/app/functions/helmless/overrides"

// Create an extractor with optional exclude keys
extractor := overrides.NewExtractor("kubeStateMetrics", "excludedKey")

// Extract overrides
overrides := extractor.Extract(configuredValues, defaultValues)

Key Features

Extractor

The Extractor type handles the comparison logic and provides:

  • Configurable exclusions: Specify keys to exclude from comparison
  • Deep comparison: Recursively compares nested maps and arrays
  • Significance filtering: Only includes values that are considered "significant"
Significance Rules

A value is considered significant if it is:

  • A non-empty string
  • Any number (including zero)
  • Any boolean value (true or false)
  • A non-empty map with at least one significant value
  • A non-empty array with at least one significant value

Values that are not significant:

  • Empty strings
  • nil values
  • Empty maps
  • Empty arrays
  • Maps/arrays containing only insignificant values

Example

configured := map[string]interface{}{
    "replicas": 5,
    "image": "nginx:latest",
    "config": map[string]interface{}{
        "database": map[string]interface{}{
            "host": "prod.db.com",
            "port": 5432,
        },
    },
    "kubeStateMetrics": map[string]interface{}{
        "enabled": true,
    },
}

defaults := map[string]interface{}{
    "replicas": 3,
    "image": "nginx:latest",
    "config": map[string]interface{}{
        "database": map[string]interface{}{
            "host": "localhost",
            "port": 5432,
        },
    },
    "kubeStateMetrics": map[string]interface{}{
        "enabled": false,
    },
}

// Exclude kubeStateMetrics from comparison
extractor := overrides.NewExtractor("kubeStateMetrics")
result := extractor.Extract(configured, defaults)

// Result will be:
// {
//   "replicas": 5,
//   "config": {
//     "database": {
//       "host": "prod.db.com"
//     }
//   }
// }

Testing

The package includes comprehensive tests covering:

  • Basic extractor creation and configuration
  • Simple and complex override scenarios
  • Nested data structure handling
  • Exclude key functionality
  • Significance value determination
  • Edge cases and type variations

Run tests with:

go test ./overrides

Documentation

Overview

Package overrides provides functionality for extracting configuration overrides by comparing configured values against default values from Helm charts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extractor

type Extractor struct {
	// ExcludeKeys is a set of keys to exclude from comparison
	ExcludeKeys map[string]bool
}

Extractor handles the extraction of configuration overrides by comparing configured values against defaults.

func NewExtractor

func NewExtractor(excludeKeys ...string) *Extractor

NewExtractor creates a new Extractor with optional configuration.

func (*Extractor) Extract

func (e *Extractor) Extract(configured, defaults map[string]interface{}) map[string]interface{}

Extract compares configured values against defaults and returns a map containing only the keys whose values differ from the defaults. It recursively compares maps and arrays, including all values that differ regardless of their content.

Jump to

Keyboard shortcuts

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