From ec8e825ecbd7bbf5ec1ccc05a9c11570195b39f6 Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Wed, 8 Dec 2021 21:15:04 +0200 Subject: [PATCH] fix: Fix read termination timeout for all namespaces mode. (#1235) * fix: Fix read termination timeout for all namespaces mode. Signed-off-by: Oleksandr Andriienko --- .../checlusterbackup/backup_data_collector.go | 2 +- main.go | 2 +- pkg/util/namespace_provider.go | 40 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 pkg/util/namespace_provider.go diff --git a/controllers/checlusterbackup/backup_data_collector.go b/controllers/checlusterbackup/backup_data_collector.go index 811b6c22f..3fe1199bd 100644 --- a/controllers/checlusterbackup/backup_data_collector.go +++ b/controllers/checlusterbackup/backup_data_collector.go @@ -178,7 +178,7 @@ func backupDatabases(bctx *BackupContext, destDir string) (bool, error) { return false, err } - // Get and seve all dumps from the Postgres container + // Get and save all dumps from the Postgres container for _, dbName := range databasesToBackup { execReason := fmt.Sprintf("getting database %s dump", dbName) dbDump, err := k8sClient.DoExecIntoPod(bctx.namespace, postgresPodName, getMoveDatabaseDumpScript(dbName), execReason) diff --git a/main.go b/main.go index 57979b86b..e9ebb34d3 100644 --- a/main.go +++ b/main.go @@ -275,7 +275,7 @@ func main() { os.Exit(1) } - period := signal.GetTerminationGracePeriodSeconds(mgr.GetAPIReader(), watchNamespace) + period := signal.GetTerminationGracePeriodSeconds(mgr.GetAPIReader(), util.GetCheOperatorNamespace()) sigHandler := signal.SetupSignalHandler(period) // we install the devworkspace CheCluster reconciler even if dw is not supported so that it diff --git a/pkg/util/namespace_provider.go b/pkg/util/namespace_provider.go new file mode 100644 index 000000000..40b03fdc7 --- /dev/null +++ b/pkg/util/namespace_provider.go @@ -0,0 +1,40 @@ +// +// Copyright (c) 2012-2021 Red Hat, Inc. +// This program and the accompanying materials are made +// available under the terms of the Eclipse Public License 2.0 +// which is available at https://www.eclipse.org/legal/epl-2.0/ +// +// SPDX-License-Identifier: EPL-2.0 +// +// Contributors: +// Red Hat, Inc. - initial API and implementation +// +package util + +import ( + "io/ioutil" + + "github.com/sirupsen/logrus" +) + +const ( + namespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace" +) + +var operator_namespace string + +func readNamespace() string { + nsBytes, err := ioutil.ReadFile(namespaceFile) + if err != nil { + logrus.Fatal("Failed to get operator namespace", err) + } + return string(nsBytes) +} + +// GetCheOperatorNamespace returns namespace for current Eclipse Che operator. +func GetCheOperatorNamespace() string { + if operator_namespace == "" && !IsTestMode() { + operator_namespace = readNamespace() + } + return operator_namespace +}