|
1 | 1 | package internal |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/json" |
5 | | - "fmt" |
6 | 4 | "reflect" |
7 | 5 | "strings" |
8 | 6 |
|
@@ -31,7 +29,7 @@ func checkEmptyFields(result *errors.ManifestResult, v reflect.Value, parentStru |
31 | 29 | // Omitted field tags will contain ",omitempty", and ignored tags will |
32 | 30 | // match "-" exactly, respectively. |
33 | 31 | isOptionalField := strings.Contains(tag, ",omitempty") || tag == "-" |
34 | | - emptyVal := isEmptyValue(fieldValue) |
| 32 | + emptyVal := fieldValue.IsZero() |
35 | 33 |
|
36 | 34 | newParentStructName := fieldType.Name |
37 | 35 | if parentStructName != "" { |
@@ -59,38 +57,3 @@ func updateResult(result *errors.ManifestResult, typeName string, newParentStruc |
59 | 57 | result.Add(errors.ErrFieldMissing("required field missing", newParentStructName, typeName)) |
60 | 58 | } |
61 | 59 | } |
62 | | - |
63 | | -// Uses reflect package to check if the value of the object passed is null, returns a boolean accordingly. |
64 | | -// TODO: replace with reflect.Kind.IsZero() in go 1.13 |
65 | | -func isEmptyValue(v reflect.Value) bool { |
66 | | - switch v.Kind() { |
67 | | - case reflect.Array, reflect.Map, reflect.Slice, reflect.String: |
68 | | - // Check if the value for 'Spec.InstallStrategy.StrategySpecRaw' field is present. This field is a RawMessage value type. Without a value, the key is explicitly set to 'null'. |
69 | | - if fieldValue, ok := v.Interface().(json.RawMessage); ok { |
70 | | - valString := string(fieldValue) |
71 | | - if valString == "null" { |
72 | | - return true |
73 | | - } |
74 | | - } |
75 | | - return v.Len() == 0 |
76 | | - // Currently the only CSV field with integer type is containerPort. Operator Verification Library raises a warning if containerPort field is missisng or if its value is 0. |
77 | | - // It is an optional field so the user can ignore the warning saying this field is missing if they intend to use port 0. |
78 | | - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
79 | | - return v.Int() == 0 |
80 | | - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: |
81 | | - return v.Uint() == 0 |
82 | | - case reflect.Float32, reflect.Float64: |
83 | | - return v.Float() == 0 |
84 | | - case reflect.Interface, reflect.Ptr: |
85 | | - return v.IsNil() |
86 | | - case reflect.Struct: |
87 | | - for i, n := 0, v.NumField(); i < n; i++ { |
88 | | - if !isEmptyValue(v.Field(i)) { |
89 | | - return false |
90 | | - } |
91 | | - } |
92 | | - return true |
93 | | - default: |
94 | | - panic(fmt.Sprintf("%v kind is not supported.", v.Kind())) |
95 | | - } |
96 | | -} |
0 commit comments