Skip to content

Commit

Permalink
Fix missing flag registration
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-t committed Jan 13, 2025
1 parent a0188ef commit 831ee15
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions clusterloader2/cmd/clusterloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ func initFlags() {

initClusterFlags()
execservice.InitFlags(&clusterLoaderConfig.ExecServiceConfig)
imagepreload.InitFlags()
modifier.InitFlags(&clusterLoaderConfig.ModifierConfig)
prometheus.InitFlags(&clusterLoaderConfig.PrometheusConfig)
prometheus.InitExperimentalFlags()
}

func validateFlags() *errors.ErrorList {
Expand Down
2 changes: 1 addition & 1 deletion clusterloader2/pkg/imagepreload/imagepreload.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var (
manifestsFS embed.FS
)

func init() {
func InitFlags() {
flags.StringSliceEnvVar(&images, "node-preload-images", "NODE_PRELOAD_IMAGES", []string{}, "List of images to preload on each node in the test cluster before executing tests")
}

Expand Down
27 changes: 17 additions & 10 deletions clusterloader2/pkg/prometheus/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"regexp"
"time"

"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/perf-tests/clusterloader2/pkg/flags"
)

var (
Expand All @@ -50,13 +50,20 @@ const (
)

var (
shouldSnapshotPrometheusDisk = pflag.Bool("experimental-gcp-snapshot-prometheus-disk", false, "(experimental, provider=gce|gke only) whether to snapshot Prometheus disk before Prometheus stack is torn down")
shouldSnapshotPrometheusToReportDir = pflag.Bool("experimental-prometheus-snapshot-to-report-dir", false, "(experimental) whether to save prometheus snapshot to the report-dir")
prometheusDiskSnapshotName = pflag.String("experimental-prometheus-disk-snapshot-name", "", "Name of the prometheus disk snapshot that will be created if snapshots are enabled. If not set, the prometheus disk name will be used.")
shouldSnapshotPrometheusDisk bool
shouldSnapshotPrometheusToReportDir bool
prometheusDiskSnapshotName string
)

// InitExperimentalFlags initializes prometheus flags.
func InitExperimentalFlags() {
flags.BoolVar(&shouldSnapshotPrometheusDisk, "experimental-gcp-snapshot-prometheus-disk", false, "(experimental, provider=gce|gke only) whether to snapshot Prometheus disk before Prometheus stack is torn down")
flags.BoolVar(&shouldSnapshotPrometheusToReportDir, "experimental-prometheus-snapshot-to-report-dir", false, "(experimental) whether to save prometheus snapshot to the report-dir")
flags.StringVar(&prometheusDiskSnapshotName, "experimental-prometheus-disk-snapshot-name", "", "Name of the prometheus disk snapshot that will be created if snapshots are enabled. If not set, the prometheus disk name will be used.")
}

func (pc *Controller) isEnabled() (bool, error) {
if !*shouldSnapshotPrometheusDisk {
if !shouldSnapshotPrometheusDisk {
return false, nil
}
if !pc.provider.Features().SupportSnapshotPrometheusDisk {
Expand Down Expand Up @@ -147,7 +154,7 @@ func (pc *Controller) snapshotPrometheusDiskIfEnabledSynchronized() error {
return pc.snapshotError
}
func (pc *Controller) snapshotPrometheusIfEnabled() error {
if !*shouldSnapshotPrometheusToReportDir {
if !shouldSnapshotPrometheusToReportDir {
return nil
}

Expand All @@ -168,11 +175,11 @@ func (pc *Controller) snapshotPrometheusDiskIfEnabled() error {
}
// Select snapshot name
snapshotName := pc.diskMetadata.name
if *prometheusDiskSnapshotName != "" {
if err := VerifySnapshotName(*prometheusDiskSnapshotName); err == nil {
snapshotName = *prometheusDiskSnapshotName
if prometheusDiskSnapshotName != "" {
if err := VerifySnapshotName(prometheusDiskSnapshotName); err == nil {
snapshotName = prometheusDiskSnapshotName
} else {
klog.Warningf("Incorrect disk name %v: %v. Using default name: %v", *prometheusDiskSnapshotName, err, snapshotName)
klog.Warningf("Incorrect disk name %v: %v. Using default name: %v", prometheusDiskSnapshotName, err, snapshotName)
}
}
// Snapshot Prometheus disk
Expand Down
2 changes: 1 addition & 1 deletion clusterloader2/pkg/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func InitFlags(p *config.PrometheusConfig) {
// ValidatePrometheusFlags validates prometheus flags.
func ValidatePrometheusFlags(p *config.PrometheusConfig) *clerrors.ErrorList {
errList := clerrors.NewErrorList()
if *shouldSnapshotPrometheusDisk && p.SnapshotProject == "" {
if shouldSnapshotPrometheusDisk && p.SnapshotProject == "" {
errList.Append(fmt.Errorf("requesting snapshot, but snapshot project not configured. Use --experimental-snapshot-project flag"))
}
return errList
Expand Down

0 comments on commit 831ee15

Please sign in to comment.