mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
ci: fix IDE setup on mac (#3226)
This commit is contained in:
parent
2de4cdba74
commit
f4a3ae7d27
@ -21,6 +21,7 @@ go_library(
|
|||||||
"//bootstrapper/internal/kubernetes/k8sapi",
|
"//bootstrapper/internal/kubernetes/k8sapi",
|
||||||
"//bootstrapper/internal/kubernetes/kubewaiter",
|
"//bootstrapper/internal/kubernetes/kubewaiter",
|
||||||
"//bootstrapper/internal/nodelock",
|
"//bootstrapper/internal/nodelock",
|
||||||
|
"//bootstrapper/internal/reboot",
|
||||||
"//internal/atls",
|
"//internal/atls",
|
||||||
"//internal/attestation/choose",
|
"//internal/attestation/choose",
|
||||||
"//internal/attestation/initialize",
|
"//internal/attestation/initialize",
|
||||||
|
@ -10,17 +10,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"log/syslog"
|
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/clean"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/clean"
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/diskencryption"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/diskencryption"
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/initserver"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/initserver"
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/joinclient"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/joinclient"
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/nodelock"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/nodelock"
|
||||||
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/reboot"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/atls"
|
"github.com/edgelesssys/constellation/v2/internal/atls"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/attestation/initialize"
|
"github.com/edgelesssys/constellation/v2/internal/attestation/initialize"
|
||||||
"github.com/edgelesssys/constellation/v2/internal/attestation/vtpm"
|
"github.com/edgelesssys/constellation/v2/internal/attestation/vtpm"
|
||||||
@ -46,13 +44,13 @@ func run(issuer atls.Issuer, openDevice vtpm.TPMOpenFunc, fileHandler file.Handl
|
|||||||
nodeBootstrapped, err := initialize.IsNodeBootstrapped(openDevice)
|
nodeBootstrapped, err := initialize.IsNodeBootstrapped(openDevice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.With(slog.Any("error", err)).Error("Failed to check if node was previously bootstrapped")
|
log.With(slog.Any("error", err)).Error("Failed to check if node was previously bootstrapped")
|
||||||
reboot(fmt.Errorf("checking if node was previously bootstrapped: %w", err))
|
reboot.Reboot(fmt.Errorf("checking if node was previously bootstrapped: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if nodeBootstrapped {
|
if nodeBootstrapped {
|
||||||
if err := kube.StartKubelet(); err != nil {
|
if err := kube.StartKubelet(); err != nil {
|
||||||
log.With(slog.Any("error", err)).Error("Failed to restart kubelet")
|
log.With(slog.Any("error", err)).Error("Failed to restart kubelet")
|
||||||
reboot(fmt.Errorf("restarting kubelet: %w", err))
|
reboot.Reboot(fmt.Errorf("restarting kubelet: %w", err))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -61,7 +59,7 @@ func run(issuer atls.Issuer, openDevice vtpm.TPMOpenFunc, fileHandler file.Handl
|
|||||||
initServer, err := initserver.New(context.Background(), nodeLock, kube, issuer, disk, fileHandler, metadata, log)
|
initServer, err := initserver.New(context.Background(), nodeLock, kube, issuer, disk, fileHandler, metadata, log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.With(slog.Any("error", err)).Error("Failed to create init server")
|
log.With(slog.Any("error", err)).Error("Failed to create init server")
|
||||||
reboot(fmt.Errorf("creating init server: %w", err))
|
reboot.Reboot(fmt.Errorf("creating init server: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
dialer := dialer.New(issuer, nil, &net.Dialer{})
|
dialer := dialer.New(issuer, nil, &net.Dialer{})
|
||||||
@ -79,7 +77,7 @@ func run(issuer atls.Issuer, openDevice vtpm.TPMOpenFunc, fileHandler file.Handl
|
|||||||
if err := joinClient.Start(cleaner); err != nil {
|
if err := joinClient.Start(cleaner); err != nil {
|
||||||
log.With(slog.Any("error", err)).Error("Failed to join cluster")
|
log.With(slog.Any("error", err)).Error("Failed to join cluster")
|
||||||
markDiskForReset(disk)
|
markDiskForReset(disk)
|
||||||
reboot(fmt.Errorf("joining cluster: %w", err))
|
reboot.Reboot(fmt.Errorf("joining cluster: %w", err))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -89,7 +87,7 @@ func run(issuer atls.Issuer, openDevice vtpm.TPMOpenFunc, fileHandler file.Handl
|
|||||||
if err := initServer.Serve(bindIP, bindPort, cleaner); err != nil {
|
if err := initServer.Serve(bindIP, bindPort, cleaner); err != nil {
|
||||||
log.With(slog.Any("error", err)).Error("Failed to serve init server")
|
log.With(slog.Any("error", err)).Error("Failed to serve init server")
|
||||||
markDiskForReset(disk)
|
markDiskForReset(disk)
|
||||||
reboot(fmt.Errorf("serving init server: %w", err))
|
reboot.Reboot(fmt.Errorf("serving init server: %w", err))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
@ -122,20 +120,6 @@ func markDiskForReset(disk *diskencryption.DiskEncryption) {
|
|||||||
_ = disk.MarkDiskForReset()
|
_ = disk.MarkDiskForReset()
|
||||||
}
|
}
|
||||||
|
|
||||||
// reboot writes an error message to the system log and reboots the system.
|
|
||||||
// We call this instead of os.Exit() since failures in the bootstrapper usually require a node reset.
|
|
||||||
func reboot(e error) {
|
|
||||||
syslogWriter, err := syslog.New(syslog.LOG_EMERG|syslog.LOG_KERN, "bootstrapper")
|
|
||||||
if err != nil {
|
|
||||||
_ = syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
|
|
||||||
}
|
|
||||||
_ = syslogWriter.Err(e.Error())
|
|
||||||
_ = syslogWriter.Emerg("bootstrapper has encountered a non recoverable error. Rebooting...")
|
|
||||||
time.Sleep(time.Minute) // sleep to allow the message to be written to syslog and seen by the user
|
|
||||||
|
|
||||||
_ = syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
|
|
||||||
}
|
|
||||||
|
|
||||||
type clusterInitJoiner interface {
|
type clusterInitJoiner interface {
|
||||||
joinclient.ClusterJoiner
|
joinclient.ClusterJoiner
|
||||||
initserver.ClusterInitializer
|
initserver.ClusterInitializer
|
||||||
|
@ -2,8 +2,20 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
|||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "etcdio",
|
name = "etcdio",
|
||||||
srcs = ["etcdio.go"],
|
srcs = [
|
||||||
|
"etcdio.go",
|
||||||
|
"setioprio_cross.go",
|
||||||
|
"setioprio_linux.go",
|
||||||
|
],
|
||||||
importpath = "github.com/edgelesssys/constellation/v2/bootstrapper/internal/etcdio",
|
importpath = "github.com/edgelesssys/constellation/v2/bootstrapper/internal/etcdio",
|
||||||
visibility = ["//bootstrapper:__subpackages__"],
|
visibility = ["//bootstrapper:__subpackages__"],
|
||||||
deps = ["@org_golang_x_sys//unix"],
|
deps = select({
|
||||||
|
"@io_bazel_rules_go//go/platform:android": [
|
||||||
|
"@org_golang_x_sys//unix",
|
||||||
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:linux": [
|
||||||
|
"@org_golang_x_sys//unix",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
@ -16,8 +16,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -97,7 +95,7 @@ func (c *Client) setIOPriority() error {
|
|||||||
prioVal := ((targetClass & ioPrioClassMask) << ioPrioClassShift) | (targetPrio & ioPrioPrioMask)
|
prioVal := ((targetClass & ioPrioClassMask) << ioPrioClassShift) | (targetPrio & ioPrioPrioMask)
|
||||||
|
|
||||||
// see https://man7.org/linux/man-pages/man2/ioprio_set.2.html
|
// see https://man7.org/linux/man-pages/man2/ioprio_set.2.html
|
||||||
ret, _, errno := unix.Syscall(unix.SYS_IOPRIO_SET, ioPrioWhoProcess, uintptr(pid), uintptr(prioVal))
|
ret, _, errno := setioprio(ioPrioWhoProcess, uintptr(pid), uintptr(prioVal))
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
return fmt.Errorf("setting I/O priority for etcd: %w", errno)
|
return fmt.Errorf("setting I/O priority for etcd: %w", errno)
|
||||||
}
|
}
|
||||||
|
17
bootstrapper/internal/etcdio/setioprio_cross.go
Normal file
17
bootstrapper/internal/etcdio/setioprio_cross.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (c) Edgeless Systems GmbH
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package etcdio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setioprio(_, _, _ uintptr) (uintptr, uintptr, syscall.Errno) {
|
||||||
|
panic("setioprio not implemented on non-Linux platforms")
|
||||||
|
}
|
19
bootstrapper/internal/etcdio/setioprio_linux.go
Normal file
19
bootstrapper/internal/etcdio/setioprio_linux.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (c) Edgeless Systems GmbH
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package etcdio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setioprio(ioPrioWhoProcess, pid, prioVal uintptr) (uintptr, uintptr, syscall.Errno) {
|
||||||
|
return unix.Syscall(unix.SYS_IOPRIO_SET, ioPrioWhoProcess, pid, prioVal)
|
||||||
|
}
|
11
bootstrapper/internal/reboot/BUILD.bazel
Normal file
11
bootstrapper/internal/reboot/BUILD.bazel
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "reboot",
|
||||||
|
srcs = [
|
||||||
|
"reboot_cross.go",
|
||||||
|
"reboot_linux.go",
|
||||||
|
],
|
||||||
|
importpath = "github.com/edgelesssys/constellation/v2/bootstrapper/internal/reboot",
|
||||||
|
visibility = ["//bootstrapper:__subpackages__"],
|
||||||
|
)
|
14
bootstrapper/internal/reboot/reboot_cross.go
Normal file
14
bootstrapper/internal/reboot/reboot_cross.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (c) Edgeless Systems GmbH
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package reboot
|
||||||
|
|
||||||
|
// Reboot is not implemented on non-Linux platforms.
|
||||||
|
func Reboot(_ error) {
|
||||||
|
panic("reboot not implemented on non-Linux platforms")
|
||||||
|
}
|
29
bootstrapper/internal/reboot/reboot_linux.go
Normal file
29
bootstrapper/internal/reboot/reboot_linux.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (c) Edgeless Systems GmbH
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package reboot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/syslog"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reboot writes an error message to the system log and reboots the system.
|
||||||
|
// We call this instead of os.Exit() since failures in the bootstrapper usually require a node reset.
|
||||||
|
func Reboot(e error) {
|
||||||
|
syslogWriter, err := syslog.New(syslog.LOG_EMERG|syslog.LOG_KERN, "bootstrapper")
|
||||||
|
if err != nil {
|
||||||
|
_ = syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
|
||||||
|
}
|
||||||
|
_ = syslogWriter.Err(e.Error())
|
||||||
|
_ = syslogWriter.Emerg("bootstrapper has encountered a non recoverable error. Rebooting...")
|
||||||
|
time.Sleep(time.Minute) // sleep to allow the message to be written to syslog and seen by the user
|
||||||
|
|
||||||
|
_ = syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user