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>
165 lines
5.2 KiB
Go
165 lines
5.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 crash
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"strings"
|
|
|
|
"github.com/rook/rook/pkg/operator/k8sutil"
|
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"sigs.k8s.io/controller-runtime/pkg/controller"
|
|
"sigs.k8s.io/controller-runtime/pkg/event"
|
|
"sigs.k8s.io/controller-runtime/pkg/handler"
|
|
"sigs.k8s.io/controller-runtime/pkg/manager"
|
|
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
|
"sigs.k8s.io/controller-runtime/pkg/source"
|
|
)
|
|
|
|
const (
|
|
controllerName = "ceph-crashcollector-controller"
|
|
// AppName is the value to the "app" label for the ceph-crash pods
|
|
AppName = "rook-ceph-crashcollector"
|
|
// NodeNameLabel is a node name label
|
|
NodeNameLabel = "node_name"
|
|
)
|
|
|
|
// Add adds a new Controller based on nodedrain.ReconcileNode and registers the relevant watches and handlers
|
|
func Add(mgr manager.Manager) error {
|
|
reconcileNode := &ReconcileNode{
|
|
client: mgr.GetClient(),
|
|
scheme: mgr.GetScheme(),
|
|
}
|
|
reconciler := reconcile.Reconciler(reconcileNode)
|
|
|
|
// Create a new controller
|
|
c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: reconciler})
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create a new %q. %+v", controllerName, err)
|
|
}
|
|
|
|
// Watch for changes to the nodes
|
|
specChangePredicate := predicate.Funcs{
|
|
UpdateFunc: func(e event.UpdateEvent) bool {
|
|
nodeOld := e.ObjectOld.DeepCopyObject().(*corev1.Node)
|
|
nodeNew := e.ObjectNew.DeepCopyObject().(*corev1.Node)
|
|
return !reflect.DeepEqual(nodeOld.Spec, nodeNew.Spec)
|
|
},
|
|
}
|
|
logger.Debugf("watch for changes to the nodes")
|
|
err = c.Watch(&source.Kind{Type: &corev1.Node{}}, &handler.EnqueueRequestForObject{}, specChangePredicate)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to watch for node changes. %+v", err)
|
|
}
|
|
|
|
// Watch for changes to the ceph-crash deployments
|
|
logger.Debugf("watch for changes to the ceph-crash deployments")
|
|
err = c.Watch(
|
|
&source.Kind{Type: &appsv1.Deployment{}},
|
|
&handler.EnqueueRequestsFromMapFunc{
|
|
ToRequests: handler.ToRequestsFunc(func(obj handler.MapObject) []reconcile.Request {
|
|
deployment, ok := obj.Object.(*appsv1.Deployment)
|
|
if !ok {
|
|
return []reconcile.Request{}
|
|
}
|
|
labels := deployment.GetLabels()
|
|
appName, ok := labels[k8sutil.AppAttr]
|
|
if !ok || appName != AppName {
|
|
return []reconcile.Request{}
|
|
}
|
|
nodeName, ok := deployment.Spec.Template.ObjectMeta.Labels[NodeNameLabel]
|
|
if !ok {
|
|
return []reconcile.Request{}
|
|
}
|
|
req := reconcile.Request{NamespacedName: types.NamespacedName{Name: nodeName}}
|
|
return []reconcile.Request{req}
|
|
}),
|
|
},
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to watch for changes on the ceph-crash deployment. %+v", err)
|
|
}
|
|
|
|
// Watch for changes to the ceph pod nodename and enqueue their nodes
|
|
logger.Debugf("watch for changes to the ceph pod nodename and enqueue their nodes")
|
|
err = c.Watch(
|
|
&source.Kind{Type: &corev1.Pod{}},
|
|
&handler.EnqueueRequestsFromMapFunc{
|
|
ToRequests: handler.ToRequestsFunc(func(obj handler.MapObject) []reconcile.Request {
|
|
pod, ok := obj.Object.(*corev1.Pod)
|
|
if !ok {
|
|
return []reconcile.Request{}
|
|
}
|
|
nodeName := pod.Spec.NodeName
|
|
if nodeName == "" {
|
|
return []reconcile.Request{}
|
|
}
|
|
if isCephPod(pod.Labels, pod.Name) {
|
|
req := reconcile.Request{NamespacedName: types.NamespacedName{Name: nodeName}}
|
|
return []reconcile.Request{req}
|
|
}
|
|
logger.Debugf("%q is not a ceph pod", pod.Name)
|
|
return []reconcile.Request{}
|
|
}),
|
|
},
|
|
// only enqueue the update event if the pod moved nodes
|
|
predicate.Funcs{
|
|
UpdateFunc: func(event event.UpdateEvent) bool {
|
|
oldPod, ok := event.ObjectOld.(*corev1.Pod)
|
|
if !ok {
|
|
return false
|
|
}
|
|
newPod, ok := event.ObjectNew.(*corev1.Pod)
|
|
if !ok {
|
|
return false
|
|
}
|
|
// only enqueue if the nodename has changed
|
|
if oldPod.Spec.NodeName == newPod.Spec.NodeName {
|
|
return false
|
|
}
|
|
return true
|
|
},
|
|
},
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to watch for changes on the ceph pod nodename and enqueue their nodes. %+v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func isCephPod(labels map[string]string, podName string) bool {
|
|
_, ok := labels["rook_cluster"]
|
|
// canary pods for monitors might stick around during startup
|
|
// at that time, the initial monitors haven't been deployed yet.
|
|
// If we don't invalidate canary pods,
|
|
// the crash collector pod will start and environment variable like 'ROOK_CEPH_MON_HOST'
|
|
// will be empty since the monitors don't exist yet
|
|
isCanaryPod := strings.Contains(podName, "-canary-")
|
|
if ok && !isCanaryPod {
|
|
logger.Debugf("%q is a ceph pod!", podName)
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|