diff --git a/cmd/eli/buildCommand.go b/cmd/eli/buildCommand.go index 9a44972a..02539e7a 100644 --- a/cmd/eli/buildCommand.go +++ b/cmd/eli/buildCommand.go @@ -7,13 +7,13 @@ import ( var buildCommand = cli.Command{ Name: "build", HelpName: "build", - Usage: `Build Device image, etc.`, - Description: "With build command, you can build device image, etc.", + Usage: `Build node image, etc.`, + Description: "With build command, you can build node image, etc.", ArgsUsage: `eli build [options] - # build device image - eli build device`, + # build node image + eli build node`, Subcommands: []cli.Command{ - buildDeviceCommand, + buildNodeCommand, }, } diff --git a/cmd/eli/buildDeviceCommand.go b/cmd/eli/buildNodeCommand.go similarity index 87% rename from cmd/eli/buildDeviceCommand.go rename to cmd/eli/buildNodeCommand.go index 103ed204..1e45b684 100644 --- a/cmd/eli/buildDeviceCommand.go +++ b/cmd/eli/buildNodeCommand.go @@ -12,22 +12,22 @@ import ( "github.com/urfave/cli" ) -var buildDeviceCommand = cli.Command{ - Name: "device", - Aliases: []string{"dev", "devices"}, - Usage: "Build device image", - UsageText: `eli build device [options] [FILE | URL] +var buildNodeCommand = cli.Command{ + Name: "node", + Aliases: []string{"nodes", "device"}, // device is deprecated command + Usage: "Build node image", + UsageText: `eli build node [options] [FILE | URL] - # Build default device image - eli build device + # Build default node image + eli build node # Create Linuxkit file but don't build it - eli build device --dry-run - eli build device --dry-run > custom-linuxkit.yml + eli build node --dry-run + eli build node --dry-run > custom-linuxkit.yml # Build from custom config and unpack to directory mkdir dist - eli build device custom-linuxkit.yml | tar xv -C dist + eli build node custom-linuxkit.yml | tar xv -C dist `, Flags: []cli.Flag{ cli.BoolFlag{ diff --git a/cmd/eli/configCommand.go b/cmd/eli/configCommand.go index 147de711..49ee781e 100644 --- a/cmd/eli/configCommand.go +++ b/cmd/eli/configCommand.go @@ -9,7 +9,7 @@ var configCommand = cli.Command{ HelpName: "config", Usage: `View and edit client configuration`, Description: `With this command you view and edit the client configurations - like device address, username, namespace, etc.`, + like ndoe address, username, namespace, etc.`, ArgsUsage: "eli config view", Subcommands: []cli.Command{ configViewCommand, diff --git a/cmd/eli/createCommand.go b/cmd/eli/createCommand.go index 21dbf6dd..accae75a 100644 --- a/cmd/eli/createCommand.go +++ b/cmd/eli/createCommand.go @@ -16,7 +16,7 @@ var createCommand = cli.Command{ Name: "create", HelpName: "create", Usage: "Create pod based on yaml spec", - Description: "With create command, you can create new pod into the device based on yaml specification", + Description: "With create command, you can create new pod into the node based on yaml specification", UsageText: `eli create [options] -f ./pod.yml # Create pod based on pod.yml diff --git a/cmd/eli/createPodCommand.go b/cmd/eli/createPodCommand.go index 6a0a9d61..67a81f00 100644 --- a/cmd/eli/createPodCommand.go +++ b/cmd/eli/createPodCommand.go @@ -16,7 +16,7 @@ var createPodCommand = cli.Command{ Name: "pod", HelpName: "pod", Usage: "Create new pod", - Description: "With create pod command, you can create new pod into the device", + Description: "With create pod command, you can create new pod into the node", UsageText: `eli create pod [options] # Create new pod 'my-pod' and create single container diff --git a/cmd/eli/describeCommand.go b/cmd/eli/describeCommand.go index 88afae47..c7083df9 100644 --- a/cmd/eli/describeCommand.go +++ b/cmd/eli/describeCommand.go @@ -19,6 +19,6 @@ var describeCommand = cli.Command{ `, Subcommands: []cli.Command{ describePodCommand, - describeDeviceCommand, + describeNodeCommand, }, } diff --git a/cmd/eli/describeDeviceCommand.go b/cmd/eli/describeNodeCommand.go similarity index 69% rename from cmd/eli/describeDeviceCommand.go rename to cmd/eli/describeNodeCommand.go index 964d9d36..3c3c0814 100644 --- a/cmd/eli/describeDeviceCommand.go +++ b/cmd/eli/describeNodeCommand.go @@ -12,17 +12,17 @@ import ( "github.com/urfave/cli" ) -var describeDeviceCommand = cli.Command{ - Name: "device", - Aliases: []string{"devices"}, - Usage: "Return details of device", - UsageText: `eli describe device [options] [NAME | IP] +var describeNodeCommand = cli.Command{ + Name: "node", + Aliases: []string{"nodes", "device"}, // device is deprecated command + Usage: "Return details of node", + UsageText: `eli describe node [options] [NAME | IP] - # Describe device - eli describe device my-device + # Describe node + eli describe node my-node # Describe all pods - eli describe devices + eli describe nodes `, Action: func(clicontext *cli.Context) error { cfg := cmd.GetConfigProvider(clicontext) @@ -45,9 +45,9 @@ var describeDeviceCommand = cli.Command{ for _, endpoint := range endpoints { info, err := api.NewClient(cfg.GetNamespace(), endpoint).GetInfo() if err != nil { - return errors.Wrap(err, "Failed to fetch device info") + return errors.Wrap(err, "Failed to fetch node info") } - if err := printer.PrintDevice(info, writer); err != nil { + if err := printer.PrintNode(info, writer); err != nil { return err } } diff --git a/cmd/eli/getCommand.go b/cmd/eli/getCommand.go index 453aedaf..2e191d19 100644 --- a/cmd/eli/getCommand.go +++ b/cmd/eli/getCommand.go @@ -15,6 +15,6 @@ var getCommand = cli.Command{ eli get pods`, Subcommands: []cli.Command{ getPodsCommand, - getDevicesCommand, + getNodesCommand, }, } diff --git a/cmd/eli/getDevicesCommand.go b/cmd/eli/getNodesCommand.go similarity index 51% rename from cmd/eli/getDevicesCommand.go rename to cmd/eli/getNodesCommand.go index cae0f553..c1836b7b 100644 --- a/cmd/eli/getDevicesCommand.go +++ b/cmd/eli/getNodesCommand.go @@ -11,27 +11,27 @@ import ( "github.com/urfave/cli" ) -var getDevicesCommand = cli.Command{ - Name: "devices", - Aliases: []string{"device"}, - Usage: "Get Device resources", - UsageText: `eli get devices [options] +var getNodesCommand = cli.Command{ + Name: "nodes", + Aliases: []string{"node", "devices"}, // devices is deprecated command + Usage: "Get Node resources", + UsageText: `eli get nodes [options] - # Get table of known devices - eli get devices`, + # Get table of known nodes + eli get nodes`, Action: func(clicontext *cli.Context) error { uiline := ui.NewLine().Loading("Discover from network automatically...") - devices, err := discovery.Devices(5 * time.Second) + nodes, err := discovery.Nodes(5 * time.Second) if err != nil { - uiline.Fatalf("Failed to auto-discover devices in network: %s", err) + uiline.Fatalf("Failed to auto-discover nodes in network: %s", err) } - uiline.Donef("Discovered %d devices from network", len(devices)) + uiline.Donef("Discovered %d nodes from network", len(nodes)) writer := printers.GetNewTabWriter(os.Stdout) defer writer.Flush() printer := cmd.GetPrinter(clicontext) - return printer.PrintDevices(devices, writer) + return printer.PrintNodes(nodes, writer) }, } diff --git a/cmd/eli/main.go b/cmd/eli/main.go index fa5a3e25..5f9434f0 100644 --- a/cmd/eli/main.go +++ b/cmd/eli/main.go @@ -21,20 +21,20 @@ func main() { app.Usage = `commandline interface for managing eliot` app.UsageText = `eli [global options] command [command options] [arguments...] - # Detect devices - eli get devices + # Detect nodes + eli get nodes # Get running pods eli get pods - # Get pods in device - eli --device hostname.local. get pods + # Get pods in node + eli --node hostname.local. get pods # See help of commands eli run --help ` - app.Description = `The 'eli' is tool for managing agent in the device. - With this tool, you can create, view and remove containers from the device.` + app.Description = `The 'eli' is tool for managing agent in the node. + With this tool, you can create, view and remove containers from the node.` app.Flags = append([]cli.Flag{ cli.StringFlag{ Name: "config, c", @@ -49,13 +49,13 @@ func main() { }, cli.StringFlag{ Name: "endpoint", - Usage: "Use specific device endpoint. E.g. '192.168.1.101:5000'", + Usage: "Use specific node endpoint. E.g. '192.168.1.101:5000'", EnvVar: "ELIOT_ENDPOINT", }, cli.StringFlag{ - Name: "device", - Usage: "Use specific device by name. E.g. 'somehost.local'", - EnvVar: "ELIOT_DEVICE", + Name: "node", + Usage: "Use specific node by name. E.g. 'somehost.local'", + EnvVar: "ELIOT_NODE", }, }, cmd.GlobalFlags...) app.Version = fmt.Sprintf("Version: %s, Commit: %s, Build at: %s", version, commit, date) diff --git a/cmd/eli/runCommand.go b/cmd/eli/runCommand.go index 9732ebc5..84b4f040 100644 --- a/cmd/eli/runCommand.go +++ b/cmd/eli/runCommand.go @@ -24,8 +24,8 @@ import ( var runCommand = cli.Command{ Name: "run", HelpName: "run", - Usage: "Run command in new container in the device", - Description: "With run command, you can run command in a new container in the device", + Usage: "Run command in new container in the node", + Description: "With run command, you can run command in a new container in the node", UsageText: `eli run [options] -- # Run shell session in 'eaapa/hello-world' container @@ -93,7 +93,7 @@ var runCommand = cli.Command{ uiline := ui.NewLine().Loading("Resolve image for the project...") info, err := client.GetInfo() if err != nil { - uiline.Fatalf("Unable to resolve image for the project. Failed to get target device architecture: %s", err) + uiline.Fatalf("Unable to resolve image for the project. Failed to get target node architecture: %s", err) } var projectType string diff --git a/cmd/eli/upCommand.go b/cmd/eli/upCommand.go index 7f357854..ad65d6d1 100644 --- a/cmd/eli/upCommand.go +++ b/cmd/eli/upCommand.go @@ -28,20 +28,20 @@ import ( var upCommand = cli.Command{ Name: "up", HelpName: "up", - Usage: "Start development session in the device", - Description: "With up command, you can start new development session in the device", + Usage: "Start development session in the node", + Description: "With up command, you can start new development session in the node", UsageText: `eli up [options] -- - # Run code in current directory in the device + # Run code in current directory in the node eli up - # Run 'build.sh' command in device with files in current directory + # Run 'build.sh' command in node with files in current directory eli up -- ./build.sh # Run container image in the container eli up --image docker.io/eaapa/hello-world:latest - # Run container with name in the device + # Run container with name in the node eli up --image docker.io/eaapa/hello-world:latest --name my-pod `, Flags: []cli.Flag{ @@ -117,7 +117,7 @@ var upCommand = cli.Command{ log := ui.NewLine().Loading("Resolve image for the project...") info, err := client.GetInfo() if err != nil { - log.Fatalf("Unable to resolve image for the project. Failed to get target device architecture: %s", err) + log.Fatalf("Unable to resolve image for the project. Failed to get target node architecture: %s", err) } var projectType string diff --git a/cmd/eliotd/main.go b/cmd/eliotd/main.go index 77e01b70..6d4bb029 100644 --- a/cmd/eliotd/main.go +++ b/cmd/eliotd/main.go @@ -11,8 +11,8 @@ import ( "github.com/ernoaapa/eliot/cmd" "github.com/ernoaapa/eliot/pkg/api" "github.com/ernoaapa/eliot/pkg/controller" - "github.com/ernoaapa/eliot/pkg/device" "github.com/ernoaapa/eliot/pkg/discovery" + "github.com/ernoaapa/eliot/pkg/node" "github.com/ernoaapa/eliot/pkg/profile" log "github.com/sirupsen/logrus" "github.com/thejerf/suture" @@ -27,7 +27,7 @@ var date = time.Now().Format("2006-01-02_15:04:05") func main() { app := cli.NewApp() app.Name = "eliotd" - app.Usage = "Daemon for the device to enable Eliot" + app.Usage = "Daemon for the node to enable Eliot" app.UsageText = `eliotd [arguments...] # By default listen port 5000 @@ -85,7 +85,7 @@ func main() { }, cli.StringFlag{ Name: "labels", - Usage: "Comma separated list of device labels. E.g. --labels device=rpi3,location=home,environment=testing", + Usage: "Comma separated list of node labels. E.g. --labels node=rpi3,location=home,environment=testing", EnvVar: "ELIOT_LABELS", }, }, cmd.GlobalFlags...) @@ -98,9 +98,9 @@ func main() { grpcPort = parseGrpcPort(grpcListen) ) - resolver := device.NewResolver(cmd.GetLabels(clicontext)) - device := resolver.GetInfo(grpcPort, version) - client := cmd.GetRuntimeClient(clicontext, device.Hostname) + resolver := node.NewResolver(cmd.GetLabels(clicontext)) + node := resolver.GetInfo(grpcPort, version) + client := cmd.GetRuntimeClient(clicontext, node.Hostname) supervisor := suture.NewSimple("eliotd") serviceCount := 0 @@ -114,7 +114,7 @@ func main() { if clicontext.Bool("grpc-api") { log.Infoln("grpc-api enabled") - supervisor.Add(api.NewServer(grpcListen, client, device)) + supervisor.Add(api.NewServer(grpcListen, client, node)) serviceCount++ } @@ -126,7 +126,7 @@ func main() { if clicontext.Bool("grpc-api") && clicontext.Bool("discovery") { log.Infoln("grpc discovery over zeroconf enabled") - supervisor.Add(discovery.NewServer(device.Hostname, grpcPort, version)) + supervisor.Add(discovery.NewServer(node.Hostname, grpcPort, version)) serviceCount++ } diff --git a/cmd/utils.go b/cmd/utils.go index b65b0f72..5e23eb57 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -79,7 +79,7 @@ func GetClient(config *config.Provider) *api.Client { endpoints := config.GetEndpoints() switch len(endpoints) { case 0: - uiline.Fatal("No devices to connect. You must give device endpoint. E.g. --endpoint=192.168.1.2") + uiline.Fatal("No node to connect. You must give node endpoint. E.g. --endpoint=192.168.1.2") return nil case 1: uiline.Loadingf("Connecting to %s (%s)", endpoints[0].Name, endpoints[0].URL) @@ -92,7 +92,7 @@ func GetClient(config *config.Provider) *api.Client { uiline.Donef("Connected to %s (%s)", info.Hostname, endpoints[0].URL) return client default: - uiline.Fatalf("%d devices found. You must give target device. E.g. --endpoint=192.168.1.2", len(endpoints)) + uiline.Fatalf("%d node found. You must give target node. E.g. --endpoint=192.168.1.2", len(endpoints)) return nil } } @@ -126,34 +126,34 @@ func GetConfigProvider(clicontext *cli.Context) *config.Provider { if len(provider.GetEndpoints()) == 0 { uiline := ui.NewLine().Loading("Discover from network automatically...") - devices, err := discovery.Devices(2 * time.Second) + node, err := discovery.Nodes(2 * time.Second) if err != nil { - uiline.Errorf("Failed to auto-discover devices in network: %s", err) + uiline.Errorf("Failed to auto-discover node in network: %s", err) } else { - if len(devices) == 0 { - uiline.Warn("No devices discovered from network") + if len(node) == 0 { + uiline.Warn("No node discovered from network") } else { - uiline.Donef("Discovered %d device(s) from network", len(devices)) + uiline.Donef("Discovered %d node(s) from network", len(node)) } } endpoints := []config.Endpoint{} - for _, device := range devices { - if len(device.Addresses) > 0 { + for _, node := range node { + if len(node.Addresses) > 0 { endpoints = append(endpoints, config.Endpoint{ - Name: device.Hostname, - URL: fmt.Sprintf("%s:%d", utils.GetFirst(device.Addresses, ""), device.GrpcPort), + Name: node.Hostname, + URL: fmt.Sprintf("%s:%d", utils.GetFirst(node.Addresses, ""), node.GrpcPort), }) } } provider.OverrideEndpoints(endpoints) } - if clicontext.GlobalIsSet("device") && clicontext.GlobalString("device") != "" { - deviceName := clicontext.GlobalString("device") - endpoint, found := provider.GetEndpointByName(deviceName) + if clicontext.GlobalIsSet("node") && clicontext.GlobalString("node") != "" { + nodeName := clicontext.GlobalString("node") + endpoint, found := provider.GetEndpointByName(nodeName) if !found { - ui.NewLine().Errorf("Failed to find device with name %s", deviceName) + ui.NewLine().Errorf("Failed to find node with name %s", nodeName) } provider.OverrideEndpoints([]config.Endpoint{endpoint}) } diff --git a/pkg/api/client.go b/pkg/api/client.go index 353597cb..54ae2b8a 100644 --- a/pkg/api/client.go +++ b/pkg/api/client.go @@ -14,7 +14,7 @@ import ( "github.com/ernoaapa/eliot/pkg/api/mapping" containers "github.com/ernoaapa/eliot/pkg/api/services/containers/v1" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" pods "github.com/ernoaapa/eliot/pkg/api/services/pods/v1" "github.com/ernoaapa/eliot/pkg/api/stream" "github.com/ernoaapa/eliot/pkg/config" @@ -22,7 +22,7 @@ import ( "github.com/rs/xid" ) -// Client connects directly to device RPC API +// Client connects directly to node RPC API type Client struct { Namespace string Endpoint config.Endpoint @@ -38,16 +38,16 @@ func NewClient(namespace string, endpoint config.Endpoint) *Client { } } -// GetInfo calls server and get device info -func (c *Client) GetInfo() (*device.Info, error) { +// GetInfo calls server and get node info +func (c *Client) GetInfo() (*node.Info, error) { conn, err := grpc.Dial(c.Endpoint.URL, grpc.WithInsecure()) if err != nil { return nil, err } defer conn.Close() - client := device.NewDeviceClient(conn) - resp, err := client.Info(c.ctx, &device.InfoRequest{}) + client := node.NewNodeClient(conn) + resp, err := client.Info(c.ctx, &node.InfoRequest{}) if err != nil { return nil, err } @@ -89,7 +89,7 @@ func (c *Client) GetPod(podName string) (*pods.Pod, error) { return nil, fmt.Errorf("Pod with name [%s] not found", podName) } -// CreatePod creates new pod to the device +// CreatePod creates new pod to the node func (c *Client) CreatePod(status chan<- []*progress.ImageFetch, pod *pods.Pod, opts ...PodOpts) error { for _, o := range opts { err := o(pod) @@ -126,7 +126,7 @@ func (c *Client) CreatePod(status chan<- []*progress.ImageFetch, pod *pods.Pod, } } -// StartPod starts created pod in device +// StartPod starts created pod in node func (c *Client) StartPod(name string) (*pods.Pod, error) { conn, err := grpc.Dial(c.Endpoint.URL, grpc.WithInsecure()) if err != nil { @@ -146,7 +146,7 @@ func (c *Client) StartPod(name string) (*pods.Pod, error) { return resp.GetPod(), nil } -// DeletePod removes pod from the device +// DeletePod removes pod from the node func (c *Client) DeletePod(pod *pods.Pod) (*pods.Pod, error) { conn, err := grpc.Dial(c.Endpoint.URL, grpc.WithInsecure()) if err != nil { diff --git a/pkg/api/mapping/internal.go b/pkg/api/mapping/internal.go index 79a56e0a..7d93cb90 100644 --- a/pkg/api/mapping/internal.go +++ b/pkg/api/mapping/internal.go @@ -5,14 +5,14 @@ import ( core "github.com/ernoaapa/eliot/pkg/api/core" containers "github.com/ernoaapa/eliot/pkg/api/services/containers/v1" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" pods "github.com/ernoaapa/eliot/pkg/api/services/pods/v1" "github.com/ernoaapa/eliot/pkg/model" ) -// MapInfoToAPIModel maps internal device info model to API model -func MapInfoToAPIModel(info *model.DeviceInfo) *device.Info { - return &device.Info{ +// MapInfoToAPIModel maps internal node info model to API model +func MapInfoToAPIModel(info *model.NodeInfo) *node.Info { + return &node.Info{ Labels: mapLabelsToAPIModel(info.Labels), Hostname: info.Hostname, Addresses: addressesToString(info.Addresses), @@ -26,9 +26,9 @@ func MapInfoToAPIModel(info *model.DeviceInfo) *device.Info { } } -func mapLabelsToAPIModel(labels map[string]string) (result []*device.Label) { +func mapLabelsToAPIModel(labels map[string]string) (result []*node.Label) { for key, value := range labels { - result = append(result, &device.Label{Key: key, Value: value}) + result = append(result, &node.Label{Key: key, Value: value}) } return result } diff --git a/pkg/api/server.go b/pkg/api/server.go index 935fbf20..32eb1de0 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -14,7 +14,7 @@ import ( "github.com/ernoaapa/eliot/pkg/api/mapping" containers "github.com/ernoaapa/eliot/pkg/api/services/containers/v1" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" pods "github.com/ernoaapa/eliot/pkg/api/services/pods/v1" "github.com/ernoaapa/eliot/pkg/api/stream" "github.com/ernoaapa/eliot/pkg/progress" @@ -27,15 +27,15 @@ import ( // Server implements the GRPC API for the eli type Server struct { - info *model.DeviceInfo + info *model.NodeInfo client runtime.Client grpc *grpc.Server listen string } -// Info is 'device' service Info implementation -func (s *Server) Info(context context.Context, req *device.InfoRequest) (*device.InfoResponse, error) { - return &device.InfoResponse{ +// Info is Node service Info implementation +func (s *Server) Info(context context.Context, req *node.InfoRequest) (*node.InfoResponse, error) { + return &node.InfoResponse{ Info: mapping.MapInfoToAPIModel(s.info), }, nil } @@ -283,7 +283,7 @@ func getMetadataValue(md metadata.MD, key string) string { } // NewServer creates new API server -func NewServer(listen string, client runtime.Client, info *model.DeviceInfo) *Server { +func NewServer(listen string, client runtime.Client, info *model.NodeInfo) *Server { apiserver := &Server{ info: info, client: client, @@ -293,7 +293,7 @@ func NewServer(listen string, client runtime.Client, info *model.DeviceInfo) *Se apiserver.grpc = grpc.NewServer() pods.RegisterPodsServer(apiserver.grpc, apiserver) containers.RegisterContainersServer(apiserver.grpc, apiserver) - device.RegisterDeviceServer(apiserver.grpc, apiserver) + node.RegisterNodeServer(apiserver.grpc, apiserver) return apiserver } diff --git a/pkg/api/services/device/v1/device.pb.go b/pkg/api/services/node/v1/node.pb.go similarity index 61% rename from pkg/api/services/device/v1/device.pb.go rename to pkg/api/services/node/v1/node.pb.go index f174d42a..886b631e 100644 --- a/pkg/api/services/device/v1/device.pb.go +++ b/pkg/api/services/node/v1/node.pb.go @@ -1,12 +1,12 @@ // Code generated by protoc-gen-go. -// source: services/device/v1/device.proto +// source: services/node/v1/node.proto // DO NOT EDIT! /* -Package device is a generated protocol buffer package. +Package node is a generated protocol buffer package. It is generated from these files: - services/device/v1/device.proto + services/node/v1/node.proto It has these top-level messages: InfoRequest @@ -14,7 +14,7 @@ It has these top-level messages: Info Label */ -package device +package node import proto "github.com/golang/protobuf/proto" import fmt "fmt" @@ -61,9 +61,9 @@ func (m *InfoResponse) GetInfo() *Info { } type Info struct { - // Labels for the device + // Labels for the node Labels []*Label `protobuf:"bytes,1,rep,name=labels" json:"labels,omitempty"` - // Device hostname + // Node hostname Hostname string `protobuf:"bytes,2,opt,name=hostname" json:"hostname,omitempty"` // IP addresses Addresses []string `protobuf:"bytes,3,rep,name=addresses" json:"addresses,omitempty"` @@ -77,9 +77,9 @@ type Info struct { SystemUUID string `protobuf:"bytes,6,opt,name=systemUUID" json:"systemUUID,omitempty"` // A random ID that is regenerated on each boot BootID string `protobuf:"bytes,7,opt,name=bootID" json:"bootID,omitempty"` - // Device operating system. One of 386, amd64, arm, s390x, and so on. + // Node operating system. One of 386, amd64, arm, s390x, and so on. Arch string `protobuf:"bytes,8,opt,name=arch" json:"arch,omitempty"` - // device operating system. One of darwin, freebsd, linux, windows, and so on + // node operating system. One of darwin, freebsd, linux, windows, and so on Os string `protobuf:"bytes,9,opt,name=os" json:"os,omitempty"` // Server version Version string `protobuf:"bytes,10,opt,name=version" json:"version,omitempty"` @@ -199,97 +199,97 @@ var _ grpc.ClientConn // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion4 -// Client API for Device service +// Client API for Node service -type DeviceClient interface { +type NodeClient interface { Info(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoResponse, error) } -type deviceClient struct { +type nodeClient struct { cc *grpc.ClientConn } -func NewDeviceClient(cc *grpc.ClientConn) DeviceClient { - return &deviceClient{cc} +func NewNodeClient(cc *grpc.ClientConn) NodeClient { + return &nodeClient{cc} } -func (c *deviceClient) Info(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoResponse, error) { +func (c *nodeClient) Info(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*InfoResponse, error) { out := new(InfoResponse) - err := grpc.Invoke(ctx, "/eliot.services.containers.v1.Device/Info", in, out, c.cc, opts...) + err := grpc.Invoke(ctx, "/eliot.services.containers.v1.Node/Info", in, out, c.cc, opts...) if err != nil { return nil, err } return out, nil } -// Server API for Device service +// Server API for Node service -type DeviceServer interface { +type NodeServer interface { Info(context.Context, *InfoRequest) (*InfoResponse, error) } -func RegisterDeviceServer(s *grpc.Server, srv DeviceServer) { - s.RegisterService(&_Device_serviceDesc, srv) +func RegisterNodeServer(s *grpc.Server, srv NodeServer) { + s.RegisterService(&_Node_serviceDesc, srv) } -func _Device_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Node_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(InfoRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(DeviceServer).Info(ctx, in) + return srv.(NodeServer).Info(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/eliot.services.containers.v1.Device/Info", + FullMethod: "/eliot.services.containers.v1.Node/Info", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DeviceServer).Info(ctx, req.(*InfoRequest)) + return srv.(NodeServer).Info(ctx, req.(*InfoRequest)) } return interceptor(ctx, in, info, handler) } -var _Device_serviceDesc = grpc.ServiceDesc{ - ServiceName: "eliot.services.containers.v1.Device", - HandlerType: (*DeviceServer)(nil), +var _Node_serviceDesc = grpc.ServiceDesc{ + ServiceName: "eliot.services.containers.v1.Node", + HandlerType: (*NodeServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Info", - Handler: _Device_Info_Handler, + Handler: _Node_Info_Handler, }, }, Streams: []grpc.StreamDesc{}, - Metadata: "services/device/v1/device.proto", + Metadata: "services/node/v1/node.proto", } -func init() { proto.RegisterFile("services/device/v1/device.proto", fileDescriptor0) } +func init() { proto.RegisterFile("services/node/v1/node.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ // 385 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xc1, 0x6a, 0xdb, 0x40, - 0x10, 0x45, 0x96, 0xad, 0x44, 0xe3, 0xb6, 0x94, 0xa5, 0x94, 0x25, 0x84, 0x56, 0xa8, 0x17, 0xb5, - 0x07, 0x2d, 0x71, 0xa1, 0x17, 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, 0xab, 0x3b, 0x3c, 0x38, 0x5b, 0x5d, 0xef, 0x8c, 0xc5, + 0xd5, 0x52, 0x4e, 0x43, 0xec, 0x3d, 0x21, 0xde, 0x02, 0xf0, 0x2d, 0x7b, 0x6c, 0xaf, 0xae, 0x56, + 0x4b, 0x39, 0x0b, 0xed, 0xff, 0x18, 0xf1, 0x1a, 0x66, 0x6b, 0x22, 0xbf, 0x5a, 0xca, 0x93, 0xd0, + 0x3b, 0x20, 0x21, 0x20, 0xd1, 0xae, 0xde, 0xc9, 0xd3, 0xc0, 0x86, 0x5a, 0xbc, 0x80, 0x09, 0xb1, + 0x4c, 0x03, 0x33, 0x21, 0x16, 0x12, 0x4e, 0x7a, 0x74, 0x6c, 0xc8, 0x4a, 0x08, 0xe4, 0x11, 0xe6, + 0x0a, 0xa6, 0xe1, 0xeb, 0xe2, 0x25, 0xc4, 0x37, 0x78, 0x1b, 0xe6, 0x9d, 0x56, 0x43, 0x29, 0x5e, + 0xc1, 0xb4, 0xd7, 0xcd, 0xfe, 0x38, 0x81, 0x11, 0x2c, 0x10, 0x92, 0x1f, 0xb4, 0x41, 0xf1, 0xfb, + 0x30, 0xe7, 0xf7, 0x4f, 0x58, 0xcd, 0xb8, 0xe3, 0xb3, 0x0f, 0x4f, 0x91, 0x8e, 0xfb, 0xff, 0xfa, + 0xe5, 0xd7, 0xe7, 0xad, 0xf1, 0xbb, 0xfd, 0xba, 0xac, 0xa9, 0x55, 0xe8, 0x2c, 0x69, 0xdd, 0x69, + 0x15, 0x02, 0x54, 0x77, 0xb3, 0x55, 0xba, 0x33, 0xea, 0xe1, 0xf5, 0x5d, 0x0e, 0xef, 0x7a, 0x16, + 0xce, 0xef, 0xe3, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x05, 0xe3, 0x6a, 0x16, 0x9d, 0x02, 0x00, 0x00, } diff --git a/pkg/api/services/device/v1/device.proto b/pkg/api/services/node/v1/node.proto similarity index 75% rename from pkg/api/services/device/v1/device.proto rename to pkg/api/services/node/v1/node.proto index faa22d53..e9565f99 100644 --- a/pkg/api/services/device/v1/device.proto +++ b/pkg/api/services/node/v1/node.proto @@ -1,10 +1,10 @@ syntax = "proto3"; package eliot.services.containers.v1; -option go_package = "github.com/ernoaapa/eliot/pkg/api/services/device/v1;device"; +option go_package = "github.com/ernoaapa/eliot/pkg/api/services/node/v1;node"; -// Device service provides access to device it self -service Device { +// Node service provides access to node itself +service Node { rpc Info(InfoRequest) returns (InfoResponse); } @@ -15,10 +15,10 @@ message InfoResponse { } message Info { - // Labels for the device + // Labels for the node repeated Label labels = 1; - // Device hostname + // Node hostname string hostname = 2; // IP addresses @@ -38,10 +38,10 @@ message Info { // A random ID that is regenerated on each boot string bootID = 7; - // Device operating system. One of 386, amd64, arm, s390x, and so on. + // Node operating system. One of 386, amd64, arm, s390x, and so on. string arch = 8; - // device operating system. One of darwin, freebsd, linux, windows, and so on + // node operating system. One of darwin, freebsd, linux, windows, and so on string os = 9; // Server version diff --git a/pkg/discovery/client.go b/pkg/discovery/client.go index 08fd1704..532b4c84 100644 --- a/pkg/discovery/client.go +++ b/pkg/discovery/client.go @@ -4,32 +4,32 @@ import ( "context" "time" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" "github.com/grandcat/zeroconf" "github.com/pkg/errors" ) -// Devices return list of DeviceInfos synchronously with given timeout -func Devices(timeout time.Duration) (devices []*device.Info, err error) { - results := make(chan *device.Info) +// Nodes return list of NodeInfos synchronously with given timeout +func Nodes(timeout time.Duration) (nodes []*node.Info, err error) { + results := make(chan *node.Info) defer close(results) go func() { - for device := range results { - devices = append(devices, device) + for node := range results { + nodes = append(nodes, node) } }() - err = DevicesAsync(results, timeout) + err = NodesAsync(results, timeout) if err != nil { return nil, err } - return devices, nil + return nodes, nil } -// DevicesAsync search for devices in network asynchronously for given timeout -func DevicesAsync(results chan<- *device.Info, timeout time.Duration) error { +// NodesAsync search for nodes in network asynchronously for given timeout +func NodesAsync(results chan<- *node.Info, timeout time.Duration) error { resolver, err := zeroconf.NewResolver(nil) if err != nil { return errors.Wrapf(err, "Failed to initialize new zeroconf resolver") @@ -46,7 +46,7 @@ func DevicesAsync(results chan<- *device.Info, timeout time.Duration) error { defer cancel() err = resolver.Browse(ctx, ZeroConfServiceName, "", entries) if err != nil { - return errors.Wrapf(err, "Failed to browse zeroconf devices") + return errors.Wrapf(err, "Failed to browse zeroconf nodes") } <-ctx.Done() diff --git a/pkg/discovery/mapping.go b/pkg/discovery/mapping.go index 312e15f5..01d74756 100644 --- a/pkg/discovery/mapping.go +++ b/pkg/discovery/mapping.go @@ -4,11 +4,11 @@ import ( "net" "strings" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" "github.com/grandcat/zeroconf" ) -func MapToAPIModel(entry *zeroconf.ServiceEntry) *device.Info { +func MapToAPIModel(entry *zeroconf.ServiceEntry) *node.Info { version := "unknown" for _, val := range entry.Text { @@ -18,7 +18,7 @@ func MapToAPIModel(entry *zeroconf.ServiceEntry) *device.Info { } } - return &device.Info{ + return &node.Info{ Hostname: entry.HostName, Addresses: addressesToString(append(entry.AddrIPv4, entry.AddrIPv6...)), GrpcPort: int64(entry.Port), diff --git a/pkg/model/device.go b/pkg/model/node.go similarity index 68% rename from pkg/model/device.go rename to pkg/model/node.go index 7dc37faf..b5e959e4 100644 --- a/pkg/model/device.go +++ b/pkg/model/node.go @@ -4,12 +4,12 @@ import ( "net" ) -// DeviceInfo contains information about current device -type DeviceInfo struct { - // Labels for the device, provided through cli +// NodeInfo contains information about current node +type NodeInfo struct { + // Labels for the node, provided through cli Labels map[string]string - // Device hostname + // Node hostname Hostname string `validate:"required,gt=0"` // IPs @@ -29,18 +29,18 @@ type DeviceInfo struct { // A random ID that is regenerated on each boot BootID string `validate:"required,gt=0"` - // Device operating system. One of 386, amd64, arm, s390x, and so on. + // Node operating system. One of 386, amd64, arm, s390x, and so on. Arch string - // device operating system. One of darwin, freebsd, linux, windows, and so on + // node operating system. One of darwin, freebsd, linux, windows, and so on OS string // Server version Version string } -// DeviceState describes current state of the device -type DeviceState struct { +// NodeState describes current state of the node +type NodeState struct { Pods []PodState `validate:"dive"` } diff --git a/pkg/device/resolver.go b/pkg/node/resolver.go similarity index 93% rename from pkg/device/resolver.go rename to pkg/node/resolver.go index 734feb53..497bbfed 100644 --- a/pkg/device/resolver.go +++ b/pkg/node/resolver.go @@ -1,4 +1,4 @@ -package device +package node import ( "io/ioutil" @@ -10,12 +10,12 @@ import ( log "github.com/sirupsen/logrus" ) -// Resolver provides information about the device +// Resolver provides information about the node type Resolver struct { labels map[string]string } -// NewResolver creates new resolver with static device labels +// NewResolver creates new resolver with static node labels func NewResolver(labels map[string]string) *Resolver { return &Resolver{ labels: withHostLabels(labels), diff --git a/pkg/device/resolver_darwin.go b/pkg/node/resolver_darwin.go similarity index 88% rename from pkg/device/resolver_darwin.go rename to pkg/node/resolver_darwin.go index 6f24fc50..03dcc54e 100644 --- a/pkg/device/resolver_darwin.go +++ b/pkg/node/resolver_darwin.go @@ -1,4 +1,4 @@ -package device +package node import ( "fmt" @@ -13,14 +13,14 @@ import ( "github.com/ernoaapa/eliot/pkg/model" ) -// GetInfo resolves information about the device +// GetInfo resolves information about the node // Note: Darwin (OSX) implementation is just for development purpose // For example, BootID get generated every time when process restarts -func (r *Resolver) GetInfo(grpcPort int, version string) *model.DeviceInfo { +func (r *Resolver) GetInfo(grpcPort int, version string) *model.NodeInfo { ioregOutput := runCommandOrFail("ioreg", "-rd1", "-c", "IOPlatformExpertDevice") hostname, _ := os.Hostname() - return &model.DeviceInfo{ + return &model.NodeInfo{ Version: version, Labels: r.labels, Arch: runtime.GOARCH, @@ -40,7 +40,7 @@ func (r *Resolver) GetInfo(grpcPort int, version string) *model.DeviceInfo { func runCommandOrFail(name string, arg ...string) string { bytes, err := exec.Command(name, arg...).Output() if err != nil { - log.Fatalf("Failed to resolve device info: %s", err) + log.Fatalf("Failed to resolve node info: %s", err) } return strings.TrimSpace(string(bytes)) } diff --git a/pkg/device/resolver_darwin_test.go b/pkg/node/resolver_darwin_test.go similarity index 70% rename from pkg/device/resolver_darwin_test.go rename to pkg/node/resolver_darwin_test.go index 97a77f50..40fb759a 100644 --- a/pkg/device/resolver_darwin_test.go +++ b/pkg/node/resolver_darwin_test.go @@ -1,4 +1,4 @@ -package device +package node import ( "testing" @@ -16,6 +16,6 @@ func TestGetInfo(t *testing.T) { assert.NotEmpty(t, info.BootID, "should resolve BootID") assert.NotEmpty(t, info.MachineID, "should resolve MachineID") assert.NotEmpty(t, info.SystemUUID, "should resolve SystemUUID") - assert.Equal(t, labels, info.Labels, "should have given device labels") - assert.Equal(t, 5000, info.GrpcPort, "should have given device grpc port") + assert.Equal(t, labels, info.Labels, "should have given node labels") + assert.Equal(t, 5000, info.GrpcPort, "should have given node grpc port") } diff --git a/pkg/device/resolver_linux.go b/pkg/node/resolver_linux.go similarity index 89% rename from pkg/device/resolver_linux.go rename to pkg/node/resolver_linux.go index f39e9b58..ef05448a 100644 --- a/pkg/device/resolver_linux.go +++ b/pkg/node/resolver_linux.go @@ -1,4 +1,4 @@ -package device +package node import ( "os" @@ -7,10 +7,10 @@ import ( "github.com/ernoaapa/eliot/pkg/model" ) -// GetInfo resolves information about the device -func (r *Resolver) GetInfo(grpcPort int, version string) *model.DeviceInfo { +// GetInfo resolves information about the node +func (r *Resolver) GetInfo(grpcPort int, version string) *model.NodeInfo { hostname, _ := os.Hostname() - return &model.DeviceInfo{ + return &model.NodeInfo{ Version: version, Labels: r.labels, Arch: runtime.GOARCH, diff --git a/pkg/device/resolver_test.go b/pkg/node/resolver_test.go similarity index 98% rename from pkg/device/resolver_test.go rename to pkg/node/resolver_test.go index 7bcf5f77..f66e2f83 100644 --- a/pkg/device/resolver_test.go +++ b/pkg/node/resolver_test.go @@ -1,4 +1,4 @@ -package device +package node import ( "fmt" diff --git a/pkg/printers/humanreadable.go b/pkg/printers/humanreadable.go index 8a534be6..a8e73c27 100644 --- a/pkg/printers/humanreadable.go +++ b/pkg/printers/humanreadable.go @@ -9,7 +9,7 @@ import ( "strings" containers "github.com/ernoaapa/eliot/pkg/api/services/containers/v1" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" pods "github.com/ernoaapa/eliot/pkg/api/services/pods/v1" "github.com/ernoaapa/eliot/pkg/config" "github.com/ernoaapa/eliot/pkg/printers/humanreadable" @@ -78,29 +78,29 @@ func getKeys(source map[string]int) (result []string) { return result } -// PrintDevices writes list of Devices in human readable table format to the writer -func (p *HumanReadablePrinter) PrintDevices(devices []*device.Info, writer io.Writer) error { - if len(devices) == 0 { - fmt.Fprintf(writer, "\n\t(No devices)\n\n") +// PrintNodes writes list of Nodes in human readable table format to the writer +func (p *HumanReadablePrinter) PrintNodes(nodes []*node.Info, writer io.Writer) error { + if len(nodes) == 0 { + fmt.Fprintf(writer, "\n\t(No nodes)\n\n") return nil } fmt.Fprintln(writer, "\nHOSTNAME\tENDPOINT\tVERSION") - for _, device := range devices { - endpoint := fmt.Sprintf("%s:%d", utils.GetFirst(device.Addresses, ""), device.GrpcPort) - _, err := fmt.Fprintf(writer, "%s\t%s\t%s\n", device.Hostname, endpoint, device.Version) + for _, node := range nodes { + endpoint := fmt.Sprintf("%s:%d", utils.GetFirst(node.Addresses, ""), node.GrpcPort) + _, err := fmt.Fprintf(writer, "%s\t%s\t%s\n", node.Hostname, endpoint, node.Version) if err != nil { - return errors.Wrapf(err, "Error while writing device row") + return errors.Wrapf(err, "Error while writing node row") } } return nil } -// PrintDevice writes a device in human readable detailed format to the writer -func (p *HumanReadablePrinter) PrintDevice(info *device.Info, writer io.Writer) error { - t := template.New("device-details") - t, err := t.Parse(humanreadable.DeviceDetailsTemplate) +// PrintNode writes a node in human readable detailed format to the writer +func (p *HumanReadablePrinter) PrintNode(info *node.Info, writer io.Writer) error { + t := template.New("node-details") + t, err := t.Parse(humanreadable.NodeDetailsTemplate) if err != nil { log.Fatalf("Invalid pod template: %s", err) } diff --git a/pkg/printers/humanreadable/DeviceDetailsTemplate.go b/pkg/printers/humanreadable/NodeDetailsTemplate.go similarity index 69% rename from pkg/printers/humanreadable/DeviceDetailsTemplate.go rename to pkg/printers/humanreadable/NodeDetailsTemplate.go index e12d2ff5..cfaef15d 100644 --- a/pkg/printers/humanreadable/DeviceDetailsTemplate.go +++ b/pkg/printers/humanreadable/NodeDetailsTemplate.go @@ -1,7 +1,7 @@ package humanreadable -// DeviceDetailsTemplate is go template for printing device details -const DeviceDetailsTemplate = `Hostname: {{.Hostname}} +// NodeDetailsTemplate is go template for printing node details +const NodeDetailsTemplate = `Hostname: {{.Hostname}} Arch/OS: {{.Os}}/{{.Arch}} Version: {{.Version}} Labels:{{range .Labels}} diff --git a/pkg/printers/humanreadable/PodDetailsTemplate.go b/pkg/printers/humanreadable/PodDetailsTemplate.go index c4dff9f1..0156ea06 100644 --- a/pkg/printers/humanreadable/PodDetailsTemplate.go +++ b/pkg/printers/humanreadable/PodDetailsTemplate.go @@ -4,7 +4,7 @@ package humanreadable const PodDetailsTemplate = `{{$pod := .Pod -}} Name: {{.Pod.Metadata.Name}} Namespace: {{.Pod.Metadata.Namespace}} -Device: {{.Pod.Status.Hostname}} +Node: {{.Pod.Status.Hostname}} State: {{.Status}} Restart Policy: {{.Pod.Spec.RestartPolicy}} Host Network: {{.Pod.Spec.HostNetwork}} diff --git a/pkg/printers/interface.go b/pkg/printers/interface.go index e319a1cb..fe50c611 100644 --- a/pkg/printers/interface.go +++ b/pkg/printers/interface.go @@ -3,7 +3,7 @@ package printers import ( "io" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" pods "github.com/ernoaapa/eliot/pkg/api/services/pods/v1" "github.com/ernoaapa/eliot/pkg/config" ) @@ -11,8 +11,8 @@ import ( // ResourcePrinter is an interface that knows how to print runtime objects. type ResourcePrinter interface { PrintPods([]*pods.Pod, io.Writer) error - PrintDevices([]*device.Info, io.Writer) error - PrintDevice(*device.Info, io.Writer) error + PrintNodes([]*node.Info, io.Writer) error + PrintNode(*node.Info, io.Writer) error PrintPod(*pods.Pod, io.Writer) error PrintConfig(*config.Config, io.Writer) error } diff --git a/pkg/printers/interface_test.go b/pkg/printers/interface_test.go index 8b54b538..42c009cd 100644 --- a/pkg/printers/interface_test.go +++ b/pkg/printers/interface_test.go @@ -6,7 +6,7 @@ import ( "github.com/ernoaapa/eliot/pkg/api/core" containers "github.com/ernoaapa/eliot/pkg/api/services/containers/v1" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" pods "github.com/ernoaapa/eliot/pkg/api/services/pods/v1" "github.com/ernoaapa/eliot/pkg/config" "github.com/stretchr/testify/assert" @@ -34,8 +34,8 @@ func TestSuite(t *testing.T) { for name, impl := range implementations { t.Run(name, func(t *testing.T) { testYamlPrintPods(t, impl) - testYamlPrintDevices(t, impl) - testPrintDevice(t, impl) + testYamlPrintNodes(t, impl) + testPrintNode(t, impl) testPrintPods(t, impl) testPrintConfig(t, impl) }) @@ -53,31 +53,31 @@ func testYamlPrintPods(t *testing.T, printer ResourcePrinter) { assert.True(t, len(result) > 0, "Should write something to the writer") } -func testYamlPrintDevices(t *testing.T, printer ResourcePrinter) { +func testYamlPrintNodes(t *testing.T, printer ResourcePrinter) { var buffer bytes.Buffer - data := []*device.Info{ + data := []*node.Info{ { Hostname: "foobar", - Labels: []*device.Label{ + Labels: []*node.Label{ {Key: "env", Value: "test"}, }, }, } - err := printer.PrintDevices(data, &buffer) - assert.NoError(t, err, "Printing devices table should not return error") + err := printer.PrintNodes(data, &buffer) + assert.NoError(t, err, "Printing nodes table should not return error") result := buffer.String() assert.True(t, len(result) > 0, "Should write something to the writer") } -func testPrintDevice(t *testing.T, printer ResourcePrinter) { +func testPrintNode(t *testing.T, printer ResourcePrinter) { var buffer bytes.Buffer - data := &device.Info{ - Labels: []*device.Label{{Key: "foo", Value: "bar"}}, + data := &node.Info{ + Labels: []*node.Label{{Key: "foo", Value: "bar"}}, Hostname: "foo-bar", Addresses: []string{"1.2.3.4"}, GrpcPort: 5000, @@ -88,7 +88,7 @@ func testPrintDevice(t *testing.T, printer ResourcePrinter) { Os: "linux", } - err := printer.PrintDevice(data, &buffer) + err := printer.PrintNode(data, &buffer) assert.NoError(t, err, "Printing pod details should not return error") result := buffer.String() diff --git a/pkg/printers/yaml.go b/pkg/printers/yaml.go index 5334a382..eef9f547 100644 --- a/pkg/printers/yaml.go +++ b/pkg/printers/yaml.go @@ -3,7 +3,7 @@ package printers import ( "io" - device "github.com/ernoaapa/eliot/pkg/api/services/device/v1" + node "github.com/ernoaapa/eliot/pkg/api/services/node/v1" pods "github.com/ernoaapa/eliot/pkg/api/services/pods/v1" "github.com/ernoaapa/eliot/pkg/config" "github.com/pkg/errors" @@ -27,18 +27,18 @@ func (p *YamlPrinter) PrintPods(pods []*pods.Pod, w io.Writer) error { return nil } -// PrintDevices takes list of devices and prints to Writer in YAML format -func (p *YamlPrinter) PrintDevices(devices []*device.Info, w io.Writer) error { - if err := writeAsYml(devices, w); err != nil { - return errors.Wrap(err, "Failed to write devices yaml") +// PrintNodes takes list of nodes and prints to Writer in YAML format +func (p *YamlPrinter) PrintNodes(nodes []*node.Info, w io.Writer) error { + if err := writeAsYml(nodes, w); err != nil { + return errors.Wrap(err, "Failed to write nodes yaml") } return nil } -// PrintDevice takes device info and prints to Writer in YAML format -func (p *YamlPrinter) PrintDevice(device *device.Info, w io.Writer) error { - if err := writeAsYml(device, w); err != nil { - return errors.Wrap(err, "Failed to write device yaml") +// PrintNode takes node info and prints to Writer in YAML format +func (p *YamlPrinter) PrintNode(node *node.Info, w io.Writer) error { + if err := writeAsYml(node, w); err != nil { + return errors.Wrap(err, "Failed to write node yaml") } return nil }