Skip to content

Commit 06bf9fe

Browse files
Merge pull request #440 from jacobweinstock/updates
Update deleting machines logic: ## Description <!--- Please describe what this PR is going to change --> Refactor DeleteMachineWithDependencies. Removes the potential for releasing Hardware before power-off jobs have been completed. ## Why is this needed <!--- Link to issue you have raised --> Fixes: #330 ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## How are existing users impacted? What migration steps/scripts do we need? <!--- Fixes a bug, unblocks installation, removes a component of the stack etc --> <!--- Requires a DB migration script, etc. --> ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents f08f05c + fcecf13 commit 06bf9fe

File tree

7 files changed

+51
-45
lines changed

7 files changed

+51
-45
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ GO_INSTALL = ./scripts/go_install.sh
5151
# Binaries.
5252
CONTROLLER_GEN := go run sigs.k8s.io/controller-tools/cmd/[email protected]
5353

54-
GOLANGCI_LINT_VER := v1.61.0
54+
GOLANGCI_LINT_VER := v1.63.4
5555
GOLANGCI_LINT_BIN := golangci-lint
5656
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
5757

Tiltfile

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ docker_build(
55
)
66
k8s_yaml(kustomize('./config/default'))
77
default_registry('ttl.sh/meohmy-dghentld')
8+
allow_k8s_contexts('capt-playground-admin@capt-playground')

controller/machine/bmc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (scope *machineReconcileScope) ensureBMCJobCompletionForDelete(hardware *ti
8383

8484
// Check the Job conditions to ensure the power off job is complete.
8585
if bmcJob.HasCondition(rufiov1.JobCompleted, rufiov1.ConditionTrue) {
86-
return scope.removeFinalizer()
86+
return nil
8787
}
8888

8989
if bmcJob.HasCondition(rufiov1.JobFailed, rufiov1.ConditionTrue) {

controller/machine/scope.go

+25-18
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (scope *machineReconcileScope) MachineScheduledForDeletion() bool {
197197
}
198198

199199
// DeleteMachineWithDependencies removes template and workflow objects associated with given machine.
200-
func (scope *machineReconcileScope) DeleteMachineWithDependencies() error {
200+
func (scope *machineReconcileScope) DeleteMachineWithDependencies() error { //nolint:cyclop
201201
scope.log.Info("Removing machine", "hardwareName", scope.tinkerbellMachine.Spec.HardwareName)
202202
// Fetch hw for the machine.
203203
hw := &tinkv1.Hardware{}
@@ -214,18 +214,14 @@ func (scope *machineReconcileScope) DeleteMachineWithDependencies() error {
214214
"hardwareName", scope.tinkerbellMachine.Spec.HardwareName,
215215
)
216216

217-
if err := scope.removeTemplate(); err != nil && !apierrors.IsNotFound(err) {
218-
return fmt.Errorf("removing Template: %w", err)
219-
}
220-
221-
if err := scope.removeWorkflow(); err != nil && !apierrors.IsNotFound(err) {
222-
return fmt.Errorf("removing Workflow: %w", err)
217+
if err := scope.removeDependencies(); err != nil {
218+
return err
223219
}
224220

225221
return scope.removeFinalizer()
226222
}
227223

228-
if err := scope.removeDependencies(hw); err != nil {
224+
if err := scope.removeDependencies(); err != nil {
229225
return err
230226
}
231227

@@ -235,27 +231,38 @@ func (scope *machineReconcileScope) DeleteMachineWithDependencies() error {
235231
scope.log.Info("Hardware BMC reference not present; skipping hardware power off",
236232
"BMCRef", hw.Spec.BMCRef, "Hardware", hw.Name)
237233

234+
if err := scope.releaseHardware(hw); err != nil {
235+
return fmt.Errorf("error releasing Hardware: %w", err)
236+
}
237+
238238
return scope.removeFinalizer()
239239
}
240240

241-
return scope.ensureBMCJobCompletionForDelete(hw)
241+
if err := scope.ensureBMCJobCompletionForDelete(hw); err != nil {
242+
return fmt.Errorf("error ensuring BMC job completion for delete: %w", err)
243+
}
244+
245+
if err := scope.releaseHardware(hw); err != nil {
246+
return fmt.Errorf("error releasing Hardware: %w", err)
247+
}
248+
249+
if err := scope.removeFinalizer(); err != nil {
250+
return fmt.Errorf("error removing finalizer: %w", err)
251+
}
252+
253+
return nil
242254
}
243255

244-
// removeDependencies removes the Template, Workflow linked to the machine.
245-
// Deletes the machine hardware labels for the machine.
246-
func (scope *machineReconcileScope) removeDependencies(hardware *tinkv1.Hardware) error {
247-
if err := scope.removeTemplate(); err != nil {
256+
// removeDependencies removes the Template and Workflow linked to the Machine/Hardware.
257+
func (scope *machineReconcileScope) removeDependencies() error {
258+
if err := scope.removeTemplate(); err != nil && !apierrors.IsNotFound(err) {
248259
return fmt.Errorf("removing Template: %w", err)
249260
}
250261

251-
if err := scope.removeWorkflow(); err != nil {
262+
if err := scope.removeWorkflow(); err != nil && !apierrors.IsNotFound(err) {
252263
return fmt.Errorf("removing Workflow: %w", err)
253264
}
254265

255-
if err := scope.releaseHardware(hardware); err != nil {
256-
return fmt.Errorf("releasing Hardware: %w", err)
257-
}
258-
259266
return nil
260267
}
261268

controller/machine/tinkerbellmachine_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ func Test_Machine_reconciliation_workflow_complete(t *testing.T) {
582582
})
583583
}
584584

585-
//nolint:funlen
586585
func Test_Machine_reconciliation(t *testing.T) {
587586
t.Parallel()
588587

go.mod

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6
2424
sigs.k8s.io/cluster-api v1.8.5
2525
sigs.k8s.io/controller-runtime v0.19.4
26-
sigs.k8s.io/kustomize/kustomize/v5 v5.5.0
26+
sigs.k8s.io/kustomize/kustomize/v5 v5.6.0
2727
sigs.k8s.io/yaml v1.4.0
2828
)
2929

@@ -45,7 +45,7 @@ require (
4545
github.com/gogo/protobuf v1.3.2 // indirect
4646
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4747
github.com/golang/protobuf v1.5.4 // indirect
48-
github.com/google/gnostic-models v0.6.8 // indirect
48+
github.com/google/gnostic-models v0.6.9 // indirect
4949
github.com/google/gofuzz v1.2.0 // indirect
5050
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
5151
github.com/imdario/mergo v0.3.16 // indirect
@@ -87,10 +87,10 @@ require (
8787
gopkg.in/yaml.v3 v3.0.1 // indirect
8888
k8s.io/apiextensions-apiserver v0.31.0 // indirect
8989
k8s.io/cluster-bootstrap v0.30.3 // indirect
90-
k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8 // indirect
90+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
9191
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
92-
sigs.k8s.io/kustomize/api v0.18.0 // indirect
93-
sigs.k8s.io/kustomize/cmd/config v0.15.0 // indirect
94-
sigs.k8s.io/kustomize/kyaml v0.18.1 // indirect
95-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
92+
sigs.k8s.io/kustomize/api v0.19.0 // indirect
93+
sigs.k8s.io/kustomize/cmd/config v0.19.0 // indirect
94+
sigs.k8s.io/kustomize/kyaml v0.19.0 // indirect
95+
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
9696
)

go.sum

+16-17
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe
1010
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
1111
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
1212
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
13-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
14-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
13+
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
14+
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
1515
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
1616
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
1717
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
@@ -86,8 +86,8 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek
8686
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
8787
github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84=
8888
github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg=
89-
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
90-
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
89+
github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw=
90+
github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw=
9191
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
9292
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
9393
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -334,7 +334,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
334334
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
335335
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
336336
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
337-
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
338337
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
339338
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
340339
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
@@ -357,8 +356,8 @@ k8s.io/component-base v0.31.3 h1:DMCXXVx546Rfvhj+3cOm2EUxhS+EyztH423j+8sOwhQ=
357356
k8s.io/component-base v0.31.3/go.mod h1:xME6BHfUOafRgT0rGVBGl7TuSg8Z9/deT7qq6w7qjIU=
358357
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
359358
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
360-
k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8 h1:1Wof1cGQgA5pqgo8MxKPtf+qN6Sh/0JzznmeGPm1HnE=
361-
k8s.io/kube-openapi v0.0.0-20240808142205-8e686545bdb8/go.mod h1:Os6V6dZwLNii3vxFpxcNaTmH8LJJBkOTg1N0tOA0fvA=
359+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=
360+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7/go.mod h1:GewRfANuJ70iYzvn+i4lezLDAFzvjxZYK1gn1lWcfas=
362361
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 h1:MDF6h2H/h4tbzmtIKTuctcwZmY0tY9mD9fNT47QO6HI=
363362
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
364363
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY=
@@ -369,15 +368,15 @@ sigs.k8s.io/controller-runtime v0.19.4 h1:SUmheabttt0nx8uJtoII4oIP27BVVvAKFvdvGF
369368
sigs.k8s.io/controller-runtime v0.19.4/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4=
370369
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
371370
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
372-
sigs.k8s.io/kustomize/api v0.18.0 h1:hTzp67k+3NEVInwz5BHyzc9rGxIauoXferXyjv5lWPo=
373-
sigs.k8s.io/kustomize/api v0.18.0/go.mod h1:f8isXnX+8b+SGLHQ6yO4JG1rdkZlvhaCf/uZbLVMb0U=
374-
sigs.k8s.io/kustomize/cmd/config v0.15.0 h1:WkdY8V2+8J+W00YbImXa2ke9oegfrHH79e+kywW7EdU=
375-
sigs.k8s.io/kustomize/cmd/config v0.15.0/go.mod h1:Jq57b0nPaoYUlOqg//0JtAh6iibboqMcfbtCYoWPM00=
376-
sigs.k8s.io/kustomize/kustomize/v5 v5.5.0 h1:o1mtt6vpxsxDYaZKrw3BnEtc+pAjLz7UffnIvHNbvW0=
377-
sigs.k8s.io/kustomize/kustomize/v5 v5.5.0/go.mod h1:AeFCmgCrXzmvjWWaeZCyBp6XzG1Y0w1svYus8GhJEOE=
378-
sigs.k8s.io/kustomize/kyaml v0.18.1 h1:WvBo56Wzw3fjS+7vBjN6TeivvpbW9GmRaWZ9CIVmt4E=
379-
sigs.k8s.io/kustomize/kyaml v0.18.1/go.mod h1:C3L2BFVU1jgcddNBE1TxuVLgS46TjObMwW5FT9FcjYo=
380-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
381-
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
371+
sigs.k8s.io/kustomize/api v0.19.0 h1:F+2HB2mU1MSiR9Hp1NEgoU2q9ItNOaBJl0I4Dlus5SQ=
372+
sigs.k8s.io/kustomize/api v0.19.0/go.mod h1:/BbwnivGVcBh1r+8m3tH1VNxJmHSk1PzP5fkP6lbL1o=
373+
sigs.k8s.io/kustomize/cmd/config v0.19.0 h1:D3uASwjHWHmNiEHu3pPJBJMBIsb+auFvHrHql3HAarU=
374+
sigs.k8s.io/kustomize/cmd/config v0.19.0/go.mod h1:29Vvdl26PidPLUDi7nfjYa/I0wHBkwCZp15Nlcc4y98=
375+
sigs.k8s.io/kustomize/kustomize/v5 v5.6.0 h1:MWtRRDWCwQEeW2rnJTqJMuV6Agy56P53SkbVoJpN7wA=
376+
sigs.k8s.io/kustomize/kustomize/v5 v5.6.0/go.mod h1:XuuZiQF7WdcvZzEYyNww9A0p3LazCKeJmCjeycN8e1I=
377+
sigs.k8s.io/kustomize/kyaml v0.19.0 h1:RFge5qsO1uHhwJsu3ipV7RNolC7Uozc0jUBC/61XSlA=
378+
sigs.k8s.io/kustomize/kyaml v0.19.0/go.mod h1:FeKD5jEOH+FbZPpqUghBP8mrLjJ3+zD3/rf9NNu1cwY=
379+
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 h1:nbCitCK2hfnhyiKo6uf2HxUPTCodY6Qaf85SbDIaMBk=
380+
sigs.k8s.io/structured-merge-diff/v4 v4.5.0/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4=
382381
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
383382
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

0 commit comments

Comments
 (0)