Skip to content

Commit

Permalink
fix target update on startup
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
fjogeleit committed Sep 20, 2024
1 parent a1de12d commit bdecfba
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 49 deletions.
Empty file.
14 changes: 0 additions & 14 deletions pkg/kubernetes/secrets/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ func (k *informer) Sync(targets *target.Collection, stopper chan struct{}) error

func (k *informer) configureInformer(targets *target.Collection, informer cache.SharedIndexInformer) cache.SharedIndexInformer {
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
if s, ok := obj.(*v1.PartialObjectMetadata); ok {
for _, t := range targets.Targets() {
if t.Secret() == s.Name {
zap.L().Info("Target Updated", zap.String("name", t.Client.Name()), zap.String("secretRef", s.Name))
targets.Update(k.UpdateTarget(t, s.Name))
}
}
}
},
DeleteFunc: func(obj interface{}) {
if _, ok := obj.(*v1.PartialObjectMetadata); ok {
}
},
UpdateFunc: func(_, newObj interface{}) {
if s, ok := newObj.(*v1.PartialObjectMetadata); ok {
for _, t := range targets.Targets() {
Expand Down
34 changes: 0 additions & 34 deletions pkg/kubernetes/secrets/informer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,6 @@ func Test_SecretInformer(t *testing.T) {
stop := make(chan struct{})
defer close(stop)

t.Run("create secretRef", func(t *testing.T) {
collection := target.NewCollection(
&target.Target{
ID: uuid.NewString(),
Type: target.Webhook,
Client: webhook.NewClient(webhook.Options{
ClientOptions: target.ClientOptions{
Name: "Webhook",
},
}),
Config: &target.Config[target.WebhookOptions]{
Name: "Webhook",
SecretRef: secretName,
Config: &target.WebhookOptions{},
},
ParentConfig: &target.Config[target.WebhookOptions]{Config: &target.WebhookOptions{}},
},
)

client, secret := NewFakeMetaClient()

informer := secrets.NewInformer(client, factory.NewFactory(secrets.NewClient(newFakeClient()), target.NewResultFilterFactory(nil)), "default")

err := informer.Sync(collection, stop)
assert.Nil(t, err)

assert.True(t, informer.HasSynced())

secret.CreateFake(&metav1.PartialObjectMetadata{ObjectMeta: metav1.ObjectMeta{Name: secretName, Namespace: "default"}}, metav1.CreateOptions{})
time.Sleep(1 * time.Second)

assert.Equal(t, collection.Targets()[0].Config.(*target.Config[target.WebhookOptions]).Config.Webhook, "http://localhost:9200/webhook")
})

t.Run("update secretRef", func(t *testing.T) {
collection := target.NewCollection(
&target.Target{
Expand Down
2 changes: 1 addition & 1 deletion pkg/target/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ func (f *TargetFactory) mapSecretValues(config any, ref, mountedSecret string) {
c.Config.SecretAccessKey = values.SecretAccessKey
}
if values.AccountID != "" {
c.Config.AccountID = values.AccessKeyID
c.Config.AccountID = values.AccountID
}

case *target.Config[target.GCSOptions]:
Expand Down

0 comments on commit bdecfba

Please sign in to comment.