Fix golangci-lint errors (#10196)
* Fix golangci-lint errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix dupl errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix comments Signed-off-by: z1cheng <imchench@gmail.com> * Fix errcheck lint errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix assert in e2e test Signed-off-by: z1cheng <imchench@gmail.com> * Not interrupt the waitForPodsReady Signed-off-by: z1cheng <imchench@gmail.com> * Replace string with constant Signed-off-by: z1cheng <imchench@gmail.com> * Fix comments Signed-off-by: z1cheng <imchench@gmail.com> * Revert write file permision Signed-off-by: z1cheng <imchench@gmail.com> --------- Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
parent
46d87d3462
commit
b3060bfbd0
253 changed files with 2434 additions and 2113 deletions
|
|
@ -47,7 +47,7 @@ func (f *Framework) EnsureSecret(secret *core.Secret) *core.Secret {
|
|||
}
|
||||
|
||||
// GetConfigMap gets a ConfigMap object from the given namespace, name and returns it, throws error if it does not exist.
|
||||
func (f *Framework) GetConfigMap(namespace string, name string) *core.ConfigMap {
|
||||
func (f *Framework) GetConfigMap(namespace, name string) *core.ConfigMap {
|
||||
cm, err := f.KubeClientSet.CoreV1().ConfigMaps(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "getting configmap")
|
||||
assert.NotNil(ginkgo.GinkgoT(), cm, "expected a configmap but none returned")
|
||||
|
|
@ -73,7 +73,7 @@ func (f *Framework) EnsureConfigMap(configMap *core.ConfigMap) *core.ConfigMap {
|
|||
}
|
||||
|
||||
// GetIngress gets an Ingress object from the given namespace, name and returns it, throws error if it does not exists.
|
||||
func (f *Framework) GetIngress(namespace string, name string) *networking.Ingress {
|
||||
func (f *Framework) GetIngress(namespace, name string) *networking.Ingress {
|
||||
ing, err := f.KubeClientSet.NetworkingV1().Ingresses(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "getting ingress")
|
||||
assert.NotNil(ginkgo.GinkgoT(), ing, "expected an ingress but none returned")
|
||||
|
|
@ -114,7 +114,7 @@ func (f *Framework) UpdateIngress(ingress *networking.Ingress) *networking.Ingre
|
|||
}
|
||||
|
||||
// GetService gets a Service object from the given namespace, name and returns it, throws error if it does not exist.
|
||||
func (f *Framework) GetService(namespace string, name string) *core.Service {
|
||||
func (f *Framework) GetService(namespace, name string) *core.Service {
|
||||
s, err := f.KubeClientSet.CoreV1().Services(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "getting service")
|
||||
assert.NotNil(ginkgo.GinkgoT(), s, "expected a service but none returned")
|
||||
|
|
@ -143,16 +143,21 @@ func (f *Framework) EnsureDeployment(deployment *appsv1.Deployment) *appsv1.Depl
|
|||
}
|
||||
|
||||
// waitForPodsReady waits for a given amount of time until a group of Pods is running in the given namespace.
|
||||
func waitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration, expectedReplicas int, namespace string, opts metav1.ListOptions) error {
|
||||
func waitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration, expectedReplicas int, namespace string, opts *metav1.ListOptions) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.PollImmediate is deprecated
|
||||
return wait.PollImmediate(1*time.Second, timeout, func() (bool, error) {
|
||||
pl, err := kubeClientSet.CoreV1().Pods(namespace).List(context.TODO(), opts)
|
||||
pl, err := kubeClientSet.CoreV1().Pods(namespace).List(context.TODO(), *opts)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
r := 0
|
||||
for _, p := range pl.Items {
|
||||
if isRunning, _ := podRunningReady(&p); isRunning {
|
||||
for i := range pl.Items {
|
||||
isRunning, err := podRunningReady(&pl.Items[i])
|
||||
if err != nil {
|
||||
Logf("error checking if pod is running : %v", err)
|
||||
}
|
||||
if isRunning {
|
||||
r++
|
||||
}
|
||||
}
|
||||
|
|
@ -166,9 +171,10 @@ func waitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration,
|
|||
}
|
||||
|
||||
// waitForPodsDeleted waits for a given amount of time until a group of Pods are deleted in the given namespace.
|
||||
func waitForPodsDeleted(kubeClientSet kubernetes.Interface, timeout time.Duration, namespace string, opts metav1.ListOptions) error {
|
||||
func waitForPodsDeleted(kubeClientSet kubernetes.Interface, timeout time.Duration, namespace string, opts *metav1.ListOptions) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
return wait.Poll(Poll, timeout, func() (bool, error) {
|
||||
pl, err := kubeClientSet.CoreV1().Pods(namespace).List(context.TODO(), opts)
|
||||
pl, err := kubeClientSet.CoreV1().Pods(namespace).List(context.TODO(), *opts)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
|
@ -186,7 +192,7 @@ func WaitForEndpoints(kubeClientSet kubernetes.Interface, timeout time.Duration,
|
|||
if expectedEndpoints == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:staticcheck // TODO: will replace it since wait.PollImmediate is deprecated
|
||||
return wait.PollImmediate(Poll, timeout, func() (bool, error) {
|
||||
endpoint, err := kubeClientSet.CoreV1().Endpoints(ns).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
if k8sErrors.IsNotFound(err) {
|
||||
|
|
@ -248,6 +254,7 @@ func isPodReady(p *core.Pod) bool {
|
|||
// getIngressNGINXPod returns the ingress controller running pod
|
||||
func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Pod, error) {
|
||||
var pod *core.Pod
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
err := wait.Poll(1*time.Second, DefaultTimeout, func() (bool, error) {
|
||||
l, err := kubeClientSet.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{
|
||||
LabelSelector: "app.kubernetes.io/name=ingress-nginx",
|
||||
|
|
@ -256,15 +263,16 @@ func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Po
|
|||
return false, nil
|
||||
}
|
||||
|
||||
for _, p := range l.Items {
|
||||
for i := range l.Items {
|
||||
p := &l.Items[i]
|
||||
if strings.HasPrefix(p.GetName(), "nginx-ingress-controller") {
|
||||
isRunning, err := podRunningReady(&p)
|
||||
isRunning, err := podRunningReady(p)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if isRunning {
|
||||
pod = &p
|
||||
pod = p
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
|
@ -273,6 +281,7 @@ func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Po
|
|||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.ErrWaitTimeout is deprecated
|
||||
if err == wait.ErrWaitTimeout {
|
||||
return nil, fmt.Errorf("timeout waiting at least one ingress-nginx pod running in namespace %v", ns)
|
||||
}
|
||||
|
|
@ -285,7 +294,7 @@ func getIngressNGINXPod(ns string, kubeClientSet kubernetes.Interface) (*core.Po
|
|||
|
||||
func createDeploymentWithRetries(c kubernetes.Interface, namespace string, obj *appsv1.Deployment) error {
|
||||
if obj == nil {
|
||||
return fmt.Errorf("Object provided to create is empty")
|
||||
return fmt.Errorf("object provided to create is empty")
|
||||
}
|
||||
createFunc := func() (bool, error) {
|
||||
_, err := c.AppsV1().Deployments(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
|
||||
|
|
@ -298,7 +307,7 @@ func createDeploymentWithRetries(c kubernetes.Interface, namespace string, obj *
|
|||
if isRetryableAPIError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("Failed to create object with non-retriable error: %v", err)
|
||||
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
|
||||
}
|
||||
|
||||
return retryWithExponentialBackOff(createFunc)
|
||||
|
|
@ -306,7 +315,7 @@ func createDeploymentWithRetries(c kubernetes.Interface, namespace string, obj *
|
|||
|
||||
func createSecretWithRetries(c kubernetes.Interface, namespace string, obj *core.Secret) error {
|
||||
if obj == nil {
|
||||
return fmt.Errorf("Object provided to create is empty")
|
||||
return fmt.Errorf("object provided to create is empty")
|
||||
}
|
||||
createFunc := func() (bool, error) {
|
||||
_, err := c.CoreV1().Secrets(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
|
||||
|
|
@ -319,14 +328,14 @@ func createSecretWithRetries(c kubernetes.Interface, namespace string, obj *core
|
|||
if isRetryableAPIError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("Failed to create object with non-retriable error: %v", err)
|
||||
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
|
||||
}
|
||||
return retryWithExponentialBackOff(createFunc)
|
||||
}
|
||||
|
||||
func createServiceWithRetries(c kubernetes.Interface, namespace string, obj *core.Service) error {
|
||||
if obj == nil {
|
||||
return fmt.Errorf("Object provided to create is empty")
|
||||
return fmt.Errorf("object provided to create is empty")
|
||||
}
|
||||
createFunc := func() (bool, error) {
|
||||
_, err := c.CoreV1().Services(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
|
||||
|
|
@ -339,7 +348,7 @@ func createServiceWithRetries(c kubernetes.Interface, namespace string, obj *cor
|
|||
if isRetryableAPIError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("Failed to create object with non-retriable error: %v", err)
|
||||
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
|
||||
}
|
||||
|
||||
return retryWithExponentialBackOff(createFunc)
|
||||
|
|
@ -347,7 +356,7 @@ func createServiceWithRetries(c kubernetes.Interface, namespace string, obj *cor
|
|||
|
||||
func createIngressWithRetries(c kubernetes.Interface, namespace string, obj *networking.Ingress) error {
|
||||
if obj == nil {
|
||||
return fmt.Errorf("Object provided to create is empty")
|
||||
return fmt.Errorf("object provided to create is empty")
|
||||
}
|
||||
createFunc := func() (bool, error) {
|
||||
_, err := c.NetworkingV1().Ingresses(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
|
||||
|
|
@ -360,7 +369,7 @@ func createIngressWithRetries(c kubernetes.Interface, namespace string, obj *net
|
|||
if isRetryableAPIError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("Failed to create object with non-retriable error: %v", err)
|
||||
return false, fmt.Errorf("failed to create object with non-retriable error: %v", err)
|
||||
}
|
||||
|
||||
return retryWithExponentialBackOff(createFunc)
|
||||
|
|
@ -368,7 +377,7 @@ func createIngressWithRetries(c kubernetes.Interface, namespace string, obj *net
|
|||
|
||||
func updateIngressWithRetries(c kubernetes.Interface, namespace string, obj *networking.Ingress) error {
|
||||
if obj == nil {
|
||||
return fmt.Errorf("Object provided to create is empty")
|
||||
return fmt.Errorf("object provided to create is empty")
|
||||
}
|
||||
updateFunc := func() (bool, error) {
|
||||
_, err := c.NetworkingV1().Ingresses(namespace).Update(context.TODO(), obj, metav1.UpdateOptions{})
|
||||
|
|
@ -378,7 +387,7 @@ func updateIngressWithRetries(c kubernetes.Interface, namespace string, obj *net
|
|||
if isRetryableAPIError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("Failed to update object with non-retriable error: %v", err)
|
||||
return false, fmt.Errorf("failed to update object with non-retriable error: %v", err)
|
||||
}
|
||||
|
||||
return retryWithExponentialBackOff(updateFunc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue