Skip to content

Commit

Permalink
Use 'cilium-agent' as the container name.
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Miguel Custódio <[email protected]>
  • Loading branch information
bmcustodio committed May 4, 2021
1 parent 1b7a901 commit 909c3f7
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ build:
ci: lint build

$(ROOT)/bin/golangci-lint:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.24.0
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.39.0

.PHONY: lint
lint: $(ROOT)/bin/golangci-lint
@$(ROOT)/bin/golangci-lint run --enable-all --disable gochecknoglobals,gochecknoinits,gomnd,lll,wsl --timeout 5m
@$(ROOT)/bin/golangci-lint run --enable-all --disable exhaustivestruct,errorlint,gochecknoglobals,gochecknoinits,goerr113,gomnd,lll,nlreturn,wrapcheck,wsl --timeout 5m
3 changes: 1 addition & 2 deletions cmd/kubectl-cilium/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
package main

import (
"github.com/bmcustodio/kubectl-cilium/internal/cmd"
_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
_ "k8s.io/client-go/plugin/pkg/client/auth/openstack"

"github.com/bmcustodio/kubectl-cilium/internal/cmd"
)

func main() {
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ replace k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.17.3
replace k8s.io/sample-controller => k8s.io/sample-controller v0.17.3

require (
github.com/google/go-cmp v0.5.4 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
k8s.io/cli-runtime v0.0.0-00010101000000-000000000000
Expand Down
36 changes: 31 additions & 5 deletions go.sum

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions internal/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ package cmd
import (
"fmt"

"github.com/spf13/cobra"
"k8s.io/client-go/tools/cache"

"github.com/bmcustodio/kubectl-cilium/internal/constants"
ciliumutils "github.com/bmcustodio/kubectl-cilium/internal/utils/cilium"
nodeutils "github.com/bmcustodio/kubectl-cilium/internal/utils/kubernetes"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/cache"
)

func init() {
Expand All @@ -35,9 +34,7 @@ var execCmd = &cobra.Command{
Short: "Execute a command in a particular Cilium agent (default: '/bin/bash').",
Use: "exec (NODE|NAMESPACE/NAME) [COMMAND [args...]]",
RunE: func(cmd *cobra.Command, args []string) error {
var (
command []string
)
var command []string
switch len(args) {
case 1:
command = []string{constants.DefaultCommand}
Expand All @@ -59,9 +56,7 @@ func exec(target string, command ...string) error {
if err != nil {
return fmt.Errorf("failed to parse %q as a target: %v", target, err)
}
var (
nn string
)
var nn string
switch {
case tns == "":
// Assume that 'target' is the name of a node.
Expand All @@ -87,5 +82,5 @@ func exec(target string, command ...string) error {
if err != nil {
return err
}
return nodeutils.Exec(kubeClient, kubeConfig, streams, ns, pn, true, true, command...)
return nodeutils.Exec(kubeClient, kubeConfig, streams, ns, pn, constants.CiliumAgentContainerName, true, true, command...)
}
7 changes: 2 additions & 5 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ package cmd
import (
"os"

"github.com/bmcustodio/kubectl-cilium/internal/version"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"github.com/bmcustodio/kubectl-cilium/internal/version"
)

func init() {
Expand All @@ -46,9 +45,7 @@ var rootCmd = &cobra.Command{
SilenceUsage: true,
Short: "A kubectl plugin for interacting with Cilium.",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var (
err error
)
var err error
kubeConfig, err = configFlags.ToRESTConfig()
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package constants

const (
CiliumLabelSelector = "k8s-app=cilium"
DefaultCommand = "/bin/bash"
CiliumAgentContainerName = "cilium-agent"
CiliumLabelSelector = "k8s-app=cilium"
DefaultCommand = "/bin/bash"
)
3 changes: 1 addition & 2 deletions internal/utils/cilium/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ package cilium
import (
"fmt"

"github.com/bmcustodio/kubectl-cilium/internal/constants"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

"github.com/bmcustodio/kubectl-cilium/internal/constants"
)

func DiscoverCiliumNamespace(kubeClient kubernetes.Interface) (string, error) {
Expand Down
3 changes: 1 addition & 2 deletions internal/utils/cilium/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ package cilium
import (
"fmt"

"github.com/bmcustodio/kubectl-cilium/internal/constants"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

"github.com/bmcustodio/kubectl-cilium/internal/constants"
)

func DiscoverCiliumPodInNode(kubeClient kubernetes.Interface, ciliumNamespace, nodeName string) (string, error) {
Expand Down
13 changes: 7 additions & 6 deletions internal/utils/kubernetes/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (
"k8s.io/client-go/tools/remotecommand"
)

func Exec(client kubernetes.Interface, config *restclient.Config, streams genericclioptions.IOStreams, podNamespace, podName string, stdin bool, tty bool, command ...string) error {
func Exec(client kubernetes.Interface, config *restclient.Config, streams genericclioptions.IOStreams, podNamespace, podName, containerName string, stdin bool, tty bool, command ...string) error {
req := client.CoreV1().RESTClient().Post().Resource("pods").Namespace(podNamespace).Name(podName).SubResource("exec")
opt := &v1.PodExecOptions{
Command: command,
Stdin: stdin,
Stdout: true,
Stderr: true,
TTY: tty,
Command: command,
Container: containerName,
Stdin: stdin,
Stdout: true,
Stderr: true,
TTY: tty,
}
req.VersionedParams(
opt,
Expand Down
4 changes: 1 addition & 3 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@

package version

var (
Version = "(UNKNOWN)"
)
var Version = "(UNKNOWN)"

0 comments on commit 909c3f7

Please sign in to comment.