diff --git a/pkg/controller/instanceset/instance_util.go b/pkg/controller/instanceset/instance_util.go index 5276b2b8a30..92f7ecb108b 100644 --- a/pkg/controller/instanceset/instance_util.go +++ b/pkg/controller/instanceset/instance_util.go @@ -434,7 +434,7 @@ func validateSpec(its *workloads.InstanceSet, tree *kubebuilderx.ObjectTree) err replicasInTemplates += replicas if templateNames.Has(template.Name) { err = fmt.Errorf("duplicate instance template name: %s", template.Name) - if tree.EventRecorder != nil { + if tree != nil { tree.EventRecorder.Event(its, corev1.EventTypeWarning, EventReasonInvalidSpec, err.Error()) } return err @@ -444,7 +444,7 @@ func validateSpec(its *workloads.InstanceSet, tree *kubebuilderx.ObjectTree) err // sum of spec.templates[*].replicas should not greater than spec.replicas if replicasInTemplates > *its.Spec.Replicas { err = fmt.Errorf("total replicas in instances(%d) should not greater than replicas in spec(%d)", replicasInTemplates, *its.Spec.Replicas) - if tree.EventRecorder != nil { + if tree != nil { tree.EventRecorder.Event(its, corev1.EventTypeWarning, EventReasonInvalidSpec, err.Error()) } return err