Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: emit InvalidSpec event #7172

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading