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

Use "never" rather than "" to mean "don't sync" for AZURE_SYNC_PERIOD. #4049

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/hugo/content/guide/aso-controller-settings-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ This sync exists to detect and correct changes that happened in Azure that Kuber
BE VERY CAREFUL setting this value low - even a modest number of resources can cause
subscription level throttling if they are re-synced frequently. If nil or empty (`""`), sync period defaults to `1h`.

Specify the special value `"never"` to stop syncing.

**Format:** `duration string`

**Example:** `"1h"`, `"15m"`, or `"60s"`. See [ParseDuration](https://pkg.go.dev/time#ParseDuration) for more details.
Expand Down
4 changes: 2 additions & 2 deletions v2/charts/azure-service-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ aadPodIdentity:
# exists to detect and correct changes that happened in Azure that Kubernetes is not
# aware about. BE VERY CAREFUL setting this value low - even a modest number of resources
# can cause subscription level throttling if they are re-synced frequently.
# If nil, no sync is performed. Durations are specified as "1h", "15m", or "60s". See
# https://pkg.go.dev/time#ParseDuration for more details.
# Durations are specified as "1h", "15m", or "60s". Specify the special value "never" to prevent
# syncing. See https://pkg.go.dev/time#ParseDuration for more details.
azureSyncPeriod: ""

# useWorkloadIdentityAuth can be set to use workload identity authentication
Expand Down
8 changes: 5 additions & 3 deletions v2/internal/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ type Values struct {
// If nil, no sync is performed. Durations are specified as "1h", "15m", or "60s". See
// https://pkg.go.dev/time#ParseDuration for more details.
//
// This can be set to nil by specifying empty string for AZURE_SYNC_PERIOD explicitly in
// the config.
// Specify the special value "never" for AZURE_SYNC_PERIOD to prevent syncing.
SyncPeriod *time.Duration

// ResourceManagerEndpoint is the Azure Resource Manager endpoint.
Expand Down Expand Up @@ -232,7 +231,7 @@ func parseTargetNamespaces(fromEnv string) []string {
// parseSyncPeriod parses the sync period from the environment
func parseSyncPeriod() (*time.Duration, error) {
syncPeriodStr := envOrDefault(config.SyncPeriod, "1h")
if syncPeriodStr == "" {
if syncPeriodStr == "never" { // magical string that means no sync
return nil, nil
}

Expand All @@ -250,6 +249,9 @@ func envOrDefault(env string, def string) string {
if !specified {
return def
}
if result == "" {
return def
}

return result
}
48 changes: 48 additions & 0 deletions v2/internal/config/vars_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package config

import (
"testing"
"time"

. "github.com/onsi/gomega"

"github.com/Azure/azure-service-operator/v2/pkg/common/config"
)

//nolint:paralleltest
func Test_ParseSyncPeriod_ReturnsNever(t *testing.T) {
g := NewGomegaWithT(t)
t.Setenv(config.SyncPeriod, "never") // Can't run in parallel

dur, err := parseSyncPeriod()

g.Expect(err).ToNot(HaveOccurred())
g.Expect(dur).To(BeNil()) // Nil means no sync
}

//nolint:paralleltest
func Test_ParseSyncPeriod_ReturnsDefaultWhenEmpty(t *testing.T) {
g := NewGomegaWithT(t)
t.Setenv(config.SyncPeriod, "") // Can't run in parallel

dur, err := parseSyncPeriod()

g.Expect(err).ToNot(HaveOccurred())
g.Expect(dur).ToNot(BeNil())
g.Expect(*dur).To(Equal(1 * time.Hour))
}

//nolint:paralleltest
func Test_ParseSyncPeriod_ReturnsValue(t *testing.T) {
g := NewGomegaWithT(t)
t.Setenv(config.SyncPeriod, "21m") // Can't run in parallel

dur, err := parseSyncPeriod()

g.Expect(err).ToNot(HaveOccurred())
g.Expect(dur).ToNot(BeNil())
g.Expect(*dur).To(Equal(21 * time.Minute))
}
4 changes: 2 additions & 2 deletions v2/pkg/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const (
// exists to detect and correct changes that happened in Azure that Kubernetes is not
// aware about. BE VERY CAREFUL setting this value low - even a modest number of resources
// can cause subscription level throttling if they are re-synced frequently.
// If nil, no sync is performed. Durations are specified as "1h", "15m", or "60s". See
// https://pkg.go.dev/time#ParseDuration for more details.
// Durations are specified as "1h", "15m", or "60s". Specify the special value "never" to prevent
// syncing. See https://pkg.go.dev/time#ParseDuration for more details.
SyncPeriod = "AZURE_SYNC_PERIOD"
// ResourceManagerEndpoint is the Azure Resource Manager endpoint.
// If not specified, the default is the Public cloud resource manager endpoint.
Expand Down
Loading