2016-11-05 17:09:05 -07:00
|
|
|
/*
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2018-08-31 13:39:02 -06:00
|
|
|
|
2016-11-10 10:59:26 -08:00
|
|
|
package osd
|
2016-08-18 14:06:14 -07:00
|
|
|
|
|
|
|
|
import (
|
2016-10-26 00:38:39 +02:00
|
|
|
"github.com/rook/rook/pkg/clusterd"
|
2020-07-01 22:46:39 -06:00
|
|
|
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
|
2023-06-22 09:59:34 +05:30
|
|
|
oposd "github.com/rook/rook/pkg/operator/ceph/cluster/osd"
|
2018-05-18 14:32:20 -07:00
|
|
|
"github.com/rook/rook/pkg/operator/ceph/cluster/osd/config"
|
2018-01-03 08:36:03 -08:00
|
|
|
"github.com/rook/rook/pkg/operator/k8sutil"
|
2016-08-18 14:06:14 -07:00
|
|
|
)
|
|
|
|
|
|
2016-08-31 10:15:04 -07:00
|
|
|
const (
|
2017-12-21 19:41:50 -08:00
|
|
|
unassignedOSDID = -1
|
2016-08-31 10:15:04 -07:00
|
|
|
)
|
|
|
|
|
|
2020-01-13 16:58:51 +01:00
|
|
|
// OsdAgent represents the OSD struct of an agent
|
2017-01-19 13:31:22 -08:00
|
|
|
type OsdAgent struct {
|
2020-07-10 16:40:16 -06:00
|
|
|
clusterInfo *cephclient.ClusterInfo
|
2018-12-04 14:57:22 -07:00
|
|
|
nodeName string
|
|
|
|
|
forceFormat bool
|
|
|
|
|
devices []DesiredDevice
|
|
|
|
|
metadataDevice string
|
|
|
|
|
storeConfig config.StoreConfig
|
|
|
|
|
kv *k8sutil.ConfigMapKVStore
|
2019-07-02 10:42:58 +05:30
|
|
|
pvcBacked bool
|
2023-06-22 09:59:34 +05:30
|
|
|
replaceOSD *oposd.OSDReplaceInfo
|
2018-12-04 14:57:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-01-13 16:58:51 +01:00
|
|
|
// NewAgent is the instantiation of the OSD agent
|
2021-02-22 14:04:56 -07:00
|
|
|
func NewAgent(context *clusterd.Context, devices []DesiredDevice, metadataDevice string, forceFormat bool,
|
2023-06-22 09:59:34 +05:30
|
|
|
storeConfig config.StoreConfig, clusterInfo *cephclient.ClusterInfo, nodeName string, kv *k8sutil.ConfigMapKVStore,
|
|
|
|
|
replaceOSD *oposd.OSDReplaceInfo, pvcBacked bool) *OsdAgent {
|
2017-01-11 20:19:47 -08:00
|
|
|
|
2018-05-01 09:01:29 -04:00
|
|
|
return &OsdAgent{
|
2018-12-04 14:57:22 -07:00
|
|
|
devices: devices,
|
|
|
|
|
metadataDevice: metadataDevice,
|
|
|
|
|
forceFormat: forceFormat,
|
|
|
|
|
storeConfig: storeConfig,
|
2020-07-10 16:40:16 -06:00
|
|
|
clusterInfo: clusterInfo,
|
2018-12-04 14:57:22 -07:00
|
|
|
nodeName: nodeName,
|
|
|
|
|
kv: kv,
|
2019-07-02 10:42:58 +05:30
|
|
|
pvcBacked: pvcBacked,
|
2023-06-22 09:59:34 +05:30
|
|
|
replaceOSD: replaceOSD,
|
2017-07-21 14:35:56 -07:00
|
|
|
}
|
2016-08-18 14:06:14 -07:00
|
|
|
}
|
|
|
|
|
|
2020-01-13 16:58:51 +01:00
|
|
|
func getDeviceLVPath(context *clusterd.Context, deviceName string) string {
|
2020-03-18 11:53:33 -06:00
|
|
|
output, err := context.Executor.ExecuteCommandWithOutput("pvdisplay", "-C", "-o", "lvpath", "--noheadings", deviceName)
|
2019-09-26 20:43:36 +05:30
|
|
|
if err != nil {
|
2020-01-13 16:58:51 +01:00
|
|
|
logger.Warningf("failed to retrieve logical volume path for %q. %v", deviceName, err)
|
|
|
|
|
return ""
|
2019-09-26 20:43:36 +05:30
|
|
|
}
|
|
|
|
|
logger.Debugf("logical volume path for device %q is %q", deviceName, output)
|
2020-01-13 16:58:51 +01:00
|
|
|
return output
|
2017-09-22 17:54:03 -07:00
|
|
|
}
|
2023-06-22 09:59:34 +05:30
|
|
|
|
|
|
|
|
// GetReplaceOSDId returns the OSD ID based on the device name
|
|
|
|
|
func (a *OsdAgent) GetReplaceOSDId(device string) int {
|
|
|
|
|
if device == a.replaceOSD.Path {
|
|
|
|
|
return a.replaceOSD.ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1
|
|
|
|
|
}
|