Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
linglingye001 committed Sep 25, 2024
1 parent a78f53e commit 588dd07
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 36 deletions.
3 changes: 1 addition & 2 deletions api/v1/azureappconfigurationprovider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ type RefreshMonitoring struct {

// Defines the keyValues to be watched.
type Sentinel struct {
// +kubebuilder:validation:MinLength=1
Key *string `json:"key"`
Key string `json:"key"`
// +kubebuilder:default="\x00"
Label *string `json:"label,omitempty"`
}
Expand Down
5 changes: 0 additions & 5 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ spec:
description: Defines the keyValues to be watched.
properties:
key:
minLength: 1
type: string
label:
default: "\0"
Expand Down
26 changes: 13 additions & 13 deletions internal/controller/appconfigurationprovider_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ var _ = Describe("AppConfiguationProvider controller", func() {
Enabled: true,
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{Key: &testKey, Label: &testLabel},
{Key: testKey, Label: &testLabel},
},
},
},
Expand Down Expand Up @@ -810,7 +810,7 @@ var _ = Describe("AppConfiguationProvider controller", func() {
Enabled: true,
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{Key: &testNewKey, Label: &testNewLabel},
{Key: testNewKey, Label: &testNewLabel},
},
},
},
Expand Down Expand Up @@ -886,7 +886,7 @@ var _ = Describe("AppConfiguationProvider controller", func() {
Enabled: false,
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{Key: &testNewKey, Label: &testNewLabel},
{Key: testNewKey, Label: &testNewLabel},
},
},
},
Expand Down Expand Up @@ -975,8 +975,8 @@ var _ = Describe("AppConfiguationProvider controller", func() {
Enabled: true,
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{Key: &testKeyOne, Label: &testLabelOne},
{Key: &testKeyTwo, Label: &testLabelTwo},
{Key: testKeyOne, Label: &testLabelOne},
{Key: testKeyTwo, Label: &testLabelTwo},
},
},
},
Expand Down Expand Up @@ -2279,15 +2279,15 @@ var _ = Describe("AppConfiguationProvider controller", func() {
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{
Key: &testKey,
Key: testKey,
Label: &testLabelOne,
},
{
Key: &testKey,
Key: testKey,
Label: &testLabelTwo,
},
{
Key: &testKey,
Key: testKey,
Label: &testLabelOne,
},
},
Expand Down Expand Up @@ -2318,19 +2318,19 @@ var _ = Describe("AppConfiguationProvider controller", func() {
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{
Key: &testKey,
Key: testKey,
Label: nil,
},
{
Key: &testKey2,
Key: testKey2,
Label: &testLabel,
},
{
Key: &testKey3,
Key: testKey3,
Label: nil,
},
{
Key: &testKey4,
Key: testKey4,
Label: &emptyLabel,
},
},
Expand Down Expand Up @@ -2414,7 +2414,7 @@ var _ = Describe("AppConfiguationProvider controller", func() {
Enabled: true,
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{Key: &testKey, Label: &testLabel},
{Key: testKey, Label: &testLabel},
},
},
},
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ var _ = Describe("AppConfiguationProvider processor", func() {
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{
Key: &sentinelKey1,
Key: sentinelKey1,
},
{
Key: &sentinelKey2,
Key: sentinelKey2,
},
},
},
Expand All @@ -104,7 +104,7 @@ var _ = Describe("AppConfiguationProvider processor", func() {
NextKeyValueRefreshReconcileTime: metav1.Now(),
SentinelETags: map[acpv1.Sentinel]*azcore.ETag{
{
Key: &sentinelKey1,
Key: sentinelKey1,
}: &fakeEtag,
},
Generation: 1,
Expand All @@ -123,10 +123,10 @@ var _ = Describe("AppConfiguationProvider processor", func() {
true,
map[acpv1.Sentinel]*azcore.ETag{
{
Key: &sentinelKey1,
Key: sentinelKey1,
}: &newFakeEtag1,
{
Key: &sentinelKey2,
Key: sentinelKey2,
}: &newFakeEtag2,
},
nil,
Expand All @@ -141,10 +141,10 @@ var _ = Describe("AppConfiguationProvider processor", func() {
_, _ = processor.Finish()

Expect(processor.ReconciliationState.SentinelETags[acpv1.Sentinel{
Key: &sentinelKey1,
Key: sentinelKey1,
}]).Should(Equal(&newFakeEtag1))
Expect(processor.ReconciliationState.SentinelETags[acpv1.Sentinel{
Key: &sentinelKey2,
Key: sentinelKey2,
}]).Should(Equal(&newFakeEtag2))
Expect(processor.ReconciliationState.NextKeyValueRefreshReconcileTime).Should(Equal(expectedNextKeyValueRefreshReconcileTime))
})
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func verifyObject(spec acpv1.AzureAppConfigurationProviderSpec) error {
sentinelMap := make(map[acpv1.Sentinel]bool)
for _, sentinel := range spec.Configuration.Refresh.Monitoring.Sentinels {
if _, ok := sentinelMap[sentinel]; ok {
return loader.NewArgumentError("spec.configuration.refresh.monitoring.keyValues", fmt.Errorf("monitoring duplicated key '%s'", *sentinel.Key))
return loader.NewArgumentError("spec.configuration.refresh.monitoring.keyValues", fmt.Errorf("monitoring duplicated key '%s'", sentinel.Key))
}
sentinelMap[sentinel] = true
}
Expand Down
8 changes: 4 additions & 4 deletions internal/loader/configuraiton_setting_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,11 +1345,11 @@ func TestGetFilters(t *testing.T) {
Monitoring: &acpv1.RefreshMonitoring{
Sentinels: []acpv1.Sentinel{
{
Key: &one,
Key: one,
Label: nil,
},
{
Key: &two,
Key: two,
Label: &emptyLabel,
},
},
Expand All @@ -1360,9 +1360,9 @@ func TestGetFilters(t *testing.T) {

sentinels := getSentinels(testSpec8.Configuration.Refresh.Monitoring.Sentinels)
assert.Len(t, sentinels, 2)
assert.Equal(t, "one", *sentinels[0].Key)
assert.Equal(t, "one", sentinels[0].Key)
assert.Nil(t, sentinels[0].Label)
assert.Equal(t, "two", *sentinels[1].Key)
assert.Equal(t, "two", sentinels[1].Key)
assert.Nil(t, sentinels[1].Label)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/loader/settings_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *EtagSettingsClient) GetSettings(ctx context.Context, client *azappconfi
}

func (s *SentinelSettingsClient) GetSettings(ctx context.Context, client *azappconfig.Client) (*SettingsResponse, error) {
sentinelSetting, err := client.GetSetting(ctx, *s.sentinel.Key, &azappconfig.GetSettingOptions{Label: s.sentinel.Label, OnlyIfChanged: s.etag})
sentinelSetting, err := client.GetSetting(ctx, s.sentinel.Key, &azappconfig.GetSettingOptions{Label: s.sentinel.Label, OnlyIfChanged: s.etag})
if err != nil {
var respErr *azcore.ResponseError
if errors.As(err, &respErr) {
Expand All @@ -100,10 +100,10 @@ func (s *SentinelSettingsClient) GetSettings(ctx context.Context, client *azappc
}
switch respErr.StatusCode {
case 404:
klog.Warningf("Sentinel key '%s' with %s label does not exists, revisit the sentinel after %s", *s.sentinel.Key, label, s.refreshInterval)
klog.Warningf("Sentinel key '%s' with %s label does not exists, revisit the sentinel after %s", s.sentinel.Key, label, s.refreshInterval)
return nil, nil
case 304:
klog.V(3).Infof("There's no change to the sentinel key '%s' with %s label , just exit and revisit the sentinel after %s", *s.sentinel.Key, label, s.refreshInterval)
klog.V(3).Infof("There's no change to the sentinel key '%s' with %s label , just exit and revisit the sentinel after %s", s.sentinel.Key, label, s.refreshInterval)
return &SettingsResponse{
Settings: []azappconfig.Setting{sentinelSetting.Setting},
}, nil
Expand Down

0 comments on commit 588dd07

Please sign in to comment.