Skip to content

Commit

Permalink
chore: add an option to launch cluster with bad RTC state
Browse files Browse the repository at this point in the history
This is useful for time sync testing.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Jun 23, 2021
1 parent d8c2bca commit 33119d2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/talosctl/cmd/mgmt/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ var (
configPatch string
configPatchControlPlane string
configPatchJoin string
badRTC bool
)

// createCmd represents the cluster up command.
Expand Down Expand Up @@ -491,6 +492,7 @@ func create(ctx context.Context) (err error) {
NanoCPUs: nanoCPUs,
Disks: disks,
SkipInjectingConfig: skipInjectingConfig,
BadRTC: badRTC,
}

if i == 0 {
Expand Down Expand Up @@ -542,6 +544,7 @@ func create(ctx context.Context) (err error) {
Disks: disks,
Config: cfg,
SkipInjectingConfig: skipInjectingConfig,
BadRTC: badRTC,
})
}

Expand Down Expand Up @@ -809,5 +812,6 @@ func init() {
createCmd.Flags().StringVar(&configPatch, "config-patch", "", "patch generated machineconfigs (applied to all node types)")
createCmd.Flags().StringVar(&configPatchControlPlane, "config-patch-control-plane", "", "patch generated machineconfigs (applied to 'init' and 'controlplane' types)")
createCmd.Flags().StringVar(&configPatchJoin, "config-patch-join", "", "patch generated machineconfigs (applied to 'join' type)")
createCmd.Flags().BoolVar(&badRTC, "bad-rtc", false, "launch VM with bad RTC state (QEMU only)")
Cmd.AddCommand(createCmd)
}
18 changes: 16 additions & 2 deletions pkg/provision/providers/qemu/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type LaunchConfig struct {
EnableKVM bool
BootloaderEnabled bool
NodeUUID uuid.UUID
BadRTC bool

// Talos config
Config string
Expand Down Expand Up @@ -219,18 +220,24 @@ func checkPartitions(config *LaunchConfig) (bool, error) {

// launchVM runs qemu with args built based on config.
//
//nolint:gocyclo
//nolint:gocyclo,cyclop
func launchVM(config *LaunchConfig) error {
bootOrder := config.DefaultBootOrder

if config.controller.ForcePXEBoot() {
bootOrder = "nc"
}

cpuArg := "max"

if config.BadRTC {
cpuArg += ",-kvmclock"
}

args := []string{
"-m", strconv.FormatInt(config.MemSize, 10),
"-smp", fmt.Sprintf("cpus=%d", config.VCPUCount),
"-cpu", "max",
"-cpu", cpuArg,
"-nographic",
"-netdev", fmt.Sprintf("tap,id=net0,ifname=%s,script=no,downscript=no", config.tapName),
"-device", fmt.Sprintf("virtio-net-pci,netdev=net0,mac=%s", config.vmMAC),
Expand Down Expand Up @@ -284,6 +291,13 @@ func launchVM(config *LaunchConfig) error {
}
}

if config.BadRTC {
args = append(args,
"-rtc",
"base=2011-11-11T11:11:00,clock=rt",
)
}

fmt.Fprintf(os.Stderr, "starting %s with args:\n%s\n", config.QemuExecutable, strings.Join(args, " "))
cmd := exec.Command(
config.QemuExecutable,
Expand Down
1 change: 1 addition & 0 deletions pkg/provision/providers/qemu/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (p *provisioner) createNode(state *vm.State, clusterReq provision.ClusterRe
PFlashImages: pflashImages,
MonitorPath: state.GetRelativePath(fmt.Sprintf("%s.monitor", nodeReq.Name)),
EnableKVM: opts.TargetArch == runtime.GOARCH,
BadRTC: nodeReq.BadRTC,
DefaultBootOrder: defaultBootOrder,
BootloaderEnabled: opts.BootloaderEnabled,
NodeUUID: nodeUUID,
Expand Down
5 changes: 5 additions & 0 deletions pkg/provision/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ type NodeRequest struct {
// BootOrder can be forced to be "nc" (PXE boot) via the API in QEMU provisioner.
DefaultBootOrder string

// Testing features

// BadRTC resets RTC to well known time in the past (QEMU provisioner).
BadRTC bool

// PXE-booted VMs
PXEBooted bool
TFTPServer string
Expand Down
1 change: 1 addition & 0 deletions website/content/docs/v0.11/Reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ talosctl cluster create [flags]

```
--arch string cluster architecture (default "amd64")
--bad-rtc launch VM with bad RTC state (QEMU only)
--cidr string CIDR of the cluster network (IPv4, ULA network for IPv6 is derived in automated way) (default "10.5.0.0/24")
--cni-bin-path strings search path for CNI binaries (VM only) (default [/home/user/.talos/cni/bin])
--cni-bundle-url string URL to download CNI bundle from (VM only) (default "https://github.com/talos-systems/talos/releases/download/v0.11.0-alpha.1/talosctl-cni-bundle-${ARCH}.tar.gz")
Expand Down

0 comments on commit 33119d2

Please sign in to comment.