Skip to content
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

Merged
merged 10 commits into from
Jul 29, 2024

Conversation

linglingye001
Copy link
Contributor

No description provided.

@linglingye001 linglingye001 marked this pull request as ready for review July 17, 2024 08:08
@@ -51,9 +51,10 @@ type AzureAppConfigurationProviderReconciler struct {
type ReconciliationState struct {
Generation int64
ConfigMapResourceVersion *string
SentinelETags map[acpv1.Sentinel]*azcore.ETag
Copy link
Contributor

@RichardChen820 RichardChen820 Jul 22, 2024

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

Copy link
Contributor Author

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.

@linglingye001 linglingye001 force-pushed the uesr/linglingye/pageEtag branch from b67c1b9 to 3143464 Compare July 22, 2024 09:13
@RichardChen820 RichardChen820 changed the base branch from release/v2/preview to release/v2/stable July 22, 2024 15:12
@@ -288,8 +316,16 @@ func (processor *AppConfigurationProviderProcessor) Finish() (ctrl.Result, error
processor.ReconciliationState.ExistingSecretReferences = processor.Settings.SecretReferences
}

if len(processor.RefreshOptions.updatedKeyValueETags) > 0 {
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor

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

selectors []acpv1.Selector
type EtagSettingsClient struct {
etags map[acpv1.Selector][]*azcore.ETag
etagChanged bool
Copy link
Contributor

@RichardChen820 RichardChen820 Jul 24, 2024

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


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)
Copy link
Contributor

@RichardChen820 RichardChen820 Jul 24, 2024

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?

@@ -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"
Copy link
Contributor

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) {
Copy link
Contributor

@RichardChen820 RichardChen820 Jul 24, 2024

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
Copy link
Contributor

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.

Copy link
Contributor

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"`
Copy link
Contributor

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
Copy link
Contributor

@RichardChen820 RichardChen820 Jul 24, 2024

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?

@@ -65,12 +68,15 @@ func (processor *AppConfigurationProviderProcessor) PopulateSettings(existingCon
}

func (processor *AppConfigurationProviderProcessor) processFullReconciliation() error {
processor.ReconciliationState.KeyValueETags, processor.ReconciliationState.FeatureFlagETags = initializeEtags(processor.Provider)
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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:
Copy link
Contributor

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

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate with line 7

nullString := "\x00"
settingsToReturn := make([]azappconfig.Setting, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings is fine

nullString := "\x00"
settingsToReturn := make([]azappconfig.Setting, 0)
refreshedEtags := make(map[acpv1.Selector][]*azcore.ETag)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pageEtags is fine

@@ -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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

}

// no change in the settings, return nil
return nil, nil
Copy link
Contributor

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 {
Copy link
Contributor

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

@linglingye001 linglingye001 merged commit f364a5a into release/v2/stable Jul 29, 2024
3 checks passed
@linglingye001 linglingye001 deleted the uesr/linglingye/pageEtag branch July 29, 2024 08:13
linglingye001 added a commit that referenced this pull request Nov 8, 2024
* draft

* update

* update etag at finish stage

* resolve conflicts

* check etags before loading settings

* update test

* update

* go mod tidy

* update

* update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants