Fix unit tests and comments
Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
parent
4b6d0c0738
commit
1d8e7f4695
7 changed files with 17 additions and 40 deletions
|
@ -18,6 +18,7 @@ package certs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -47,7 +48,8 @@ func CreateCommand(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
||||||
|
|
||||||
cmd.Flags().String("host", "", "Get the cert for this hostname")
|
cmd.Flags().String("host", "", "Get the cert for this hostname")
|
||||||
if err := cobra.MarkFlagRequired(cmd.Flags(), "host"); err != nil {
|
if err := cobra.MarkFlagRequired(cmd.Flags(), "host"); err != nil {
|
||||||
fmt.Printf("error marking flag as required: %v", err)
|
util.PrintError(err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
pod = util.AddPodFlag(cmd)
|
pod = util.AddPodFlag(cmd)
|
||||||
deployment = util.AddDeploymentFlag(cmd)
|
deployment = util.AddDeploymentFlag(cmd)
|
||||||
|
|
|
@ -78,9 +78,7 @@ func execToWriter(args []string, writer io.Writer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if _, err := io.Copy(writer, op); err != nil {
|
io.Copy(writer, op) //nolint:errcheck
|
||||||
fmt.Printf("Error copying output: %v\n", err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -103,9 +103,7 @@ func TestNginxCheck(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
if err := cmd.Wait(); err != nil {
|
cmd.Wait() //nolint:errcheck
|
||||||
t.Errorf("unexpected error waiting for the process: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if _, err := pidFile.Write([]byte(fmt.Sprintf("%v", pid))); err != nil {
|
if _, err := pidFile.Write([]byte(fmt.Sprintf("%v", pid))); err != nil {
|
||||||
|
@ -123,9 +121,7 @@ func TestNginxCheck(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// pollute pid file
|
// pollute pid file
|
||||||
if _, err := pidFile.Write([]byte("999999")); err != nil {
|
pidFile.Write([]byte("999999")) //nolint:errcheck
|
||||||
t.Errorf("unexpected error polluting the pid file: %v", err)
|
|
||||||
}
|
|
||||||
pidFile.Close()
|
pidFile.Close()
|
||||||
|
|
||||||
t.Run("bad pid", func(t *testing.T) {
|
t.Run("bad pid", func(t *testing.T) {
|
||||||
|
|
|
@ -92,11 +92,7 @@ func TestStore(t *testing.T) {
|
||||||
|
|
||||||
emptySelector, _ := labels.Parse("")
|
emptySelector, _ := labels.Parse("")
|
||||||
|
|
||||||
defer func() {
|
defer te.Stop() //nolint:errcheck
|
||||||
if err := te.Stop(); err != nil {
|
|
||||||
t.Errorf("error: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
clientSet, err := kubernetes.NewForConfig(cfg)
|
clientSet, err := kubernetes.NewForConfig(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -18,13 +18,14 @@ package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
"crypto/sha1" // #nosec
|
"crypto/sha1" // #nosec
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand" // #nosec
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -34,7 +35,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
text_template "text/template"
|
text_template "text/template"
|
||||||
"time"
|
|
||||||
|
|
||||||
networkingv1 "k8s.io/api/networking/v1"
|
networkingv1 "k8s.io/api/networking/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
@ -1186,16 +1186,16 @@ func buildAuthSignURLLocation(location, authSignURL string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
var random *rand.Rand
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
random = rand.New(rand.NewSource(time.Now().UnixNano())) // #nosec
|
|
||||||
}
|
|
||||||
|
|
||||||
func randomString() string {
|
func randomString() string {
|
||||||
b := make([]rune, 32)
|
b := make([]rune, 32)
|
||||||
for i := range b {
|
for i := range b {
|
||||||
b[i] = letters[random.Intn(len(letters))] // #nosec
|
idx, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("unexpected error generating random index: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
b[i] = letters[idx.Int64()]
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(b)
|
return string(b)
|
||||||
|
|
|
@ -48,10 +48,7 @@ func TestProcessCollector(t *testing.T) {
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
err = cmd.Wait()
|
cmd.Wait() //nolint:errcheck
|
||||||
if err != nil {
|
|
||||||
t.Errorf("unexpected error waiting for dummy process: %v", err)
|
|
||||||
}
|
|
||||||
status := cmd.ProcessState.Sys().(syscall.WaitStatus)
|
status := cmd.ProcessState.Sys().(syscall.WaitStatus)
|
||||||
if status.Signaled() {
|
if status.Signaled() {
|
||||||
t.Logf("Signal: %v", status.Signal())
|
t.Logf("Signal: %v", status.Signal())
|
||||||
|
@ -72,11 +69,8 @@ func TestProcessCollector(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
cm.Stop()
|
cm.Stop()
|
||||||
|
|
||||||
err = cmd.Process.Kill()
|
cmd.Process.Kill() //nolint:errcheck
|
||||||
<-done
|
<-done
|
||||||
if err != nil {
|
|
||||||
t.Errorf("unexpected error killing dummy process: %v", err)
|
|
||||||
}
|
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
@ -228,20 +228,11 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
|
||||||
flags.IntVar(&nginx.MaxmindRetriesCount, "maxmind-retries-count", 1, "Number of attempts to download the GeoIP DB.")
|
flags.IntVar(&nginx.MaxmindRetriesCount, "maxmind-retries-count", 1, "Number of attempts to download the GeoIP DB.")
|
||||||
flags.DurationVar(&nginx.MaxmindRetriesTimeout, "maxmind-retries-timeout", time.Second*0, "Maxmind downloading delay between 1st and 2nd attempt, 0s - do not retry to download if something went wrong.")
|
flags.DurationVar(&nginx.MaxmindRetriesTimeout, "maxmind-retries-timeout", time.Second*0, "Maxmind downloading delay between 1st and 2nd attempt, 0s - do not retry to download if something went wrong.")
|
||||||
|
|
||||||
if err := flag.Set("logtostderr", "true"); err != nil {
|
|
||||||
return false, nil, err
|
|
||||||
}
|
|
||||||
flags.AddGoFlagSet(flag.CommandLine)
|
flags.AddGoFlagSet(flag.CommandLine)
|
||||||
if err := flags.Parse(os.Args); err != nil {
|
if err := flags.Parse(os.Args); err != nil {
|
||||||
return false, nil, err
|
return false, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround for this issue:
|
|
||||||
// https://github.com/kubernetes/kubernetes/issues/17162
|
|
||||||
if err := flag.CommandLine.Parse([]string{}); err != nil {
|
|
||||||
return false, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
pflag.VisitAll(func(flag *pflag.Flag) {
|
pflag.VisitAll(func(flag *pflag.Flag) {
|
||||||
klog.V(2).InfoS("FLAG", flag.Name, flag.Value)
|
klog.V(2).InfoS("FLAG", flag.Name, flag.Value)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue