From 19b99aec40325940ae18ebfcf279f2b2a6d2c81f Mon Sep 17 00:00:00 2001 From: michaelhtm <98621731+michaelhtm@users.noreply.github.com> Date: Wed, 2 Jul 2025 09:48:10 -0700 Subject: [PATCH] feat: add SkipIncompleteLateInitializeCheck When a field is marked for lateInitialize, the controller tries to ensure that field is never nil. If by chance the field is nil, the controller will reconcile every 5 seconds until the field is no longer nil. Although we want certain fields lateInitialized, we don't expect them to be nonNil. In the example of RDS DBInstance, DBInstance contains PerformanceInsightsKMSID, that we want to lateInitialize only when PerformanceInsights is Enabled. For now this change only allows us the incomplete check, but moving forward, we may want to add certain conditions, to skip or not to skip... --- pkg/config/field.go | 11 +++++++++++ pkg/generate/code/late_initialize.go | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/config/field.go b/pkg/config/field.go index c7dda412..1a3555d5 100644 --- a/pkg/config/field.go +++ b/pkg/config/field.go @@ -318,6 +318,17 @@ type LateInitializeConfig struct { // MaxBackoffSeconds provide the maximum allowed backoff when retrying late initialization after an // unsuccessful attempt. MaxBackoffSeconds int `json:"max_backoff_seconds"` + // SkipIncompleteCheck skips the LateInitialization incomplete check for resources. + // NOTE: (michaelhtm) This skip is best used on resource fields we're sure will be set before being synced + // eg. A resource is marked as synced before the field is lateInitialized, we wouldn't want to wait until + // the next drift detection for the field to be set + SkipIncompleteCheck *SkipIncompleteLateInitializeCheckConfig `json:"skip_incomplete_check,omitempty"` +} + +// SkipIncompleteLateInitializeCheckConfig is a config that defines the scenarios in which +// we would want to skip lateInitialization. +// TODO: (michaelhtm) Populate this struct with conditions...? +type SkipIncompleteLateInitializeCheckConfig struct { } // ReferencesConfig contains the instructions for how to add the referenced resource diff --git a/pkg/generate/code/late_initialize.go b/pkg/generate/code/late_initialize.go index 0853348d..9c3f2c5b 100644 --- a/pkg/generate/code/late_initialize.go +++ b/pkg/generate/code/late_initialize.go @@ -276,7 +276,10 @@ func IncompleteLateInitialization( indent := strings.Repeat("\t", indentLevel) var lateInitFieldNames []string lateInitConfigs := cfg.GetLateInitConfigs(r.Names.Original) - for fieldName := range lateInitConfigs { + for fieldName, lateInitConfig := range lateInitConfigs { + if lateInitConfig.SkipIncompleteCheck != nil { + continue + } lateInitFieldNames = append(lateInitFieldNames, fieldName) } if len(lateInitFieldNames) == 0 {