Skip to content

Commit

Permalink
fix: make vmware platform common code build on all arches
Browse files Browse the repository at this point in the history
Even though VMWare doesn't support non-amd64 case, for the imager (and
Image Factory), the common stuff should work correctly for any arch the
imager is running with (as arm64 imager can generate amd64 VMWare
image).

See siderolabs/image-factory#164

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Nov 20, 2024
1 parent cc76803 commit c4c1a0d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// Package vmware provides the VMware platform implementation.
package vmware

import (
"github.com/siderolabs/go-procfs/procfs"

"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/pkg/machinery/constants"
)

// VMware is the concrete type that implements the platform.Platform interface.
type VMware struct{}

// Name implements the platform.Platform interface.
func (v *VMware) Name() string {
return "vmware"
}

// Mode implements the platform.Platform interface.
func (v *VMware) Mode() runtime.Mode {
return runtime.ModeCloud
}

// KernelArgs implements the runtime.Platform interface.
func (v *VMware) KernelArgs(arch string) procfs.Parameters {
switch arch {
case "amd64":
return []*procfs.Parameter{
procfs.NewParameter(constants.KernelParamConfig).Append(constants.ConfigGuestInfo),
procfs.NewParameter("console").Append("tty0").Append("ttyS0"),
procfs.NewParameter("earlyprintk").Append("ttyS0,115200"),
procfs.NewParameter(constants.KernelParamNetIfnames).Append("0"),
}
default:
return nil // not supported on !amd64
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

//go:build amd64

// Package vmware provides the VMware platform implementation.
package vmware

import (
Expand All @@ -27,14 +26,6 @@ import (
runtimeres "github.com/siderolabs/talos/pkg/machinery/resources/runtime"
)

// VMware is the concrete type that implements the platform.Platform interface.
type VMware struct{}

// Name implements the platform.Platform interface.
func (v *VMware) Name() string {
return "vmware"
}

// Read and de-base64 a property from `extraConfig`. This is commonly referred to as `guestinfo`.
func readConfigFromExtraConfig(extraConfig *rpcvmx.Config, key string) ([]byte, error) {
val, err := extraConfig.String(key, "")
Expand Down Expand Up @@ -214,21 +205,6 @@ func (v *VMware) Configuration(context.Context, state.State) ([]byte, error) {
return nil, nil
}

// Mode implements the platform.Platform interface.
func (v *VMware) Mode() runtime.Mode {
return runtime.ModeCloud
}

// KernelArgs implements the runtime.Platform interface.
func (v *VMware) KernelArgs(string) procfs.Parameters {
return []*procfs.Parameter{
procfs.NewParameter(constants.KernelParamConfig).Append(constants.ConfigGuestInfo),
procfs.NewParameter("console").Append("tty0").Append("ttyS0"),
procfs.NewParameter("earlyprintk").Append("ttyS0,115200"),
procfs.NewParameter(constants.KernelParamNetIfnames).Append("0"),
}
}

// Read VMware GuestInfo metadata if available.
func (v *VMware) readMetadata(extraConfig *rpcvmx.Config) ([]byte, error) {
guestInfoMetadata, err := readConfigFromExtraConfig(extraConfig, constants.VMwareGuestInfoMetadataKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,15 @@ import (
"errors"

"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/go-procfs/procfs"

"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
)

// VMware is the concrete type that implements the platform.Platform interface.
type VMware struct{}

// Name implements the platform.Platform interface.
func (v *VMware) Name() string {
return "vmware"
}

// Configuration implements the platform.Platform interface.
func (v *VMware) Configuration(context.Context, state.State) ([]byte, error) {
return nil, errors.New("arch not supported")
}

// Mode implements the platform.Platform interface.
func (v *VMware) Mode() runtime.Mode {
return runtime.ModeCloud
}

// KernelArgs implements the runtime.Platform interface.
func (v *VMware) KernelArgs(string) procfs.Parameters {
return []*procfs.Parameter{}
}

// NetworkConfiguration implements the runtime.Platform interface.
func (v *VMware) NetworkConfiguration(ctx context.Context, _ state.State, ch chan<- *runtime.PlatformNetworkConfig) error {
return nil
Expand Down

0 comments on commit c4c1a0d

Please sign in to comment.