From ed3bed697d41f7b287fe316a4f4644368998c02a Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 14 Jan 2025 10:26:59 +0800 Subject: [PATCH] fix(patch): fixed assignment for nil annotation --- internal/dashboard/business/oceanbase/obcluster.go | 3 +++ internal/dashboard/business/oceanbase/obtenant.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/internal/dashboard/business/oceanbase/obcluster.go b/internal/dashboard/business/oceanbase/obcluster.go index a72dda13..6c794f7f 100644 --- a/internal/dashboard/business/oceanbase/obcluster.go +++ b/internal/dashboard/business/oceanbase/obcluster.go @@ -852,6 +852,9 @@ func PatchOBCluster(ctx context.Context, nn *param.K8sObjectIdentity, param *par if param.AddDeletionProtection && !alreadyIgnoredDeletion { // Update deletion protection if specified + if obcluster.Annotations == nil { + obcluster.Annotations = make(map[string]string) + } obcluster.Annotations[oceanbaseconst.AnnotationsIgnoreDeletion] = "true" } else if param.RemoveDeletionProtection && alreadyIgnoredDeletion { delete(obcluster.Annotations, oceanbaseconst.AnnotationsIgnoreDeletion) diff --git a/internal/dashboard/business/oceanbase/obtenant.go b/internal/dashboard/business/oceanbase/obtenant.go index f6c28915..e6bf4c9c 100644 --- a/internal/dashboard/business/oceanbase/obtenant.go +++ b/internal/dashboard/business/oceanbase/obtenant.go @@ -639,6 +639,9 @@ func PatchTenant(ctx context.Context, nn types.NamespacedName, p *param.PatchTen if alreadyIgnoreDeletion && p.RemoveDeletionProtection { delete(tenant.Annotations, oceanbaseconst.AnnotationsIgnoreDeletion) } else if !alreadyIgnoreDeletion && p.AddDeletionProtection { + if tenant.Annotations == nil { + tenant.Annotations = make(map[string]string) + } tenant.Annotations[oceanbaseconst.AnnotationsIgnoreDeletion] = "true" } if len(p.Variables) > 0 {