refactor(*): move gRPC service to dedicated binary (#73)
This commit is contained in:
parent
5701ea6858
commit
05f65c1ab4
@ -15,6 +15,8 @@ policies:
|
||||
- init
|
||||
- initramfs
|
||||
- kernel
|
||||
- osctl
|
||||
- osd
|
||||
- rootfs
|
||||
- tools
|
||||
- '*'
|
||||
|
@ -29,6 +29,7 @@ tasks:
|
||||
COPY --from=dianemo/rootfs:{{ .Docker.Image.Tag }} /rootfs /rootfs
|
||||
COPY --from=dianemo/kernel:{{ .Docker.Image.Tag }} /tmp/vmlinuz /rootfs/boot/vmlinuz
|
||||
COPY --from=dianemo/kernel:{{ .Docker.Image.Tag }} /tmp/lib/modules /rootfs/lib/modules
|
||||
COPY --from=dianemo/initramfs:{{ .Docker.Image.Tag }} /tmp/osd /rootfs/bin/osd
|
||||
COPY --from=dianemo/initramfs:{{ .Docker.Image.Tag }} /tmp/initramfs.xz /rootfs/boot/initramfs.xz
|
||||
COPY --from=dianemo/initramfs:{{ .Docker.Image.Tag }} /tmp/init /rootfs/bin/init
|
||||
WORKDIR /rootfs
|
||||
|
@ -7,46 +7,48 @@ pipeline:
|
||||
stages:
|
||||
build:
|
||||
artifacts:
|
||||
- source: /tmp/cli
|
||||
- source: /tmp/osctl
|
||||
destination: ../build/osctl
|
||||
tasks:
|
||||
- src
|
||||
- test
|
||||
- cli
|
||||
- osd
|
||||
- osctl
|
||||
- init
|
||||
- image
|
||||
generate:
|
||||
artifacts:
|
||||
- source: /go/src/github.com/autonomy/dianemo/proto
|
||||
destination: ./src/init
|
||||
destination: ./cmd/osd
|
||||
tasks:
|
||||
- proto
|
||||
tasks:
|
||||
cli:
|
||||
image:
|
||||
template: |
|
||||
FROM dianemo/tools:{{ .Docker.Image.Tag }} AS {{ .Docker.CurrentStage }}
|
||||
RUN ln -s /tools/lib64 /lib64
|
||||
RUN mkdir /tmp
|
||||
WORKDIR $GOPATH/src/github.com/autonomy/dianemo/initramfs/src/init
|
||||
COPY src/init ./
|
||||
WORKDIR $GOPATH/src/github.com/autonomy/dianemo/initramfs/src/init/cli
|
||||
RUN GOOS=darwin go build -o /cli
|
||||
RUN chmod +x /cli
|
||||
FROM scratch
|
||||
WORKDIR /tmp
|
||||
COPY --from=src /osctl osctl
|
||||
COPY --from=src /osd osd
|
||||
COPY --from=src /initramfs/init init
|
||||
COPY --from=src /initramfs/initramfs.xz initramfs.xz
|
||||
CMD false
|
||||
init:
|
||||
template: |
|
||||
FROM dianemo/tools:{{ .Docker.Image.Tag }} AS {{ .Docker.CurrentStage }}
|
||||
RUN ln -s /tools/lib64 /lib64
|
||||
RUN mkdir /tmp
|
||||
WORKDIR $GOPATH/src/github.com/autonomy/dianemo/initramfs/src/init
|
||||
COPY src/init ./
|
||||
WORKDIR $GOPATH/src/github.com/autonomy/dianemo/initramfs/cmd/init
|
||||
RUN go build -ldflags '-s -w -linkmode external -extldflags "-static -L/usr/lib -lblkid -luuid"' -o /initramfs/init
|
||||
RUN chmod +x /initramfs/init
|
||||
WORKDIR /initramfs
|
||||
RUN find . 2>/dev/null | cpio -H newc -o | xz -v -C crc32 -9 -e -T 0 -z >/initramfs/initramfs.xz
|
||||
FROM scratch
|
||||
WORKDIR /tmp
|
||||
COPY --from=init /initramfs/init init
|
||||
COPY --from=init /initramfs/initramfs.xz initramfs.xz
|
||||
COPY --from=cli /cli cli
|
||||
CMD false
|
||||
osctl:
|
||||
template: |
|
||||
WORKDIR $GOPATH/src/github.com/autonomy/dianemo/initramfs/cmd/{{ .Docker.CurrentStage }}
|
||||
RUN GOOS=darwin go build -o /{{ .Docker.CurrentStage }}
|
||||
RUN chmod +x /{{ .Docker.CurrentStage }}
|
||||
osd:
|
||||
template: |
|
||||
WORKDIR $GOPATH/src/github.com/autonomy/dianemo/initramfs/cmd/{{ .Docker.CurrentStage }}
|
||||
RUN go build -o /{{ .Docker.CurrentStage }}
|
||||
RUN chmod +x /{{ .Docker.CurrentStage }}
|
||||
proto:
|
||||
template: |
|
||||
FROM golang:1.10.0 AS {{ .Docker.CurrentStage }}
|
||||
@ -58,15 +60,17 @@ tasks:
|
||||
&& mv /tmp/bin/protoc /bin \
|
||||
&& mv /tmp/include/* /usr/local/include \
|
||||
&& chmod +x /bin/protoc
|
||||
COPY ./src/init/proto ./proto
|
||||
COPY ./cmd/osd/proto ./proto
|
||||
RUN protoc -I/usr/local/include -I./proto --go_out=plugins=grpc:proto proto/api.proto
|
||||
test:
|
||||
src:
|
||||
template: |
|
||||
FROM dianemo/tools:{{ .Docker.Image.Tag }} AS {{ .Docker.CurrentStage }}
|
||||
RUN ln -s /tools/lib64 /lib64
|
||||
RUN mkdir /tmp
|
||||
RUN curl -L https://github.com/alecthomas/gometalinter/releases/download/v2.0.5/gometalinter-2.0.5-linux-amd64.tar.gz | tar -xz --strip-components=1 -C /tools/bin
|
||||
WORKDIR $GOPATH/src/github.com/autonomy/dianemo/initramfs/src/init
|
||||
COPY src/init ./
|
||||
COPY --from=autonomy/golang:1.10 /bin/test.sh /bin/test.sh
|
||||
WORKDIR $GOPATH/src/github.com/autonomy/dianemo/initramfs
|
||||
COPY ./ ./
|
||||
test:
|
||||
template: |
|
||||
RUN test.sh
|
||||
|
@ -9,13 +9,12 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/mount"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/rootfs"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/server"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/service"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/switchroot"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/mount"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/rootfs"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/switchroot"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -57,7 +56,7 @@ func initram() (err error) {
|
||||
if err = rootfs.Prepare(constants.NewRoot, data); err != nil {
|
||||
return
|
||||
}
|
||||
// Unmount the ROOT and DATA block devices
|
||||
// Unmount the ROOT and DATA block devices.
|
||||
if err = mount.Unmount(); err != nil {
|
||||
return
|
||||
}
|
||||
@ -76,23 +75,26 @@ func root() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Start the services essential to running Kubernetes.
|
||||
services := &service.Manager{
|
||||
UserData: data,
|
||||
}
|
||||
|
||||
// Start the Dianemo gRPC service.
|
||||
services.Start(&service.OSD{})
|
||||
|
||||
// Start the services essential to running Kubernetes.
|
||||
switch data.Kubernetes.ContainerRuntime {
|
||||
case constants.ContainerRuntimeDocker:
|
||||
services.Start(&service.Docker{})
|
||||
case constants.ContainerRuntimeCRIO:
|
||||
services.Start(&service.CRIO{})
|
||||
fallthrough
|
||||
default:
|
||||
services.Start(&service.CRIO{})
|
||||
}
|
||||
services.Start(&service.Kubelet{})
|
||||
services.Start(&service.Kubeadm{})
|
||||
|
||||
return server.NewServer(data.OS.Security).Listen()
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -107,4 +109,6 @@ func main() {
|
||||
if err := root(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
select {}
|
||||
}
|
@ -43,6 +43,9 @@ const (
|
||||
|
||||
// KubeadmCAKey is the path to the root CA private key.
|
||||
KubeadmCAKey = "/etc/kubernetes/pki/ca.key"
|
||||
|
||||
// UserDataPath is the path to the downloaded user data.
|
||||
UserDataPath = "/var/run/userdata.yaml"
|
||||
)
|
||||
|
||||
// See https://linux.die.net/man/3/klogctl
|
@ -7,7 +7,7 @@ import (
|
||||
"path"
|
||||
"text/template"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
)
|
||||
|
||||
const hostsTemplate = `
|
@ -8,9 +8,9 @@ import (
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/blkid"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/kernel"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/blkid"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/kernel"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
56
initramfs/cmd/init/pkg/rootfs/rootfs.go
Normal file
56
initramfs/cmd/init/pkg/rootfs/rootfs.go
Normal file
@ -0,0 +1,56 @@
|
||||
package rootfs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/etc"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func ip() string {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, address := range addrs {
|
||||
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
return ipnet.IP.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// Prepare creates the files required by the installed binaries and libraries.
|
||||
func Prepare(s string, userdata userdata.UserData) (err error) {
|
||||
// Create /etc/hosts.
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ip := ip()
|
||||
if err = etc.Hosts(s, hostname, ip); err != nil {
|
||||
return
|
||||
}
|
||||
// Create /etc/resolv.conf.
|
||||
if err = etc.ResolvConf(s, userdata); err != nil {
|
||||
return
|
||||
}
|
||||
// Save the user data to disk.
|
||||
data, err := yaml.Marshal(&userdata)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = ioutil.WriteFile(path.Join(constants.NewRoot, constants.UserDataPath), data, 0400); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
)
|
||||
|
||||
const crioConf = `
|
@ -1,8 +1,8 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
)
|
||||
|
||||
// Docker implements the Service interface. It serves as the concrete type with
|
@ -9,9 +9,9 @@ import (
|
||||
"path"
|
||||
"text/template"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
)
|
||||
|
||||
// MasterConfiguration is the kubeadm manifest for master nodes.
|
@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
)
|
||||
|
||||
// Kubelet implements the Service interface. It serves as the concrete type with
|
@ -3,12 +3,11 @@ package log
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/chunker"
|
||||
"github.com/autonomy/dianemo/initramfs/pkg/chunker"
|
||||
)
|
||||
|
||||
var instance = map[string]*Log{}
|
||||
@ -17,9 +16,9 @@ var mu = &sync.Mutex{}
|
||||
// Log represents the log of a service. It supports streaming of the contents of
|
||||
// the log file by way of implementing the chunker.Chunker interface.
|
||||
type Log struct {
|
||||
Name string
|
||||
Path string
|
||||
writeCloser io.WriteCloser
|
||||
Name string
|
||||
Path string
|
||||
source chunker.ChunkSource
|
||||
}
|
||||
|
||||
// New initializes and registers a log for a service.
|
||||
@ -27,16 +26,16 @@ func New(name string) (*Log, error) {
|
||||
if l, ok := instance[name]; ok {
|
||||
return l, nil
|
||||
}
|
||||
logpath := path.Join("/var/log", name)
|
||||
logpath := FormatLogPath(name)
|
||||
w, err := os.Create(logpath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create log file: %s", err.Error())
|
||||
}
|
||||
|
||||
l := &Log{
|
||||
Name: name,
|
||||
Path: logpath,
|
||||
writeCloser: w,
|
||||
Name: name,
|
||||
Path: logpath,
|
||||
source: w,
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
@ -46,27 +45,23 @@ func New(name string) (*Log, error) {
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// Chunker returns a chunker.Chunker implementation.
|
||||
func Chunker(name string) chunker.Chunker {
|
||||
if l, ok := instance[name]; ok {
|
||||
return l
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write implements io.WriteCloser.
|
||||
func (l *Log) Write(p []byte) (n int, err error) {
|
||||
return l.writeCloser.Write(p)
|
||||
return l.source.Write(p)
|
||||
}
|
||||
|
||||
// Close implements io.WriteCloser.
|
||||
func (l *Log) Close() error {
|
||||
return l.writeCloser.Close()
|
||||
return l.source.Close()
|
||||
}
|
||||
|
||||
// Read implements chunker.Chunker.
|
||||
func (l *Log) Read(ctx context.Context) <-chan []byte {
|
||||
c := chunker.NewDefaultChunker(l.Path)
|
||||
c := chunker.NewDefaultChunker(l.source)
|
||||
return c.Read(ctx)
|
||||
}
|
||||
|
||||
// FormatLogPath formats the path the log file.
|
||||
func FormatLogPath(p string) string {
|
||||
return path.Join("/var/log", p)
|
||||
}
|
38
initramfs/cmd/init/pkg/service/osd.go
Normal file
38
initramfs/cmd/init/pkg/service/osd.go
Normal file
@ -0,0 +1,38 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service/conditions"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
)
|
||||
|
||||
// OSD implements the Service interface. It serves as the concrete type with
|
||||
// the required methods.
|
||||
type OSD struct{}
|
||||
|
||||
// Pre implements the Service interface.
|
||||
func (p *OSD) Pre(data userdata.UserData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Cmd implements the Service interface.
|
||||
func (p *OSD) Cmd(data userdata.UserData) (name string, args []string) {
|
||||
name = "/bin/osd"
|
||||
args = []string{
|
||||
"--port=50000",
|
||||
"--userdata=" + constants.UserDataPath,
|
||||
}
|
||||
|
||||
return name, args
|
||||
}
|
||||
|
||||
// Condition implements the Service interface.
|
||||
func (p *OSD) Condition(data userdata.UserData) func() (bool, error) {
|
||||
return conditions.None()
|
||||
}
|
||||
|
||||
// Env implements the Service interface.
|
||||
func (p *OSD) Env() []string { return []string{} }
|
||||
|
||||
// Type implements the Service interface.
|
||||
func (p *OSD) Type() Type { return Forever }
|
@ -7,9 +7,9 @@ import (
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/constants"
|
||||
servicelog "github.com/autonomy/dianemo/initramfs/src/init/pkg/service/log"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
servicelog "github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service/log"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
)
|
||||
|
||||
// Type represents the service's restart policy.
|
@ -7,8 +7,8 @@ import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/mount"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/mount/cgroups"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/mount"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/mount/cgroups"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/kernel"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/kernel"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/client"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/osctl/pkg/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/crypto/x509"
|
||||
"github.com/autonomy/dianemo/initramfs/pkg/crypto/x509"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
"github.com/spf13/cobra"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
@ -5,7 +5,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/client"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/osctl/pkg/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/client"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/proto"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/osctl/pkg/client"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/osd/proto"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
7
initramfs/cmd/osctl/main.go
Normal file
7
initramfs/cmd/osctl/main.go
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "github.com/autonomy/dianemo/initramfs/cmd/osctl/cmd"
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
@ -10,7 +10,7 @@ import (
|
||||
"os/user"
|
||||
"path"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/proto"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/osd/proto"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
@ -24,11 +24,11 @@ type Credentials struct {
|
||||
key string
|
||||
}
|
||||
|
||||
// Client implements the proto.DianemoClient interface. It serves as the
|
||||
// Client implements the proto.OSDClient interface. It serves as the
|
||||
// concrete type with the required methods.
|
||||
type Client struct {
|
||||
conn *grpc.ClientConn
|
||||
client proto.DianemoClient
|
||||
client proto.OSDClient
|
||||
}
|
||||
|
||||
// NewDefaultClientCredentials initializes ClientCredentials using default paths
|
||||
@ -82,12 +82,12 @@ func NewClient(address string, port int, clientcreds *Credentials) (c *Client, e
|
||||
return
|
||||
}
|
||||
|
||||
c.client = proto.NewDianemoClient(c.conn)
|
||||
c.client = proto.NewOSDClient(c.conn)
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Kubeconfig implements the proto.DianemoClient interface.
|
||||
// Kubeconfig implements the proto.OSDClient interface.
|
||||
func (c *Client) Kubeconfig() (err error) {
|
||||
ctx := context.Background()
|
||||
r, err := c.client.Kubeconfig(ctx, &empty.Empty{})
|
||||
@ -99,7 +99,7 @@ func (c *Client) Kubeconfig() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dmesg implements the proto.DianemoClient interface.
|
||||
// Dmesg implements the proto.OSDClient interface.
|
||||
func (c *Client) Dmesg() (err error) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@ -112,7 +112,7 @@ func (c *Client) Dmesg() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Logs implements the proto.DianemoClient interface.
|
||||
// Logs implements the proto.OSDClient interface.
|
||||
func (c *Client) Logs(r *proto.LogsRequest) (err error) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
37
initramfs/cmd/osd/main.go
Normal file
37
initramfs/cmd/osd/main.go
Normal file
@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/osd/pkg/server"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
dataPath *string
|
||||
port *int
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetFlags(log.Lshortfile | log.Ldate | log.Lmicroseconds | log.Ltime)
|
||||
dataPath = flag.String("userdata", "", "the path to the user data")
|
||||
port = flag.Int("port", 50000, "the port to listen on")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func main() {
|
||||
fileBytes, err := ioutil.ReadFile(*dataPath)
|
||||
if err != nil {
|
||||
log.Fatalf("read user data: %v", err)
|
||||
}
|
||||
data := &userdata.UserData{}
|
||||
if err := yaml.Unmarshal(fileBytes, data); err != nil {
|
||||
log.Fatalf("unmarshal user data: %v", err)
|
||||
}
|
||||
if err := server.NewServer(*port, data.OS.Security).Listen(); err != nil {
|
||||
log.Fatalf("start gRPC server: %v", err)
|
||||
}
|
||||
}
|
@ -11,13 +11,14 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/chunker"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/constants"
|
||||
servicelog "github.com/autonomy/dianemo/initramfs/src/init/pkg/service/log"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/proto"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/constants"
|
||||
servicelog "github.com/autonomy/dianemo/initramfs/cmd/init/pkg/service/log"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/init/pkg/userdata"
|
||||
"github.com/autonomy/dianemo/initramfs/cmd/osd/proto"
|
||||
"github.com/autonomy/dianemo/initramfs/pkg/chunker"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/kubernetes-incubator/cri-o/client"
|
||||
"golang.org/x/sys/unix"
|
||||
@ -25,7 +26,7 @@ import (
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
// Server implements the proto.DianemoServer interface. It serves as the
|
||||
// Server implements the proto.OSDServer interface. It serves as the
|
||||
// concrete type with the required methods.
|
||||
type Server struct {
|
||||
server *grpc.Server
|
||||
@ -36,9 +37,9 @@ type Server struct {
|
||||
}
|
||||
|
||||
// NewServer initializes a Server.
|
||||
func NewServer(data *userdata.Security) (s *Server) {
|
||||
func NewServer(port int, data *userdata.Security) (s *Server) {
|
||||
s = &Server{
|
||||
port: 50000,
|
||||
port: port,
|
||||
ca: data.CA.Crt,
|
||||
crt: data.Identity.Crt,
|
||||
key: data.Identity.Key,
|
||||
@ -100,7 +101,7 @@ func (s *Server) Listen() (err error) {
|
||||
})
|
||||
grpcOpts = append(grpcOpts, grpc.Creds(creds))
|
||||
s.server = grpc.NewServer(grpcOpts...)
|
||||
proto.RegisterDianemoServer(s.server, s)
|
||||
proto.RegisterOSDServer(s.server, s)
|
||||
|
||||
log.Printf("Started gRPC on :%d", s.port)
|
||||
err = s.server.Serve(listener)
|
||||
@ -111,7 +112,7 @@ func (s *Server) Listen() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Kubeconfig implements the proto.DianemoServer interface. The admin kubeconfig
|
||||
// Kubeconfig implements the proto.OSDServer interface. The admin kubeconfig
|
||||
// is generated by kubeadm and placed at /etc/kubernetes/admin.conf. This method
|
||||
// returns the contents of the generated admin.conf and returns it in the
|
||||
// response.
|
||||
@ -127,12 +128,12 @@ func (s *Server) Kubeconfig(ctx context.Context, in *empty.Empty) (data *proto.D
|
||||
return data, err
|
||||
}
|
||||
|
||||
// Processes implements the proto.DianemoServer interface.
|
||||
// Processes implements the proto.OSDServer interface.
|
||||
func (s *Server) Processes(ctx context.Context, in *proto.ProcessesRequest) (r *proto.ProcessesReply, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Dmesg implements the proto.DianemoServer interface. The klogctl syscall is
|
||||
// Dmesg implements the proto.OSDServer interface. The klogctl syscall is
|
||||
// used to read from the ring buffer at /proc/kmsg by taking the
|
||||
// SYSLOG_ACTION_READ_ALL action. This action reads all messages remaining in
|
||||
// the ring buffer non-destructively.
|
||||
@ -154,29 +155,36 @@ func (s *Server) Dmesg(ctx context.Context, in *empty.Empty) (data *proto.Data,
|
||||
return data, err
|
||||
}
|
||||
|
||||
// Logs implements the proto.DianemoServer interface. Service or container logs
|
||||
// Logs implements the proto.OSDServer interface. Service or container logs
|
||||
// can be requested and the contents of the log file are streamed in chunks.
|
||||
func (s *Server) Logs(r *proto.LogsRequest, l proto.Dianemo_LogsServer) (err error) {
|
||||
func (s *Server) Logs(r *proto.LogsRequest, l proto.OSD_LogsServer) (err error) {
|
||||
var chunk chunker.ChunkReader
|
||||
if r.Container {
|
||||
// TODO: Use the specified container runtime.
|
||||
cli, e := client.New("/var/run/crio/crio.sock")
|
||||
if e != nil {
|
||||
err = e
|
||||
cli, _err := client.New("/var/run/crio/crio.sock")
|
||||
if _err != nil {
|
||||
err = _err
|
||||
return
|
||||
}
|
||||
info, e := cli.ContainerInfo(r.Process)
|
||||
if e != nil {
|
||||
err = e
|
||||
info, _err := cli.ContainerInfo(r.Process)
|
||||
if _err != nil {
|
||||
err = _err
|
||||
return
|
||||
}
|
||||
chunk = chunker.NewDefaultChunker(info.LogPath)
|
||||
file, _err := os.OpenFile(info.LogPath, os.O_RDONLY, 0)
|
||||
if _err != nil {
|
||||
err = _err
|
||||
return
|
||||
}
|
||||
chunk = chunker.NewDefaultChunker(file)
|
||||
} else {
|
||||
chunk = servicelog.Chunker(r.Process)
|
||||
if chunk == nil {
|
||||
err = fmt.Errorf("no such process: %s", r.Process)
|
||||
logpath := servicelog.FormatLogPath(r.Process)
|
||||
file, _err := os.OpenFile(logpath, os.O_RDONLY, 0)
|
||||
if _err != nil {
|
||||
err = _err
|
||||
return
|
||||
}
|
||||
chunk = chunker.NewDefaultChunker(file)
|
||||
}
|
||||
|
||||
for data := range chunk.Read(l.Context()) {
|
||||
@ -185,5 +193,5 @@ func (s *Server) Logs(r *proto.LogsRequest, l proto.Dianemo_LogsServer) (err err
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
@ -36,7 +36,7 @@ func (m *ProcessesRequest) Reset() { *m = ProcessesRequest{} }
|
||||
func (m *ProcessesRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ProcessesRequest) ProtoMessage() {}
|
||||
func (*ProcessesRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_api_7e61790eeabe0b0b, []int{0}
|
||||
return fileDescriptor_api_d41b6d9a87209f4b, []int{0}
|
||||
}
|
||||
func (m *ProcessesRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_ProcessesRequest.Unmarshal(m, b)
|
||||
@ -75,7 +75,7 @@ func (m *ProcessesReply) Reset() { *m = ProcessesReply{} }
|
||||
func (m *ProcessesReply) String() string { return proto.CompactTextString(m) }
|
||||
func (*ProcessesReply) ProtoMessage() {}
|
||||
func (*ProcessesReply) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_api_7e61790eeabe0b0b, []int{1}
|
||||
return fileDescriptor_api_d41b6d9a87209f4b, []int{1}
|
||||
}
|
||||
func (m *ProcessesReply) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_ProcessesReply.Unmarshal(m, b)
|
||||
@ -115,7 +115,7 @@ func (m *LogsRequest) Reset() { *m = LogsRequest{} }
|
||||
func (m *LogsRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*LogsRequest) ProtoMessage() {}
|
||||
func (*LogsRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_api_7e61790eeabe0b0b, []int{2}
|
||||
return fileDescriptor_api_d41b6d9a87209f4b, []int{2}
|
||||
}
|
||||
func (m *LogsRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_LogsRequest.Unmarshal(m, b)
|
||||
@ -161,7 +161,7 @@ func (m *Data) Reset() { *m = Data{} }
|
||||
func (m *Data) String() string { return proto.CompactTextString(m) }
|
||||
func (*Data) ProtoMessage() {}
|
||||
func (*Data) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_api_7e61790eeabe0b0b, []int{3}
|
||||
return fileDescriptor_api_d41b6d9a87209f4b, []int{3}
|
||||
}
|
||||
func (m *Data) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Data.Unmarshal(m, b)
|
||||
@ -203,47 +203,47 @@ var _ grpc.ClientConn
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion4
|
||||
|
||||
// Client API for Dianemo service
|
||||
// Client API for OSD service
|
||||
|
||||
type DianemoClient interface {
|
||||
type OSDClient interface {
|
||||
Kubeconfig(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*Data, error)
|
||||
Processes(ctx context.Context, in *ProcessesRequest, opts ...grpc.CallOption) (*ProcessesReply, error)
|
||||
Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Dianemo_LogsClient, error)
|
||||
Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (OSD_LogsClient, error)
|
||||
Dmesg(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*Data, error)
|
||||
}
|
||||
|
||||
type dianemoClient struct {
|
||||
type oSDClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewDianemoClient(cc *grpc.ClientConn) DianemoClient {
|
||||
return &dianemoClient{cc}
|
||||
func NewOSDClient(cc *grpc.ClientConn) OSDClient {
|
||||
return &oSDClient{cc}
|
||||
}
|
||||
|
||||
func (c *dianemoClient) Kubeconfig(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*Data, error) {
|
||||
func (c *oSDClient) Kubeconfig(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*Data, error) {
|
||||
out := new(Data)
|
||||
err := grpc.Invoke(ctx, "/proto.Dianemo/Kubeconfig", in, out, c.cc, opts...)
|
||||
err := grpc.Invoke(ctx, "/proto.OSD/Kubeconfig", in, out, c.cc, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *dianemoClient) Processes(ctx context.Context, in *ProcessesRequest, opts ...grpc.CallOption) (*ProcessesReply, error) {
|
||||
func (c *oSDClient) Processes(ctx context.Context, in *ProcessesRequest, opts ...grpc.CallOption) (*ProcessesReply, error) {
|
||||
out := new(ProcessesReply)
|
||||
err := grpc.Invoke(ctx, "/proto.Dianemo/Processes", in, out, c.cc, opts...)
|
||||
err := grpc.Invoke(ctx, "/proto.OSD/Processes", in, out, c.cc, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *dianemoClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Dianemo_LogsClient, error) {
|
||||
stream, err := grpc.NewClientStream(ctx, &_Dianemo_serviceDesc.Streams[0], c.cc, "/proto.Dianemo/Logs", opts...)
|
||||
func (c *oSDClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (OSD_LogsClient, error) {
|
||||
stream, err := grpc.NewClientStream(ctx, &_OSD_serviceDesc.Streams[0], c.cc, "/proto.OSD/Logs", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &dianemoLogsClient{stream}
|
||||
x := &oSDLogsClient{stream}
|
||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -253,16 +253,16 @@ func (c *dianemoClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Dianemo_LogsClient interface {
|
||||
type OSD_LogsClient interface {
|
||||
Recv() (*Data, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type dianemoLogsClient struct {
|
||||
type oSDLogsClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *dianemoLogsClient) Recv() (*Data, error) {
|
||||
func (x *oSDLogsClient) Recv() (*Data, error) {
|
||||
m := new(Data)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
@ -270,149 +270,149 @@ func (x *dianemoLogsClient) Recv() (*Data, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *dianemoClient) Dmesg(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*Data, error) {
|
||||
func (c *oSDClient) Dmesg(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*Data, error) {
|
||||
out := new(Data)
|
||||
err := grpc.Invoke(ctx, "/proto.Dianemo/Dmesg", in, out, c.cc, opts...)
|
||||
err := grpc.Invoke(ctx, "/proto.OSD/Dmesg", in, out, c.cc, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Dianemo service
|
||||
// Server API for OSD service
|
||||
|
||||
type DianemoServer interface {
|
||||
type OSDServer interface {
|
||||
Kubeconfig(context.Context, *empty.Empty) (*Data, error)
|
||||
Processes(context.Context, *ProcessesRequest) (*ProcessesReply, error)
|
||||
Logs(*LogsRequest, Dianemo_LogsServer) error
|
||||
Logs(*LogsRequest, OSD_LogsServer) error
|
||||
Dmesg(context.Context, *empty.Empty) (*Data, error)
|
||||
}
|
||||
|
||||
func RegisterDianemoServer(s *grpc.Server, srv DianemoServer) {
|
||||
s.RegisterService(&_Dianemo_serviceDesc, srv)
|
||||
func RegisterOSDServer(s *grpc.Server, srv OSDServer) {
|
||||
s.RegisterService(&_OSD_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _Dianemo_Kubeconfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _OSD_Kubeconfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(empty.Empty)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DianemoServer).Kubeconfig(ctx, in)
|
||||
return srv.(OSDServer).Kubeconfig(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/proto.Dianemo/Kubeconfig",
|
||||
FullMethod: "/proto.OSD/Kubeconfig",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DianemoServer).Kubeconfig(ctx, req.(*empty.Empty))
|
||||
return srv.(OSDServer).Kubeconfig(ctx, req.(*empty.Empty))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Dianemo_Processes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _OSD_Processes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ProcessesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DianemoServer).Processes(ctx, in)
|
||||
return srv.(OSDServer).Processes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/proto.Dianemo/Processes",
|
||||
FullMethod: "/proto.OSD/Processes",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DianemoServer).Processes(ctx, req.(*ProcessesRequest))
|
||||
return srv.(OSDServer).Processes(ctx, req.(*ProcessesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Dianemo_Logs_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
func _OSD_Logs_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
m := new(LogsRequest)
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return srv.(DianemoServer).Logs(m, &dianemoLogsServer{stream})
|
||||
return srv.(OSDServer).Logs(m, &oSDLogsServer{stream})
|
||||
}
|
||||
|
||||
type Dianemo_LogsServer interface {
|
||||
type OSD_LogsServer interface {
|
||||
Send(*Data) error
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type dianemoLogsServer struct {
|
||||
type oSDLogsServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *dianemoLogsServer) Send(m *Data) error {
|
||||
func (x *oSDLogsServer) Send(m *Data) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func _Dianemo_Dmesg_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _OSD_Dmesg_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(empty.Empty)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DianemoServer).Dmesg(ctx, in)
|
||||
return srv.(OSDServer).Dmesg(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/proto.Dianemo/Dmesg",
|
||||
FullMethod: "/proto.OSD/Dmesg",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DianemoServer).Dmesg(ctx, req.(*empty.Empty))
|
||||
return srv.(OSDServer).Dmesg(ctx, req.(*empty.Empty))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _Dianemo_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "proto.Dianemo",
|
||||
HandlerType: (*DianemoServer)(nil),
|
||||
var _OSD_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "proto.OSD",
|
||||
HandlerType: (*OSDServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Kubeconfig",
|
||||
Handler: _Dianemo_Kubeconfig_Handler,
|
||||
Handler: _OSD_Kubeconfig_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Processes",
|
||||
Handler: _Dianemo_Processes_Handler,
|
||||
Handler: _OSD_Processes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Dmesg",
|
||||
Handler: _Dianemo_Dmesg_Handler,
|
||||
Handler: _OSD_Dmesg_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
StreamName: "Logs",
|
||||
Handler: _Dianemo_Logs_Handler,
|
||||
Handler: _OSD_Logs_Handler,
|
||||
ServerStreams: true,
|
||||
},
|
||||
},
|
||||
Metadata: "api.proto",
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("api.proto", fileDescriptor_api_7e61790eeabe0b0b) }
|
||||
func init() { proto.RegisterFile("api.proto", fileDescriptor_api_d41b6d9a87209f4b) }
|
||||
|
||||
var fileDescriptor_api_7e61790eeabe0b0b = []byte{
|
||||
// 264 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xbf, 0x4e, 0xc3, 0x30,
|
||||
0x10, 0x87, 0x1b, 0xd4, 0x52, 0x72, 0x45, 0x08, 0x9d, 0xf8, 0x13, 0x85, 0x0e, 0x95, 0xa7, 0x0a,
|
||||
0x90, 0x8b, 0xe8, 0xcc, 0x96, 0x4e, 0x30, 0xa0, 0xbc, 0x81, 0x13, 0x5d, 0xa3, 0x48, 0x89, 0x6d,
|
||||
0x62, 0x67, 0xc8, 0xab, 0xf2, 0x34, 0xc8, 0x71, 0x02, 0x55, 0x19, 0x60, 0xb2, 0x7e, 0x77, 0x9f,
|
||||
0xef, 0xfc, 0x19, 0x42, 0xa1, 0x4b, 0xae, 0x1b, 0x65, 0x15, 0xce, 0xfa, 0x23, 0xbe, 0x2b, 0x94,
|
||||
0x2a, 0x2a, 0xda, 0xf4, 0x29, 0x6b, 0xf7, 0x1b, 0xaa, 0xb5, 0xed, 0x3c, 0xc3, 0x1e, 0xe1, 0xf2,
|
||||
0xbd, 0x51, 0x39, 0x19, 0x43, 0x26, 0xa5, 0x8f, 0x96, 0x8c, 0xc5, 0x08, 0xe6, 0xda, 0xd7, 0xa2,
|
||||
0x60, 0x15, 0xac, 0xc3, 0x74, 0x8c, 0xec, 0x1e, 0x2e, 0x0e, 0x68, 0x5d, 0x75, 0x8e, 0xcd, 0x95,
|
||||
0xb4, 0x24, 0x6d, 0xcf, 0x9e, 0xa7, 0x63, 0x64, 0x3b, 0x58, 0xbc, 0xa9, 0xe2, 0xef, 0xa1, 0xb8,
|
||||
0x84, 0xd0, 0xdd, 0x11, 0xa5, 0xa4, 0x26, 0x3a, 0x59, 0x05, 0xeb, 0xb3, 0xf4, 0xa7, 0xc0, 0x96,
|
||||
0x30, 0x4d, 0x84, 0x15, 0x78, 0x05, 0xb3, 0xac, 0xb3, 0x64, 0x86, 0x35, 0x3e, 0x3c, 0x7f, 0x06,
|
||||
0x30, 0x4f, 0x4a, 0x21, 0xa9, 0x56, 0xb8, 0x05, 0x78, 0x6d, 0x33, 0xca, 0x95, 0xdc, 0x97, 0x05,
|
||||
0xde, 0x70, 0xaf, 0xcd, 0x47, 0x6d, 0xbe, 0x73, 0xda, 0xf1, 0xc2, 0x17, 0xb8, 0x1b, 0xca, 0x26,
|
||||
0xf8, 0x02, 0xe1, 0xb7, 0x11, 0xde, 0x0e, 0xbd, 0xe3, 0x1f, 0x89, 0xaf, 0x7f, 0x37, 0x74, 0xd5,
|
||||
0xb1, 0x09, 0x3e, 0xc0, 0xd4, 0x49, 0x22, 0x0e, 0xc0, 0x81, 0xf1, 0xd1, 0xa6, 0xa7, 0x00, 0x39,
|
||||
0xcc, 0x92, 0x9a, 0xcc, 0x7f, 0xdf, 0x96, 0x9d, 0xf6, 0x69, 0xfb, 0x15, 0x00, 0x00, 0xff, 0xff,
|
||||
0x1a, 0x57, 0x7d, 0xd0, 0xd3, 0x01, 0x00, 0x00,
|
||||
var fileDescriptor_api_d41b6d9a87209f4b = []byte{
|
||||
// 263 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xcf, 0x4e, 0x84, 0x30,
|
||||
0x10, 0x87, 0xb7, 0xba, 0xa8, 0xcc, 0x1a, 0x63, 0x26, 0xfe, 0x21, 0xb8, 0x87, 0x4d, 0x4f, 0x1b,
|
||||
0x35, 0x5d, 0xe3, 0x9e, 0xbd, 0xb1, 0x27, 0x4d, 0x34, 0xf8, 0x04, 0x40, 0x66, 0x09, 0x09, 0x4b,
|
||||
0x2b, 0x2d, 0x07, 0x5e, 0xd4, 0xe7, 0x31, 0xa5, 0xa0, 0x1b, 0x3c, 0xe8, 0xa9, 0xf9, 0xcd, 0x7c,
|
||||
0x9d, 0xe9, 0x57, 0xf0, 0x13, 0x55, 0x08, 0x55, 0x4b, 0x23, 0xd1, 0xeb, 0x8e, 0xf0, 0x26, 0x97,
|
||||
0x32, 0x2f, 0x69, 0xd5, 0xa5, 0xb4, 0xd9, 0xae, 0x68, 0xa7, 0x4c, 0xeb, 0x18, 0x7e, 0x0f, 0xe7,
|
||||
0x6f, 0xb5, 0xcc, 0x48, 0x6b, 0xd2, 0x31, 0x7d, 0x34, 0xa4, 0x0d, 0x06, 0x70, 0xac, 0x5c, 0x2d,
|
||||
0x60, 0x0b, 0xb6, 0xf4, 0xe3, 0x21, 0xf2, 0x5b, 0x38, 0xdb, 0xa3, 0x55, 0xd9, 0x5a, 0x36, 0x93,
|
||||
0x95, 0xa1, 0xca, 0x74, 0xec, 0x69, 0x3c, 0x44, 0xbe, 0x81, 0xd9, 0x8b, 0xcc, 0xff, 0x1e, 0x8a,
|
||||
0x73, 0xf0, 0xed, 0x9d, 0xa4, 0xa8, 0xa8, 0x0e, 0x0e, 0x16, 0x6c, 0x79, 0x12, 0xff, 0x14, 0xf8,
|
||||
0x1c, 0xa6, 0x51, 0x62, 0x12, 0xbc, 0x00, 0x2f, 0x6d, 0x0d, 0xe9, 0x7e, 0x8d, 0x0b, 0x8f, 0x9f,
|
||||
0x0c, 0x0e, 0x5f, 0xdf, 0x23, 0x5c, 0x03, 0x3c, 0x37, 0x29, 0x65, 0xb2, 0xda, 0x16, 0x39, 0x5e,
|
||||
0x09, 0xa7, 0x2c, 0x06, 0x65, 0xb1, 0xb1, 0xca, 0xe1, 0xcc, 0x15, 0x84, 0x1d, 0xc8, 0x27, 0xf8,
|
||||
0x04, 0xfe, 0xb7, 0x0d, 0x5e, 0xf7, 0xbd, 0xf1, 0x6f, 0x84, 0x97, 0xbf, 0x1b, 0xaa, 0x6c, 0xf9,
|
||||
0x04, 0xef, 0x60, 0x6a, 0x05, 0x11, 0x7b, 0x60, 0xcf, 0x76, 0xb4, 0xe9, 0x81, 0xa1, 0x00, 0x2f,
|
||||
0xda, 0x91, 0xfe, 0xef, 0xdb, 0xd2, 0xa3, 0x2e, 0xad, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x47,
|
||||
0x96, 0x39, 0x24, 0xcf, 0x01, 0x00, 0x00,
|
||||
}
|
@ -5,8 +5,8 @@ package proto;
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
// The Dianemo service definition.
|
||||
service Dianemo {
|
||||
// The OSD service definition.
|
||||
service OSD {
|
||||
rpc Kubeconfig(google.protobuf.Empty) returns (Data) {}
|
||||
rpc Processes(ProcessesRequest) returns (ProcessesReply) {}
|
||||
rpc Logs(LogsRequest) returns (stream Data) {}
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Chunker is an interface for embedding all chunking interfaces under one name.
|
||||
@ -20,12 +19,20 @@ type ChunkReader interface {
|
||||
|
||||
// DefaultChunker is a conecrete type that implements the Chunker interface.
|
||||
type DefaultChunker struct {
|
||||
path string
|
||||
source ChunkSource
|
||||
options *Options
|
||||
}
|
||||
|
||||
// ChunkSource is an interface describing the source of a Chunker.
|
||||
type ChunkSource interface {
|
||||
io.ReaderAt
|
||||
io.Seeker
|
||||
io.Closer
|
||||
io.Writer
|
||||
}
|
||||
|
||||
// NewDefaultChunker initializes a DefaultChunker with default values.
|
||||
func NewDefaultChunker(path string, setters ...Option) Chunker {
|
||||
func NewDefaultChunker(source ChunkSource, setters ...Option) Chunker {
|
||||
opts := &Options{
|
||||
Size: 1024,
|
||||
}
|
||||
@ -33,8 +40,9 @@ func NewDefaultChunker(path string, setters ...Option) Chunker {
|
||||
for _, setter := range setters {
|
||||
setter(opts)
|
||||
}
|
||||
|
||||
return &DefaultChunker{
|
||||
path,
|
||||
source,
|
||||
opts,
|
||||
}
|
||||
}
|
||||
@ -58,17 +66,13 @@ func Size(s int) Option {
|
||||
func (c *DefaultChunker) Read(ctx context.Context) <-chan []byte {
|
||||
// Create a buffered channel of length 1.
|
||||
ch := make(chan []byte, 1)
|
||||
file, err := os.OpenFile(c.path, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
go func(ch chan []byte, f *os.File) {
|
||||
go func(ch chan []byte) {
|
||||
defer close(ch)
|
||||
// nolint: errcheck
|
||||
defer f.Close()
|
||||
defer c.source.Close()
|
||||
|
||||
offset, err := f.Seek(0, io.SeekStart)
|
||||
offset, err := c.source.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -78,10 +82,10 @@ func (c *DefaultChunker) Read(ctx context.Context) <-chan []byte {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
n, err := f.ReadAt(buf, offset)
|
||||
n, err := c.source.ReadAt(buf, offset)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
fmt.Printf("read %s: %s\n", c.path, err.Error())
|
||||
fmt.Printf("read error: %s\n", err.Error())
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -98,7 +102,7 @@ func (c *DefaultChunker) Read(ctx context.Context) <-chan []byte {
|
||||
}
|
||||
}
|
||||
}
|
||||
}(ch, file)
|
||||
}(ch)
|
||||
|
||||
return ch
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package main
|
||||
|
||||
import "github.com/autonomy/dianemo/initramfs/src/init/cli/cmd"
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package rootfs
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/etc"
|
||||
"github.com/autonomy/dianemo/initramfs/src/init/pkg/userdata"
|
||||
)
|
||||
|
||||
func ip() string {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, address := range addrs {
|
||||
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
return ipnet.IP.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// Prepare creates the files required by the installed binaries and libraries.
|
||||
func Prepare(s string, userdata userdata.UserData) error {
|
||||
// Create /etc/hosts
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ip := ip()
|
||||
if err := etc.Hosts(s, hostname, ip); err != nil {
|
||||
return err
|
||||
}
|
||||
// Create /etc/resolv.conf
|
||||
if err := etc.ResolvConf(s, userdata); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user