From a603f149e8b46b1994802b26290eda448768d57e Mon Sep 17 00:00:00 2001 From: Tam Mach Date: Sat, 30 Apr 2022 18:11:03 +1000 Subject: [PATCH] sysdump: Add support for Ingress, CCWEC, CEV This commit is to add support for 3 new resources Ingress, CCEC and CEV. Signed-off-by: Tam Mach --- install/uninstall.go | 8 ++++---- k8s/client.go | 12 ++++++++++++ sysdump/client.go | 3 +++ sysdump/constants.go | 3 +++ sysdump/sysdump.go | 42 +++++++++++++++++++++++++++++++++++++++++ sysdump/sysdump_test.go | 18 ++++++++++++++++-- 6 files changed, 80 insertions(+), 6 deletions(-) diff --git a/install/uninstall.go b/install/uninstall.go index 399c569156..7ac5987229 100644 --- a/install/uninstall.go +++ b/install/uninstall.go @@ -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 diff --git a/k8s/client.go b/k8s/client.go index 8c6d062089..e86e764bd0 100644 --- a/k8s/client.go +++ b/k8s/client.go @@ -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) } @@ -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) } @@ -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) } diff --git a/sysdump/client.go b/sysdump/client.go index d1c7cda2d5..68cd96a425 100644 --- a/sysdump/client.go +++ b/sysdump/client.go @@ -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) diff --git a/sysdump/constants.go b/sysdump/constants.go index 5f0567756d..1ca07ddfef 100644 --- a/sysdump/constants.go +++ b/sysdump/constants.go @@ -33,10 +33,13 @@ const ( awsNodeDaemonSetFileName = "aws-node-daemonset-.yaml" ciliumBugtoolFileName = "cilium-bugtool-%s-.tar.gz" ciliumClusterWideNetworkPoliciesFileName = "ciliumclusterwidenetworkpolicies-.yaml" + ciliumClusterwideEnvoyConfigsFileName = "ciliumclusterwideenvoyconfigs-.yaml" ciliumConfigMapFileName = "cilium-configmap-.yaml" ciliumDaemonSetFileName = "cilium-daemonset-.yaml" + ciliumIngressesFileName = "ciliumingresses-.yaml" ciliumEgressNATPoliciesFileName = "ciliumegressnatpolicies-.yaml" ciliumEndpointsFileName = "ciliumendpoints-.yaml" + ciliumEnvoyConfigsFileName = "ciliumenvoyconfigs-.yaml" ciliumEtcdSecretFileName = "cilium-etcd-secrets-secret-.yaml" ciliumIdentitiesFileName = "ciliumidentities-.yaml" ciliumLocalRedirectPoliciesFileName = "ciliumlocalredirectpolicies-.yaml" diff --git a/sysdump/sysdump.go b/sysdump/sysdump.go index 4df44d7a4e..dbff0bd310 100644 --- a/sysdump/sysdump.go +++ b/sysdump/sysdump.go @@ -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, diff --git a/sysdump/sysdump_test.go b/sysdump/sysdump_test.go index cd6f56a5f8..c246827497 100644 --- a/sysdump/sysdump_test.go +++ b/sysdump/sysdump_test.go @@ -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" @@ -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" ) @@ -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") }