Skip to content

Commit

Permalink
PTEUDO-1990: fix label name
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabricio committed Nov 28, 2024
1 parent c24c0a2 commit dd3fcea
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
10 changes: 4 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,11 @@ func main() {
os.Exit(1)
}

// nolint:goconst
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = webhookpersistancev1.SetupDatabaseClaimWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "DatabaseClaim")
os.Exit(1)
}
if err = webhookpersistancev1.SetupDatabaseClaimWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "DatabaseClaim")
os.Exit(1)
}

// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Describe("annotation conversions", func() {
ObjectMeta: metav1.ObjectMeta{
Name: dbcName,
Namespace: "default",
Labels: map[string]string{"override-deletion": "true"},
Labels: map[string]string{"persistance.atlas.infoblox.com/allow-deletion": "true"},
},
Spec: v1.DatabaseClaimSpec{
SecretName: dbcSecretName,
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/dbproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Describe("dbproxy defaulting", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "default-db",
Namespace: "default",
Labels: map[string]string{"override-deletion": "true"},
Labels: map[string]string{"persistance.atlas.infoblox.com/allow-deletion": "true"},
},
Spec: v1.DatabaseClaimSpec{
SecretName: "test",
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/dsnexec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Describe("dsnexec defaulting", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "default-db",
Namespace: "default",
Labels: map[string]string{"override-deletion": "true"},
Labels: map[string]string{"persistance.atlas.infoblox.com/allow-deletion": "true"},
},
Spec: v1.DatabaseClaimSpec{
SecretName: "test",
Expand Down
6 changes: 3 additions & 3 deletions internal/webhook/v1/databaseclaim_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// log is for logging in this package.
var databaseclaimlog = logf.Log.WithName("databaseclaim-resource")

const deletionOverrideKey = "override-deletion"
const deletionOverrideLabel = "persistance.atlas.infoblox.com/allow-deletion"

// SetupDatabaseClaimWebhookWithManager registers the webhook for DatabaseClaim in the manager.
func SetupDatabaseClaimWebhookWithManager(mgr ctrl.Manager) error {
Expand Down Expand Up @@ -67,11 +67,11 @@ func (v *DatabaseClaimCustomValidator) ValidateDelete(ctx context.Context, obj r

databaseclaimlog.Info("Validation for DatabaseClaim upon deletion", "name", claim.Name)

if value, exists := claim.GetLabels()[deletionOverrideKey]; exists && value == "true" {
if value, exists := claim.GetLabels()[deletionOverrideLabel]; exists && value == "true" {
databaseclaimlog.Info("Deletion override label found; allowing deletion", "name", claim.Name)
return nil, nil
}

return nil, fmt.Errorf("deletion is denied for DatabaseClaim '%s'; set annotation or label '%s=true' to override",
claim.Name, deletionOverrideKey)
claim.Name, deletionOverrideLabel)
}
8 changes: 4 additions & 4 deletions internal/webhook/v1/databaseclaim_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("DatabaseClaim Webhook", func() {
Context("When deleting a DatabaseClaim under Validating Webhook", func() {
It("Should allow deletion if the deletion override label is set to true", func() {
By("Setting the deletion override label")
obj.SetLabels(map[string]string{deletionOverrideKey: "true"})
obj.SetLabels(map[string]string{deletionOverrideLabel: "true"})

By("Calling ValidateDelete")
warnings, err := validator.ValidateDelete(ctx, obj)
Expand All @@ -49,12 +49,12 @@ var _ = Describe("DatabaseClaim Webhook", func() {

By("Validating the error message")
Expect(err.Error()).To(ContainSubstring("deletion is denied for DatabaseClaim"))
Expect(err.Error()).To(ContainSubstring(deletionOverrideKey))
Expect(err.Error()).To(ContainSubstring(deletionOverrideLabel))
})

It("Should deny deletion if the deletion override label is set to false", func() {
By("Setting the deletion override label to false")
obj.SetLabels(map[string]string{deletionOverrideKey: "false"})
obj.SetLabels(map[string]string{deletionOverrideLabel: "false"})

By("Calling ValidateDelete")
warnings, err := validator.ValidateDelete(ctx, obj)
Expand All @@ -65,7 +65,7 @@ var _ = Describe("DatabaseClaim Webhook", func() {

By("Validating the error message")
Expect(err.Error()).To(ContainSubstring("deletion is denied for DatabaseClaim"))
Expect(err.Error()).To(ContainSubstring(deletionOverrideKey))
Expect(err.Error()).To(ContainSubstring(deletionOverrideLabel))
})
})

Expand Down

0 comments on commit dd3fcea

Please sign in to comment.