Skip to content

Commit cb21eea

Browse files
committed
Update To Global Eventing System
make generate manifests revert test file since tests are being added in another PR update controller changes update event path code clean up make genereate manifests Update Secret Struct Name update secret type to VaultStaticSecretConfig changes for global event listener updates Remove unused stubVaultClient event methods Add joinVaultPath helper to build Vault paths Trim leading/trailing slashes and skip empty segments when joining update tests make fmt
1 parent 4cefcce commit cb21eea

15 files changed

+609
-816
lines changed

api/v1beta1/vaultdynamicsecret_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type VaultDynamicSecretSpec struct {
6262
// Destination provides configuration necessary for syncing the Vault secret to Kubernetes.
6363
Destination Destination `json:"destination"`
6464
// SyncConfig configures sync behavior from Vault to VSO
65-
SyncConfig *DyanmicSecretSyncConfig `json:"syncConfig,omitempty"`
65+
SyncConfig *VaultDynamicSecretSyncConfig `json:"syncConfig,omitempty"`
6666
// RefreshAfter a period of time for VSO to sync the source secret data, in
6767
// duration notation e.g. 30s, 1m, 24h. This value only needs to be set when
6868
// syncing from a secret's engine that does not provide a lease TTL in its
@@ -131,10 +131,10 @@ type VaultStaticCredsMetaData struct {
131131
TTL int64 `json:"ttl"`
132132
}
133133

134-
// DyanmicSecretSyncConfig configures sync behavior from Vault to VSO for dynamic secrets
135-
type DyanmicSecretSyncConfig struct {
134+
// VaultDynamicSecretSyncConfig configures sync behavior from Vault to VSO for dynamic secrets
135+
type VaultDynamicSecretSyncConfig struct {
136136
// InstantUpdates is a flag to indicate that event-driven updates are
137-
// enabled for a VaultDynamicSecret
137+
// enabled for this VaultDynamicSecret
138138
InstantUpdates bool `json:"instantUpdates,omitempty"`
139139
}
140140

api/v1beta1/vaultstaticsecret_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type VaultStaticSecretSpec struct {
4141
// Destination provides configuration necessary for syncing the Vault secret to Kubernetes.
4242
Destination Destination `json:"destination"`
4343
// SyncConfig configures sync behavior from Vault to VSO
44-
SyncConfig *StaticSecretSyncConfig `json:"syncConfig,omitempty"`
44+
SyncConfig *VaultStaticSecretSyncConfig `json:"syncConfig,omitempty"`
4545

4646
VaultStaticSecretCommon `json:",inline"`
4747
}
@@ -69,10 +69,10 @@ type VaultStaticSecretCollectable struct {
6969
Transformation *Transformation `json:"transformation,omitempty"`
7070
}
7171

72-
// StaticSecretSyncConfig configures sync behavior from Vault to VSO
73-
type StaticSecretSyncConfig struct {
72+
// VaultStaticSecretSyncConfig configures sync behavior from Vault to VSO
73+
type VaultStaticSecretSyncConfig struct {
7474
// InstantUpdates is a flag to indicate that event-driven updates are
75-
// enabled for a VaultStaticSecret
75+
// enabled for this VaultStaticSecret
7676
InstantUpdates bool `json:"instantUpdates,omitempty"`
7777
}
7878

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 32 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chart/crds/secrets.hashicorp.com_vaultdynamicsecrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ spec:
296296
instantUpdates:
297297
description: |-
298298
InstantUpdates is a flag to indicate that event-driven updates are
299-
enabled for VaultStaticSecret/VaultDynamicSecret
299+
enabled for this VaultDynamicSecret
300300
type: boolean
301301
type: object
302302
vaultAuthRef:

chart/crds/secrets.hashicorp.com_vaultstaticsecrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ spec:
257257
instantUpdates:
258258
description: |-
259259
InstantUpdates is a flag to indicate that event-driven updates are
260-
enabled for VaultStaticSecret/VaultDynamicSecret
260+
enabled for this VaultStaticSecret
261261
type: boolean
262262
type: object
263263
type:

config/crd/bases/secrets.hashicorp.com_vaultdynamicsecrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ spec:
296296
instantUpdates:
297297
description: |-
298298
InstantUpdates is a flag to indicate that event-driven updates are
299-
enabled for VaultDynamicSecret
299+
enabled for this VaultDynamicSecret
300300
type: boolean
301301
type: object
302302
vaultAuthRef:

config/crd/bases/secrets.hashicorp.com_vaultstaticsecrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ spec:
257257
instantUpdates:
258258
description: |-
259259
InstantUpdates is a flag to indicate that event-driven updates are
260-
enabled for VaultStaticSecret
260+
enabled for this VaultStaticSecret
261261
type: boolean
262262
type: object
263263
type:

controllers/event_watcher_registry.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ package controllers
55

66
import (
77
"context"
8+
"fmt"
9+
"time"
810

11+
"github.com/cenkalti/backoff/v4"
12+
"github.com/go-logr/logr"
913
gocache "github.com/patrickmn/go-cache"
1014
"k8s.io/apimachinery/pkg/types"
1115
)
@@ -23,6 +27,19 @@ type eventWatcherMeta struct {
2327
// LastClientID - vault client ID for the last successful connection, used
2428
// to detect if the Vault client has changed since the event watcher started
2529
LastClientID string
30+
// ListenerID tracks the identifier for event listeners registered on a
31+
// Vault client.
32+
ListenerID string
33+
// ErrorCount records the number of consecutive errors encountered while
34+
// handling events for this watcher/listener.
35+
ErrorCount int
36+
// ErrorThreshold defines how many consecutive errors should trigger a
37+
// requeue of the resource.
38+
ErrorThreshold int
39+
// Backoff defines the retry behavior when handling errors.
40+
Backoff *backoff.ExponentialBackOff `json:"-"`
41+
// RetryCancel cancels any pending requeue timers.
42+
RetryCancel context.CancelFunc `json:"-"`
2643
}
2744

2845
// eventWatcherRegistry - registry for keeping track of running event watcher
@@ -32,6 +49,8 @@ type eventWatcherRegistry struct {
3249
registry *gocache.Cache
3350
}
3451

52+
const defaultEventWatcherErrorThreshold = 5
53+
3554
func newEventWatcherRegistry() *eventWatcherRegistry {
3655
return &eventWatcherRegistry{
3756
registry: gocache.New(gocache.NoExpiration, gocache.NoExpiration),
@@ -57,3 +76,46 @@ func (r *eventWatcherRegistry) Get(key types.NamespacedName) (*eventWatcherMeta,
5776
func (r *eventWatcherRegistry) Delete(key types.NamespacedName) {
5877
r.registry.Delete(key.String())
5978
}
79+
80+
func resetEventWatcherMeta(meta *eventWatcherMeta) {
81+
if meta == nil {
82+
return
83+
}
84+
meta.ErrorCount = 0
85+
if meta.Backoff != nil {
86+
meta.Backoff.Reset()
87+
}
88+
if meta.RetryCancel != nil {
89+
meta.RetryCancel()
90+
meta.RetryCancel = nil
91+
}
92+
}
93+
94+
// Stop cancels the watcher/listener referenced by meta, waits for it to finish,
95+
// and deletes the registry entry.
96+
func (r *eventWatcherRegistry) Stop(ctx context.Context, key types.NamespacedName, meta *eventWatcherMeta, logger logr.Logger) {
97+
if meta == nil {
98+
r.Delete(key)
99+
return
100+
}
101+
102+
if meta.Cancel != nil {
103+
meta.Cancel()
104+
} else if logger.GetSink() != nil {
105+
logger.Error(fmt.Errorf("nil cancel function"), "event watcher has nil cancel function", "key", key)
106+
}
107+
108+
if meta.StoppedCh != nil {
109+
waitCtx, cancel := context.WithTimeout(ctx, 2*time.Minute)
110+
defer cancel()
111+
if err := waitForStoppedCh(waitCtx, meta.StoppedCh); err != nil && logger.GetSink() != nil {
112+
logger.Error(err, "Failed to stop event watcher", "key", key)
113+
}
114+
}
115+
if meta.RetryCancel != nil {
116+
meta.RetryCancel()
117+
meta.RetryCancel = nil
118+
}
119+
120+
r.Delete(key)
121+
}

0 commit comments

Comments
 (0)