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
|
|
@ -49,24 +49,24 @@ func nowStamp() string {
|
|||
return time.Now().Format(time.StampMilli)
|
||||
}
|
||||
|
||||
func log(level string, format string, args ...interface{}) {
|
||||
func logf(level, format string, args ...interface{}) {
|
||||
fmt.Fprintf(ginkgo.GinkgoWriter, nowStamp()+": "+level+": "+format+"\n", args...)
|
||||
}
|
||||
|
||||
// Logf logs to the INFO logs.
|
||||
func Logf(format string, args ...interface{}) {
|
||||
log("INFO", format, args...)
|
||||
logf("INFO", format, args...)
|
||||
}
|
||||
|
||||
// Failf logs to the INFO logs and fails the test.
|
||||
func Failf(format string, args ...interface{}) {
|
||||
msg := fmt.Sprintf(format, args...)
|
||||
log("INFO", msg)
|
||||
logf("INFO", msg)
|
||||
ginkgo.Fail(nowStamp()+": "+msg, 1)
|
||||
}
|
||||
|
||||
// RestclientConfig deserializes the contents of a kubeconfig file into a Config object.
|
||||
func RestclientConfig(config, context string) (*api.Config, error) {
|
||||
func RestclientConfig(config, newContext string) (*api.Config, error) {
|
||||
Logf(">>> config: %s\n", config)
|
||||
if config == "" {
|
||||
return nil, fmt.Errorf("config file must be specified to load client config")
|
||||
|
|
@ -75,9 +75,9 @@ func RestclientConfig(config, context string) (*api.Config, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading config: %v", err.Error())
|
||||
}
|
||||
if context != "" {
|
||||
Logf(">>> context: %s\n", context)
|
||||
c.CurrentContext = context
|
||||
if newContext != "" {
|
||||
Logf(">>> context: %s\n", newContext)
|
||||
c.CurrentContext = newContext
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
|
@ -98,6 +98,7 @@ func createNamespace(baseName string, labels map[string]string, c kubernetes.Int
|
|||
var got *corev1.Namespace
|
||||
var err error
|
||||
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
err = wait.Poll(Poll, DefaultTimeout, func() (bool, error) {
|
||||
got, err = c.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
|
|
@ -114,13 +115,11 @@ func createNamespace(baseName string, labels map[string]string, c kubernetes.Int
|
|||
|
||||
// CreateKubeNamespace creates a new namespace in the cluster
|
||||
func CreateKubeNamespace(baseName string, c kubernetes.Interface) (string, error) {
|
||||
|
||||
return createNamespace(baseName, nil, c)
|
||||
}
|
||||
|
||||
// CreateKubeNamespaceWithLabel creates a new namespace with given labels in the cluster
|
||||
func CreateKubeNamespaceWithLabel(baseName string, labels map[string]string, c kubernetes.Interface) (string, error) {
|
||||
|
||||
return createNamespace(baseName, labels, c)
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +149,7 @@ func CreateIngressClass(namespace string, c kubernetes.Interface) (string, error
|
|||
},
|
||||
}, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unexpected error creating IngressClass %s: %v", icname, err)
|
||||
return "", fmt.Errorf("unexpected error creating IngressClass %s: %v", icname, err)
|
||||
}
|
||||
|
||||
_, err = c.RbacV1().ClusterRoles().Create(context.TODO(), &rbacv1.ClusterRole{
|
||||
|
|
@ -162,7 +161,7 @@ func CreateIngressClass(namespace string, c kubernetes.Interface) (string, error
|
|||
}},
|
||||
}, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unexpected error creating IngressClass ClusterRole %s: %v", icname, err)
|
||||
return "", fmt.Errorf("unexpected error creating IngressClass ClusterRole %s: %v", icname, err)
|
||||
}
|
||||
|
||||
_, err = c.RbacV1().ClusterRoleBindings().Create(context.TODO(), &rbacv1.ClusterRoleBinding{
|
||||
|
|
@ -184,7 +183,7 @@ func CreateIngressClass(namespace string, c kubernetes.Interface) (string, error
|
|||
},
|
||||
}, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unexpected error creating IngressClass ClusterRoleBinding %s: %v", icname, err)
|
||||
return "", fmt.Errorf("unexpected error creating IngressClass ClusterRoleBinding %s: %v", icname, err)
|
||||
}
|
||||
return ic.Name, nil
|
||||
}
|
||||
|
|
@ -200,16 +199,16 @@ func deleteIngressClass(c kubernetes.Interface, ingressclass string) error {
|
|||
}
|
||||
err = c.NetworkingV1().IngressClasses().Delete(context.TODO(), ingressclass, deleteOptions)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unexpected error deleting IngressClass %s: %v", ingressclass, err)
|
||||
return fmt.Errorf("unexpected error deleting IngressClass %s: %v", ingressclass, err)
|
||||
}
|
||||
|
||||
err = c.RbacV1().ClusterRoleBindings().Delete(context.TODO(), ingressclass, deleteOptions)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unexpected error deleting IngressClass ClusterRoleBinding %s: %v", ingressclass, err)
|
||||
return fmt.Errorf("unexpected error deleting IngressClass ClusterRoleBinding %s: %v", ingressclass, err)
|
||||
}
|
||||
err = c.RbacV1().ClusterRoles().Delete(context.TODO(), ingressclass, deleteOptions)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unexpected error deleting IngressClass ClusterRole %s: %v", ingressclass, err)
|
||||
return fmt.Errorf("unexpected error deleting IngressClass ClusterRole %s: %v", ingressclass, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -223,6 +222,7 @@ func GetIngressClassName(namespace string) *string {
|
|||
|
||||
// WaitForKubeNamespaceNotExist waits until a namespaces is not present in the cluster
|
||||
func WaitForKubeNamespaceNotExist(c kubernetes.Interface, namespace string) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
return wait.Poll(Poll, DefaultTimeout, namespaceNotExist(c, namespace))
|
||||
}
|
||||
|
||||
|
|
@ -241,6 +241,7 @@ func namespaceNotExist(c kubernetes.Interface, namespace string) wait.ConditionF
|
|||
|
||||
// WaitForNoPodsInNamespace waits until there are no pods running in a namespace
|
||||
func WaitForNoPodsInNamespace(c kubernetes.Interface, namespace string) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
return wait.Poll(Poll, DefaultTimeout, noPodsInNamespace(c, namespace))
|
||||
}
|
||||
|
||||
|
|
@ -267,15 +268,17 @@ func WaitForPodRunningInNamespace(c kubernetes.Interface, pod *corev1.Pod) error
|
|||
if pod.Status.Phase == corev1.PodRunning {
|
||||
return nil
|
||||
}
|
||||
return waitTimeoutForPodRunningInNamespace(c, pod.Name, pod.Namespace, DefaultTimeout)
|
||||
return waitTimeoutForPodRunningInNamespace(c, pod.Name, pod.Namespace)
|
||||
}
|
||||
|
||||
func waitTimeoutForPodRunningInNamespace(c kubernetes.Interface, podName, namespace string, timeout time.Duration) error {
|
||||
func waitTimeoutForPodRunningInNamespace(c kubernetes.Interface, podName, namespace string) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
return wait.Poll(Poll, DefaultTimeout, podRunning(c, podName, namespace))
|
||||
}
|
||||
|
||||
// WaitForSecretInNamespace waits a default amount of time for the specified secret is present in a particular namespace
|
||||
func WaitForSecretInNamespace(c kubernetes.Interface, namespace, name string) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
return wait.Poll(Poll, DefaultTimeout, secretInNamespace(c, namespace, name))
|
||||
}
|
||||
|
||||
|
|
@ -298,6 +301,7 @@ func secretInNamespace(c kubernetes.Interface, namespace, name string) wait.Cond
|
|||
|
||||
// WaitForFileInFS waits a default amount of time for the specified file is present in the filesystem
|
||||
func WaitForFileInFS(file string) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
return wait.Poll(Poll, DefaultTimeout, fileInFS(file))
|
||||
}
|
||||
|
||||
|
|
@ -322,6 +326,7 @@ func fileInFS(file string) wait.ConditionFunc {
|
|||
|
||||
// WaitForNoIngressInNamespace waits until there is no ingress object in a particular namespace
|
||||
func WaitForNoIngressInNamespace(c kubernetes.Interface, namespace, name string) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
return wait.Poll(Poll, DefaultTimeout, noIngressInNamespace(c, namespace, name))
|
||||
}
|
||||
|
||||
|
|
@ -344,6 +349,7 @@ func noIngressInNamespace(c kubernetes.Interface, namespace, name string) wait.C
|
|||
|
||||
// WaitForIngressInNamespace waits until a particular ingress object exists namespace
|
||||
func WaitForIngressInNamespace(c kubernetes.Interface, namespace, name string) error {
|
||||
//nolint:staticcheck // TODO: will replace it since wait.Poll is deprecated
|
||||
return wait.Poll(Poll, DefaultTimeout, ingressInNamespace(c, namespace, name))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue