diff --git a/pkg/dclient/client.go b/pkg/dclient/client.go index 1336a9788a..9b4ef410ba 100644 --- a/pkg/dclient/client.go +++ b/pkg/dclient/client.go @@ -8,7 +8,6 @@ import ( "github.com/go-logr/logr" openapiv2 "github.com/googleapis/gnostic/openapiv2" - helperv1 "k8s.io/apimachinery/pkg/apis/meta/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -131,7 +130,7 @@ func (c *Client) GetDynamicInterface() dynamic.Interface { func (c *Client) ListResource(apiVersion string, kind string, namespace string, lselector *meta.LabelSelector) (*unstructured.UnstructuredList, error) { options := meta.ListOptions{} if lselector != nil { - options = meta.ListOptions{LabelSelector: helperv1.FormatLabelSelector(lselector)} + options = meta.ListOptions{LabelSelector: meta.FormatLabelSelector(lselector)} } return c.getResourceInterface(apiVersion, kind, namespace).List(context.TODO(), options) diff --git a/pkg/engine/jmespath/functions.go b/pkg/engine/jmespath/functions.go index 67e13b1c32..e5591ebb04 100644 --- a/pkg/engine/jmespath/functions.go +++ b/pkg/engine/jmespath/functions.go @@ -503,17 +503,17 @@ func jpModulo(arguments []interface{}) (interface{}, error) { // InterfaceToString casts an interface to a string type func ifaceToString(iface interface{}) (string, error) { - switch iface.(type) { + switch i := iface.(type) { case int: - return strconv.Itoa(iface.(int)), nil + return strconv.Itoa(i), nil case float64: - return strconv.FormatFloat(iface.(float64), 'f', -1, 32), nil + return strconv.FormatFloat(i, 'f', -1, 32), nil case float32: - return strconv.FormatFloat(iface.(float64), 'f', -1, 32), nil + return strconv.FormatFloat(float64(i), 'f', -1, 32), nil case string: - return iface.(string), nil + return i, nil case bool: - return strconv.FormatBool(iface.(bool)), nil + return strconv.FormatBool(i), nil default: return "", errors.New("error, undefined type cast") } diff --git a/pkg/engine/validate/pattern.go b/pkg/engine/validate/pattern.go index 7b12f73163..cde899ff3e 100644 --- a/pkg/engine/validate/pattern.go +++ b/pkg/engine/validate/pattern.go @@ -195,21 +195,21 @@ func validateString(log logr.Logger, value interface{}, pattern string, operator if operator.NotEqual == operatorVariable || operator.Equal == operatorVariable { var strValue string var ok bool = false - switch value.(type) { + switch v := value.(type) { case float64: - strValue = strconv.FormatFloat(value.(float64), 'E', -1, 64) + strValue = strconv.FormatFloat(v, 'E', -1, 64) ok = true case int: - strValue = strconv.FormatInt(int64(value.(int)), 10) + strValue = strconv.FormatInt(int64(v), 10) ok = true case int64: - strValue = strconv.FormatInt(value.(int64), 10) + strValue = strconv.FormatInt(v, 10) ok = true case string: - strValue = value.(string) + strValue = v ok = true case bool: - strValue = strconv.FormatBool(value.(bool)) + strValue = strconv.FormatBool(v) ok = true case nil: ok = false diff --git a/pkg/engine/variables/evaluate.go b/pkg/engine/variables/evaluate.go index 4dbb0731a2..ec41499690 100644 --- a/pkg/engine/variables/evaluate.go +++ b/pkg/engine/variables/evaluate.go @@ -55,12 +55,10 @@ func evaluateAnyAllConditions(log logr.Logger, ctx context.EvalInterface, condit } // update the allConditionsResult if they are present - if allConditions != nil { - for _, condition := range allConditions { - if !Evaluate(log, ctx, condition) { - allConditionsResult = false - break - } + for _, condition := range allConditions { + if !Evaluate(log, ctx, condition) { + allConditionsResult = false + break } } diff --git a/pkg/engine/variables/evaluate_test.go b/pkg/engine/variables/evaluate_test.go index 0ff80f19c5..59184e2ec9 100644 --- a/pkg/engine/variables/evaluate_test.go +++ b/pkg/engine/variables/evaluate_test.go @@ -1633,7 +1633,7 @@ func Test_Eval_In_String_Set_Pass(t *testing.T) { func Test_Eval_In_String_Set_Fail(t *testing.T) { ctx := context.NewContext() key := [2]string{"1.1.1.1", "4.4.4.4"} - keyInterface := make([]interface{}, len(key), len(key)) + keyInterface := make([]interface{}, len(key)) for i := range key { keyInterface[i] = key[i] } diff --git a/pkg/tls/tls.go b/pkg/tls/tls.go index 5076d9ebb4..a678a6690e 100644 --- a/pkg/tls/tls.go +++ b/pkg/tls/tls.go @@ -120,13 +120,13 @@ func GenerateCertPem(caCert *KeyPair, props CertificateProps, serverIP string, c end := now.Add(certValidityDuration) dnsNames := make([]string, 3) - dnsNames[0] = fmt.Sprintf("%s", props.Service) + dnsNames[0] = props.Service csCommonName := dnsNames[0] dnsNames[1] = fmt.Sprintf("%s.%s", props.Service, props.Namespace) // The full service name is the CommonName for the certificate commonName := generateInClusterServiceName(props) - dnsNames[2] = fmt.Sprintf("%s", commonName) + dnsNames[2] = commonName var ips []net.IP apiServerIP := net.ParseIP(props.APIServerHost) @@ -210,7 +210,5 @@ func IsTLSPairShouldBeUpdated(tlsPair *PemPair) bool { if err != nil { return true } - - // TODO : should use time.Until instead of t.Sub(time.Now()) (gosimple) - return expirationDate.Sub(time.Now()) < timeReserveBeforeCertificateExpiration + return time.Until(*expirationDate) < timeReserveBeforeCertificateExpiration }