Files
my-rook-config/pkg/daemon/ceph/mds/init.go
T
Blaine Gardner ce803fbf9d Ceph mds/file: Set up config in init container
Progress toward issue #2003.
Includes design from design doc PR #1578

Use init containers to create configuration for Ceph mgrs. There is only
one init container in this design. The init container calls the Rook
binary to create Ceph config files which are then shared with the mds
daemon main container.

Once this init is run, the main mds daemon is run. Leaving room to use
the Ceph-versioned image in the future, call `ceph-mds --foreground ...`
to run the Ceph mds.

The refactor to using an init container also necessitated refactoring
the mdses replicaset implementation to a deployment-per-pod
implementation due to a chicken-egg problem. With a single container (in
the before times) the Rook binary was able to call the ceph-mds daemon
with an id generated from the pod name. Since the pod name is not known
before runtime, and the id is one of the few params that must be
specified to Ceph daemons on run, it is necessary to know the id
beforehand; thus the move to a deployment architecture following the
likes of the mon and mgr daemons.

Signed-off-by: Blaine Gardner <blaine.gardner@suse.com>
2018-10-05 19:01:12 -06:00

109 lines
3.2 KiB
Go

/*
Copyright 2016 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 mds provides methods for setting up Ceph configuration for mds daemons.
// It also provides methods for creating/deleting/managing Ceph filesystems served by the mds.
package mds
import (
"fmt"
"path"
"strconv"
"github.com/coreos/pkg/capnslog"
"github.com/rook/rook/pkg/clusterd"
cephconfig "github.com/rook/rook/pkg/daemon/ceph/config"
"github.com/rook/rook/pkg/util"
)
const (
// InitCommand is the `rook ceph` subcommand which will perform mds initialization
InitCommand = "mds-init"
keyringTemplate = `
[mds.%s]
key = %s
caps mon = "allow profile mds"
caps osd = "allow *"
caps mds = "allow"
`
)
var logger = capnslog.NewPackageLogger("github.com/rook/rook", "cephmds")
// Config contains the necessary parameters Rook needs to know to set up a mds for a Ceph cluster.
type Config struct {
FilesystemID string
Name string
Keyring string
ActiveStandby bool
ClusterInfo *cephconfig.ClusterInfo
}
// Initialize generates configuration files for a Ceph mds
func Initialize(context *clusterd.Context, config *Config) error {
logger.Infof("Creating config for mds %s [filesystem ID: %s] [active standby?: %+v]",
config.Name, config.FilesystemID, config.ActiveStandby)
err := generateConfigFiles(context, config)
if err != nil {
return fmt.Errorf("failed to generate mds config files: %+v", err)
}
util.WriteFileToLog(logger, cephconfig.DefaultConfigFilePath())
return err
}
func generateConfigFiles(context *clusterd.Context, config *Config) error {
// write the latest config to the config dir
if err := cephconfig.GenerateAdminConnectionConfig(context, config.ClusterInfo); err != nil {
return fmt.Errorf("failed to write connection config: %+v", err)
}
settings := map[string]string{
"mds_standby_for_fscid": config.FilesystemID,
"mds_standby_replay": strconv.FormatBool(config.ActiveStandby),
}
keyringPath := getMdsKeyringPath(context.ConfigDir, config.Name)
_, err := cephconfig.GenerateConfigFile(context, config.ClusterInfo,
getMdsConfDir(context.ConfigDir, config.Name), fmt.Sprintf("mds.%s", config.Name),
keyringPath, nil, settings)
if err != nil {
return fmt.Errorf("failed to create mds config file: %+v", err)
}
keyringEval := func(key string) string {
r := fmt.Sprintf(keyringTemplate, config.Name, key)
return r
}
err = cephconfig.WriteKeyring(keyringPath, config.Keyring, keyringEval)
if err != nil {
return fmt.Errorf("failed to create mds keyring: %+v", err)
}
return nil
}
func getMdsConfDir(dir, name string) string {
return path.Join(dir, fmt.Sprintf("mds-%s", name))
}
func getMdsKeyringPath(dir, name string) string {
return path.Join(getMdsConfDir(dir, name), "keyring")
}