-
Notifications
You must be signed in to change notification settings - Fork 463
/
container.go
71 lines (55 loc) · 1.75 KB
/
container.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 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 container
import (
"bytes"
"context"
"encoding/base64"
"io/ioutil"
"log"
"net"
"os"
"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"
)
// Container is a platform for installing Talos via an Container image.
type Container struct{}
// Name implements the platform.Platform interface.
func (c *Container) Name() string {
return "container"
}
// Configuration implements the platform.Platform interface.
func (c *Container) Configuration(context.Context) ([]byte, error) {
log.Printf("fetching machine config from: USERDATA environment variable")
s := os.Getenv("USERDATA")
if s == "" {
return nil, errors.ErrNoConfigSource
}
decoded, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return nil, err
}
return decoded, nil
}
// Hostname implements the platform.Platform interface.
func (c *Container) Hostname(context.Context) (hostname []byte, err error) {
hostname, err = ioutil.ReadFile("/etc/hostname")
if err == nil {
hostname = bytes.TrimSpace(hostname)
}
return
}
// Mode implements the platform.Platform interface.
func (c *Container) Mode() runtime.Mode {
return runtime.ModeContainer
}
// ExternalIPs implements the runtime.Platform interface.
func (c *Container) ExternalIPs(context.Context) (addrs []net.IP, err error) {
return addrs, err
}
// KernelArgs implements the runtime.Platform interface.
func (c *Container) KernelArgs() procfs.Parameters {
return nil
}