Skip to content

Commit 91adc1e

Browse files
committed
fix(controller): guard toCreate against negative, remove dead vmName variable
1 parent b7803ad commit 91adc1e

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

internal/controller/impwarmpool_controller.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package controller
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"time"
2322

2423
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -112,6 +111,9 @@ func (r *ImpWarmPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request)
112111

113112
// Create missing VMs to reach spec.size.
114113
toCreate := pool.Spec.Size - activeCount
114+
if toCreate < 0 {
115+
toCreate = 0
116+
}
115117
for i := int32(0); i < toCreate; i++ {
116118
if err := r.createPoolMember(ctx, pool, tpl, baseSnapshot); err != nil {
117119
return ctrl.Result{}, err
@@ -138,8 +140,6 @@ func (r *ImpWarmPoolReconciler) createPoolMember(
138140
tpl *impv1alpha1.ImpVMTemplate,
139141
baseSnapshot string,
140142
) error {
141-
vmName := fmt.Sprintf("%s-%s", pool.Name, time.Now().UTC().Format("20060102-150405-000000"))
142-
143143
vm := &impv1alpha1.ImpVM{
144144
ObjectMeta: metav1.ObjectMeta{
145145
GenerateName: pool.Name + "-",
@@ -154,8 +154,6 @@ func (r *ImpWarmPoolReconciler) createPoolMember(
154154
SnapshotRef: baseSnapshot,
155155
},
156156
}
157-
_ = vmName // GenerateName is used instead; vmName would conflict on fast loops
158-
159157
if tpl.Spec.NetworkRef != nil {
160158
vm.Spec.NetworkRef = tpl.Spec.NetworkRef
161159
}

0 commit comments

Comments
 (0)