Skip to content
Open
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
78 changes: 75 additions & 3 deletions api/v1/azureappconfigurationprovider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ limitations under the License.
package v1

import (
"encoding/json"
"sort"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -83,9 +87,13 @@ type AzureAppConfigurationFeatureFlagOptions struct {

// KeyLabelSelector defines the filters when fetching the data from Azure AppConfiguration
type Selector struct {
KeyFilter *string `json:"keyFilter,omitempty"`
LabelFilter *string `json:"labelFilter,omitempty"`
SnapshotName *string `json:"snapshotName,omitempty"`
KeyFilter *string `json:"keyFilter,omitempty"`
LabelFilter *string `json:"labelFilter,omitempty"`
// +kubebuilder:validation:MaxItems=5
// +kubebuilder:validation:items:MinLength=1
// +kubebuilder:validation:items:Pattern=^[^=]+=[^=]*$
TagFilters []string `json:"tagFilters,omitempty"`
SnapshotName *string `json:"snapshotName,omitempty"`
}

// Defines the settings for dynamic configuration.
Expand Down Expand Up @@ -243,6 +251,70 @@ type AzureAppConfigurationProviderList struct {
Items []AzureAppConfigurationProvider `json:"items"`
}

type ComparableSelector struct {
KeyFilter *string
LabelFilter *string
TagFilters *string
SnapshotName *string
}

func MakeComparable(selector Selector) ComparableSelector {
comparable := ComparableSelector{}

if selector.KeyFilter != nil {
comparable.KeyFilter = selector.KeyFilter
}
if selector.LabelFilter != nil {
comparable.LabelFilter = selector.LabelFilter
}
if selector.SnapshotName != nil {
comparable.SnapshotName = selector.SnapshotName
}
if len(selector.TagFilters) > 0 {
sortedTags := make([]string, len(selector.TagFilters))
copy(sortedTags, selector.TagFilters)
sort.Strings(sortedTags)
// Use JSON encoding to safely handle tags
tagFiltersBytes, err := json.Marshal(sortedTags)
if err != nil {
// Fallback to comma-separated string if JSON marshaling fails
tagFiltersStr := strings.Join(sortedTags, ",")
comparable.TagFilters = &tagFiltersStr
} else {
tagFiltersStr := string(tagFiltersBytes)
comparable.TagFilters = &tagFiltersStr
}
}

return comparable
}

func FromComparable(comparable ComparableSelector) Selector {
selector := Selector{}

if comparable.KeyFilter != nil {
selector.KeyFilter = comparable.KeyFilter
}
if comparable.LabelFilter != nil {
selector.LabelFilter = comparable.LabelFilter
}
if comparable.SnapshotName != nil {
selector.SnapshotName = comparable.SnapshotName
}
if comparable.TagFilters != nil && *comparable.TagFilters != "" {
// Try JSON decoding first to safely deserialize tags
var tagFilters []string
err := json.Unmarshal([]byte(*comparable.TagFilters), &tagFilters)
if err != nil {
// Fallback to comma-separated parsing if JSON fails
tagFilters = strings.Split(*comparable.TagFilters, ",")
}
selector.TagFilters = tagFilters
}

return selector
}

func init() {
SchemeBuilder.Register(&AzureAppConfigurationProvider{}, &AzureAppConfigurationProviderList{})
}
40 changes: 40 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

14 changes: 14 additions & 0 deletions config/crd/bases/azconfig.io_azureappconfigurationproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ spec:
type: string
snapshotName:
type: string
tagFilters:
items:
minLength: 1
pattern: ^[^=]+=[^=]*$
type: string
maxItems: 5
type: array
type: object
type: array
trimKeyPrefixes:
Expand Down Expand Up @@ -163,6 +170,13 @@ spec:
type: string
snapshotName:
type: string
tagFilters:
items:
minLength: 1
pattern: ^[^=]+=[^=]*$
type: string
maxItems: 5
type: array
type: object
type: array
type: object
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.24.0

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.2
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig/v2 v2.0.0
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.4.0
github.com/golang/mock v1.6.0
github.com/onsi/gomega v1.36.1
Expand Down Expand Up @@ -43,7 +44,6 @@ require (

require (
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.11.0
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v1.2.0
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.11.0 h1:MhRfI58HblXzCtWEZCO0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.11.0/go.mod h1:okZ+ZURbArNdlJ+ptXoyHNuOETzOl1Oww19rm8I2WLA=
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2 h1:yz1bePFlP5Vws5+8ez6T3HWXPmwOK7Yvq8QxDBD3SKY=
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2/go.mod h1:Pa9ZNPuoNu/GztvBSKk9J1cDJW6vk/n0zLtV4mgd8N8=
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v1.2.0 h1:uU4FujKFQAz31AbWOO3INV9qfIanHeIUSsGhRlcJJmg=
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v1.2.0/go.mod h1:qr3M3Oy6V98VR0c5tCHKUpaeJTRQh6KYzJewRtFWqfc=
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig/v2 v2.0.0 h1:K7LqZL3VW+DElZhW+5tY/cp2RRFrB3W45WUG/9fhhls=
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig/v2 v2.0.0/go.mod h1:4IPby+BYf0rPMnMur/mNtowysFd4NoEW5U1vhrkhARA=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 h1:9iefClla7iYpfYWdzPCRDozdmndjTm8DXdpCzPajMgA=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2/go.mod h1:XtLgD3ZD34DAaVIIAyG3objl5DynM3CQ/vMcbBNJZGI=
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.4.0 h1:/g8S6wk65vfC6m3FIxJ+i5QDyN9JWwXI8Hb0Img10hU=
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/appconfigurationprovider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ type ReconciliationState struct {
ConfigMapResourceVersion *string
Annotations map[string]string
SentinelETags map[acpv1.Sentinel]*azcore.ETag
KeyValueETags map[acpv1.Selector][]*azcore.ETag
FeatureFlagETags map[acpv1.Selector][]*azcore.ETag
KeyValueETags map[acpv1.ComparableSelector][]*azcore.ETag
FeatureFlagETags map[acpv1.ComparableSelector][]*azcore.ETag
ExistingK8sSecrets map[string]*loader.TargetK8sSecretMetadata
NextKeyValueRefreshReconcileTime metav1.Time
NextSecretReferenceRefreshReconcileTime metav1.Time
Expand Down Expand Up @@ -147,8 +147,8 @@ func (reconciler *AzureAppConfigurationProviderReconciler) Reconcile(ctx context
ConfigMapResourceVersion: nil,
Annotations: make(map[string]string),
SentinelETags: make(map[acpv1.Sentinel]*azcore.ETag),
KeyValueETags: make(map[acpv1.Selector][]*azcore.ETag),
FeatureFlagETags: make(map[acpv1.Selector][]*azcore.ETag),
KeyValueETags: make(map[acpv1.ComparableSelector][]*azcore.ETag),
FeatureFlagETags: make(map[acpv1.ComparableSelector][]*azcore.ETag),
ExistingK8sSecrets: make(map[string]*loader.TargetK8sSecretMetadata),
ClientManager: nil,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type RefreshOptions struct {
sentinelChanged bool
keyValuePageETagsChanged bool
updatedSentinelETags map[acpv1.Sentinel]*azcore.ETag
updatedKeyValueETags map[acpv1.Selector][]*azcore.ETag
updatedFeatureFlagETags map[acpv1.Selector][]*azcore.ETag
updatedKeyValueETags map[acpv1.ComparableSelector][]*azcore.ETag
updatedFeatureFlagETags map[acpv1.ComparableSelector][]*azcore.ETag
}

func (processor *AppConfigurationProviderProcessor) PopulateSettings(existingConfigMap *corev1.ConfigMap, existingSecrets map[string]corev1.Secret) error {
Expand Down
Loading
Loading