Skip to content

Commit

Permalink
Merge pull request #604 from erdeiattila/fix/event-storms
Browse files Browse the repository at this point in the history
azure-keyvault-controller: restrict Kubernetes event generation to changes
  • Loading branch information
181192 authored Oct 1, 2023
2 parents ceceb1a + 7aa38c0 commit 6ddfeee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func (c *Controller) syncDeletedAzureKeyVaultSecret(key string) error {
}

klog.V(4).InfoS("sync successful", "azurekeyvaultsecret", klog.KObj(akvs), "secret", klog.KObj(secret))
c.recorder.Event(secret, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
outputObject = secret
}

Expand All @@ -146,7 +145,6 @@ func (c *Controller) syncDeletedAzureKeyVaultSecret(key string) error {
}

klog.V(4).InfoS("sync successful", "azurekeyvaultsecret", klog.KObj(akvs), "configmap", klog.KObj(cm))
c.recorder.Event(cm, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
outputObject = cm
}

Expand Down Expand Up @@ -179,7 +177,6 @@ func (c *Controller) syncAzureKeyVaultSecret(key string) error {
}

klog.V(4).InfoS("sync successful", "azurekeyvaultsecret", klog.KObj(akvs), "secret", klog.KObj(secret))
c.recorder.Event(secret, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
outputObject = secret
}

Expand All @@ -190,7 +187,6 @@ func (c *Controller) syncAzureKeyVaultSecret(key string) error {
}

klog.V(4).InfoS("sync successful", "azurekeyvaultsecret", klog.KObj(akvs), "configmap", klog.KObj(cm))
c.recorder.Event(cm, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
outputObject = cm
}

Expand Down Expand Up @@ -258,6 +254,7 @@ func (c *Controller) syncAzureKeyVault(key string) error {
}

secretName = secret.Name
c.recorder.Event(akvs, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSyncedWithAzureKeyVault)
klog.InfoS("secret changed - any resources (like pods) using this secret must be restarted to pick up the new value - details: https://github.com/kubernetes/kubernetes/issues/22368", "azurekeyvaultsecret", klog.KObj(secret), "secret", klog.KObj(akvs))
}
}
Expand Down Expand Up @@ -299,6 +296,7 @@ func (c *Controller) syncAzureKeyVault(key string) error {
return fmt.Errorf("failed to update configmap, error: %+v", err)
}
cmName = cm.Name
c.recorder.Event(akvs, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSyncedWithAzureKeyVault)
klog.InfoS("configmap changed - any resources (like pods) using this configmap must be restarted to pick up the new value - details: https://github.com/kubernetes/kubernetes/issues/22368", "azurekeyvaultsecret", klog.KObj(akvs), "configmap", klog.KObj(cm))
}
}
Expand All @@ -310,7 +308,6 @@ func (c *Controller) syncAzureKeyVault(key string) error {
}

klog.V(4).InfoS("sync successful", "azurekeyvaultsecret", klog.KObj(akvs))
c.recorder.Event(akvs, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSyncedWithAzureKeyVault)
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/azure-keyvault-controller/controller/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *Controller) getOrCreateKubernetesConfigMap(akvs *akv.AzureKeyVaultSecre
if err = c.updateAzureKeyVaultSecretStatusForConfigMap(akvs, getMD5HashOfStringValues(cmValues)); err != nil {
return nil, fmt.Errorf("failed to update status for azurekeyvaultsecret %s, error: %+v", akvs.Name, err)
}

c.recorder.Event(cm, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
return cm, nil
}
}
Expand All @@ -131,6 +131,7 @@ func (c *Controller) getOrCreateKubernetesConfigMap(akvs *akv.AzureKeyVaultSecre
if cm, err = c.kubeclientset.CoreV1().ConfigMaps(akvs.Namespace).Create(context.TODO(), createNewConfigMap(akvs, cmValues), metav1.CreateOptions{}); err != nil {
return nil, err
}
c.recorder.Event(cm, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
return cm, nil
}

Expand All @@ -145,6 +146,7 @@ func (c *Controller) getOrCreateKubernetesConfigMap(akvs *akv.AzureKeyVaultSecre
cm, err = c.kubeclientset.CoreV1().ConfigMaps(akvs.Namespace).Update(context.TODO(), updatedCM, metav1.UpdateOptions{})
if err == nil {
klog.InfoS("configmap updated", "azurekeyvaultsecret", klog.KObj(akvs), "configmap", klog.KObj(cm))
c.recorder.Event(cm, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
}
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/azure-keyvault-controller/controller/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *Controller) getOrCreateKubernetesSecret(akvs *akv.AzureKeyVaultSecret)
if err = c.updateAzureKeyVaultSecretStatusForSecret(akvs, getMD5HashOfByteValues(secretValues)); err != nil {
return nil, err
}

c.recorder.Event(secret, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
return secret, nil
}
}
Expand All @@ -128,6 +128,7 @@ func (c *Controller) getOrCreateKubernetesSecret(akvs *akv.AzureKeyVaultSecret)
if secret, err = c.kubeclientset.CoreV1().Secrets(akvs.Namespace).Create(context.TODO(), createNewSecret(akvs, secretValues), metav1.CreateOptions{}); err != nil {
return nil, err
}
c.recorder.Event(secret, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
return secret, nil
}

Expand All @@ -141,6 +142,7 @@ func (c *Controller) getOrCreateKubernetesSecret(akvs *akv.AzureKeyVaultSecret)
secret, err = c.kubeclientset.CoreV1().Secrets(akvs.Namespace).Update(context.TODO(), updatedSecret, metav1.UpdateOptions{})
if err == nil {
klog.InfoS("secret updated", "azurekeyvaultsecret", klog.KObj(akvs), "secret", klog.KObj(secret))
c.recorder.Event(secret, corev1.EventTypeNormal, SuccessSynced, MessageAzureKeyVaultSecretSynced)
}
}

Expand Down

0 comments on commit 6ddfeee

Please sign in to comment.