func()

in internal/controller/processor.go [87:133]


func (processor *AppConfigurationProviderProcessor) processFeatureFlagRefresh(existingConfigMap *corev1.ConfigMap) error {
	provider := *processor.Provider
	reconcileState := processor.ReconciliationState
	var err error
	// Check if the feature flag dynamic feature if enabled
	if provider.Spec.FeatureFlag != nil &&
		provider.Spec.FeatureFlag.Refresh != nil &&
		provider.Spec.FeatureFlag.Refresh.Enabled {
		processor.RefreshOptions.featureFlagRefreshEnabled = true
	} else {
		reconcileState.NextFeatureFlagRefreshReconcileTime = metav1.Time{}
		return nil
	}

	refreshInterval, _ := time.ParseDuration(provider.Spec.FeatureFlag.Refresh.Interval)
	nextFeatureFlagRefreshReconcileTime := metav1.Time{Time: processor.CurrentTime.Add(refreshInterval)}
	if processor.ShouldReconcile {
		reconcileState.NextFeatureFlagRefreshReconcileTime = nextFeatureFlagRefreshReconcileTime
		return nil
	}

	if !processor.CurrentTime.After(reconcileState.NextFeatureFlagRefreshReconcileTime.Time) {
		return nil
	}

	if processor.RefreshOptions.featureFlagRefreshNeeded, err = (processor.Retriever).CheckPageETags(processor.Context, reconcileState.FeatureFlagETags); err != nil {
		return err
	}

	if !processor.RefreshOptions.featureFlagRefreshNeeded {
		reconcileState.NextFeatureFlagRefreshReconcileTime = nextFeatureFlagRefreshReconcileTime
		return nil
	}

	featureFlagRefreshedSettings, err := (processor.Retriever).RefreshFeatureFlagSettings(processor.Context, &existingConfigMap.Data)
	if err != nil {
		return err
	}

	processor.RefreshOptions.updatedFeatureFlagETags = featureFlagRefreshedSettings.FeatureFlagETags
	processor.Settings = featureFlagRefreshedSettings
	processor.RefreshOptions.ConfigMapSettingPopulated = true
	// Update next refresh time only if settings updated successfully
	reconcileState.NextFeatureFlagRefreshReconcileTime = nextFeatureFlagRefreshReconcileTime

	return nil
}