Skip to content

Commit

Permalink
chore: emit InvalidSpec event
Browse files Browse the repository at this point in the history
  • Loading branch information
free6om committed Apr 25, 2024
1 parent 5b2c44d commit 73cc98b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func main() {
if err = (&workloadscontrollers.InstanceSetReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("replicated-state-machine-controller"),
Recorder: mgr.GetEventRecorderFor("instance-set-controller"),
}).SetupWithManager(mgr, multiClusterMgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "InstanceSet")
os.Exit(1)
Expand Down
8 changes: 6 additions & 2 deletions pkg/controller/instanceset/instance_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,17 @@ func validateSpec(its *workloads.InstanceSet, tree *kubebuilderx.ObjectTree) err
}
replicasInTemplates += replicas
if templateNames.Has(template.Name) {
return fmt.Errorf("duplicate instance template name: %s", template.Name)
err = fmt.Errorf("duplicate instance template name: %s", template.Name)
tree.EventRecorder.Event(its, corev1.EventTypeWarning, EventReasonInvalidSpec, err.Error())
return err
}
templateNames.Insert(template.Name)
}
// sum of spec.templates[*].replicas should not greater than spec.replicas
if replicasInTemplates > *its.Spec.Replicas {
return fmt.Errorf("total replicas in instances(%d) should not greater than replicas in spec(%d)", replicasInTemplates, *its.Spec.Replicas)
err = fmt.Errorf("total replicas in instances(%d) should not greater than replicas in spec(%d)", replicasInTemplates, *its.Spec.Replicas)
tree.EventRecorder.Event(its, corev1.EventTypeWarning, EventReasonInvalidSpec, err.Error())
return err
}

return nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/instanceset/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ const (
)
)

const (
EventReasonInvalidSpec = "InvalidSpec"
)

const (
// MaxPlainRevisionCount specified max number of plain revision stored in status.updateRevisions.
// All revisions will be compressed if exceeding this value.
Expand Down

0 comments on commit 73cc98b

Please sign in to comment.