Skip to content

Commit

Permalink
chore: update packet to equinix
Browse files Browse the repository at this point in the history
Update `packet` to `equinix` for `talos.platform` kernel argument

Fixes: #5010

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Feb 24, 2022
1 parent 7917b1a commit dc23715
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 54 deletions.
6 changes: 6 additions & 0 deletions hack/release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ preface = """\

[notes]

[notes.equinixMetal]
title = "Rename packer to equinixMetal in talos.platform"
description="""\
`talos.platform` for Equinix Metal is renamed from `packet` to `equinixMetal`, the older name is still supported for backwards compatibility.
"""

[notes.applyconfig]
title = "Apply Config Enhancements"
description="""\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func (handler *EquinixMetalHandler) Release(ctx context.Context) error {
return nil
}

// PacketMetaDataEndpoint is the local endpoint for machine info like networking.
const PacketMetaDataEndpoint = "https://metadata.platformequinix.com/metadata"
// EquinixMetalMetaDataEndpoint is the local endpoint for machine info like networking.
const EquinixMetalMetaDataEndpoint = "https://metadata.platformequinix.com/metadata"

// GetProjectAndDeviceIDs fills in parts of the spec based on the API token and instance metadata.
func GetProjectAndDeviceIDs(ctx context.Context, spec *network.VIPEquinixMetalSpec) error {
metadataConfig, err := download.Download(ctx, PacketMetaDataEndpoint)
metadataConfig, err := download.Download(ctx, EquinixMetalMetaDataEndpoint)
if err != nil {
return fmt.Errorf("error downloading metadata: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func TestEquinixMetalHandler(t *testing.T) {
// WARNING: this test requires interaction with Packet API with real device IDs and API token
// WARNING: this test requires interaction with Equinix Metal API with real device IDs and API token
// it is skipped by default unless following variables are set:
// TALOS_EM_API_TOKEN
// TALOS_EM_PROJECT_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 packet
package equinixmetal

import (
"context"
Expand All @@ -23,33 +23,33 @@ import (
"github.com/talos-systems/talos/pkg/machinery/resources/network"
)

// Metadata holds packet metadata info.
// Metadata holds equinixmetal metadata info.
type Metadata struct {
Hostname string `json:"hostname"`
Network Network `json:"network"`
PrivateSubnets []string `json:"private_subnets"`
}

// Network holds network info from the packet metadata.
// Network holds network info from the equinixmetal metadata.
type Network struct {
Bonding Bonding `json:"bonding"`
Interfaces []Interface `json:"interfaces"`
Addresses []Address `json:"addresses"`
}

// Bonding holds bonding info from the packet metadata.
// Bonding holds bonding info from the equinixmetal metadata.
type Bonding struct {
Mode int `json:"mode"`
}

// Interface holds interface info from the packet metadata.
// Interface holds interface info from the equinixmetal metadata.
type Interface struct {
Name string `json:"name"`
MAC string `json:"mac"`
Bond string `json:"bond"`
}

// Address holds address info from the packet metadata.
// Address holds address info from the equinixmetal metadata.
type Address struct {
Public bool `json:"public"`
Management bool `json:"management"`
Expand All @@ -63,51 +63,51 @@ type Address struct {
}

const (
// PacketUserDataEndpoint is the local metadata endpoint for Packet.
PacketUserDataEndpoint = "https://metadata.platformequinix.com/userdata"
// PacketMetaDataEndpoint is the local endpoint for machine info like networking.
PacketMetaDataEndpoint = "https://metadata.platformequinix.com/metadata"
// EquinixMetalUserDataEndpoint is the local metadata endpoint for Equinix.
EquinixMetalUserDataEndpoint = "https://metadata.platformequinix.com/userdata"
// EquinixMetalMetaDataEndpoint is the local endpoint for machine info like networking.
EquinixMetalMetaDataEndpoint = "https://metadata.platformequinix.com/metadata"
)

// Packet is a platform for Equinix Metal cloud.
type Packet struct{}
// EquinixMetal is a platform for EquinixMetal Metal cloud.
type EquinixMetal struct{}

// Name implements the platform.Platform interface.
func (p *Packet) Name() string {
return "packet"
func (p *EquinixMetal) Name() string {
return "equinix"
}

// Configuration implements the platform.Platform interface.
func (p *Packet) Configuration(ctx context.Context) ([]byte, error) {
log.Printf("fetching machine config from: %q", PacketUserDataEndpoint)
func (p *EquinixMetal) Configuration(ctx context.Context) ([]byte, error) {
log.Printf("fetching machine config from: %q", EquinixMetalUserDataEndpoint)

return download.Download(ctx, PacketUserDataEndpoint,
return download.Download(ctx, EquinixMetalUserDataEndpoint,
download.WithErrorOnNotFound(errors.ErrNoConfigSource),
download.WithErrorOnEmptyResponse(errors.ErrNoConfigSource))
}

// Mode implements the platform.Platform interface.
func (p *Packet) Mode() runtime.Mode {
func (p *EquinixMetal) Mode() runtime.Mode {
return runtime.ModeMetal
}

// KernelArgs implements the runtime.Platform interface.
func (p *Packet) KernelArgs() procfs.Parameters {
func (p *EquinixMetal) KernelArgs() procfs.Parameters {
return []*procfs.Parameter{
procfs.NewParameter("console").Append("ttyS1,115200n8"),
}
}

// ParseMetadata converts Equinix Metal (Packet) metadata into Talos network configuration.
// ParseMetadata converts Equinix Metal metadata into Talos network configuration.
//
//nolint:gocyclo,cyclop
func (p *Packet) ParseMetadata(packetMetadata *Metadata) (*runtime.PlatformNetworkConfig, error) {
func (p *EquinixMetal) ParseMetadata(equinixMetadata *Metadata) (*runtime.PlatformNetworkConfig, error) {
networkConfig := &runtime.PlatformNetworkConfig{}

// 1. Links

// translate the int returned from bond mode metadata to the type needed by network resources
bondMode := nethelpers.BondMode(uint8(packetMetadata.Network.Bonding.Mode))
bondMode := nethelpers.BondMode(uint8(equinixMetadata.Network.Bonding.Mode))

// determine bond name and build list of interfaces enslaved by the bond
bondName := ""
Expand All @@ -117,7 +117,7 @@ func (p *Packet) ParseMetadata(packetMetadata *Metadata) (*runtime.PlatformNetwo
return nil, fmt.Errorf("error listing host interfaces: %w", err)
}

for _, iface := range packetMetadata.Network.Interfaces {
for _, iface := range equinixMetadata.Network.Interfaces {
if iface.Bond == "" {
continue
}
Expand Down Expand Up @@ -181,7 +181,7 @@ func (p *Packet) ParseMetadata(packetMetadata *Metadata) (*runtime.PlatformNetwo

// 2. addresses

for _, addr := range packetMetadata.Network.Addresses {
for _, addr := range equinixMetadata.Network.Addresses {
if !(addr.Enabled && addr.Management) {
continue
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func (p *Packet) ParseMetadata(packetMetadata *Metadata) (*runtime.PlatformNetwo

// 3. routes

for _, addr := range packetMetadata.Network.Addresses {
for _, addr := range equinixMetadata.Network.Addresses {
if !(addr.Enabled && addr.Management) {
continue
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func (p *Packet) ParseMetadata(packetMetadata *Metadata) (*runtime.PlatformNetwo
networkConfig.Routes = append(networkConfig.Routes, route)
} else {
// for "Private" addresses, we add a route that goes out the gateway for the private subnets.
for _, privSubnet := range packetMetadata.PrivateSubnets {
for _, privSubnet := range equinixMetadata.PrivateSubnets {
gw, err := netaddr.ParseIP(addr.Gateway)
if err != nil {
return nil, err
Expand Down Expand Up @@ -283,12 +283,12 @@ func (p *Packet) ParseMetadata(packetMetadata *Metadata) (*runtime.PlatformNetwo

// 4. hostname

if packetMetadata.Hostname != "" {
if equinixMetadata.Hostname != "" {
hostnameSpec := network.HostnameSpecSpec{
ConfigLayer: network.ConfigPlatform,
}

if err := hostnameSpec.ParseFQDN(packetMetadata.Hostname); err != nil {
if err := hostnameSpec.ParseFQDN(equinixMetadata.Hostname); err != nil {
return nil, err
}

Expand All @@ -299,20 +299,20 @@ func (p *Packet) ParseMetadata(packetMetadata *Metadata) (*runtime.PlatformNetwo
}

// NetworkConfiguration implements the runtime.Platform interface.
func (p *Packet) NetworkConfiguration(ctx context.Context, ch chan<- *runtime.PlatformNetworkConfig) error {
log.Printf("fetching equinix network config from: %q", PacketMetaDataEndpoint)
func (p *EquinixMetal) NetworkConfiguration(ctx context.Context, ch chan<- *runtime.PlatformNetworkConfig) error {
log.Printf("fetching equinix network config from: %q", EquinixMetalMetaDataEndpoint)

metadataConfig, err := download.Download(ctx, PacketMetaDataEndpoint)
metadataConfig, err := download.Download(ctx, EquinixMetalMetaDataEndpoint)
if err != nil {
return err
}

var packetMetadata Metadata
if err = json.Unmarshal(metadataConfig, &packetMetadata); err != nil {
var equinixMetadata Metadata
if err = json.Unmarshal(metadataConfig, &equinixMetadata); err != nil {
return err
}

networkConfig, err := p.ParseMetadata(&packetMetadata)
networkConfig, err := p.ParseMetadata(&equinixMetadata)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 packet_test
package equinixmetal_test

import (
_ "embed"
Expand All @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"

"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/packet"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/equinixmetal"
)

//go:embed testdata/metadata.json
Expand All @@ -23,9 +23,9 @@ var rawMetadata []byte
var expectedNetworkConfig string

func TestParseMetadata(t *testing.T) {
p := &packet.Packet{}
p := &equinixmetal.EquinixMetal{}

var m packet.Metadata
var m equinixmetal.Metadata

require.NoError(t, json.Unmarshal(rawMetadata, &m))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/azure"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/container"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/digitalocean"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/equinixmetal"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/gcp"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/hcloud"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/metal"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/nocloud"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/openstack"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/oracle"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/packet"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/upcloud"
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/vmware"
Expand Down Expand Up @@ -77,8 +77,9 @@ func newPlatform(platform string) (p runtime.Platform, err error) {
p = &oracle.Oracle{}
case "nocloud":
p = &nocloud.Nocloud{}
case "packet":
p = &packet.Packet{}
// "packet" kept for backwards compatibility
case "equinixMetal", "packet":
p = &equinixmetal.EquinixMetal{}
case "scaleway":
p = &scaleway.Scaleway{}
case "upcloud":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: "Creating Talos cluster using Equinix Metal."

## Prerequisites

This guide assumes the user has a working API token, the Equinix Metal CLI installed, and some familiarity with the CLI.
This guide assumes the user has a working API token, the [Equinix Metal CLI](https://github.com/equinix/metal-cli/) installed, and some familiarity with the CLI.

## Network Booting

Expand Down Expand Up @@ -76,7 +76,7 @@ talosctl validate --config worker.yaml --mode metal
#### Create the Control Plane Nodes

```bash
packet device create \
metal device create \
--project-id $PROJECT_ID \
--facility $FACILITY \
--ipxe-script-url $PXE_SERVER \
Expand All @@ -91,7 +91,7 @@ packet device create \
#### Create the Worker Nodes

```bash
packet device create \
metal device create \
--project-id $PROJECT_ID \
--facility $FACILITY \
--ipxe-script-url $PXE_SERVER \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: "Creating Talos cluster using Equinix Metal."

## Prerequisites

This guide assumes the user has a working API token, the Equinix Metal CLI installed, and some familiarity with the CLI.
This guide assumes the user has a working API token, the [Equinix Metal CLI](https://github.com/equinix/metal-cli/) installed, and some familiarity with the CLI.

## Network Booting

Expand All @@ -20,7 +20,7 @@ These assets can be downloaded from a given [release](https://github.com/talos-s

The following is a list of kernel parameters required by Talos:

- `talos.platform`: set this to `packet`
- `talos.platform`: set this to `equinixMetal`
- `init_on_alloc=1`: required by KSPP
- `slab_nomerge`: required by KSPP
- `pti=on`: required by KSPP
Expand Down Expand Up @@ -76,7 +76,7 @@ talosctl validate --config worker.yaml --mode metal
#### Create the Control Plane Nodes

```bash
packet device create \
metal device create \
--project-id $PROJECT_ID \
--facility $FACILITY \
--ipxe-script-url $PXE_SERVER \
Expand All @@ -91,7 +91,7 @@ packet device create \
#### Create the Worker Nodes

```bash
packet device create \
metal device create \
--project-id $PROJECT_ID \
--facility $FACILITY \
--ipxe-script-url $PXE_SERVER \
Expand Down
4 changes: 2 additions & 2 deletions website/content/docs/v0.15/Reference/kernel.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Several of these are enforced by the Kernel Self Protection Project [KSPP](https
**Required** parameters:

- `talos.config`: the HTTP(S) URL at which the machine configuration data can be found
- `talos.platform`: can be one of `aws`, `azure`, `container`, `digitalocean`, `gcp`, `metal`, `packet`, or `vmware`
- `talos.platform`: can be one of `aws`, `azure`, `container`, `digitalocean`, `gcp`, `metal`, `equinixMetal`, or `vmware`
- `init_on_alloc=1`: required by KSPP
- `slab_nomerge`: required by KSPP
- `pti=on`: required by KSPP
Expand Down Expand Up @@ -67,7 +67,7 @@ Several of these are enforced by the Kernel Self Protection Project [KSPP](https
- `digitalocean`
- `gcp`
- `metal`
- `packet`
- `equinixMetal`
- `vmware`

#### `talos.board`
Expand Down

0 comments on commit dc23715

Please sign in to comment.