1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 02:45:06 +00:00

Fix remaining static check findings (#2541)

Signed-off-by: Marcel Mueller <marcel.mueller1@rwth-aachen.de>
This commit is contained in:
Bricktop 2021-10-14 01:00:41 +02:00 committed by GitHub
parent ab8822963b
commit d62234d776
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 26 deletions

View file

@ -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)

View file

@ -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")
}

View file

@ -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

View file

@ -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
}
}

View file

@ -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]
}

View file

@ -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
}