-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refresh ConfigMap when data change #59
Conversation
@@ -51,9 +51,10 @@ type AzureAppConfigurationProviderReconciler struct { | |||
type ReconciliationState struct { | |||
Generation int64 | |||
ConfigMapResourceVersion *string | |||
SentinelETags map[acpv1.Sentinel]*azcore.ETag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the Sentinel Etags is still required to be noted, we still need to check etags of the sentinels, if sentinals are set and they are not changes, we should not refresh the configmap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if user set sentinels, they would be cached in KeyValueEtags
.
b67c1b9
to
3143464
Compare
internal/controller/processor.go
Outdated
@@ -288,8 +316,16 @@ func (processor *AppConfigurationProviderProcessor) Finish() (ctrl.Result, error | |||
processor.ReconciliationState.ExistingSecretReferences = processor.Settings.SecretReferences | |||
} | |||
|
|||
if len(processor.RefreshOptions.updatedKeyValueETags) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How abou tusing nil check instead of length check? If not updated, return nil.
} | ||
|
||
type SentinelSettingsClient struct { | ||
sentinel acpv1.Sentinel | ||
etag *azcore.ETag | ||
refreshInterval string | ||
} | ||
type SelectorSettingsClient struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add an extra line before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not addressed
internal/loader/settings_client.go
Outdated
selectors []acpv1.Selector | ||
type EtagSettingsClient struct { | ||
etags map[acpv1.Selector][]*azcore.ETag | ||
etagChanged bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't expect to have this field in EtagSettingsClient
, if the etag is not changed, just return nil etgas is fine, if not just return non-nil etags
internal/loader/settings_client.go
Outdated
|
||
type SettingsClient interface { | ||
GetSettings(ctx context.Context, client *azappconfig.Client) ([]azappconfig.Setting, error) | ||
GetSettings(ctx context.Context, client *azappconfig.Client) ([]azappconfig.Setting, map[acpv1.Selector][]*azcore.ETag, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like such return types in an interface method, what if we need more returns in the future? Could we create a new type for them?
internal/loader/settings_client.go
Outdated
@@ -11,26 +11,78 @@ import ( | |||
|
|||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | |||
"github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig" | |||
"k8s.io/klog/v2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this change?
@@ -354,6 +331,56 @@ func (csl *ConfigurationSettingLoader) CheckAndRefreshSentinels( | |||
return sentinelChanged, refreshedETags, nil | |||
} | |||
|
|||
func (csl *ConfigurationSettingLoader) CheckPageETags(ctx context.Context, provider *acpv1.AzureAppConfigurationProvider, eTags map[acpv1.Selector][]*azcore.ETag) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provider *acpv1.AzureAppConfigurationProvider
parameter is not used
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. | ||
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - | ||
|
||
.PHONY: helm-generate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep these two items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the helm-generate and helm-push
@@ -53,7 +53,7 @@ type AzureAppConfigurationProviderStatus struct { | |||
// RefreshStatus defines last refresh time of configmap and secret when dynamic feature is enabled | |||
type RefreshStatus struct { | |||
LastKeyVaultReferenceRefreshTime metav1.Time `json:"lastKeyVaultReferenceRefreshTime,omitempty"` | |||
LastSentinelBasedRefreshTime metav1.Time `json:"lastSentinelBasedRefreshTime,omitempty"` | |||
LastKeyValueRefreshTime metav1.Time `json:"lastKeyValueRefreshTime,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test the upgrade scenario to see whether the field change in CRD would break upgrade scenario, You can try install 1.3.1 first then upgrade to this version to see if it block anything.
go.mod
Outdated
@@ -82,6 +82,7 @@ require ( | |||
gopkg.in/yaml.v3 v3.0.1 | |||
k8s.io/api v0.30.1 | |||
k8s.io/apiextensions-apiserver v0.30.1 // indirect | |||
k8s.io/klog v1.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need the klog v1?
internal/controller/processor.go
Outdated
@@ -65,12 +68,15 @@ func (processor *AppConfigurationProviderProcessor) PopulateSettings(existingCon | |||
} | |||
|
|||
func (processor *AppConfigurationProviderProcessor) processFullReconciliation() error { | |||
processor.ReconciliationState.KeyValueETags, processor.ReconciliationState.FeatureFlagETags = initializeEtags(processor.Provider) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason that initializeEtags
is required?
func (s *SentinelSettingsClient) GetSettings(ctx context.Context, client *azappconfig.Client) ([]azappconfig.Setting, error) { | ||
func (s *EtagSettingsClient) GetSettings(ctx context.Context, client *azappconfig.Client) ([]azappconfig.Setting, map[acpv1.Selector][]*azcore.ETag, error) { | ||
nullString := "\x00" | ||
for filter, pageEtags := range s.etags { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we check the etags
is nil or not? if it's nil, just need to return non-nil etags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean check s.etags
? What scenario will it be nil
?
@@ -345,9 +347,3 @@ spec: | |||
storage: true | |||
subresources: | |||
status: {} | |||
status: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't expect to remove this section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's auto-generated by make command. What's the influence of removing this section?
@@ -5,6 +5,7 @@ package loader | |||
|
|||
import ( | |||
acpv1 "azappconfig/provider/api/v1" | |||
v1 "azappconfig/provider/api/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate with line 7
internal/loader/settings_client.go
Outdated
nullString := "\x00" | ||
settingsToReturn := make([]azappconfig.Setting, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings
is fine
internal/loader/settings_client.go
Outdated
nullString := "\x00" | ||
settingsToReturn := make([]azappconfig.Setting, 0) | ||
refreshedEtags := make(map[acpv1.Selector][]*azcore.ETag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pageEtags
is fine
internal/loader/settings_client.go
Outdated
@@ -72,15 +133,19 @@ func (s *SelectorSettingsClient) GetSettings(ctx context.Context, client *azappc | |||
Fields: azappconfig.AllSettingFields(), | |||
} | |||
pager := client.NewListSettingsPager(selector, nil) | |||
latestEtags := make([]*azcore.ETag, 0) | |||
|
|||
for pager.More() { | |||
page, err := pager.NextPage(ctx) | |||
if err != nil { | |||
return nil, err | |||
} else if len(page.Settings) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this check be problematic? What if it returns an empty setting list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should check if page.Settings == nil
, when empty setting returned, pageEtag
is not empty.
internal/loader/settings_client.go
Outdated
} | ||
|
||
// no change in the settings, return nil | ||
return nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetSetting()
should never return nil without any error, I would suggest return nil etags and settings rather than nil response.
// Get the latest key value settings | ||
existingConfigMapSettings := &existingConfigMap.Data | ||
if processor.Settings.ConfigMapSettings != nil { | ||
existingConfigMapSettings = &processor.Settings.ConfigMapSettings | ||
} | ||
|
||
if provider.Spec.Configuration.Refresh.Monitoring != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we put the line164- line178 right before the line 158, seems don't need to read the existing data if etag checking decides not refresh
* draft * update * update etag at finish stage * resolve conflicts * check etags before loading settings * update test * update * go mod tidy * update * update
No description provided.