Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit aa900b3

Browse files
authored
Merge pull request #31 from gianarb/fix/merge-basetags
fix device tags
2 parents 0be9274 + da73f9d commit aa900b3

File tree

6 files changed

+70
-8
lines changed

6 files changed

+70
-8
lines changed

api/v1alpha3/packetcluster_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ type PacketClusterSpec struct {
3232
ProjectID string `json:"projectID"`
3333
}
3434

35+
// APIEndpoint represents a reachable Kubernetes API endpoint.
36+
type APIEndpoint struct {
37+
// The hostname on which the API server is serving.
38+
Host string `json:"host"`
39+
// The port on which the API server is serving.
40+
Port int `json:"port"`
41+
}
42+
3543
// PacketClusterStatus defines the observed state of PacketCluster
3644
type PacketClusterStatus struct {
3745
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
@@ -40,6 +48,9 @@ type PacketClusterStatus struct {
4048
// Ready denotes that the cluster (infrastructure) is ready.
4149
// +optional
4250
Ready bool `json:"ready"`
51+
// APIEndpoints represents the endpoints to communicate with the control plane.
52+
// +optional
53+
APIEndpoints []APIEndpoint `json:"apiEndpoints,omitempty"`
4354
}
4455

4556
// +kubebuilder:subresource:status

api/v1alpha3/zz_generated.deepcopy.go

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/packetcluster_controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"time"
2122

2223
"github.com/go-logr/logr"
2324
"github.com/pkg/errors"
@@ -68,6 +69,14 @@ func (r *PacketClusterReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
6869
return ctrl.Result{}, err
6970
}
7071

72+
if cluster == nil {
73+
logger.Info("OwenerCluster is not set yet. Requeuing...")
74+
return ctrl.Result{
75+
Requeue: true,
76+
RequeueAfter: 2 * time.Second,
77+
}, nil
78+
}
79+
7180
// Create the cluster scope
7281
clusterScope, err := scope.NewClusterScope(scope.ClusterScopeParams{
7382
Logger: logger,

controllers/packetmachine_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
208208
} else {
209209
tags = append(tags, infrastructurev1alpha3.WorkerTag)
210210
}
211+
211212
name := machineScope.Name()
212-
dev, err = r.PacketClient.NewDevice(name, clusterScope.PacketCluster.Spec.ProjectID, machineScope.PacketMachine.Spec)
213+
dev, err = r.PacketClient.NewDevice(name, clusterScope.PacketCluster.Spec.ProjectID, machineScope.PacketMachine.Spec, tags)
213214
if err != nil {
214215
errs := fmt.Errorf("failed to create machine %s: %v", name, err)
215216
machineScope.SetErrorReason(capierrors.CreateMachineError)

pkg/cloud/packet/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ func (p *PacketClient) GetDevice(deviceID string) (*packngo.Device, error) {
4343
return dev, err
4444
}
4545

46-
func (p *PacketClient) NewDevice(hostname, project string, spec infrav1.PacketMachineSpec) (*packngo.Device, error) {
46+
func (p *PacketClient) NewDevice(hostname, project string, spec infrav1.PacketMachineSpec, extraTags []string) (*packngo.Device, error) {
47+
tags := append(spec.Tags, extraTags...)
4748
serverCreateOpts := &packngo.DeviceCreateRequest{
4849
Hostname: hostname,
4950
ProjectID: project,
5051
Facility: spec.Facility,
5152
BillingCycle: spec.BillingCycle,
5253
Plan: spec.MachineType,
5354
OS: spec.OS,
54-
Tags: spec.Tags,
55+
Tags: tags,
5556
}
5657

5758
dev, _, err := p.Client.Devices.Create(serverCreateOpts)

templates/cluster-template.yaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kind: KubeadmConfig
33
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
44
metadata:
5-
name: my-control-plane1-config
5+
name: "${CLUSTER_NAME}-control-plane1-config"
66
spec:
77
initConfiguration:
88
nodeRegistration:
@@ -46,7 +46,7 @@ spec:
4646
configRef:
4747
kind: KubeadmConfig
4848
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
49-
name: my-control-plane1-config
49+
name: "${CLUSTER_NAME}-control-plane1-config"
5050
infrastructureRef:
5151
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
5252
kind: PacketMachine
@@ -78,7 +78,7 @@ spec:
7878
configRef:
7979
kind: KubeadmConfig
8080
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
81-
name: my-control-plane1-config
81+
name: "${CLUSTER_NAME}-worker0-config"
8282
infrastructureRef:
8383
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
8484
kind: PacketMachine
@@ -110,7 +110,7 @@ spec:
110110
configRef:
111111
kind: KubeadmConfig
112112
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
113-
name: my-control-plane1-config
113+
name: "${CLUSTER_NAME}-worker1-config"
114114
infrastructureRef:
115115
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha3
116116
kind: PacketMachine
@@ -129,3 +129,23 @@ spec:
129129
sshKeys:
130130
- "${SSH_KEY}"
131131
tags: []
132+
---
133+
kind: KubeadmConfig
134+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
135+
metadata:
136+
name: "${CLUSTER_NAME}-worker1-config"
137+
spec:
138+
joinConfiguration:
139+
nodeRegistration:
140+
kubeletExtraArgs:
141+
eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0%
142+
---
143+
kind: KubeadmConfig
144+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
145+
metadata:
146+
name: "${CLUSTER_NAME}-worker0-config"
147+
spec:
148+
joinConfiguration:
149+
nodeRegistration:
150+
kubeletExtraArgs:
151+
eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0%

0 commit comments

Comments
 (0)