Skip to content

Commit 601847e

Browse files
committed
feat: Add IPAM integration
- Added RBAC rules - Fixed reconcile Signed-off-by: appkins <[email protected]>
1 parent b33eb28 commit 601847e

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

.goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22

33
env:
44
- REGISTRY={{ if index .Env "REGISTRY" }}{{ .Env.REGISTRY }}{{ else }}ghcr.io{{ end }}
5-
- IMAGE_NAME={{ if index .Env "IMAGE_NAME" }}{{ .Env.IMAGE_NAME }}{{ else }}{{.GitURL | trimprefix "https://" | trimprefix "github.com/" | trimsuffix ".git"}}{{ end }}
5+
- IMAGE_NAME={{ if index .Env "IMAGE_NAME" }}{{ .Env.IMAGE_NAME }}{{ else }}{{.GitURL | trimprefix "https://" | trimprefix "git@" | trimprefix "github.com" | trimprefix ":" | trimprefix "/" | trimsuffix ".git"}}{{ end }}
66
- BINARY=capt
77
- IS_RELEASE={{ if index .Env "IS_RELEASE" }}{{ .Env.IS_RELEASE }}{{ else }}true{{ end }}
88

@@ -60,4 +60,4 @@ kos:
6060
creation_time: "{{.CommitTimestamp}}"
6161
ko_data_creation_time: "{{.CommitTimestamp}}"
6262
sbom: none
63-
local_domain: ghcr.io/tinkerbell-community/cluster-api-provider-tinkerbell
63+
disable: "{{ .IsSnapshot }}"

config/rbac/role.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ rules:
5454
- get
5555
- patch
5656
- update
57+
- apiGroups:
58+
- ipam.cluster.x-k8s.io
59+
resources:
60+
- ipaddressclaims
61+
verbs:
62+
- create
63+
- delete
64+
- get
65+
- list
66+
- patch
67+
- update
68+
- watch
69+
- apiGroups:
70+
- ipam.cluster.x-k8s.io
71+
resources:
72+
- ipaddressclaims/status
73+
verbs:
74+
- get
75+
- patch
76+
- update
77+
- apiGroups:
78+
- ipam.cluster.x-k8s.io
79+
resources:
80+
- ipaddresses
81+
verbs:
82+
- get
83+
- list
84+
- watch
5785
- apiGroups:
5886
- tinkerbell.org
5987
resources:

controller/machine/hardware.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package machine
22

33
import (
44
"fmt"
5+
"maps"
56
"sort"
67
"strings"
78

@@ -84,9 +85,7 @@ func (scope *machineReconcileScope) patchHardwareAnnotations(hw *tinkv1.Hardware
8485
hw.Annotations = map[string]string{}
8586
}
8687

87-
for k, v := range annotations {
88-
hw.Annotations[k] = v
89-
}
88+
maps.Copy(hw.Annotations, annotations)
9089

9190
if err := patchHelper.Patch(scope.ctx, hw); err != nil {
9291
return fmt.Errorf("patching Hardware object: %w", err)
@@ -152,6 +151,14 @@ func (scope *machineReconcileScope) ensureHardware() (*tinkv1.Hardware, error) {
152151
return nil, fmt.Errorf("ensuring Hardware user data: %w", err)
153152
}
154153

154+
// Check if IPAM pool is configured and handle IP allocation
155+
poolRef := scope.getIPAMPoolRef()
156+
if poolRef != nil {
157+
if err := scope.reconcileIPAM(hw, poolRef); err != nil {
158+
return hw, fmt.Errorf("failed to reconcile IPAM: %w", err)
159+
}
160+
}
161+
155162
return hw, scope.setStatus(hw)
156163
}
157164

controller/machine/tinkerbellmachine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ type TinkerbellMachineReconciler struct {
5656
// +kubebuilder:rbac:groups=tinkerbell.org,resources=templates;templates/status,verbs=get;list;watch;create;update;patch;delete
5757
// +kubebuilder:rbac:groups=tinkerbell.org,resources=workflows;workflows/status,verbs=get;list;watch;create;update;patch;delete
5858
// +kubebuilder:rbac:groups=bmc.tinkerbell.org,resources=jobs,verbs=get;list;watch;create
59+
// +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddressclaims,verbs=get;list;watch;create;update;patch;delete
60+
// +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddressclaims/status,verbs=get;update;patch
61+
// +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddresses,verbs=get;list;watch
5962

6063
// Reconcile ensures that all Tinkerbell machines are aligned with a given spec.
6164
//

0 commit comments

Comments
 (0)