Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vineeth Pothulapati <vineethpothulapati@outlook.com>
- Loading branch information
1 parent
4cb0454
commit dc0a5ca
Showing
6 changed files
with
376 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// volumeCmd represents the volume command | ||
var volumeCmd = &cobra.Command{ | ||
Use: "volume", | ||
Short: "Subcommand for Volume operations", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(volumeCmd) | ||
} |
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,83 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/timescale/tobs/cli/pkg/k8s" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// volumeExpandCmd represents the volume expand command | ||
var volumeExpandCmd = &cobra.Command{ | ||
Use: "expand", | ||
Short: "Expand PVC's", | ||
Args: cobra.ExactArgs(0), | ||
RunE: volumeExpand, | ||
} | ||
|
||
func init() { | ||
volumeCmd.AddCommand(volumeExpandCmd) | ||
volumeExpandCmd.Flags().StringP("timescaleDB-wal", "w", "", "Expand volume of timescaleDB wal") | ||
volumeExpandCmd.Flags().StringP("timescaleDB-storage", "s", "", "Expand volume of timescaleDB storage") | ||
volumeExpandCmd.Flags().StringP("prometheus-storage", "p", "", "Expand volume of prometheus storage") | ||
} | ||
|
||
func volumeExpand(cmd *cobra.Command, args []string) error { | ||
tsDBWal, err := cmd.Flags().GetString("timescaleDB-wal") | ||
if err != nil { | ||
return fmt.Errorf("could not get timescaleDB-wal flag %w", err) | ||
} | ||
|
||
tsDBStorage, err := cmd.Flags().GetString("timescaleDB-storage") | ||
if err != nil { | ||
return fmt.Errorf("could not get timescaleDB-storage flag %w", err) | ||
} | ||
|
||
promStorage, err := cmd.Flags().GetString("prometheus-storage") | ||
if err != nil { | ||
return fmt.Errorf("could not get prometheus-storage flag %w", err) | ||
} | ||
|
||
if tsDBStorage != "" { | ||
pvcPrefix := "storage-volume" | ||
results, err := k8s.ExpandTimescaleDBPVC(namespace, tsDBStorage, pvcPrefix , map[string]string{"app": name+"-timescaledb"}) | ||
if err != nil { | ||
return fmt.Errorf("could not expand timescaleDB-storage: %w", err) | ||
} | ||
expandSuccessPrint(pvcPrefix, results) | ||
} | ||
|
||
if tsDBWal != "" { | ||
pvcPrefix := "wal-volume" | ||
results, err := k8s.ExpandTimescaleDBPVC(namespace, tsDBWal, "wal-volume", map[string]string{"app": name+"-timescaledb"}) | ||
if err != nil { | ||
return fmt.Errorf("could not expand timescaleDB-wal: %w", err) | ||
} | ||
|
||
expandSuccessPrint(pvcPrefix, results) | ||
} | ||
|
||
if promStorage != "" { | ||
pvcPrefix := name+"-prometheus-server" | ||
err := k8s.ExpandPVC(namespace, pvcPrefix, promStorage) | ||
if err != nil { | ||
return fmt.Errorf("could not expand prometheus-storage: %w", err) | ||
} | ||
|
||
expandSuccessPrint(pvcPrefix, map[string]string{pvcPrefix: promStorage}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func expandSuccessPrint(pvcPrefix string, results map[string]string) { | ||
if len(results) == 0 { | ||
return | ||
} | ||
|
||
fmt.Printf("PVC's of %s\n", pvcPrefix) | ||
for pvcName, value := range results { | ||
fmt.Printf("Successfully expanded PVC: %s to %s\n", pvcName, value) | ||
} | ||
fmt.Println() | ||
} |
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,80 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/timescale/tobs/cli/pkg/k8s" | ||
) | ||
|
||
// volumeGetCmd represents the volume expand command | ||
var volumeGetCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Get PVC's volume", | ||
Args: cobra.ExactArgs(0), | ||
RunE: volumeGet, | ||
} | ||
|
||
func init() { | ||
volumeCmd.AddCommand(volumeGetCmd) | ||
volumeGetCmd.Flags().BoolP("timescaleDB-wal", "w", false, "Get volume of timescaleDB wal") | ||
volumeGetCmd.Flags().BoolP("timescaleDB-storage", "s", false, "Get volume of timescaleDB storage") | ||
volumeGetCmd.Flags().BoolP("prometheus-storage", "p", false, "Get volume of prometheus storage") | ||
} | ||
|
||
func volumeGet(cmd *cobra.Command, args []string) error { | ||
tsDBWal, err := cmd.Flags().GetBool("timescaleDB-wal") | ||
if err != nil { | ||
return fmt.Errorf("could not get timescaleDB-wal flag %w", err) | ||
} | ||
|
||
tsDBStorage, err := cmd.Flags().GetBool("timescaleDB-storage") | ||
if err != nil { | ||
return fmt.Errorf("could not get timescaleDB-storage flag %w", err) | ||
} | ||
|
||
promStorage, err := cmd.Flags().GetBool("prometheus-storage") | ||
if err != nil { | ||
return fmt.Errorf("could not get prometheus-storage flag %w", err) | ||
} | ||
|
||
if tsDBStorage { | ||
pvcPrefix := "storage-volume" | ||
results, err := k8s.GetPVCSizes(namespace, pvcPrefix, map[string]string{"app": name+"-timescaledb"}) | ||
if err != nil { | ||
return fmt.Errorf("could not get timescaleDB-storage: %w", err) | ||
} | ||
volumeGetPrint(pvcPrefix, results) | ||
} | ||
|
||
if tsDBWal { | ||
pvcPrefix := "wal-volume" | ||
results, err := k8s.GetPVCSizes(namespace, pvcPrefix, map[string]string{"app": name+"-timescaledb"}) | ||
if err != nil { | ||
return fmt.Errorf("could not get timescaleDB-wal: %w", err) | ||
} | ||
volumeGetPrint(pvcPrefix, results) | ||
} | ||
|
||
if promStorage { | ||
pvcPrefix := name+"-prometheus-server" | ||
results, err := k8s.GetPVCSizes(namespace, pvcPrefix, nil) | ||
if err != nil { | ||
return fmt.Errorf("could not get prometheus-storage: %w", err) | ||
} | ||
volumeGetPrint(pvcPrefix, results) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func volumeGetPrint(pvcPrefix string, results map[string]string) { | ||
if len(results) == 0 { | ||
return | ||
} | ||
|
||
fmt.Printf("PVC's of %s\n", pvcPrefix) | ||
for pvcName, value := range results { | ||
fmt.Printf("Existing size of PVC: %s is %s\n", pvcName, value) | ||
} | ||
fmt.Println() | ||
} |
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,80 @@ | ||
package tests | ||
|
||
import ( | ||
"github.com/timescale/tobs/cli/pkg/k8s" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func testVolumeExpansion(t testing.TB, timescaleDBStorage, timescaleDBWal, prometheusStorage string) { | ||
cmds := []string{"volume", "expand", "-n", RELEASE_NAME, "--namespace", NAMESPACE} | ||
if timescaleDBStorage != "" { | ||
cmds = append(cmds, "--timescaleDB-storage", timescaleDBStorage) | ||
} | ||
|
||
if timescaleDBWal != "" { | ||
cmds = append(cmds, "--timescaleDB-wal", timescaleDBWal) | ||
} | ||
|
||
if prometheusStorage != "" { | ||
cmds = append(cmds, "--prometheus-storage", prometheusStorage) | ||
} | ||
|
||
t.Logf("Running '%v'", "tobs "+strings.Join(cmds, " ")) | ||
expand := exec.Command("./../bin/tobs", cmds...) | ||
out, err := expand.CombinedOutput() | ||
if err != nil { | ||
t.Logf(string(out)) | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func testVolumeGet(t testing.TB, timescaleDBStorage, timescaleDBWal, prometheusStorage bool) { | ||
cmds := []string{"volume", "get", "-n", RELEASE_NAME, "--namespace", NAMESPACE} | ||
if timescaleDBStorage { | ||
cmds = append(cmds, "--timescaleDB-storage") | ||
} | ||
|
||
if timescaleDBWal { | ||
cmds = append(cmds, "--timescaleDB-wal") | ||
} | ||
|
||
if prometheusStorage { | ||
cmds = append(cmds, "--prometheus-storage") | ||
} | ||
|
||
t.Logf("Running '%v'", "tobs "+strings.Join(cmds, " ")) | ||
expand := exec.Command("./../bin/tobs", cmds...) | ||
out, err := expand.CombinedOutput() | ||
if err != nil { | ||
t.Logf(string(out)) | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
|
||
func TestVolume(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping Prometheus tests") | ||
} | ||
|
||
testVolumeGet(t, true, true, true) | ||
testVolumeGet(t, false, true, true) | ||
testVolumeGet(t, true, true, false) | ||
testVolumeGet(t, true, false, false) | ||
testVolumeGet(t, false, false, true) | ||
|
||
// update default storageClass in Kind to allow pvc expansion | ||
err := k8s.UpdateStorageClassAllowVolumeExpand() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
testVolumeExpansion(t, "151Gi", "21Gi", "9Gi") | ||
testVolumeExpansion(t, "152Gi", "22Gi", "") | ||
testVolumeExpansion(t, "153Gi", "", "") | ||
testVolumeExpansion(t, "", "23Gi", "") | ||
testVolumeExpansion(t, "", "24Gi", "10Gi") | ||
testVolumeExpansion(t, "", "", "11Gi") | ||
} |