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

decrease likelihood of possible race condition #272

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 33 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ GO_INSTALL = ./scripts/go_install.sh
# Binaries.
CONTROLLER_GEN := go run sigs.k8s.io/controller-tools/cmd/[email protected]

GOLANGCI_LINT_VER := v1.49.0
GOLANGCI_LINT_VER := v1.51.2
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)

Expand Down Expand Up @@ -128,9 +128,6 @@ test: ## Run tests
## Tooling Binaries
## --------------------------------------

$(GOLANGCI_LINT): ## Build golangci-lint from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)

$(KUBECTL): ## Build kubectl
mkdir -p $(TOOLS_BIN_DIR)
rm -f "$(KUBECTL)*"
Expand All @@ -149,9 +146,39 @@ $(KIND): ## Build kind
## Linting
## --------------------------------------

# BEGIN: lint-install
# http://github.com/tinkerbell/lint-install

.PHONY: lint
lint: $(GOLANGCI_LINT) ## Lint codebase
$(GOLANGCI_LINT) run -v --fast=false
lint: _lint ## Lint codebase

LINT_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

LINTERS :=
FIXERS :=

GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
$(GOLANGCI_LINT):
mkdir -p $(TOOLS_BIN_DIR)
rm -rf $(TOOLS_BIN_DIR)/golangci-lint-*
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN_DIR) $(GOLANGCI_LINT_VER)
mv $(TOOLS_BIN_DIR)/golangci-lint $@

LINTERS += golangci-lint-lint
golangci-lint-lint: $(GOLANGCI_LINT)
find . -name go.mod -execdir "$(GOLANGCI_LINT)" run -c "$(GOLANGCI_LINT_CONFIG)" \;

FIXERS += golangci-lint-fix
golangci-lint-fix: $(GOLANGCI_LINT)
find . -name go.mod -execdir "$(GOLANGCI_LINT)" run -c "$(GOLANGCI_LINT_CONFIG)" --fix \;

.PHONY: _lint $(LINTERS)
_lint: $(LINTERS)

.PHONY: fix $(FIXERS)
fix: $(FIXERS)

# END: lint-install

## --------------------------------------
## Generate
Expand Down
47 changes: 25 additions & 22 deletions controllers/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,37 +143,40 @@ func (mrc *machineReconcileContext) Reconcile() error {
}

func (mrc *machineReconcileContext) reconcile(hw *tinkv1.Hardware) error {
if !isHardwareReady(hw) {
wf, err := mrc.ensureTemplateAndWorkflow(hw)
if isHardwareReady(hw) {
mrc.log.Info("Marking TinkerbellMachine as Ready")
mrc.tinkerbellMachine.Status.Ready = true

if ensureJobErr := mrc.ensureHardwareProvisionJob(hw); ensureJobErr != nil {
return fmt.Errorf("failed to ensure hardware ready for provisioning: %w", ensureJobErr)
}
return nil
}

switch {
case errors.Is(err, &errRequeueRequested{}):
return nil
case err != nil:
return fmt.Errorf("ensure template and workflow returned: %w", err)
}
if ensureJobErr := mrc.ensureHardwareProvisionJob(hw); ensureJobErr != nil {
return fmt.Errorf("failed to ensure hardware ready for provisioning: %w", ensureJobErr)
}

s := wf.GetCurrentActionState()
wf, err := mrc.ensureTemplateAndWorkflow(hw)

if s == tinkv1.WorkflowStateFailed || s == tinkv1.WorkflowStateTimeout {
return errWorkflowFailed
}
switch {
case errors.Is(err, &errRequeueRequested{}):
return nil
case err != nil:
return fmt.Errorf("ensure template and workflow returned: %w", err)
}

if !lastActionStarted(wf) {
return nil
}
s := wf.GetCurrentActionState()
if s == tinkv1.WorkflowStateFailed || s == tinkv1.WorkflowStateTimeout {
return errWorkflowFailed
}

if err := mrc.patchHardwareStates(hw, inUse, provisioned); err != nil {
return fmt.Errorf("failed to patch hardware: %w", err)
}
if !lastActionStarted(wf) {
return nil
}

mrc.log.Info("Marking TinkerbellMachine as Ready")
if err := mrc.patchHardwareStates(hw, inUse, provisioned); err != nil {
return fmt.Errorf("failed to patch hardware: %w", err)
}

mrc.log.Info("Marking TinkerbellMachine as Ready")
mrc.tinkerbellMachine.Status.Ready = true

return nil
Expand Down