-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a GRPC client/server to kando to run/check processes (#2832)
Co-authored-by: Daniil Fedotov <[email protected]> Co-authored-by: Aaron Alpar <[email protected]> Co-authored-by: Aaron Alpar <[email protected]> Co-authored-by: Denis Voytyuk <[email protected]>
- Loading branch information
1 parent
bd6a040
commit 6055b35
Showing
18 changed files
with
1,779 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
# Copyright 2024 The Kanister Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
find ./pkg -name "*.proto" | xargs -t -I PROTO_FILE \ | ||
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative PROTO_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ LABEL maintainer="Tom Manville<[email protected]>" | |
|
||
ARG TARGETPLATFORM | ||
|
||
RUN apt-get update && apt-get -y install apt-transport-https ca-certificates bash git gnupg2 software-properties-common curl jq wget \ | ||
RUN apt-get update && apt-get -y install \ | ||
apt-transport-https bash ca-certificates curl git gnupg2 jq protobuff-compiler software-properties-common wget \ | ||
&& update-ca-certificates | ||
|
||
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2020 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kando | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
processAddressFlagName = "address" | ||
) | ||
|
||
func newProcessCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "process <command>", | ||
Short: "Manage kando processes", | ||
} | ||
cmd.AddCommand(newProcessServerCommand()) | ||
cmd.AddCommand(newProcessClientCommand()) | ||
cmd.PersistentFlags().StringP(processAddressFlagName, "a", "/tmp/kanister.sock", "The path of a unix socket of the process server") | ||
return cmd | ||
} | ||
|
||
func processAddressFlagValue(cmd *cobra.Command) (string, error) { | ||
a := cmd.Flag(processAddressFlagName).Value.String() | ||
_, err := net.ResolveUnixAddr("unix", a) | ||
return a, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2020 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kando | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
processAsJSONFlagName = "as-json" | ||
) | ||
|
||
func newProcessClientCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "client <command>", | ||
Short: "Send commands to the process server", | ||
} | ||
cmd.AddCommand(newProcessClientCreateCommand()) | ||
cmd.AddCommand(newProcessClientListCommand()) | ||
cmd.AddCommand(newProcessClientOutputCommand()) | ||
cmd.PersistentFlags().BoolP(processAsJSONFlagName, "j", false, "Display output as json") | ||
return cmd | ||
} | ||
|
||
func processAsJSONFlagValue(cmd *cobra.Command) bool { | ||
b, err := cmd.Flags().GetBool(processAsJSONFlagName) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
return b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2020 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kando | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"google.golang.org/protobuf/encoding/protojson" | ||
|
||
"github.com/kanisterio/kanister/pkg/kanx" | ||
) | ||
|
||
func newProcessClientCreateCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "create", | ||
Short: "create", | ||
RunE: runProcessClientCreate, | ||
} | ||
return cmd | ||
} | ||
|
||
func runProcessClientCreate(cmd *cobra.Command, args []string) error { | ||
addr, err := processAddressFlagValue(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
asJSON := processAsJSONFlagValue(cmd) | ||
cmd.SilenceUsage = true | ||
p, err := kanx.CreateProcess(cmd.Context(), addr, args[0], args[1:]) | ||
if !asJSON { | ||
fmt.Printf("Created process: %v\n", p) | ||
return err | ||
} | ||
buf, err := protojson.Marshal(p) | ||
fmt.Println(string(buf)) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2020 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kando | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"google.golang.org/protobuf/encoding/protojson" | ||
|
||
"github.com/kanisterio/kanister/pkg/kanx" | ||
) | ||
|
||
func newProcessClientListCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "list", | ||
RunE: runProcessClientList, | ||
} | ||
return cmd | ||
} | ||
|
||
func runProcessClientList(cmd *cobra.Command, _args []string) error { | ||
return runProcessClientListWithOutput(os.Stdout, cmd) | ||
} | ||
|
||
func runProcessClientListWithOutput(out io.Writer, cmd *cobra.Command) error { | ||
addr, err := processAddressFlagValue(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
asJSON := processAsJSONFlagValue(cmd) | ||
cmd.SilenceUsage = true | ||
ps, err := kanx.ListProcesses(cmd.Context(), addr) | ||
if err != nil { | ||
return err | ||
} | ||
for _, p := range ps { | ||
if asJSON { | ||
buf, err := protojson.Marshal(p) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprintln(out, string(buf)) | ||
} else { | ||
fmt.Fprintln(out, "Process: ", p.String()) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2020 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kando | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/kanisterio/kanister/pkg/kanx" | ||
) | ||
|
||
func newProcessClientOutputCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "output", | ||
Short: "output", | ||
RunE: runProcessClientOutput, | ||
} | ||
return cmd | ||
} | ||
|
||
func runProcessClientOutput(cmd *cobra.Command, args []string) error { | ||
cmd.SetContext(context.Background()) | ||
pid, err := strconv.Atoi(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
addr, err := processAddressFlagValue(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
cmd.SilenceUsage = true | ||
return kanx.Stdout(cmd.Context(), addr, int64(pid), os.Stdout) | ||
} |
Oops, something went wrong.