Skip to content

Commit

Permalink
make defaults configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Ang <josephangbc@gmail.com>
  • Loading branch information
josephangbc committed Nov 5, 2024
1 parent 25a0c93 commit f82a8b5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
13 changes: 13 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/spf13/cobra"
pvcautoresizer "github.com/topolvm/pvc-autoresizer"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
//+kubebuilder:scaffold:imports
Expand All @@ -25,6 +26,10 @@ var config struct {
development bool
zapOpts zap.Options
pvcMutatingWebhookEnabled bool
defaultThreshold string
defaultInodesThreshold string
defaultIncrease string
defaultLimit string
}

// rootCmd represents the base command when called without any subcommands
Expand Down Expand Up @@ -61,6 +66,14 @@ func init() {
fs.BoolVar(&config.development, "development", false, "Use development logger config")
fs.BoolVar(&config.pvcMutatingWebhookEnabled, "pvc-mutating-webhook-enabled", true,
"Enable the pvc mutating webhook endpoint")
fs.StringVar(&config.defaultThreshold, "default-threshold", pvcautoresizer.DefaultThreshold,
"Default value of ResizeThresholdAnnotation")
fs.StringVar(&config.defaultInodesThreshold, "default-inodes-threshold", pvcautoresizer.DefaultInodesThreshold,
"Default value of ResizeInodesThresholdAnnotation")
fs.StringVar(&config.defaultIncrease, "default-increase", pvcautoresizer.DefaultIncrease,
"Default value of ResizeIncreaseAnnotation")
fs.StringVar(&config.defaultLimit, "default-limit", pvcautoresizer.DefaultLimit,
"Default value of StorageLimitAnnotation")

goflags := flag.NewFlagSet("zap", flag.ExitOnError)
config.zapOpts.BindFlags(goflags)
Expand Down
14 changes: 14 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"
"time"

pvcautoresizer "github.com/topolvm/pvc-autoresizer"
"github.com/topolvm/pvc-autoresizer/internal/hooks"
"github.com/topolvm/pvc-autoresizer/internal/runners"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -148,6 +149,19 @@ func subMain() error {
}
}

if config.defaultThreshold != "" {
pvcautoresizer.DefaultThreshold = config.defaultThreshold
}
if config.defaultInodesThreshold != "" {
pvcautoresizer.DefaultInodesThreshold = config.defaultInodesThreshold
}
if config.defaultIncrease != "" {
pvcautoresizer.DefaultIncrease = config.defaultIncrease
}
if config.defaultLimit != "" {
pvcautoresizer.DefaultLimit = config.defaultLimit
}

//+kubebuilder:scaffold:builder

setupLog.Info("starting manager")
Expand Down
17 changes: 11 additions & 6 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ const PreviousCapacityBytesAnnotation = "resize.topolvm.io/pre_capacity_bytes"
// InitialResizeGroupByAnnotation is the key of the initial-resize group by.
const InitialResizeGroupByAnnotation = "resize.topolvm.io/initial-resize-group-by"

// DefaultThreshold is the default value of ResizeThresholdAnnotation.
const DefaultThreshold = "10%"
var (
// DefaultThreshold is the default value of ResizeThresholdAnnotation.
DefaultThreshold = "10%"

// DefaultInodesThreshold is the default value of ResizeInodesThresholdAnnotation.
const DefaultInodesThreshold = "10%"
// DefaultInodesThreshold is the default value of ResizeInodesThresholdAnnotation.
DefaultInodesThreshold = "10%"

// DefaultIncrease is the default value of ResizeIncreaseAnnotation.
const DefaultIncrease = "10%"
// DefaultIncrease is the default value of ResizeIncreaseAnnotation.
DefaultIncrease = "10%"

// DefaultLimit is the default value of StorageLimitAnnotation.
DefaultLimit = "100Gi"
)
2 changes: 1 addition & 1 deletion internal/runners/pvc_autoresizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,5 @@ func PvcStorageLimit(pvc *corev1.PersistentVolumeClaim) (resource.Quantity, erro
return resource.ParseQuantity(annotation)
}

return *resource.NewQuantity(0, resource.BinarySI), nil
return resource.ParseQuantity(pvcautoresizer.DefaultLimit)
}
2 changes: 1 addition & 1 deletion test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestMtest(t *testing.T) {
RegisterFailHandler(Fail)

SetDefaultEventuallyPollingInterval(time.Second)
SetDefaultEventuallyTimeout(5 * time.Minute)
SetDefaultEventuallyTimeout(10 * time.Minute)

RunSpecs(t, "Test on sanity")
}
Expand Down

0 comments on commit f82a8b5

Please sign in to comment.