Skip to content

Commit e450a1c

Browse files
authored
Repair pipeline (#6)
1 parent 0241cb3 commit e450a1c

File tree

13 files changed

+152
-47
lines changed

13 files changed

+152
-47
lines changed

.github/release-drafter.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name-template: 'v$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
4+
template: |
5+
## General Changes
6+
7+
$CHANGES
8+
9+
categories:
10+
- title: '🚀 Features'
11+
labels:
12+
- 'feature'
13+
- 'enhancement'
14+
- title: '🐛 Bug Fixes'
15+
labels:
16+
- 'fix'
17+
- 'bugfix'
18+
- 'bug'
19+
20+
version-resolver:
21+
major:
22+
labels:
23+
- 'major'
24+
minor:
25+
labels:
26+
- 'minor'
27+
patch:
28+
labels:
29+
- 'patch'
30+
default: patch

.github/workflows/docker.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
name: Docker Build Action
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
release:
8+
types:
9+
- published
10+
push:
11+
branches:
12+
- main
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
17+
jobs:
18+
build:
19+
name: Docker Build
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Log in to the container registry
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ${{ env.REGISTRY }}
27+
username: ${{ secrets.DOCKER_REGISTRY_USER }}
28+
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
29+
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Make tag
34+
run: |
35+
[ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true
36+
[ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true
37+
[ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true
38+
39+
- name: Build and push image
40+
uses: docker/build-push-action@v5
41+
with:
42+
context: .
43+
push: true
44+
tags: ${{ env.REGISTRY }}/metal-stack/capms-controller:${{ env.tag }}

.github/workflows/lint.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ name: Lint
22

33
on:
44
push:
5+
branches:
6+
- main
57
pull_request:
8+
branches:
9+
- main
610

711
jobs:
812
lint:
@@ -15,9 +19,8 @@ jobs:
1519
- name: Setup Go
1620
uses: actions/setup-go@v5
1721
with:
18-
go-version: '~1.23'
22+
go-version-file: 'go.mod'
23+
cache: false
1924

20-
- name: Run linter
25+
- name: Run Linter
2126
uses: golangci/golangci-lint-action@v6
22-
with:
23-
version: v1.59
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: Release Drafter Action
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: release-drafter/release-drafter@v6
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test-e2e.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ name: E2E Tests
22

33
on:
44
push:
5+
branches:
6+
- main
57
pull_request:
8+
branches:
9+
- main
610

711
jobs:
812
test-e2e:
@@ -15,7 +19,7 @@ jobs:
1519
- name: Setup Go
1620
uses: actions/setup-go@v5
1721
with:
18-
go-version: '~1.23'
22+
go-version-file: 'go.mod'
1923

2024
- name: Install the latest version of kind
2125
run: |

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ name: Tests
22

33
on:
44
push:
5+
branches:
6+
- main
57
pull_request:
8+
branches:
9+
- main
610

711
jobs:
812
test:
@@ -15,7 +19,7 @@ jobs:
1519
- name: Setup Go
1620
uses: actions/setup-go@v5
1721
with:
18-
go-version: '~1.23'
22+
go-version-file: 'go.mod'
1923

2024
- name: Running Tests
2125
run: |

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ vet: ## Run go vet against code.
7979
test: manifests generate fmt vet envtest ## Run tests.
8080
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
8181

82-
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
8382
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
8483
# Prometheus and CertManager are installed by default; skip with:
8584
# - PROMETHEUS_INSTALL_SKIP=true
@@ -193,7 +192,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
193192
KUSTOMIZE_VERSION ?= v5.4.3
194193
CONTROLLER_TOOLS_VERSION ?= v0.16.4
195194
ENVTEST_VERSION ?= release-0.19
196-
GOLANGCI_LINT_VERSION ?= v1.59.1
195+
GOLANGCI_LINT_VERSION ?= v1.61.0
197196

198197
.PHONY: kustomize
199198
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.

config/default/kustomization.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ resources:
1818
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
1919
#- ../certmanager
2020
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
21-
#- ../prometheus
21+
- ../prometheus
2222
# [METRICS] Expose the controller manager metrics service.
23-
# - metrics_service.yaml
23+
- metrics_service.yaml
2424
# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy.
2525
# Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics.
2626
# Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will
2727
# be able to communicate with the Webhook Server.
2828
#- ../network-policy
2929

3030
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
31-
# patches:
31+
patches:
3232
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
3333
# More info: https://book.kubebuilder.io/reference/metrics
34-
# - path: manager_metrics_patch.yaml
35-
# target:
36-
# kind: Deployment
34+
- path: manager_metrics_patch.yaml
35+
target:
36+
kind: Deployment
3737

3838
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3939
# crd/kustomization.yaml

internal/controller/metalstackcluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func (r *MetalStackClusterReconciler) status(ctx context.Context, infraCluster *
388388

389389
conditionUpdates <- func() {
390390
if err != nil {
391-
conditions.MarkFalse(infraCluster, v1alpha1.ClusterNodeNetworkEnsured, "InternalError", clusterv1.ConditionSeverityError, err.Error())
391+
conditions.MarkFalse(infraCluster, v1alpha1.ClusterNodeNetworkEnsured, "InternalError", clusterv1.ConditionSeverityError, "%s", err.Error())
392392
return
393393
}
394394

@@ -417,7 +417,7 @@ func (r *MetalStackClusterReconciler) status(ctx context.Context, infraCluster *
417417

418418
conditionUpdates <- func() {
419419
if err != nil && !apierrors.IsNotFound(err) {
420-
conditions.MarkFalse(infraCluster, v1alpha1.ClusterFirewallDeploymentReady, "InternalError", clusterv1.ConditionSeverityError, err.Error())
420+
conditions.MarkFalse(infraCluster, v1alpha1.ClusterFirewallDeploymentReady, "InternalError", clusterv1.ConditionSeverityError, "%s", err.Error())
421421
return
422422
}
423423

internal/controller/metalstackmachine_controller.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ func (r *MetalStackMachineReconciler) SetupWithManager(mgr ctrl.Manager) error {
167167
Complete(r)
168168
}
169169

170-
func (r *MetalStackMachineReconciler) create(ctx context.Context, log logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
170+
func (r *MetalStackMachineReconciler) create(ctx context.Context, _ logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
171171
helper, err := patch.NewHelper(infraMachine, r.Client)
172172
if err != nil {
173173
return err
174174
}
175175

176-
//TODO: Find any existing machine by tag first
176+
// TODO: Find any existing machine by tag first
177177
const TagInfraMachineID = "machine.metal-stack.infrastructure.cluster.x-k8s.io/id"
178178
infraMachineOwnerTag := fmt.Sprintf("%s=%s", TagInfraMachineID, infraMachine.GetUID())
179179

@@ -218,8 +218,8 @@ func (r *MetalStackMachineReconciler) create(ctx context.Context, log logr.Logge
218218
return nil
219219
}
220220

221-
func (r *MetalStackMachineReconciler) reconcile(ctx context.Context, log logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
222-
_, err := r.findProviderMachine(ctx, infraMachine, infraCluster)
221+
func (r *MetalStackMachineReconciler) reconcile(ctx context.Context, _ logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
222+
err := r.findProviderMachine(ctx, infraMachine, infraCluster)
223223
if err != nil && !errors.Is(err, errProviderMachineNotFound) {
224224
return err
225225
}
@@ -231,7 +231,7 @@ func (r *MetalStackMachineReconciler) reconcile(ctx context.Context, log logr.Lo
231231
}
232232

233233
func (r *MetalStackMachineReconciler) delete(ctx context.Context, log logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
234-
_, err := r.findProviderMachine(ctx, infraMachine, infraCluster)
234+
err := r.findProviderMachine(ctx, infraMachine, infraCluster)
235235
if errors.Is(err, errProviderMachineNotFound) {
236236
// metal-stack machine already freed
237237
return nil
@@ -248,27 +248,29 @@ func (r *MetalStackMachineReconciler) delete(ctx context.Context, log logr.Logge
248248
return nil
249249
}
250250

251-
func (r *MetalStackMachineReconciler) status(ctx context.Context, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
251+
func (r *MetalStackMachineReconciler) status(_ context.Context, _ *v1alpha1.MetalStackMachine, _ *v1alpha1.MetalStackCluster) error {
252252
return nil
253253
}
254254

255-
func (r *MetalStackMachineReconciler) findProviderMachine(ctx context.Context, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) (*models.V1MachineResponse, error) {
255+
func (r *MetalStackMachineReconciler) findProviderMachine(ctx context.Context, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
256256
mfr := &models.V1MachineFindRequest{
257257
ID: infraMachine.Spec.ProviderID,
258258
AllocationProject: infraCluster.Spec.ProjectID,
259259
Tags: []string{fmt.Sprintf("%s%s", tag.ClusterID, infraCluster.GetUID())},
260260
}
261+
261262
resp, err := r.MetalClient.Machine().FindMachines(metalmachine.NewFindMachinesParamsWithContext(ctx).WithBody(mfr), nil)
262263
if err != nil {
263-
return nil, err
264+
return err
264265
}
266+
265267
switch len(resp.Payload) {
266268
case 0:
267269
// metal-stack machine already freed
268-
return nil, errProviderMachineNotFound
270+
return errProviderMachineNotFound
269271
case 1:
270-
return resp.Payload[0], nil
272+
return nil
271273
default:
272-
return nil, errProviderMachineTooManyFound
274+
return errProviderMachineTooManyFound
273275
}
274276
}

0 commit comments

Comments
 (0)