Files
my-rook-config/pkg/operator/ceph/cluster/osd/config/config.go
T
subhamkrai 1e9bb8e6e2 ceph: handle golangci-lint linter deadcode
this commit will enable one more linter `deadcode`
in golangci-lint .

Signed-off-by: subhamkrai <subhamkumarrai03@gmail.com>
2020-09-18 16:53:49 +05:30

124 lines
3.4 KiB
Go

/*
Copyright 2018 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 for OSD config managed by the operator
package config
import (
"strconv"
"github.com/rook/rook/pkg/operator/k8sutil"
)
const (
OSDFSStoreNameFmt = "rook-ceph-osd-%d-fs-backup"
configStoreNameFmt = "rook-ceph-osd-%s-config"
)
func GetConfigStoreName(nodeName string) string {
return k8sutil.TruncateNodeName(configStoreNameFmt, nodeName)
}
const (
StoreTypeKey = "storeType"
WalSizeMBKey = "walSizeMB"
DatabaseSizeMBKey = "databaseSizeMB"
JournalSizeMBKey = "journalSizeMB"
OSDsPerDeviceKey = "osdsPerDevice"
EncryptedDeviceKey = "encryptedDevice"
MetadataDeviceKey = "metadataDevice"
DeviceClassKey = "deviceClass"
)
// StoreConfig represents the configuration of an OSD on a device.
type StoreConfig struct {
StoreType string `json:"storeType,omitempty"`
WalSizeMB int `json:"walSizeMB,omitempty"`
DatabaseSizeMB int `json:"databaseSizeMB,omitempty"`
OSDsPerDevice int `json:"osdsPerDevice,omitempty"`
EncryptedDevice bool `json:"encryptedDevice,omitempty"`
MetadataDevice string `json:"metadataDevice,omitempty"`
DeviceClass string `json:"deviceClass,omitempty"`
}
// NewStoreConfig returns a StoreConfig with proper defaults set.
func NewStoreConfig() StoreConfig {
return StoreConfig{
OSDsPerDevice: 1,
}
}
// ToStoreConfig converts a config string-string map to a StoreConfig.
func ToStoreConfig(config map[string]string) StoreConfig {
storeConfig := NewStoreConfig()
for k, v := range config {
switch k {
case StoreTypeKey:
storeConfig.StoreType = v
case WalSizeMBKey:
storeConfig.WalSizeMB = convertToIntIgnoreErr(v)
case DatabaseSizeMBKey:
storeConfig.DatabaseSizeMB = convertToIntIgnoreErr(v)
case OSDsPerDeviceKey:
i := convertToIntIgnoreErr(v)
if i > 0 { // only allow values 1 or more to be set
storeConfig.OSDsPerDevice = i
}
case EncryptedDeviceKey:
storeConfig.EncryptedDevice = (v == "true")
case MetadataDeviceKey:
storeConfig.MetadataDevice = v
case DeviceClassKey:
storeConfig.DeviceClass = v
}
}
return storeConfig
}
func MetadataDevice(config map[string]string) string {
for k, v := range config {
switch k {
case MetadataDeviceKey:
return v
}
}
return ""
}
func convertToIntIgnoreErr(raw string) int {
val, err := strconv.Atoi(raw)
if err != nil {
val = 0
}
return val
}
// A DriveGroupBlob is a simple JSON blob defining a Ceph Drive Group. Drive Group blobs are passed
// to ceph-volume for node disk configuration.
type DriveGroupBlob string
// DriveGroupBlobs is a mapping from Ceph Drive Group names to JSON blobs of Drive Group specs.
type DriveGroupBlobs map[string]string
// ConfiguredDevice is a device with a corresponding configuration.
type ConfiguredDevice struct {
ID string `json:"id"`
StoreConfig StoreConfig `json:"storeConfig"`
}