Skip to content

Commit

Permalink
issue-747: rename annotaion
Browse files Browse the repository at this point in the history
  • Loading branch information
shunki-fujita committed Nov 11, 2024
1 parent c3c6f62 commit 9aa05c2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions charts/moco/templates/generated/generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ spec:
validations:
- expression: |
!has(oldObject.metadata.annotations) ||
!("moco.cybozu.com/prevent" in oldObject.metadata.annotations) ||
!(oldObject.metadata.annotations["moco.cybozu.com/prevent"] == "delete")
!("moco.cybozu.com/prevent-delete" in oldObject.metadata.annotations) ||
!(oldObject.metadata.annotations["moco.cybozu.com/prevent-delete"] == "true")
messageExpression: oldObject.metadata.name + ' is protected from deletion'
---
apiVersion: admissionregistration.k8s.io/v1beta1
Expand Down
12 changes: 7 additions & 5 deletions clustering/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,19 @@ func (p *managerProcess) GatherStatus(ctx context.Context) (*StatusSet, error) {
if primary.Annotations == nil {
primary.Annotations = make(map[string]string)
}
if _, exists := primary.Annotations[constants.AnnPrevent]; !exists {
if _, exists := primary.Annotations[constants.AnnPreventDelete]; !exists {
logFromContext(ctx).Info("replication delay detected, prevent pod deletion", "instance", ss.Primary)
primary.Annotations[constants.AnnPrevent] = "delete"
primary.Annotations[constants.AnnPreventDelete] = "true"
p.client.Update(ctx, primary)
}
} else {
for i, pod := range ss.Pods {
if pod.Annotations != nil {
logFromContext(ctx).Info("replication delay resolved, allow pod deletion", "instance", i)
delete(pod.Annotations, constants.AnnPrevent)
p.client.Update(ctx, pod)
if _, exists := pod.Annotations[constants.AnnPreventDelete]; exists {
logFromContext(ctx).Info("replication delay resolved, allow pod deletion", "instance", i)
delete(pod.Annotations, constants.AnnPreventDelete)
p.client.Update(ctx, pod)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions config/webhook/validate_preventdelete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ spec:
validations:
- expression: |
!has(oldObject.metadata.annotations) ||
!("moco.cybozu.com/prevent" in oldObject.metadata.annotations) ||
!(oldObject.metadata.annotations["moco.cybozu.com/prevent"] == "delete")
!("moco.cybozu.com/prevent-delete" in oldObject.metadata.annotations) ||
!(oldObject.metadata.annotations["moco.cybozu.com/prevent-delete"] == "true")
messageExpression: oldObject.metadata.name + ' is protected from deletion'
---
apiVersion: admissionregistration.k8s.io/v1beta1
Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
AnnClusteringStopped = "moco.cybozu.com/clustering-stopped"
AnnReconciliationStopped = "moco.cybozu.com/reconciliation-stopped"
AnnForceRollingUpdate = "moco.cybozu.com/force-rolling-update"
AnnPrevent = "moco.cybozu.com/prevent"
AnnPreventDelete = "moco.cybozu.com/prevent-delete"
)

// MySQLClusterFinalizer is the finalizer specifier for MySQLCluster.
Expand Down

0 comments on commit 9aa05c2

Please sign in to comment.