Skip to content

Commit

Permalink
*: add maintain mode, for delete leader svc
Browse files Browse the repository at this point in the history
  • Loading branch information
acekingke committed Jul 11, 2023
1 parent 203e7b6 commit 8afca99
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
31 changes: 29 additions & 2 deletions controllers/mysqlcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ func (r *MysqlClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
clustersyncer.NewRoleBindingSyncer(r.Client, instance),
clustersyncer.NewServiceAccountSyncer(r.Client, instance),
clustersyncer.NewHeadlessSVCSyncer(r.Client, instance),
clustersyncer.NewLeaderSVCSyncer(r.Client, instance),
}
if instance.Unwrap().Labels[utils.LabelMaintain] == "true" {
log.V(1).Info("It has got a maintain label")
r.deletLeaderService(ctx, req, instance.Unwrap())
} else {
syncers = append(syncers, clustersyncer.NewLeaderSVCSyncer(r.Client, instance))
}
if instance.Unwrap().Spec.ReadOnlys != nil {
syncers = append(syncers, clustersyncer.NewHeadlessReadOnlySVCSyncer(r.Client, instance),
Expand Down Expand Up @@ -237,7 +242,29 @@ func (r *MysqlClusterReconciler) deleteFollowerService(ctx context.Context, req
}
for _, svc := range serviceList.Items {
if err := r.Delete(context.TODO(), &svc); err != nil {
log.Error(err, "failed to delete a backup", "backup", svc)
log.Error(err, "failed to delete a service", "service", svc)
}
}
return nil
}

// For SingleNode, follower service do not need.
func (r *MysqlClusterReconciler) deletLeaderService(ctx context.Context, req ctrl.Request, instance *apiv1alpha1.MysqlCluster) error {
log := log.FromContext(ctx).WithName("controllers").WithName("MysqlCluster")
labelSet := labels.Set{"mysql.radondb.com/service-type": string(utils.LeaderService)}
serviceList := corev1.ServiceList{}
if err := r.List(ctx,
&serviceList,
&client.ListOptions{
Namespace: instance.Namespace,
LabelSelector: labelSet.AsSelector(),
},
); err != nil {
return err
}
for _, svc := range serviceList.Items {
if err := r.Delete(context.TODO(), &svc); err != nil {
log.Error(err, "failed to delete a leader service", "service", svc)
}
}
return nil
Expand Down
1 change: 1 addition & 0 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ const (

const LableRebuild = "rebuild"
const LabelRebuildFrom = "rebuild-from"
const LabelMaintain = "maintain"

// XenonHttpUrl is a http url corresponding to the xenon instruction.
type XenonHttpUrl string
Expand Down

0 comments on commit 8afca99

Please sign in to comment.