From 171cb589e217188ded0e42f968e894579c917224 Mon Sep 17 00:00:00 2001 From: parth-gr Date: Tue, 2 Sep 2025 18:57:53 +0530 Subject: [PATCH] osd: remove the osd bootstrap keyring when the osd is created there is no need for osd bootstrap keyring, so remove the keyring and keyring file, New keyring will be created if new osd need to be provisoned Signed-off-by: parth-gr (cherry picked from commit 794a232835149a0d9c02fb67a38b787104cd1ce2) --- pkg/daemon/ceph/client/keyring.go | 10 -------- pkg/daemon/ceph/osd/volume_test.go | 29 ++++++++++++++++++----- pkg/operator/ceph/cluster/osd/osd.go | 12 ++++++++++ pkg/operator/ceph/cluster/osd/osd_test.go | 7 +++++- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/pkg/daemon/ceph/client/keyring.go b/pkg/daemon/ceph/client/keyring.go index 2a7cada8f..04e4713ae 100644 --- a/pkg/daemon/ceph/client/keyring.go +++ b/pkg/daemon/ceph/client/keyring.go @@ -56,16 +56,6 @@ func CephKeyring(cred CephCred) string { // CreateKeyring creates a keyring for access to the cluster with the desired set of privileges // and writes it to disk at the keyring path func CreateKeyring(context *clusterd.Context, clusterInfo *ClusterInfo, username, keyringPath string, access []string, generateContents func(string) string) error { - _, err := os.Stat(keyringPath) - if err == nil { - // no error, the file exists, bail out with no error - logger.Debugf("keyring already exists at %s", keyringPath) - return nil - } else if !os.IsNotExist(err) { - // some other error besides "does not exist", bail out with error - return errors.Wrapf(err, "failed to stat %s", keyringPath) - } - // get-or-create-key for the user account key, err := AuthGetOrCreateKey(context, clusterInfo, username, access) if err != nil { diff --git a/pkg/daemon/ceph/osd/volume_test.go b/pkg/daemon/ceph/osd/volume_test.go index 9b1559a8c..5b29d0b6a 100644 --- a/pkg/daemon/ceph/osd/volume_test.go +++ b/pkg/daemon/ceph/osd/volume_test.go @@ -576,11 +576,21 @@ func TestConfigureCVDevices(t *testing.T) { } return "", errors.Errorf("unknown command %s %s", command, args) } - - context := &clusterd.Context{Executor: executor, ConfigDir: cephConfigDir} - clusterInfo := &cephclient.ClusterInfo{ - FSID: clusterFSID, + executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) { + logger.Infof("[MockExecuteCommandWithOutput] %s %v", command, args) + if args[0] == "auth" && args[1] == "get-or-create-key" { + return "{\"key\":\"mysecurekey\"}", nil + } + if args[1] == "ceph-volume" && args[2] == "--log-path" && args[3] == "/tmp/ceph-log" { + return `{}`, nil + } + return "", errors.Errorf("unknown command %s %s", command, args) } + clusterInfo := &cephclient.ClusterInfo{ + FSID: clusterFSID, + Context: context.TODO(), + } + context := &clusterd.Context{Executor: executor, ConfigDir: cephConfigDir} agent := &OsdAgent{clusterInfo: clusterInfo, nodeName: nodeName, storeConfig: config.StoreConfig{DeviceClass: "myclass", StoreType: "bluestore"}} devices := &DeviceOsdMapping{ Entries: map[string]*DeviceOsdIDEntry{ @@ -611,6 +621,12 @@ func TestConfigureCVDevices(t *testing.T) { if command == "sgdisk" { return "Disk identifier (GUID): 18484D7E-5287-4CE9-AC73-D02FB69055CE", nil } + if args[0] == "auth" && args[1] == "get-or-create-key" { + return "{\"key\":\"mysecurekey\"}", nil + } + if args[1] == "ceph-volume" && args[2] == "--log-path" && args[3] == "/tmp/ceph-log" { + return `{}`, nil + } return "", errors.Errorf("unknown command %s %s", command, args) } deviceClassSet := false @@ -624,10 +640,11 @@ func TestConfigureCVDevices(t *testing.T) { return "", errors.Errorf("unknown command %s %s", command, args) } - context := &clusterd.Context{Executor: executor, ConfigDir: cephConfigDir} clusterInfo := &cephclient.ClusterInfo{ - FSID: clusterFSID, + FSID: clusterFSID, + Context: context.TODO(), } + context := &clusterd.Context{Executor: executor, ConfigDir: cephConfigDir} agent := &OsdAgent{clusterInfo: clusterInfo, nodeName: nodeName, storeConfig: config.StoreConfig{DeviceClass: "myclass", StoreType: "bluestore"}} devices := &DeviceOsdMapping{ Entries: map[string]*DeviceOsdIDEntry{ diff --git a/pkg/operator/ceph/cluster/osd/osd.go b/pkg/operator/ceph/cluster/osd/osd.go index cb9d104b2..82c480972 100644 --- a/pkg/operator/ceph/cluster/osd/osd.go +++ b/pkg/operator/ceph/cluster/osd/osd.go @@ -350,10 +350,22 @@ func (c *Cluster) Start() error { return errors.Wrapf(err, "failed to update ceph storage status") } + // remove the osdBootstrapKey as the osds are running + c.deleteOsdBootstrapKeyring() + logger.Infof("finished running OSDs in namespace %q", namespace) return nil } +func (c *Cluster) deleteOsdBootstrapKeyring() { + err := cephclient.AuthDelete(c.context, c.clusterInfo, "client.bootstrap-osd") + if err != nil { + logger.Debugf("failed to delete client.bootstrap-osd bootstrap key in the namespace %q. Error: %v", c.clusterInfo.Namespace, err) + } else { + logger.Debugf("successfully deleted client.bootstrap-osd bootstrap key in the namespace %q", c.clusterInfo.Namespace) + } +} + func (c *Cluster) startOSDMigration() (*migrationConfig, error) { if !c.isMigrationRequested() { logger.Debug("no OSD migration is requested") diff --git a/pkg/operator/ceph/cluster/osd/osd_test.go b/pkg/operator/ceph/cluster/osd/osd_test.go index 8518b0302..e3b082bd6 100644 --- a/pkg/operator/ceph/cluster/osd/osd_test.go +++ b/pkg/operator/ceph/cluster/osd/osd_test.go @@ -18,6 +18,7 @@ package osd import ( "context" + "strings" "testing" "github.com/pkg/errors" @@ -343,7 +344,11 @@ func TestAddRemoveNode(t *testing.T) { return `{}`, nil } if args[0] == "auth" && args[1] == "del" { - assert.Equal(t, "osd.1", args[2]) + if strings.HasPrefix(args[2], "osd.") { + assert.Equal(t, "osd.1", args[2]) + } else if strings.HasPrefix(args[2], "client.") { + assert.Equal(t, "client.bootstrap-osd", args[2]) + } return "", nil } return "", errors.Errorf("unexpected ceph command %q", args)