Skip to content

Commit eda8232

Browse files
dannyzakenliranmauda
authored andcommitted
disable HAC + set noobaa-core term grace to 1
- HAC can be enabled with the env HAC_ENABLED=true - Also changed the default grace period of the HAC when enabled from 0 to 1. This change avoids force deletion of the pods, to prevent multiple containers running concurrently. - The grace period can be set to 0 with the env HAC_FORCE_DELETE=true - Also setting the terminationGracePeriodSeconds of noobaa-core to 1. By default this is 30 seconds. Since we don't have any handler in noobaa-core for SIGETRM, there isn't a need to wait 30 seconds before killing the container. Signed-off-by: Danny Zaken <dannyzaken@gmail.com> (cherry picked from commit 38294af) (cherry picked from commit b7652a4) (cherry picked from commit 1e0e4ee) (cherry picked from commit e8592ca) (cherry picked from commit b3e5a89) (cherry picked from commit 45f36a5)
1 parent 6b3dbe4 commit eda8232

5 files changed

Lines changed: 20 additions & 5 deletions

File tree

.github/workflows/run_hac_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: HAC on KIND cluster Test
2-
on: [push, pull_request, workflow_dispatch]
2+
on: [workflow_dispatch]
33

44
jobs:
55
run-hac-test:

pkg/controller/add_hac.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package controller
22

33
import (
4+
"os"
5+
46
hac "github.com/noobaa/noobaa-operator/v5/pkg/controller/ha"
57
)
68

79
func init() {
8-
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
9-
AddToManagerFuncs = append(AddToManagerFuncs, hac.Add)
10+
hacEnabled := os.Getenv("HAC_ENABLED")
11+
if hacEnabled == "true" {
12+
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
13+
AddToManagerFuncs = append(AddToManagerFuncs, hac.Add)
14+
}
1015
}

pkg/controller/ha/ha_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func nodeNotReadyPredicate() predicate.Predicate {
7171

7272
// Add creates a nodewatcher Controller and adds it to the Manager.
7373
func Add(mgr manager.Manager) error {
74+
util.Logger().Info("Adding high availability controller (HAC)")
7475

7576
opts := controller.Options{
7677
MaxConcurrentReconciles: 1,

pkg/hac/hac.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package hac
55

66
import (
77
"context"
8+
"os"
89

910
"github.com/pkg/errors"
1011
"github.com/sirupsen/logrus"
@@ -43,8 +44,12 @@ func (pd *PodDeleter) DeletePodsOnNode() error {
4344
return errors.Errorf("failed to list noobaa pods on the node %v in namespace %v", pd.NodeName, options.Namespace)
4445
}
4546

46-
// delete the found pods
47-
var gracePeriod int64 = 0
47+
// delete the found pods. by default using a 1 second grace period.
48+
var gracePeriod int64 = 1
49+
if os.Getenv("HAC_FORCE_DELETE") == "true" {
50+
// if HAC_FORCE_DELETE is set to true, use a 0 second grace period.
51+
gracePeriod = 0
52+
}
4853
deleteOpts := client.DeleteOptions{GracePeriodSeconds: &gracePeriod}
4954
for _, pod := range podList.Items {
5055
if err := pd.Client.Delete(context.Background(), &pod, &deleteOpts); err != nil {

pkg/system/phase2_creating.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ func (r *Reconciler) SetDesiredCoreApp() error {
445445
r.CoreApp.Spec.ServiceName = r.ServiceMgmt.Name
446446

447447
podSpec := &r.CoreApp.Spec.Template.Spec
448+
// set the termination grace period for noobaa-core pod.
449+
// For now we set it to 1 second. A better approach should be to implement a graceful shutdown for the noobaa-core pod when SIGTERM is received.
450+
terminationGracePeriodSeconds := int64(1)
451+
podSpec.TerminationGracePeriodSeconds = &terminationGracePeriodSeconds
448452
podSpec.ServiceAccountName = "noobaa-core"
449453
coreImageChanged := false
450454

0 commit comments

Comments
 (0)