-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the ability to list RBD images. Signed-off-by: Oded Viner <[email protected]>
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package rbd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"text/tabwriter" | ||
|
||
"github.com/rook/kubectl-rook-ceph/pkg/exec" | ||
"github.com/rook/kubectl-rook-ceph/pkg/k8sutil" | ||
"github.com/rook/kubectl-rook-ceph/pkg/logging" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// List retrieves and displays the Ceph block pools and their associated images. | ||
func List(ctx context.Context, clientsets *k8sutil.Clientsets, clusterNamespace string) { | ||
blockPoolList, err := clientsets.Rook.CephV1().CephBlockPools(clusterNamespace).List(ctx, v1.ListOptions{}) | ||
if err != nil { | ||
logging.Fatal(err) | ||
} | ||
// var blockPoolNames []string | ||
var blockPoolNames map[string]string | ||
blockPoolNames = make(map[string]string) | ||
|
||
for _, blockPool := range blockPoolList.Items { | ||
// blockPoolNames = append(blockPoolNames, blockPool.Name) | ||
blockPoolNames[blockPool.Name] = "--" | ||
} | ||
|
||
cmd := "rbd" | ||
for poolName, _ := range blockPoolNames { | ||
args := []string{"ls", "--pool=" + poolName} | ||
list, err := exec.RunCommandInOperatorPod(ctx, clientsets, cmd, args, clusterNamespace, clusterNamespace, true) | ||
if err == nil && len(list) > 0 { | ||
blockPoolNames[poolName] = strings.ReplaceAll(list, "\n", "") | ||
} | ||
} | ||
PrintBlockPoolNames(blockPoolNames) | ||
} | ||
|
||
// PrintBlockPoolNames takes a map of block pool names to image names and prints them in a tabular format. | ||
func PrintBlockPoolNames(blockPoolNames map[string]string) { | ||
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) | ||
|
||
// Print header with column names | ||
fmt.Fprintln(writer, "poolName\timageName\t") | ||
fmt.Fprintln(writer, "--------\t---------\t") | ||
|
||
// Print each row from the map | ||
for poolName, imageName := range blockPoolNames { | ||
fmt.Fprintf(writer, "%s\t%s\t\n", poolName, imageName) | ||
} | ||
|
||
// Flush the writer | ||
writer.Flush() | ||
} |