Skip to content

Commit 35f9368

Browse files
Fix lint errors (#567)
* Fix lint errors * Update pkg/controller/instance/controller_reconcile.go * Add openApi key types constants
1 parent 8f53372 commit 35f9368

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

pkg/controller/instance/controller_reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func (igr *instanceGraphReconciler) finalizeDeletion(ctx context.Context) error
439439
}
440440

441441
// setManaged ensures the instance has the necessary finalizer and labels.
442-
func (igr *instanceGraphReconciler) setManaged(ctx context.Context, obj *unstructured.Unstructured, uid types.UID) (*unstructured.Unstructured, error) {
442+
func (igr *instanceGraphReconciler) setManaged(ctx context.Context, obj *unstructured.Unstructured, _ types.UID) (*unstructured.Unstructured, error) {
443443
if exist, _ := metadata.HasInstanceFinalizerUnstructured(obj); exist {
444444
return obj, nil
445445
}

pkg/dynamiccontroller/dynamic_controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,12 @@ func (dc *DynamicController) StartServingGVK(ctx context.Context, gvr schema.Gro
463463
dc.log.Error(err, "Failed to add event handler", "gvr", gvr)
464464
return fmt.Errorf("failed to add event handler for GVR %s: %w", gvr, err)
465465
}
466-
informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
466+
if err := informer.SetWatchErrorHandler(func(r *cache.Reflector, err error) {
467467
dc.log.Error(err, "Watch error", "gvr", gvr)
468-
})
468+
}); err != nil {
469+
dc.log.Error(err, "Failed to set watch error handler", "gvr", gvr)
470+
return fmt.Errorf("failed to set watch error handler for GVR %s: %w", gvr, err)
471+
}
469472
dc.handlers.Store(gvr, handler)
470473

471474
informerContext := context.Background()

pkg/graph/schema/field_descriptor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type fieldDescriptor struct {
6666
// The path is typically found by calling `parser.ParseSchemalessResource` see the
6767
// `typesystem/parser` package for more information.
6868
Path string
69-
// Schema is the schema for the field. This is typically inferred by dry runing
69+
// Schema is the schema for the field. This is typically inferred by dry running
7070
// the CEL expression that generates the field value, then converting the result
7171
// into an OpenAPI schema.
7272
Schema *extv1.JSONSchemaProps

pkg/simpleschema/transform.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ import (
2323
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2424
)
2525

26-
// A predefined type is a type that is predefined in the schema.
26+
const (
27+
keyTypeString = string(AtomicTypeString)
28+
keyTypeInteger = string(AtomicTypeInteger)
29+
keyTypeBoolean = string(AtomicTypeBool)
30+
keyTypeNumber = "number"
31+
)
32+
33+
// A predefinedType is a type that is predefined in the schema.
2734
// It is used to resolve references in the schema, while capturing the fact
2835
// whether the type has the required marker set (this information would
2936
// otherwise be lost in the parsing process).
@@ -112,7 +119,7 @@ func (tf *transformer) parseFieldSchema(key, fieldValue string, parentSchema *ex
112119
fieldJSONSchemaProps := &extv1.JSONSchemaProps{}
113120

114121
if isAtomicType(fieldType) {
115-
fieldJSONSchemaProps.Type = string(fieldType)
122+
fieldJSONSchemaProps.Type = fieldType
116123
} else if isCollectionType(fieldType) {
117124
if isMapType(fieldType) {
118125
fieldJSONSchemaProps, err = tf.handleMapType(key, fieldType)
@@ -147,7 +154,7 @@ func (tf *transformer) handleMapType(key, fieldType string) (*extv1.JSONSchemaPr
147154
if err != nil {
148155
return nil, fmt.Errorf("failed to parse map type for %s: %w", key, err)
149156
}
150-
if keyType != "string" {
157+
if keyType != keyTypeString {
151158
return nil, fmt.Errorf("unsupported key type for maps: %s", keyType)
152159
}
153160

@@ -215,9 +222,9 @@ func (tf *transformer) applyMarkers(schema *extv1.JSONSchemaProps, markers []*Ma
215222
case MarkerTypeDefault:
216223
var defaultValue []byte
217224
switch schema.Type {
218-
case "string":
225+
case keyTypeString:
219226
defaultValue = []byte(fmt.Sprintf("\"%s\"", marker.Value))
220-
case "integer", "number", "boolean":
227+
case keyTypeInteger, keyTypeNumber, keyTypeBoolean:
221228
defaultValue = []byte(marker.Value)
222229
default:
223230
defaultValue = []byte(marker.Value)
@@ -260,9 +267,9 @@ func (tf *transformer) applyMarkers(schema *extv1.JSONSchemaProps, markers []*Ma
260267

261268
var rawValue []byte
262269
switch schema.Type {
263-
case "string":
270+
case keyTypeString:
264271
rawValue = []byte(fmt.Sprintf("%q", val))
265-
case "integer":
272+
case keyTypeInteger:
266273
if _, err := strconv.ParseInt(val, 10, 64); err != nil {
267274
return fmt.Errorf("failed to parse integer enum value: %w", err)
268275
}

0 commit comments

Comments
 (0)