Skip to content

Commit

Permalink
sysdump: Add support for Ingress, CCWEC, CEV
Browse files Browse the repository at this point in the history
This commit is to add support for 3 new resources Ingress, CCEC and CEV.

Signed-off-by: Tam Mach <tam.mach@cilium.io>
  • Loading branch information
sayboras committed May 3, 2022
1 parent 5680b42 commit a603f14
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
8 changes: 4 additions & 4 deletions install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func (k *K8sUninstaller) Log(format string, a ...interface{}) {
func (k *K8sUninstaller) Uninstall(ctx context.Context) error {
k.autodetect(ctx)

k.Log("🔥 Deleting %s namespace...", k.params.TestNamespace)
k.client.DeleteNamespace(ctx, k.params.TestNamespace, metav1.DeleteOptions{})
k.Log("🔥 Deleting Ingress Secrets Namespace...")
k.client.DeleteNamespace(ctx, defaults.IngressSecretsNamespace, metav1.DeleteOptions{})
for _, n := range []string{k.params.TestNamespace, defaults.IngressSecretsNamespace} {
k.Log("🔥 Deleting %s namespace...", n)
k.client.DeleteNamespace(ctx, n, metav1.DeleteOptions{})
}

// To avoid cases where test pods are stuck in terminating state because
// cni (cilium) pods were deleted sooner, wait until test pods are deleted
Expand Down
12 changes: 12 additions & 0 deletions k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ func (c *Client) ListCiliumEndpoints(ctx context.Context, namespace string, opti
return c.CiliumClientset.CiliumV2().CiliumEndpoints(namespace).List(ctx, options)
}

func (c *Client) ListCiliumEnvoyConfigs(ctx context.Context, namespace string, options metav1.ListOptions) (*ciliumv2alpha1.CiliumEnvoyConfigList, error) {
return c.CiliumClientset.CiliumV2alpha1().CiliumEnvoyConfigs(namespace).List(ctx, options)
}

func (c *Client) ListNodes(ctx context.Context, options metav1.ListOptions) (*corev1.NodeList, error) {
return c.Clientset.CoreV1().Nodes().List(ctx, options)
}
Expand Down Expand Up @@ -583,6 +587,10 @@ func (c *Client) ListCiliumClusterwideNetworkPolicies(ctx context.Context, opts
return c.CiliumClientset.CiliumV2().CiliumClusterwideNetworkPolicies().List(ctx, opts)
}

func (c *Client) ListCiliumClusterwideEnvoyConfigs(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumClusterwideEnvoyConfigList, error) {
return c.CiliumClientset.CiliumV2alpha1().CiliumClusterwideEnvoyConfigs().List(ctx, opts)
}

func (c *Client) GetCiliumClusterwideNetworkPolicy(ctx context.Context, name string, opts metav1.GetOptions) (*ciliumv2.CiliumClusterwideNetworkPolicy, error) {
return c.CiliumClientset.CiliumV2().CiliumClusterwideNetworkPolicies().Get(ctx, name, opts)
}
Expand Down Expand Up @@ -656,6 +664,10 @@ func (c *Client) ListEndpoints(ctx context.Context, o metav1.ListOptions) (*core
return c.Clientset.CoreV1().Endpoints(corev1.NamespaceAll).List(ctx, o)
}

func (c *Client) ListIngresses(ctx context.Context, o metav1.ListOptions) (*networkingv1.IngressList, error) {
return c.Clientset.NetworkingV1().Ingresses(corev1.NamespaceAll).List(ctx, o)
}

func (c *Client) ListNetworkPolicies(ctx context.Context, o metav1.ListOptions) (*networkingv1.NetworkPolicyList, error) {
return c.Clientset.NetworkingV1().NetworkPolicies(corev1.NamespaceAll).List(ctx, o)
}
Expand Down
3 changes: 3 additions & 0 deletions sysdump/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ type KubernetesClient interface {
GetSecret(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.Secret, error)
GetVersion(ctx context.Context) (string, error)
ListCiliumClusterwideNetworkPolicies(ctx context.Context, opts metav1.ListOptions) (*ciliumv2.CiliumClusterwideNetworkPolicyList, error)
ListCiliumClusterwideEnvoyConfigs(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumClusterwideEnvoyConfigList, 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)
ListCiliumEnvoyConfigs(ctx context.Context, namespace string, options metav1.ListOptions) (*ciliumv2alpha1.CiliumEnvoyConfigList, 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)
ListDaemonSet(ctx context.Context, namespace string, o metav1.ListOptions) (*appsv1.DaemonSetList, error)
ListEvents(ctx context.Context, o metav1.ListOptions) (*corev1.EventList, error)
ListEndpoints(ctx context.Context, o metav1.ListOptions) (*corev1.EndpointsList, error)
ListIngresses(ctx context.Context, o metav1.ListOptions) (*networkingv1.IngressList, error)
ListNamespaces(ctx context.Context, o metav1.ListOptions) (*corev1.NamespaceList, error)
ListNetworkPolicies(ctx context.Context, o metav1.ListOptions) (*networkingv1.NetworkPolicyList, error)
ListNodes(ctx context.Context, options metav1.ListOptions) (*corev1.NodeList, error)
Expand Down
3 changes: 3 additions & 0 deletions sysdump/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ const (
awsNodeDaemonSetFileName = "aws-node-daemonset-<ts>.yaml"
ciliumBugtoolFileName = "cilium-bugtool-%s-<ts>.tar.gz"
ciliumClusterWideNetworkPoliciesFileName = "ciliumclusterwidenetworkpolicies-<ts>.yaml"
ciliumClusterwideEnvoyConfigsFileName = "ciliumclusterwideenvoyconfigs-<ts>.yaml"
ciliumConfigMapFileName = "cilium-configmap-<ts>.yaml"
ciliumDaemonSetFileName = "cilium-daemonset-<ts>.yaml"
ciliumIngressesFileName = "ciliumingresses-<ts>.yaml"
ciliumEgressNATPoliciesFileName = "ciliumegressnatpolicies-<ts>.yaml"
ciliumEndpointsFileName = "ciliumendpoints-<ts>.yaml"
ciliumEnvoyConfigsFileName = "ciliumenvoyconfigs-<ts>.yaml"
ciliumEtcdSecretFileName = "cilium-etcd-secrets-secret-<ts>.yaml"
ciliumIdentitiesFileName = "ciliumidentities-<ts>.yaml"
ciliumLocalRedirectPoliciesFileName = "ciliumlocalredirectpolicies-<ts>.yaml"
Expand Down
42 changes: 42 additions & 0 deletions sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,48 @@ func (c *Collector) Run() error {
return nil
},
},
{
Description: "Collecting Ingresses",
Quick: true,
Task: func(ctx context.Context) error {
v, err := c.Client.ListIngresses(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to collect Ingresses: %w", err)
}
if err := c.WriteYAML(ciliumIngressesFileName, v); err != nil {
return fmt.Errorf("failed to collect Ingresses: %w", err)
}
return nil
},
},
{
Description: "Collecting CiliumClusterwideEnvoyConfigs",
Quick: true,
Task: func(ctx context.Context) error {
v, err := c.Client.ListCiliumClusterwideEnvoyConfigs(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to collect CiliumClusterwideEnvoyConfigs: %w", err)
}
if err := c.WriteYAML(ciliumClusterwideEnvoyConfigsFileName, v); err != nil {
return fmt.Errorf("failed to collect CiliumClusterwideEnvoyConfigs: %w", err)
}
return nil
},
},
{
Description: "Collecting CiliumEnvoyConfigs",
Quick: true,
Task: func(ctx context.Context) error {
v, err := c.Client.ListCiliumEnvoyConfigs(ctx, corev1.NamespaceAll, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to collect CiliumEnvoyConfigs: %w", err)
}
if err := c.WriteYAML(ciliumEnvoyConfigsFileName, v); err != nil {
return fmt.Errorf("failed to collect CiliumEnvoyConfigs: %w", err)
}
return nil
},
},
{
Description: "Collecting Cilium etcd secret",
Quick: true,
Expand Down
18 changes: 16 additions & 2 deletions sysdump/sysdump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"testing"
"time"

ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
ciliumv2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
"gopkg.in/check.v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -22,6 +20,9 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"

ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
ciliumv2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"

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

Expand Down Expand Up @@ -145,6 +146,19 @@ type fakeClient struct {
nodeList *corev1.NodeList
}

func (c *fakeClient) ListCiliumClusterwideEnvoyConfigs(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumClusterwideEnvoyConfigList, error) {
//TODO implement me
panic("implement me")
}

func (c *fakeClient) ListCiliumEnvoyConfigs(ctx context.Context, namespace string, options metav1.ListOptions) (*ciliumv2alpha1.CiliumEnvoyConfigList, error) {
panic("implement me")
}

func (c *fakeClient) ListIngresses(ctx context.Context, o metav1.ListOptions) (*networkingv1.IngressList, error) {
panic("implement me")
}

func (c *fakeClient) CopyFromPod(ctx context.Context, namespace, pod, container string, fromFile, destFile string) error {
panic("implement me")
}
Expand Down

0 comments on commit a603f14

Please sign in to comment.