Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysdump: collect CiliumEgressNATPolicy and CiliumLocalRedirectPolicy resources #540

Merged
merged 2 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/cilium/cilium/api/v1/models"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
ciliumv2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
ciliumClientset "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -683,3 +684,11 @@ func (c *Client) GetRunningCiliumVersion(ctx context.Context, namespace string)
}
return "", errors.New("unable to obtain cilium version: no cilium pods found")
}

func (c *Client) ListCiliumEgressNATPolicies(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumEgressNATPolicyList, error) {
return c.CiliumClientset.CiliumV2alpha1().CiliumEgressNATPolicies().List(ctx, opts)
}

func (c *Client) ListCiliumLocalRedirectPolicies(ctx context.Context, namespace string, opts metav1.ListOptions) (*ciliumv2.CiliumLocalRedirectPolicyList, error) {
return c.CiliumClientset.CiliumV2().CiliumLocalRedirectPolicies(namespace).List(ctx, opts)
}
3 changes: 3 additions & 0 deletions sysdump/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/cilium/cilium-cli/internal/k8s"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
ciliumv2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
Expand All @@ -31,7 +32,9 @@ type KubernetesClient interface {
GetVersion(ctx context.Context) (string, error)
ListCiliumClusterwideNetworkPolicies(ctx context.Context, opts metav1.ListOptions) (*ciliumv2.CiliumClusterwideNetworkPolicyList, error)
ListCiliumIdentities(ctx context.Context) (*ciliumv2.CiliumIdentityList, error)
ListCiliumEgressNATPolicies(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumEgressNATPolicyList, error)
ListCiliumEndpoints(ctx context.Context, namespace string, options metav1.ListOptions) (*ciliumv2.CiliumEndpointList, error)
ListCiliumLocalRedirectPolicies(ctx context.Context, namespace string, options metav1.ListOptions) (*ciliumv2.CiliumLocalRedirectPolicyList, error)
ListCiliumNetworkPolicies(ctx context.Context, namespace string, opts metav1.ListOptions) (*ciliumv2.CiliumNetworkPolicyList, error)
ListCiliumNodes(ctx context.Context) (*ciliumv2.CiliumNodeList, error)
ListEvents(ctx context.Context, o metav1.ListOptions) (*corev1.EventList, error)
Expand Down
2 changes: 2 additions & 0 deletions sysdump/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ const (
ciliumClusterWideNetworkPoliciesFileName = "ciliumclusterwidenetworkpolicies-<ts>.yaml"
ciliumConfigMapFileName = "cilium-configmap-<ts>.yaml"
ciliumDaemonSetFileName = "cilium-daemonset-<ts>.yaml"
ciliumEgressNATPoliciesFileName = "ciliumegressnatpolicies-<ts>.yaml"
ciliumEndpointsFileName = "ciliumendpoints-<ts>.yaml"
ciliumEtcdSecretFileName = "cilium-etcd-secrets-secret-<ts>.yaml"
ciliumIdentitiesFileName = "ciliumidentities-<ts>.yaml"
ciliumLocalRedirectPoliciesFileName = "ciliumlocalredirectpolicies-<ts>.yaml"
ciliumLogsFileName = "logs-%s-%s-<ts>.log"
ciliumPreviousLogsFileName = "logs-%s-%s-<ts>-prev.log"
ciliumNetworkPoliciesFileName = "ciliumnetworkpolicies-<ts>.yaml"
Expand Down
28 changes: 28 additions & 0 deletions sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,34 @@ func (c *Collector) Run() error {
return nil
},
},
{
Description: "Collecting Cilium egress NAT policies",
Quick: true,
Task: func(ctx context.Context) error {
v, err := c.client.ListCiliumEgressNATPolicies(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to collect Cilium egress NAT policies: %w", err)
}
if err := writeYaml(absoluteTempPath(ciliumEgressNATPoliciesFileName), v); err != nil {
return fmt.Errorf("failed to collect Cilium egress NAT policies: %w", err)
}
return nil
},
},
{
Description: "Collecting Cilium local redirect policies",
Quick: true,
Task: func(ctx context.Context) error {
v, err := c.client.ListCiliumLocalRedirectPolicies(ctx, corev1.NamespaceAll, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to collect Cilium local redirect policies: %w", err)
}
if err := writeYaml(absoluteTempPath(ciliumLocalRedirectPoliciesFileName), v); err != nil {
return fmt.Errorf("failed to collect Cilium local redirect policies: %w", err)
}
return nil
},
},
{
Description: "Collecting Cilium endpoints",
Quick: true,
Expand Down
1 change: 0 additions & 1 deletion sysdump/tasks.go

This file was deleted.