Skip to content

Commit

Permalink
Merge #122099
Browse files Browse the repository at this point in the history
122099: roachprod: flag to enable cron on GCE r=renatolabs a=herkolategan

Previously, the cron service was masked and disabled on GCE via the start-up script.

This change allows a flag to be passed to prevent the script from masking and disabling cron.

Fixes: #122098

Epic: None
Release Note: None

Co-authored-by: Herko Lategan <[email protected]>
  • Loading branch information
craig[bot] and herkolategan committed Apr 16, 2024
2 parents 06c9608 + 7b47dfa commit 3133675
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/roachprod/vm/gce/gcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ type ProviderOpts struct {
// Use an instance template and a managed instance group to create VMs. This
// enables cluster resizing, load balancing, and health monitoring.
Managed bool
// Enable the cron service. It is disabled by default.
EnableCron bool

// GCE allows two availability policies in case of a maintenance event (see --maintenance-policy via gcloud),
// 'TERMINATE' or 'MIGRATE'. The default is 'MIGRATE' which we denote by 'TerminateOnMigration == false'.
Expand Down Expand Up @@ -951,6 +953,8 @@ func (o *ProviderOpts) ConfigureCreateFlags(flags *pflag.FlagSet) {
"use 'TERMINATE' maintenance policy (for GCE live migrations)")
flags.BoolVar(&o.Managed, ProviderName+"-managed", false,
"use a managed instance group (enables resizing, load balancing, and health monitoring)")
flags.BoolVar(&o.EnableCron, ProviderName+"-enable-cron",
false, "Enables the cron service (it is disabled by default)")
}

// ConfigureClusterFlags implements vm.ProviderFlags.
Expand Down Expand Up @@ -1222,7 +1226,11 @@ func (p *Provider) computeInstanceArgs(
}

// Create GCE startup script file.
filename, err := writeStartupScript(extraMountOpts, opts.SSDOpts.FileSystem, providerOpts.UseMultipleDisks, opts.Arch == string(vm.ArchFIPS))
filename, err := writeStartupScript(
extraMountOpts, opts.SSDOpts.FileSystem,
providerOpts.UseMultipleDisks, opts.Arch == string(vm.ArchFIPS),
providerOpts.EnableCron,
)
if err != nil {
return nil, cleanUpFn, errors.Wrapf(err, "could not write GCE startup script to temp file")
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/roachprod/vm/gce/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ sudo apt-get install -qy chrony
systemctl stop unattended-upgrades
apt-get purge -y unattended-upgrades
{{ if not .EnableCron }}
systemctl stop cron
systemctl mask cron
{{ end }}
# Override the chrony config. In particular,
# log aggressively when clock is adjusted (0.01s)
Expand Down Expand Up @@ -266,7 +268,7 @@ sudo touch /mnt/data1/.roachprod-initialized
// extraMountOpts, if not empty, is appended to the default mount options. It is
// a comma-separated list of options for the "mount -o" flag.
func writeStartupScript(
extraMountOpts string, fileSystem string, useMultiple bool, enableFIPS bool,
extraMountOpts string, fileSystem string, useMultiple bool, enableFIPS bool, enableCron bool,
) (string, error) {
type tmplParams struct {
ExtraMountOpts string
Expand All @@ -275,6 +277,7 @@ func writeStartupScript(
EnableFIPS bool
SharedUser string
PublicKey string
EnableCron bool
}

publicKey, err := config.SSHPublicKey()
Expand All @@ -289,6 +292,7 @@ func writeStartupScript(
EnableFIPS: enableFIPS,
SharedUser: config.SharedUser,
PublicKey: publicKey,
EnableCron: enableCron,
}

tmpfile, err := os.CreateTemp("", "gce-startup-script")
Expand Down

0 comments on commit 3133675

Please sign in to comment.