Skip to content

Commit 144c53a

Browse files
committed
fix logic
Signed-off-by: Pavel Tishkov <[email protected]>
1 parent 14437a7 commit 144c53a

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

images/hooks/pkg/hooks/create-generic-vmclass/hook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func Reconcile(_ context.Context, input *pkg.HookInput) error {
9696
if decodedBytes, err := base64.StdEncoding.DecodeString(encodedStr); err == nil {
9797
if string(decodedBytes) == "true" {
9898
shouldCreateVMClass = true
99-
input.Logger.Info("Found record in module-state that generic vmclass was created previously")
99+
input.Logger.Info("Found record in module-state that generic VirtualMachineClass was created previously")
100100
}
101101
}
102102
}
@@ -107,7 +107,7 @@ func Reconcile(_ context.Context, input *pkg.HookInput) error {
107107
vmClassExists := len(vmClasses) > 0
108108

109109
if shouldCreateVMClass && !vmClassExists {
110-
input.Logger.Info("Creating generic VirtualMachineClass as it was previously created but is now missing")
110+
input.Logger.Info("Creating generic VirtualMachineClass")
111111

112112
vmClass := &v1alpha2.VirtualMachineClass{
113113
TypeMeta: metav1.TypeMeta{
@@ -168,7 +168,7 @@ func Reconcile(_ context.Context, input *pkg.HookInput) error {
168168
} else if shouldCreateVMClass && vmClassExists {
169169
input.Logger.Info("Generic VirtualMachineClass already exists, no action needed")
170170
} else if !shouldCreateVMClass && !vmClassExists {
171-
input.Logger.Info("No record of generic vmclass creation in module-state, skipping creation")
171+
input.Logger.Info("No record of generic VirtualMachineClass creation in module-state, skipping creation")
172172
}
173173

174174
return nil

images/hooks/pkg/hooks/update-module-state/hook.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,14 @@ func Reconcile(_ context.Context, input *pkg.HookInput) error {
134134
needsUpdate = true
135135
input.Logger.Info("Generic VirtualMachineClass exists but module-state doesn't reflect this, updating secret")
136136
} else if !vmClassExists && currentState {
137-
needsUpdate = true
138-
input.Logger.Info("Generic VirtualMachineClass doesn't exist but module-state indicates it was created, updating secret")
137+
input.Logger.Info("Generic VirtualMachineClass doesn't exist but module-state indicates it was created previously - keeping historical record")
139138
} else if len(moduleStateSecrets) == 0 {
140139
needsUpdate = true
141140
input.Logger.Info("Module-state secret doesn't exist, creating it")
142141
} else if vmClassExists && currentState {
143-
input.Logger.Info("Module-state correctly reflects that generic vmclass exists")
142+
input.Logger.Info("Module-state correctly reflects that generic VirtualMachineClass exists")
144143
} else {
145-
input.Logger.Info("Module-state correctly reflects that generic vmclass doesn't exist")
144+
input.Logger.Info("Module-state correctly reflects that generic VirtualMachineClass doesn't exist")
146145
}
147146

148147
if needsUpdate {

images/hooks/pkg/hooks/update-module-state/hook_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ var _ = Describe("Update Module State hook", func() {
175175
Expect(patchCollector.PatchWithMergeMock.Calls()).To(HaveLen(0))
176176
})
177177

178-
It("should update module-state secret when it exists but has wrong value", func() {
178+
It("should keep historical record when vmclass doesn't exist but module-state indicates it was created", func() {
179179
moduleStateData := map[string]interface{}{
180180
"generic-vmclass-created": base64.StdEncoding.EncodeToString([]byte("true")),
181181
}
@@ -189,24 +189,11 @@ var _ = Describe("Update Module State hook", func() {
189189
}),
190190
})
191191

192-
patchCollector.PatchWithMergeMock.Set(func(obj interface{}, apiVersion, kind, namespace, name string, opts ...pkg.PatchCollectorOption) {
193-
patchData, ok := obj.(map[string]interface{})
194-
Expect(ok).To(BeTrue())
195-
Expect(patchData).To(HaveKey("data"))
196-
197-
data, ok := patchData["data"].(map[string]string)
198-
Expect(ok).To(BeTrue())
199-
Expect(data).To(HaveKey("generic-vmclass-created"))
200-
201-
decoded, err := base64.StdEncoding.DecodeString(data["generic-vmclass-created"])
202-
Expect(err).ToNot(HaveOccurred())
203-
Expect(string(decoded)).To(Equal("false"))
204-
})
205-
192+
patchCollector.PatchWithMergeMock.Optional()
206193
patchCollector.CreateMock.Optional()
207194

208195
Expect(Reconcile(context.Background(), newInput())).To(Succeed())
209-
Expect(patchCollector.PatchWithMergeMock.Calls()).To(HaveLen(1))
196+
Expect(patchCollector.PatchWithMergeMock.Calls()).To(HaveLen(0))
210197
Expect(patchCollector.CreateMock.Calls()).To(HaveLen(0))
211198
})
212199
})

0 commit comments

Comments
 (0)