Files
my-rook-config/pkg/operator/ceph/config/config.go
T
Sébastien HanandRohan CJ 90cd8224f4 ceph: add ceph-crash controller
A new controller to bootstrap ceph-crash pod on Ceph nodes running Ceph
pods only.

This implementation is unfortunately a mix of 'hacks' to make the daemon
working correclty. The ceph-crash script faced different issues:

* it's not a daemon
* it does not have any key in cephx
* it runs ceph commands under the hood which need an admin key and a
ceph.conf

On upstream Ceph, ceph-crash needs to grow better, once that happens we
will improve our implementation.

This also enhances osd provisionConfig struct with DataPathMap

Pod volumes and volume mount needs DataPathMap to perform the right
actions on log and crash dir. Exposing DataPathMap makes that possible.

Obviously, this is exposing ceph crash reports on the host as
well as pushing them into the mgr.
Basically, if a daemon fails, it'll put its core dump into
/var/lib/ceph/crash, bindmounting this dir on the host, ensures that the
crashes don't get lost when the pod dies.

Example:

```
[leseb@tarox~/go/src/github.com/rook/rook][rgw-liveprobe !] kubectl -n rook-ceph exec -ti rook-ceph-crashcollector-minikube-574858b99c-zvg4z bash
bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_MESSAGES: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_NUMERIC: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8): No such file or directory
[root@rook-ceph-crashcollector-minikube-574858b99c-zvg4z /]# ceph crash ls

[root@rook-ceph-osd-2-7644f99695-cljzh /]# pidof ceph-osd
13258 5415 5397
[root@rook-ceph-osd-2-7644f99695-cljzh /]# kill -SIGABRT 13258
[root@rook-ceph-osd-2-7644f99695-cljzh /]# ls /var/lib/ceph/crash/
2019-11-12_12:56:51.404109Z_39f060e1-776d-4605-8f28-85c97e53de96     posted

... wait maximum 10 min (ceph-crash scraps every 10 minutes)
... the container will exit

[root@rook-ceph-osd-2-7644f99695-cljzh /]# exit
[leseb@tarox~/go/src/github.com/rook/rook][rgw-liveprobe !]
[leseb@tarox~/go/src/github.com/rook/rook][rgw-liveprobe !] kubectl -n rook-ceph exec -ti rook-ceph-crashcollector-minikube-574858b99c-zvg4z bash
bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_MESSAGES: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_NUMERIC: cannot change locale (en_US.UTF-8): No such file or directory
bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8): No such file or directory
[root@rook-ceph-crashcollector-minikube-574858b99c-zvg4z /]#
[root@rook-ceph-crashcollector-minikube-574858b99c-zvg4z /]#
[root@rook-ceph-crashcollector-minikube-574858b99c-zvg4z /]# ceph crash ls
2019-11-12_12:56:51.404109Z_39f060e1-776d-4605-8f28-85c97e53de96 osd.1
[root@rook-ceph-crashcollector-minikube-574858b99c-zvg4z /]# ls /var/lib/ceph/crash/
posted
[root@rook-ceph-crashcollector-minikube-574858b99c-zvg4z /]# ls /var/lib/ceph/crash/posted/
2019-11-12_12:56:51.404109Z_39f060e1-776d-4605-8f28-85c97e53de96
[root@rook-ceph-crashcollector-minikube-574858b99c-zvg4z /]# tail /var/lib/ceph/crash/posted/2019-11-12_12\:56\:51.404109Z_39f060e1-776d-4605-8f28-85c97e53de96/log
   1/ 5 mgr
   1/ 5 mgrc
   1/ 5 dpdk
   1/ 5 eventtrace
  -2/-2 (syslog threshold)
  -1/-1 (stderr threshold)
  max_recent     10000
  max_new         1000
  log_file /var/lib/ceph/crash/2019-11-12_12:56:51.404109Z_39f060e1-776d-4605-8f28-85c97e53de96/log
--- end dump of recent events ---
```

Signed-off-by: Sébastien Han <seb@redhat.com>
Co-authored-by: Rohan CJ <rohantmp@gmail.com>
2019-11-12 16:06:07 +01:00

123 lines
4.2 KiB
Go

/*
Copyright 2019 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package config provides methods for generating the Ceph config for a Ceph cluster and for
// producing a "ceph.conf" compatible file from the config as well as Ceph command line-compatible
// flags.
package config
import (
"fmt"
"path"
"strings"
"github.com/coreos/pkg/capnslog"
"github.com/rook/rook/pkg/clusterd"
cephconfig "github.com/rook/rook/pkg/daemon/ceph/config"
)
var logger = capnslog.NewPackageLogger("github.com/rook/rook", "op-config")
// DaemonType defines the type of a daemon. e.g., mon, mgr, osd, mds, rgw
type DaemonType string
const (
// MonType defines the mon DaemonType
MonType DaemonType = "mon"
// MgrType defines the mgr DaemonType
MgrType DaemonType = "mgr"
// OsdType defines the osd DaemonType
OsdType DaemonType = "osd"
// MdsType defines the mds DaemonType
MdsType DaemonType = "mds"
// RgwType defines the rgw DaemonType
RgwType DaemonType = "rgw"
// RbdMirrorType defines the rbd-mirror DaemonType
RbdMirrorType DaemonType = "rbd-mirror"
// CrashType defines the crash collector DaemonType
CrashType DaemonType = "crashcollector"
// CephUser is the Linux Ceph username
CephUser = "ceph"
// CephGroup is the Linux Ceph groupname
CephGroup = "ceph"
)
var (
// VarLibCephDir is simply "/var/lib/ceph". It is made overwriteable only for unit tests where it
// may be needed to send data intended for /var/lib/ceph to a temporary test dir.
VarLibCephDir = "/var/lib/ceph"
// EtcCephDir is simply "/etc/ceph". It is made overwriteable only for unit tests where it
// may be needed to send data intended for /etc/ceph to a temporary test dir.
EtcCephDir = "/etc/ceph"
// VarLogCephDir defines Ceph logging directory. It is made overwriteable only for unit tests where it
// may be needed to send data intended for /var/log/ceph to a temporary test dir.
VarLogCephDir = "/var/log/ceph"
// VarLibCephCrashDir defines Ceph crash reports directory.
VarLibCephCrashDir = path.Join(VarLibCephDir, "crash")
)
// normalizeKey converts a key in any format to a key with underscores.
//
// The internal representation of Ceph config keys uses underscores only, where Ceph supports both
// spaces, underscores, and hyphens. This is so that Rook can properly match and override keys even
// when they are specified as "some config key" in one section, "some_config_key" in another
// section, and "some-config-key" in yet another section.
func normalizeKey(key string) string {
return strings.Replace(strings.Replace(key, " ", "_", -1), "-", "_", -1)
}
// NewFlag returns the key-value pair in the format of a Ceph command line-compatible flag.
func NewFlag(key, value string) string {
// A flag is a normalized key with underscores replaced by dashes.
// "debug default" ~normalize~> "debug_default" ~to~flag~> "debug-default"
n := normalizeKey(key)
f := strings.Replace(n, "_", "-", -1)
return fmt.Sprintf("--%s=%s", f, value)
}
// SetDefaultConfigs sets Rook's desired default configs in the centralized monitor database. This
// cannot be called before at least one monitor is established.
func SetDefaultConfigs(
context *clusterd.Context,
namespace string,
clusterInfo *cephconfig.ClusterInfo,
) error {
// ceph.conf is never used. All configurations are made in the centralized mon config database,
// or they are specified on the commandline when daemons are called.
monStore := GetMonStore(context, namespace)
if err := monStore.SetAll(DefaultCentralizedConfigs(clusterInfo.CephVersion)...); err != nil {
return fmt.Errorf("failed to apply default Ceph configurations. %+v", err)
}
if err := monStore.SetAll(DefaultLegacyConfigs()...); err != nil {
return fmt.Errorf("failed to apply legacy config overrides. %+v", err)
}
return nil
}