Skip to content

Commit

Permalink
sysdump: avoid redefining constants
Browse files Browse the repository at this point in the history
Reuse constants defined in the 'defaults' package.

Signed-off-by: Bruno Miguel Custódio <brunomcustodio@gmail.com>
  • Loading branch information
bmcustodio committed Sep 2, 2021
1 parent 03824ac commit eacf95c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion connectivity/check/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func (ct *ConnectivityTest) waitForIPCache(ctx context.Context, pod Pod) error {
r := time.After(time.Second)

stdout, err := pod.K8sClient.ExecInPodWithTTY(ctx, pod.Pod.Namespace, pod.Pod.Name,
"cilium-agent", []string{"cilium", "bpf", "ipcache", "list", "-o", "json"})
defaults.AgentContainerName, []string{"cilium", "bpf", "ipcache", "list", "-o", "json"})
if err == nil {
var ic ipCache

Expand Down
4 changes: 2 additions & 2 deletions connectivity/check/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (t *Test) waitCiliumPolicyRevisions(ctx context.Context, revisions map[Pod]
// getCiliumPolicyRevision returns the current policy revision of a Cilium pod.
func getCiliumPolicyRevision(ctx context.Context, pod Pod) (int, error) {
stdout, err := pod.K8sClient.ExecInPodWithTTY(ctx, pod.Pod.Namespace, pod.Pod.Name,
"cilium-agent", []string{"cilium", "policy", "get", "-o", "jsonpath='{.revision}'"})
defaults.AgentContainerName, []string{"cilium", "policy", "get", "-o", "jsonpath='{.revision}'"})
if err != nil {
return 0, err
}
Expand All @@ -100,7 +100,7 @@ func getCiliumPolicyRevision(ctx context.Context, pod Pod) (int, error) {
func waitCiliumPolicyRevision(ctx context.Context, pod Pod, rev int, timeout time.Duration) error {
timeoutStr := strconv.Itoa(int(timeout.Seconds()))
_, err := pod.K8sClient.ExecInPodWithTTY(ctx, pod.Pod.Namespace, pod.Pod.Name,
"cilium-agent", []string{"cilium", "policy", "wait", strconv.Itoa(rev), "--max-wait-time", timeoutStr})
defaults.AgentContainerName, []string{"cilium", "policy", "wait", strconv.Itoa(rev), "--max-wait-time", timeoutStr})
return err
}

Expand Down
2 changes: 2 additions & 0 deletions defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package defaults
import "time"

const (
AgentContainerName = "cilium-agent"
AgentServiceAccountName = "cilium"
AgentClusterRoleName = "cilium"
AgentDaemonSetName = "cilium"
Expand All @@ -29,6 +30,7 @@ const (
HubbleSocketPath = "/var/run/cilium/hubble.sock"
HubbleServerSecretName = "hubble-server-certs"

RelayContainerName = "hubble-relay"
RelayDeploymentName = "hubble-relay"
RelayClusterRoleName = "hubble-relay"
RelayServiceAccountName = "hubble-relay"
Expand Down
2 changes: 1 addition & 1 deletion hubble/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (k *K8sHubble) generateRelayDeployment() *appsv1.Deployment {
ServiceAccountName: defaults.RelayServiceAccountName,
Containers: []corev1.Container{
{
Name: "hubble-relay",
Name: defaults.RelayContainerName,
Command: []string{"hubble-relay"},
Args: []string{
"serve",
Expand Down
2 changes: 1 addition & 1 deletion install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (k *K8sInstaller) generateAgentDaemonSet() *appsv1.DaemonSet {
},
Containers: []corev1.Container{
{
Name: "cilium-agent",
Name: defaults.AgentContainerName,
Command: []string{"cilium-agent"},
Args: []string{"--config-dir=/tmp/cilium/config-map"},
Image: k.fqAgentImage(),
Expand Down
6 changes: 4 additions & 2 deletions internal/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (

// Register all auth providers (azure, gcp, oidc, openstack, ..).
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/cilium/cilium-cli/defaults"
)

type Client struct {
Expand Down Expand Up @@ -281,7 +283,7 @@ var logSplitter = regexp.MustCompile(`\r?\n[^ ]+ level=[[:alpha:]]+ msg=`)

func (c *Client) CiliumLogs(ctx context.Context, namespace, pod string, since time.Time, filter *regexp.Regexp) (string, error) {
opts := &corev1.PodLogOptions{
Container: "cilium-agent",
Container: defaults.AgentContainerName,
Timestamps: true,
SinceTime: &metav1.Time{Time: since},
}
Expand Down Expand Up @@ -371,7 +373,7 @@ func (c *Client) ExecInPod(ctx context.Context, namespace, pod, container string
}

func (c *Client) CiliumStatus(ctx context.Context, namespace, pod string) (*models.StatusResponse, error) {
stdout, err := c.ExecInPod(ctx, namespace, pod, "cilium-agent", []string{"cilium", "status", "-o", "json"})
stdout, err := c.ExecInPod(ctx, namespace, pod, defaults.AgentContainerName, []string{"cilium", "status", "-o", "json"})
if err != nil {
return nil, err
}
Expand Down
21 changes: 12 additions & 9 deletions sysdump/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ package sysdump
import (
"regexp"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/cilium/cilium-cli/defaults"
)

const (
awsNodeDaemonSetName = "aws-node"
awsNodeDaemonSetNamespace = "kube-system"
ciliumAgentContainerName = "cilium-agent"
ciliumConfigConfigMapName = "cilium-config"
ciliumDaemonSetName = "cilium"
awsNodeDaemonSetNamespace = metav1.NamespaceSystem
ciliumAgentContainerName = defaults.AgentContainerName
ciliumConfigConfigMapName = defaults.ConfigMapName
ciliumDaemonSetName = defaults.AgentDaemonSetName
ciliumEtcdSecretsSecretName = "cilium-etcd-secrets"
ciliumOperatorDeploymentName = "cilium-operator"
clustermeshApiserverDeploymentName = "clustermesh-apiserver"
ciliumOperatorDeploymentName = defaults.OperatorDeploymentName
clustermeshApiserverDeploymentName = defaults.ClusterMeshDeploymentName
hubbleContainerName = "hubble"
hubbleDaemonSetName = "hubble"
hubbleRelayContainerName = "hubble-relay"
hubbleRelayDeploymentName = "hubble-relay"
hubbleUIDeploymentName = "hubble-ui"
hubbleRelayContainerName = defaults.RelayContainerName
hubbleRelayDeploymentName = defaults.RelayDeploymentName
hubbleUIDeploymentName = defaults.HubbleUIDeploymentName
redacted = "XXXXXX"
)

Expand Down

0 comments on commit eacf95c

Please sign in to comment.