-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scaleway.com cloud support
* cloud-init for scaleway * set ipv6 to the interface Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev> Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
- Loading branch information
1 parent
f156ab1
commit 3b5f403
Showing
8 changed files
with
278 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// 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 scaleway | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net" | ||
|
||
"github.com/scaleway/scaleway-sdk-go/api/instance/v1" | ||
"github.com/talos-systems/go-procfs/procfs" | ||
|
||
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime" | ||
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/errors" | ||
"github.com/talos-systems/talos/pkg/download" | ||
"github.com/talos-systems/talos/pkg/machinery/config" | ||
"github.com/talos-systems/talos/pkg/machinery/config/configloader" | ||
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1" | ||
) | ||
|
||
const ( | ||
// ScalewayMetadataEndpoint is the local Scaleway endpoint. | ||
ScalewayMetadataEndpoint = "http://169.254.42.42/conf?format=json" | ||
) | ||
|
||
// Scaleway is the concrete type that implements the runtime.Platform interface. | ||
type Scaleway struct{} | ||
|
||
// Name implements the runtime.Platform interface. | ||
func (s *Scaleway) Name() string { | ||
return "scaleway" | ||
} | ||
|
||
// ConfigurationNetwork implements the network configuration interface. | ||
func (s *Scaleway) ConfigurationNetwork(metadataConfig *instance.Metadata, confProvider config.Provider) (config.Provider, error) { | ||
var machineConfig *v1alpha1.Config | ||
|
||
machineConfig, ok := confProvider.(*v1alpha1.Config) | ||
if !ok { | ||
return nil, fmt.Errorf("unable to determine machine config type") | ||
} | ||
|
||
if machineConfig.MachineConfig == nil { | ||
machineConfig.MachineConfig = &v1alpha1.MachineConfig{} | ||
} | ||
|
||
if machineConfig.MachineConfig.MachineNetwork == nil { | ||
machineConfig.MachineConfig.MachineNetwork = &v1alpha1.NetworkConfig{} | ||
} | ||
|
||
iface := v1alpha1.Device{ | ||
DeviceInterface: "eth0", | ||
DeviceDHCP: true, | ||
} | ||
|
||
if metadataConfig.IPv6.Address != "" { | ||
iface.DeviceAddresses = append(iface.DeviceAddresses, | ||
fmt.Sprintf("%s/%s", metadataConfig.IPv6.Address, metadataConfig.IPv6.Netmask), | ||
) | ||
|
||
iface.DeviceRoutes = []*v1alpha1.Route{ | ||
{ | ||
RouteNetwork: "::/0", | ||
RouteGateway: metadataConfig.IPv6.Gateway, | ||
RouteMetric: 1024, | ||
}, | ||
} | ||
} | ||
|
||
machineConfig.MachineConfig.MachineNetwork.NetworkInterfaces = append( | ||
machineConfig.MachineConfig.MachineNetwork.NetworkInterfaces, | ||
&iface, | ||
) | ||
|
||
return confProvider, nil | ||
} | ||
|
||
// Configuration implements the runtime.Platform interface. | ||
func (s *Scaleway) Configuration(ctx context.Context) ([]byte, error) { | ||
log.Printf("fetching scaleway instance config from: %q ", ScalewayMetadataEndpoint) | ||
|
||
metadataDl, err := download.Download(ctx, ScalewayMetadataEndpoint, | ||
download.WithErrorOnNotFound(errors.ErrNoConfigSource), | ||
download.WithErrorOnEmptyResponse(errors.ErrNoConfigSource)) | ||
if err != nil { | ||
return nil, errors.ErrNoConfigSource | ||
} | ||
|
||
metadata := &instance.Metadata{} | ||
if err = json.Unmarshal(metadataDl, metadata); err != nil { | ||
return nil, errors.ErrNoConfigSource | ||
} | ||
|
||
log.Printf("fetching machine config from scaleway metadata server") | ||
|
||
instanceAPI := instance.NewMetadataAPI() | ||
|
||
machineConfigDl, err := instanceAPI.GetUserData("cloud-init") | ||
if err != nil { | ||
return nil, errors.ErrNoConfigSource | ||
} | ||
|
||
confProvider, err := configloader.NewFromBytes(machineConfigDl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
confProvider, err = s.ConfigurationNetwork(metadata, confProvider) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return confProvider.Bytes() | ||
} | ||
|
||
// Mode implements the runtime.Platform interface. | ||
func (s *Scaleway) Mode() runtime.Mode { | ||
return runtime.ModeCloud | ||
} | ||
|
||
// Hostname implements the runtime.Platform interface. | ||
func (s *Scaleway) Hostname(ctx context.Context) (hostname []byte, err error) { | ||
log.Printf("fetching hostname from: %q", ScalewayMetadataEndpoint) | ||
|
||
metadataDl, err := download.Download(ctx, ScalewayMetadataEndpoint, | ||
download.WithErrorOnNotFound(errors.ErrNoExternalIPs), | ||
download.WithErrorOnEmptyResponse(errors.ErrNoExternalIPs)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
metadata := &instance.Metadata{} | ||
if err = json.Unmarshal(metadataDl, metadata); err != nil { | ||
return nil, err | ||
} | ||
|
||
return []byte(metadata.Hostname), nil | ||
} | ||
|
||
// ExternalIPs implements the runtime.Platform interface. | ||
func (s *Scaleway) ExternalIPs(ctx context.Context) (addrs []net.IP, err error) { | ||
log.Printf("fetching external IP from: %q", ScalewayMetadataEndpoint) | ||
|
||
metadataDl, err := download.Download(ctx, ScalewayMetadataEndpoint, | ||
download.WithErrorOnNotFound(errors.ErrNoExternalIPs), | ||
download.WithErrorOnEmptyResponse(errors.ErrNoExternalIPs)) | ||
if err != nil { | ||
return addrs, err | ||
} | ||
|
||
metadata := &instance.Metadata{} | ||
if err = json.Unmarshal(metadataDl, metadata); err != nil { | ||
return addrs, err | ||
} | ||
|
||
addrs = append(addrs, net.ParseIP(metadata.PublicIP.Address)) | ||
|
||
return addrs, err | ||
} | ||
|
||
// KernelArgs implements the runtime.Platform interface. | ||
func (s *Scaleway) KernelArgs() procfs.Parameters { | ||
return []*procfs.Parameter{ | ||
procfs.NewParameter("console").Append("tty1").Append("ttyS0"), | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway/scaleway_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// 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 scaleway_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/scaleway/scaleway-sdk-go/api/instance/v1" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/talos-systems/talos/internal/app/machined/pkg/runtime/v1alpha1/platform/scaleway" | ||
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1" | ||
) | ||
|
||
type ConfigSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func (suite *ConfigSuite) TestNetworkConfig() { | ||
cfg := []byte(`{ | ||
"id": "11111111-1111-1111-1111-111111111111", | ||
"name": "scw-talos", | ||
"commercial_type": "DEV1-S", | ||
"hostname": "scw-talos", | ||
"tags": [], | ||
"state_detail": "booted", | ||
"public_ip": { | ||
"id": "11111111-1111-1111-1111-111111111111", | ||
"address": "11.22.222.222", | ||
"dynamic": false | ||
}, | ||
"private_ip": "10.00.222.222", | ||
"ipv6": { | ||
"address": "2001:111:222:3333::1", | ||
"gateway": "2001:111:222:3333::", | ||
"netmask": "64" | ||
} | ||
}`) | ||
|
||
metadata := &instance.Metadata{} | ||
err := json.Unmarshal(cfg, &metadata) | ||
suite.Require().NoError(err) | ||
|
||
p := &scaleway.Scaleway{} | ||
|
||
defaultMachineConfig := &v1alpha1.Config{} | ||
|
||
machineConfig := &v1alpha1.Config{ | ||
MachineConfig: &v1alpha1.MachineConfig{ | ||
MachineNetwork: &v1alpha1.NetworkConfig{ | ||
NetworkInterfaces: []*v1alpha1.Device{ | ||
{ | ||
DeviceInterface: "eth0", | ||
DeviceDHCP: true, | ||
DeviceAddresses: []string{"2001:111:222:3333::1/64"}, | ||
DeviceRoutes: []*v1alpha1.Route{ | ||
{ | ||
RouteNetwork: "::/0", | ||
RouteGateway: "2001:111:222:3333::", | ||
RouteMetric: 1024, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
result, err := p.ConfigurationNetwork(metadata, defaultMachineConfig) | ||
|
||
suite.Require().NoError(err) | ||
suite.Assert().Equal(machineConfig, result) | ||
} | ||
|
||
func TestConfigSuite(t *testing.T) { | ||
suite.Run(t, new(ConfigSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: "Scaleway" | ||
description: "Creating a cluster via the CLI (scw) on scaleway.com." | ||
--- | ||
|
||
Talos is known to work on scaleway.com; however, it is currently undocumented. |