improvements jan2025 (#6)

* feat(controller): add lazy watcher, improve resource usage and add pattern validation

- [x] Add cache sync health check for readiness probe verification
- [x] Create namespace lister with API reader support for fresh label queries
- [x] Add pattern validation with warning logs for invalid glob patterns
- [x] Implement lazy watcher initialization mode to scan for active resources
- [x] Add requeue delay to namespace reconciler for cache settlement
- [x] Replace custom containsString with slices.Contains from stdlib
- [x] Add structured logging context to reconcilers (kind, group, version)
- [x] Improve error variable naming for clarity in nested conditions
- [x] Add nil-safe label access in namespace reconciler setup
- [x] Add APIReader to namespace and source reconcilers for fresh data
- [x] Improve type assertions with proper error handling in mirror operations
- [x] Reorder struct fields for consistency and readability
- [x] Add comprehensive pattern validation tests and validation API

* feat(controller): add lazy watcher, improve resource usage and add pattern validation

- [x] Add circuit breaker for reconciliation failure tracking and prevention
- [x] Implement granular registration state tracking (not-registered, source-only, fully-registered)
- [x] Add lazy controller initialization for active resource types only
- [x] Consolidate namespace listing into single API call for efficiency
- [x] Add mirror creation verification to catch webhook rejections
- [x] Implement high-cardinality resource detection and warnings
- [x] Add source deletion check in mirror reconciler to prevent races
- [x] Preserve transformation annotations on errors in mirror reconciliation
- [x] Expand constants documentation with labels vs annotations design rationale
- [x] Add comprehensive test coverage for circuit breaker and registration states
- [x] Add mutation-safety tests for hash computation

* fixup! feat(controller): add lazy watcher, improve resource usage and add pattern validation
This commit is contained in:
2026-01-14 13:07:11 +00:00
committed by GitHub
parent 4f8e2783cf
commit 096dca47d1
22 changed files with 1937 additions and 266 deletions
+8 -8
View File
@@ -15,13 +15,13 @@ import (
func TestTransformer_Transform(t *testing.T) {
tests := []struct {
name string
source runtime.Object
ctx TransformContext
source runtime.Object
validate func(t *testing.T, result runtime.Object)
name string
errMsg string
options TransformOptions
wantErr bool
errMsg string
validate func(t *testing.T, result runtime.Object)
}{
// Good cases - Value rules
{
@@ -566,12 +566,12 @@ func TestParsePath(t *testing.T) {
func TestSetNestedField(t *testing.T) {
tests := []struct {
name string
obj map[string]interface{}
path []string
value interface{}
wantErr bool
obj map[string]interface{}
want map[string]interface{}
name string
path []string
wantErr bool
}{
{
name: "set top-level field",
+10 -34
View File
@@ -13,46 +13,22 @@ type TransformRules struct {
// Rule represents a single transformation rule.
type Rule struct {
// Path is the JSONPath to the field to transform (e.g., "data.LOG_LEVEL", "metadata.labels.env")
Path string `yaml:"path"`
// Value sets a static value (mutually exclusive with Template, Merge, Delete)
Value *string `yaml:"value,omitempty"`
// Template uses Go templates to generate the value (mutually exclusive with Value, Merge, Delete)
Template *string `yaml:"template,omitempty"`
// Merge merges a map into the target field (mutually exclusive with Value, Template, Delete)
Merge map[string]interface{} `yaml:"merge,omitempty"`
// Delete removes the field (mutually exclusive with Value, Template, Merge)
Delete bool `yaml:"delete,omitempty"`
// NamespacePattern is an optional glob pattern that limits this rule to specific target namespaces
// Examples: "prod-*", "*-staging", "preprod-*"
// If not specified, the rule applies to all namespaces
NamespacePattern *string `yaml:"namespacePattern,omitempty"`
Value *string `yaml:"value,omitempty"`
Template *string `yaml:"template,omitempty"`
Merge map[string]interface{} `yaml:"merge,omitempty"`
NamespacePattern *string `yaml:"namespacePattern,omitempty"`
Path string `yaml:"path"`
Delete bool `yaml:"delete,omitempty"`
}
// TransformContext provides context variables for template evaluation.
type TransformContext struct {
// TargetNamespace is the namespace where the mirror is being created
Labels map[string]string
Annotations map[string]string
TargetNamespace string
// SourceNamespace is the namespace of the source resource
SourceNamespace string
// SourceName is the name of the source resource
SourceName string
// TargetName is the name of the target resource (usually same as source)
TargetName string
// Labels is a copy of the source resource's labels
Labels map[string]string
// Annotations is a copy of the source resource's annotations
Annotations map[string]string
SourceName string
TargetName string
}
// TransformOptions configures the transformation behavior.
+2 -2
View File
@@ -10,9 +10,9 @@ import (
func TestRule_Validate(t *testing.T) {
tests := []struct {
name string
errMsg string
rule Rule
wantErr bool
errMsg string
}{
// Good cases
{
@@ -191,8 +191,8 @@ func TestRule_Type(t *testing.T) {
func TestRuleType_String(t *testing.T) {
tests := []struct {
name string
ruleType RuleType
want string
ruleType RuleType
}{
{name: "value", ruleType: RuleTypeValue, want: "value"},
{name: "template", ruleType: RuleTypeTemplate, want: "template"},