Remove unused DeleteSecretIfAny/DeleteConfigMapIfAny helpers

These single-object delete helpers were introduced earlier but are no
longer called in production code: DeleteSecretsWithLabel and
DeleteConfigMapsWithLabel now delete inline with UID preconditions.
Remove the dead functions and their tests.

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
This commit is contained in:
Shubham Pampattiwar
2026-08-18 10:28:27 -07:00
parent e498c5f79b
commit f457a95802
2 changed files with 0 additions and 68 deletions
-24
View File
@@ -113,18 +113,6 @@ func CopySecret(ctx context.Context, client corev1client.CoreV1Interface, secret
return ErrSecretCollision
}
// DeleteSecretIfAny deletes a secret if it exists, logging but not returning errors.
func DeleteSecretIfAny(ctx context.Context, client corev1client.CoreV1Interface, secretName, namespace string, log logrus.FieldLogger) {
err := client.Secrets(namespace).Delete(ctx, secretName, metav1.DeleteOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
log.Debugf("Secret %s/%s not found, skipping delete", namespace, secretName)
} else {
log.WithError(err).Errorf("Failed to delete secret %s/%s", namespace, secretName)
}
}
}
// DeleteSecretsWithLabel deletes all secrets in a namespace matching a label key=value pair.
// Uses UID preconditions to avoid deleting a recreated object with the same name.
func DeleteSecretsWithLabel(ctx context.Context, client corev1client.CoreV1Interface, namespace, labelKey, labelValue string, log logrus.FieldLogger) {
@@ -193,18 +181,6 @@ func CopyConfigMap(ctx context.Context, client corev1client.CoreV1Interface, cmN
return ErrSecretCollision
}
// DeleteConfigMapIfAny deletes a configmap if it exists, logging but not returning errors.
func DeleteConfigMapIfAny(ctx context.Context, client corev1client.CoreV1Interface, cmName, namespace string, log logrus.FieldLogger) {
err := client.ConfigMaps(namespace).Delete(ctx, cmName, metav1.DeleteOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
log.Debugf("ConfigMap %s/%s not found, skipping delete", namespace, cmName)
} else {
log.WithError(err).Errorf("Failed to delete configmap %s/%s", namespace, cmName)
}
}
}
// DeleteConfigMapsWithLabel deletes all configmaps in a namespace matching a label key=value pair.
// Uses UID preconditions to avoid deleting a recreated object with the same name.
func DeleteConfigMapsWithLabel(ctx context.Context, client corev1client.CoreV1Interface, namespace, labelKey, labelValue string, log logrus.FieldLogger) {
-44
View File
@@ -163,28 +163,6 @@ func TestCopySecret(t *testing.T) {
}
}
func TestDeleteSecretIfAny(t *testing.T) {
log := logrus.New()
t.Run("deletes existing secret", func(t *testing.T) {
secret := &corev1api.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "test-secret", Namespace: "velero"},
}
fakeClient := fake.NewSimpleClientset(secret)
DeleteSecretIfAny(context.Background(), fakeClient.CoreV1(), "test-secret", "velero", log)
_, err := fakeClient.CoreV1().Secrets("velero").Get(
context.Background(), "test-secret", metav1.GetOptions{})
assert.Error(t, err)
})
t.Run("no error when secret does not exist", func(t *testing.T) {
fakeClient := fake.NewSimpleClientset()
DeleteSecretIfAny(context.Background(), fakeClient.CoreV1(), "missing", "velero", log)
})
}
func TestDeleteSecretsWithLabel(t *testing.T) {
log := logrus.New()
@@ -353,28 +331,6 @@ func TestCopyConfigMap(t *testing.T) {
}
}
func TestDeleteConfigMapIfAny(t *testing.T) {
log := logrus.New()
t.Run("deletes existing configmap", func(t *testing.T) {
cm := &corev1api.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: "test-cm", Namespace: "velero"},
}
fakeClient := fake.NewSimpleClientset(cm)
DeleteConfigMapIfAny(context.Background(), fakeClient.CoreV1(), "test-cm", "velero", log)
_, err := fakeClient.CoreV1().ConfigMaps("velero").Get(
context.Background(), "test-cm", metav1.GetOptions{})
assert.Error(t, err)
})
t.Run("no error when configmap does not exist", func(t *testing.T) {
fakeClient := fake.NewSimpleClientset()
DeleteConfigMapIfAny(context.Background(), fakeClient.CoreV1(), "missing", "velero", log)
})
}
func TestDeleteConfigMapsWithLabel(t *testing.T) {
log := logrus.New()