diff --git a/acceptance/framework/consul/helm_cluster.go b/acceptance/framework/consul/helm_cluster.go index 6dd1df4f67..fafaceaca1 100644 --- a/acceptance/framework/consul/helm_cluster.go +++ b/acceptance/framework/consul/helm_cluster.go @@ -165,12 +165,7 @@ func (h *HelmCluster) Create(t *testing.T) { require.NoError(r, err) }) - k8s.WaitForAllPodsToBeReady( - t, - h.kubernetesClient, - h.helmOptions.KubectlOptions.Namespace, - fmt.Sprintf("release=%s", h.releaseName), - ) + k8s.WaitForAllPodsToBeReady(t, h.kubernetesClient, h.helmOptions.KubectlOptions.Namespace, fmt.Sprintf("release=%s", h.releaseName)) } func (h *HelmCluster) Destroy(t *testing.T) { @@ -192,11 +187,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { require.NoError(t, err) // Forcibly delete all gateway classes and remove their finalizers. - _ = h.runtimeClient.DeleteAllOf( - context.Background(), - &gwv1beta1.GatewayClass{}, - client.HasLabels{"release=" + h.releaseName}, - ) + _ = h.runtimeClient.DeleteAllOf(context.Background(), &gwv1beta1.GatewayClass{}, client.HasLabels{"release=" + h.releaseName}) var gatewayClassList gwv1beta1.GatewayClassList if h.runtimeClient.List(context.Background(), &gatewayClassList, &client.ListOptions{ @@ -209,11 +200,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Forcibly delete all gateway class configs and remove their finalizers. - _ = h.runtimeClient.DeleteAllOf( - context.Background(), - &v1alpha1.GatewayClassConfig{}, - client.HasLabels{"release=" + h.releaseName}, - ) + _ = h.runtimeClient.DeleteAllOf(context.Background(), &v1alpha1.GatewayClassConfig{}, client.HasLabels{"release=" + h.releaseName}) var gatewayClassConfigList v1alpha1.GatewayClassConfigList if h.runtimeClient.List(context.Background(), &gatewayClassConfigList, &client.ListOptions{ @@ -236,16 +223,12 @@ func (h *HelmCluster) Destroy(t *testing.T) { // Force delete any pods that have h.releaseName in their name because sometimes // graceful termination takes a long time and since this is an uninstall // we don't care that they're stopped gracefully. - pods, err := h.kubernetesClient.CoreV1(). - Pods(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + pods, err := h.kubernetesClient.CoreV1().Pods(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, pod := range pods.Items { if strings.Contains(pod.Name, h.releaseName) { var gracePeriod int64 = 0 - err := h.kubernetesClient.CoreV1(). - Pods(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), pod.Name, metav1.DeleteOptions{GracePeriodSeconds: &gracePeriod}) + err := h.kubernetesClient.CoreV1().Pods(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{GracePeriodSeconds: &gracePeriod}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -253,9 +236,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any deployments that have h.releaseName in their name. - deployments, err := h.kubernetesClient.AppsV1(). - Deployments(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + deployments, err := h.kubernetesClient.AppsV1().Deployments(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, deployment := range deployments.Items { if strings.Contains(deployment.Name, h.releaseName) { @@ -269,15 +250,11 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any replicasets that have h.releaseName in their name. - replicasets, err := h.kubernetesClient.AppsV1(). - ReplicaSets(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + replicasets, err := h.kubernetesClient.AppsV1().ReplicaSets(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, replicaset := range replicasets.Items { if strings.Contains(replicaset.Name, h.releaseName) { - err := h.kubernetesClient.AppsV1(). - ReplicaSets(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), replicaset.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.AppsV1().ReplicaSets(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), replicaset.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -285,15 +262,11 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any statefulsets that have h.releaseName in their name. - statefulsets, err := h.kubernetesClient.AppsV1(). - StatefulSets(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + statefulsets, err := h.kubernetesClient.AppsV1().StatefulSets(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, statefulset := range statefulsets.Items { if strings.Contains(statefulset.Name, h.releaseName) { - err := h.kubernetesClient.AppsV1(). - StatefulSets(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), statefulset.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.AppsV1().StatefulSets(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), statefulset.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -301,15 +274,11 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any daemonsets that have h.releaseName in their name. - daemonsets, err := h.kubernetesClient.AppsV1(). - DaemonSets(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + daemonsets, err := h.kubernetesClient.AppsV1().DaemonSets(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, daemonset := range daemonsets.Items { if strings.Contains(daemonset.Name, h.releaseName) { - err := h.kubernetesClient.AppsV1(). - DaemonSets(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), daemonset.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.AppsV1().DaemonSets(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), daemonset.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -317,15 +286,11 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any services that have h.releaseName in their name. - services, err := h.kubernetesClient.CoreV1(). - Services(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + services, err := h.kubernetesClient.CoreV1().Services(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, service := range services.Items { if strings.Contains(service.Name, h.releaseName) { - err := h.kubernetesClient.CoreV1(). - Services(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), service.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.CoreV1().Services(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), service.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -333,21 +298,15 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete PVCs. - err = h.kubernetesClient.CoreV1(). - PersistentVolumeClaims(h.helmOptions.KubectlOptions.Namespace). - DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + err = h.kubernetesClient.CoreV1().PersistentVolumeClaims(h.helmOptions.KubectlOptions.Namespace).DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) // Delete any serviceaccounts that have h.releaseName in their name. - sas, err := h.kubernetesClient.CoreV1(). - ServiceAccounts(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + sas, err := h.kubernetesClient.CoreV1().ServiceAccounts(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, sa := range sas.Items { if strings.Contains(sa.Name, h.releaseName) { - err := h.kubernetesClient.CoreV1(). - ServiceAccounts(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), sa.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.CoreV1().ServiceAccounts(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), sa.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -355,15 +314,11 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any roles that have h.releaseName in their name. - roles, err := h.kubernetesClient.RbacV1(). - Roles(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + roles, err := h.kubernetesClient.RbacV1().Roles(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, role := range roles.Items { if strings.Contains(role.Name, h.releaseName) { - err := h.kubernetesClient.RbacV1(). - Roles(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), role.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.RbacV1().Roles(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), role.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -371,15 +326,11 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any rolebindings that have h.releaseName in their name. - roleBindings, err := h.kubernetesClient.RbacV1(). - RoleBindings(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + roleBindings, err := h.kubernetesClient.RbacV1().RoleBindings(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, roleBinding := range roleBindings.Items { if strings.Contains(roleBinding.Name, h.releaseName) { - err := h.kubernetesClient.RbacV1(). - RoleBindings(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), roleBinding.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.RbacV1().RoleBindings(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), roleBinding.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -387,15 +338,11 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any secrets that have h.releaseName in their name. - secrets, err := h.kubernetesClient.CoreV1(). - Secrets(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{}) + secrets, err := h.kubernetesClient.CoreV1().Secrets(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{}) require.NoError(r, err) for _, secret := range secrets.Items { if strings.Contains(secret.Name, h.releaseName) { - err := h.kubernetesClient.CoreV1(). - Secrets(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), secret.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.CoreV1().Secrets(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), secret.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -403,15 +350,11 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Delete any jobs that have h.releaseName in their name. - jobs, err := h.kubernetesClient.BatchV1(). - Jobs(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + jobs, err := h.kubernetesClient.BatchV1().Jobs(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, job := range jobs.Items { if strings.Contains(job.Name, h.releaseName) { - err := h.kubernetesClient.BatchV1(). - Jobs(h.helmOptions.KubectlOptions.Namespace). - Delete(context.Background(), job.Name, metav1.DeleteOptions{}) + err := h.kubernetesClient.BatchV1().Jobs(h.helmOptions.KubectlOptions.Namespace).Delete(context.Background(), job.Name, metav1.DeleteOptions{}) if !errors.IsNotFound(err) { require.NoError(r, err) } @@ -419,9 +362,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify that all deployments have been deleted. - deployments, err = h.kubernetesClient.AppsV1(). - Deployments(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + deployments, err = h.kubernetesClient.AppsV1().Deployments(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, deployment := range deployments.Items { if strings.Contains(deployment.Name, h.releaseName) { @@ -430,9 +371,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify that all replicasets have been deleted. - replicasets, err = h.kubernetesClient.AppsV1(). - ReplicaSets(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + replicasets, err = h.kubernetesClient.AppsV1().ReplicaSets(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, replicaset := range replicasets.Items { if strings.Contains(replicaset.Name, h.releaseName) { @@ -441,9 +380,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify that all statefulets have been deleted. - statefulsets, err = h.kubernetesClient.AppsV1(). - StatefulSets(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + statefulsets, err = h.kubernetesClient.AppsV1().StatefulSets(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, statefulset := range statefulsets.Items { if strings.Contains(statefulset.Name, h.releaseName) { @@ -452,9 +389,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify that all daemonsets have been deleted. - daemonsets, err = h.kubernetesClient.AppsV1(). - DaemonSets(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + daemonsets, err = h.kubernetesClient.AppsV1().DaemonSets(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, daemonset := range daemonsets.Items { if strings.Contains(daemonset.Name, h.releaseName) { @@ -463,9 +398,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify that all services have been deleted. - services, err = h.kubernetesClient.CoreV1(). - Services(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + services, err = h.kubernetesClient.CoreV1().Services(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, service := range services.Items { if strings.Contains(service.Name, h.releaseName) { @@ -474,9 +407,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify all Consul Pods are deleted. - pods, err = h.kubernetesClient.CoreV1(). - Pods(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + pods, err = h.kubernetesClient.CoreV1().Pods(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, pod := range pods.Items { if strings.Contains(pod.Name, h.releaseName) { @@ -485,16 +416,12 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify all Consul PVCs are deleted. - pvcs, err := h.kubernetesClient.CoreV1(). - PersistentVolumeClaims(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + pvcs, err := h.kubernetesClient.CoreV1().PersistentVolumeClaims(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) require.Len(r, pvcs.Items, 0) // Verify all Consul Service Accounts are deleted. - sas, err = h.kubernetesClient.CoreV1(). - ServiceAccounts(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + sas, err = h.kubernetesClient.CoreV1().ServiceAccounts(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, sa := range sas.Items { if strings.Contains(sa.Name, h.releaseName) { @@ -503,9 +430,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify all Consul Roles are deleted. - roles, err = h.kubernetesClient.RbacV1(). - Roles(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + roles, err = h.kubernetesClient.RbacV1().Roles(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, role := range roles.Items { if strings.Contains(role.Name, h.releaseName) { @@ -514,9 +439,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify all Consul Role Bindings are deleted. - roleBindings, err = h.kubernetesClient.RbacV1(). - RoleBindings(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + roleBindings, err = h.kubernetesClient.RbacV1().RoleBindings(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, roleBinding := range roleBindings.Items { if strings.Contains(roleBinding.Name, h.releaseName) { @@ -525,9 +448,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify all Consul Secrets are deleted. - secrets, err = h.kubernetesClient.CoreV1(). - Secrets(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{}) + secrets, err = h.kubernetesClient.CoreV1().Secrets(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{}) require.NoError(r, err) for _, secret := range secrets.Items { if strings.Contains(secret.Name, h.releaseName) { @@ -536,9 +457,7 @@ func (h *HelmCluster) Destroy(t *testing.T) { } // Verify all Consul Jobs are deleted. - jobs, err = h.kubernetesClient.BatchV1(). - Jobs(h.helmOptions.KubectlOptions.Namespace). - List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) + jobs, err = h.kubernetesClient.BatchV1().Jobs(h.helmOptions.KubectlOptions.Namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "release=" + h.releaseName}) require.NoError(r, err) for _, job := range jobs.Items { if strings.Contains(job.Name, h.releaseName) { @@ -557,12 +476,7 @@ func (h *HelmCluster) Upgrade(t *testing.T, helmValues map[string]string) { chartName = config.HelmChartPath } helm.Upgrade(t, h.helmOptions, chartName, h.releaseName) - k8s.WaitForAllPodsToBeReady( - t, - h.kubernetesClient, - h.helmOptions.KubectlOptions.Namespace, - fmt.Sprintf("release=%s", h.releaseName), - ) + k8s.WaitForAllPodsToBeReady(t, h.kubernetesClient, h.helmOptions.KubectlOptions.Namespace, fmt.Sprintf("release=%s", h.releaseName)) } // CreatePortForwardTunnel returns the local address:port of a tunnel to the consul server pod in the given release. @@ -595,11 +509,7 @@ func (h *HelmCluster) ResourceClient(t *testing.T, secure bool, release ...strin return resourceClient } -func (h *HelmCluster) SetupConsulClient( - t *testing.T, - secure bool, - release ...string, -) (client *api.Client, configAddress string) { +func (h *HelmCluster) SetupConsulClient(t *testing.T, secure bool, release ...string) (client *api.Client, configAddress string) { t.Helper() releaseName := h.releaseName @@ -744,9 +654,7 @@ func configurePodSecurityPolicies(t *testing.T, client kubernetes.Interface, cfg }, } - _, err = client.RbacV1(). - RoleBindings(namespace). - Create(context.Background(), pspRoleBinding, metav1.CreateOptions{}) + _, err = client.RbacV1().RoleBindings(namespace).Create(context.Background(), pspRoleBinding, metav1.CreateOptions{}) require.NoError(t, err) } else { require.NoError(t, err) @@ -790,14 +698,7 @@ func configureNamespace(t *testing.T, client kubernetes.Interface, cfg *config.T return } - require.Failf( - t, - "Failed to create or update namespace", - "Namespace=%s, CreateError=%s, UpdateError=%s", - namespace, - createErr, - updateErr, - ) + require.Failf(t, "Failed to create or update namespace", "Namespace=%s, CreateError=%s, UpdateError=%s", namespace, createErr, updateErr) } // configureSCCs creates RoleBindings that bind the default service account to cluster roles @@ -859,12 +760,7 @@ func defaultValues() map[string]string { return values } -func CreateK8sSecret( - t *testing.T, - client kubernetes.Interface, - cfg *config.TestConfig, - namespace, secretName, secretKey, secret string, -) { +func CreateK8sSecret(t *testing.T, client kubernetes.Interface, cfg *config.TestConfig, namespace, secretName, secretKey, secret string) { retry.RunWith(&retry.Counter{Wait: 2 * time.Second, Count: 15}, t, func(r *retry.R) { _, err := client.CoreV1().Secrets(namespace).Get(context.Background(), secretName, metav1.GetOptions{}) if errors.IsNotFound(err) { diff --git a/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go b/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go index 3f70468eb3..0c617c5c51 100644 --- a/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go +++ b/control-plane/connect-inject/webhook/consul_dataplane_sidecar.go @@ -24,11 +24,7 @@ const ( consulDataplaneDNSBindPort = 8600 ) -func (w *MeshWebhook) consulDataplaneSidecar( - namespace corev1.Namespace, - pod corev1.Pod, - mpi multiPortInfo, -) (corev1.Container, error) { +func (w *MeshWebhook) consulDataplaneSidecar(namespace corev1.Namespace, pod corev1.Pod, mpi multiPortInfo) (corev1.Container, error) { resources, err := w.sidecarResources(pod) if err != nil { return corev1.Container{}, err @@ -273,12 +269,7 @@ func (w *MeshWebhook) consulDataplaneSidecar( return container, nil } -func (w *MeshWebhook) getContainerSidecarArgs( - namespace corev1.Namespace, - mpi multiPortInfo, - bearerTokenFile string, - pod corev1.Pod, -) ([]string, error) { +func (w *MeshWebhook) getContainerSidecarArgs(namespace corev1.Namespace, mpi multiPortInfo, bearerTokenFile string, pod corev1.Pod) ([]string, error) { proxyIDFileName := "/consul/connect-inject/proxyid" if mpi.serviceName != "" { proxyIDFileName = fmt.Sprintf("/consul/connect-inject/proxyid-%s", mpi.serviceName) @@ -413,14 +404,7 @@ func (w *MeshWebhook) getContainerSidecarArgs( } if serviceMetricsPath != "" && serviceMetricsPort != "" { - args = append( - args, - "-telemetry-prom-service-metrics-url="+fmt.Sprintf( - "http://127.0.0.1:%s%s", - serviceMetricsPort, - serviceMetricsPath, - ), - ) + args = append(args, "-telemetry-prom-service-metrics-url="+fmt.Sprintf("http://127.0.0.1:%s%s", serviceMetricsPort, serviceMetricsPath)) } // Pull the TLS config from the relevant annotations. @@ -447,23 +431,13 @@ func (w *MeshWebhook) getContainerSidecarArgs( // Validate required Prometheus TLS config is present if set. if prometheusCAFile != "" || prometheusCAPath != "" || prometheusCertFile != "" || prometheusKeyFile != "" { if prometheusCAFile == "" && prometheusCAPath == "" { - return nil, fmt.Errorf( - "must set one of %q or %q when providing prometheus TLS config", - constants.AnnotationPrometheusCAFile, - constants.AnnotationPrometheusCAPath, - ) + return nil, fmt.Errorf("must set one of %q or %q when providing prometheus TLS config", constants.AnnotationPrometheusCAFile, constants.AnnotationPrometheusCAPath) } if prometheusCertFile == "" { - return nil, fmt.Errorf( - "must set %q when providing prometheus TLS config", - constants.AnnotationPrometheusCertFile, - ) + return nil, fmt.Errorf("must set %q when providing prometheus TLS config", constants.AnnotationPrometheusCertFile) } if prometheusKeyFile == "" { - return nil, fmt.Errorf( - "must set %q when providing prometheus TLS config", - constants.AnnotationPrometheusKeyFile, - ) + return nil, fmt.Errorf("must set %q when providing prometheus TLS config", constants.AnnotationPrometheusKeyFile) } // TLS config has been validated, add them to the consul-dataplane cmd args args = append(args, "-telemetry-prom-ca-certs-file="+prometheusCAFile, @@ -543,12 +517,7 @@ func (w *MeshWebhook) sidecarResources(pod corev1.Pod) (corev1.ResourceRequireme if anno, ok := pod.Annotations[constants.AnnotationSidecarProxyCPULimit]; ok { cpuLimit, err := resource.ParseQuantity(anno) if err != nil { - return corev1.ResourceRequirements{}, fmt.Errorf( - "parsing annotation %s:%q: %s", - constants.AnnotationSidecarProxyCPULimit, - anno, - err, - ) + return corev1.ResourceRequirements{}, fmt.Errorf("parsing annotation %s:%q: %s", constants.AnnotationSidecarProxyCPULimit, anno, err) } resources.Limits[corev1.ResourceCPU] = cpuLimit } else if w.DefaultProxyCPULimit != zeroQuantity { @@ -559,12 +528,7 @@ func (w *MeshWebhook) sidecarResources(pod corev1.Pod) (corev1.ResourceRequireme if anno, ok := pod.Annotations[constants.AnnotationSidecarProxyCPURequest]; ok { cpuRequest, err := resource.ParseQuantity(anno) if err != nil { - return corev1.ResourceRequirements{}, fmt.Errorf( - "parsing annotation %s:%q: %s", - constants.AnnotationSidecarProxyCPURequest, - anno, - err, - ) + return corev1.ResourceRequirements{}, fmt.Errorf("parsing annotation %s:%q: %s", constants.AnnotationSidecarProxyCPURequest, anno, err) } resources.Requests[corev1.ResourceCPU] = cpuRequest } else if w.DefaultProxyCPURequest != zeroQuantity { @@ -575,12 +539,7 @@ func (w *MeshWebhook) sidecarResources(pod corev1.Pod) (corev1.ResourceRequireme if anno, ok := pod.Annotations[constants.AnnotationSidecarProxyMemoryLimit]; ok { memoryLimit, err := resource.ParseQuantity(anno) if err != nil { - return corev1.ResourceRequirements{}, fmt.Errorf( - "parsing annotation %s:%q: %s", - constants.AnnotationSidecarProxyMemoryLimit, - anno, - err, - ) + return corev1.ResourceRequirements{}, fmt.Errorf("parsing annotation %s:%q: %s", constants.AnnotationSidecarProxyMemoryLimit, anno, err) } resources.Limits[corev1.ResourceMemory] = memoryLimit } else if w.DefaultProxyMemoryLimit != zeroQuantity { @@ -591,12 +550,7 @@ func (w *MeshWebhook) sidecarResources(pod corev1.Pod) (corev1.ResourceRequireme if anno, ok := pod.Annotations[constants.AnnotationSidecarProxyMemoryRequest]; ok { memoryRequest, err := resource.ParseQuantity(anno) if err != nil { - return corev1.ResourceRequirements{}, fmt.Errorf( - "parsing annotation %s:%q: %s", - constants.AnnotationSidecarProxyMemoryRequest, - anno, - err, - ) + return corev1.ResourceRequirements{}, fmt.Errorf("parsing annotation %s:%q: %s", constants.AnnotationSidecarProxyMemoryRequest, anno, err) } resources.Requests[corev1.ResourceMemory] = memoryRequest } else if w.DefaultProxyMemoryRequest != zeroQuantity { diff --git a/control-plane/connect-inject/webhook/container_init.go b/control-plane/connect-inject/webhook/container_init.go index c5ecab117a..24c71461af 100644 --- a/control-plane/connect-inject/webhook/container_init.go +++ b/control-plane/connect-inject/webhook/container_init.go @@ -300,12 +300,7 @@ func (w *MeshWebhook) containerInit(namespace corev1.Namespace, pod corev1.Pod, // consulDNSEnabled returns true if Consul DNS should be enabled for this pod. // It returns an error when the annotation value cannot be parsed by strconv.ParseBool or if we are unable // to read the pod's namespace label when it exists. -func consulDNSEnabled( - namespace corev1.Namespace, - pod corev1.Pod, - globalDNSEnabled bool, - globalTProxyEnabled bool, -) (bool, error) { +func consulDNSEnabled(namespace corev1.Namespace, pod corev1.Pod, globalDNSEnabled bool, globalTProxyEnabled bool) (bool, error) { // DNS is only possible when tproxy is also enabled because it relies // on traffic being redirected. tproxy, err := common.TransparentProxyEnabled(namespace, pod, globalTProxyEnabled)