Skip to content

Commit 70ab1f1

Browse files
committed
add pxe
1 parent 1ebf67f commit 70ab1f1

File tree

14 files changed

+194
-276
lines changed

14 files changed

+194
-276
lines changed

cmd/common/common.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
)
77

88
type Config struct {
9-
Listen string `yaml:"listen"`
9+
DhcpPort int `yaml:"dhcpPort"`
10+
PxePort int `yaml:"pxePort"`
1011
Log LogConfig `yaml:"log"`
1112
DynamicClient *dynamic.DynamicClient
1213
KubernetesClient *kubernetes.Clientset

cmd/kubernetes/api/v1alpha1/pxe.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package v1alpha1
2+
3+
import "github.com/CRASH-Tech/dhcp-operator/cmd/kubernetes/api"
4+
5+
type PXE struct {
6+
APIVersion string `json:"apiVersion"`
7+
Kind string `json:"kind"`
8+
Metadata api.CustomResourceMetadata `json:"metadata"`
9+
Spec PXESpec `json:"spec"`
10+
}
11+
12+
type PXESpec struct {
13+
Data string `json:"data"`
14+
}

cmd/kubernetes/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,16 @@ func (v1alpha1 *V1alpha1) Lease() *Lease {
167167

168168
return &lease
169169
}
170+
171+
func (v1alpha1 *V1alpha1) PXE() *PXE {
172+
pxe := PXE{
173+
client: v1alpha1.client,
174+
resourceId: schema.GroupVersionResource{
175+
Group: "dhcp.xfix.org",
176+
Version: "v1alpha1",
177+
Resource: "pxe",
178+
},
179+
}
180+
181+
return &pxe
182+
}

cmd/kubernetes/pxe.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package kubernetes
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/CRASH-Tech/dhcp-operator/cmd/kubernetes/api/v1alpha1"
7+
"k8s.io/apimachinery/pkg/runtime/schema"
8+
)
9+
10+
type PXE struct {
11+
client *Client
12+
resourceId schema.GroupVersionResource
13+
}
14+
15+
func (PXE *PXE) Get(name string) (v1alpha1.PXE, error) {
16+
item, err := PXE.client.dynamicGet(PXE.resourceId, name)
17+
if err != nil {
18+
return v1alpha1.PXE{}, err
19+
}
20+
21+
var result v1alpha1.PXE
22+
err = json.Unmarshal(item, &result)
23+
if err != nil {
24+
return v1alpha1.PXE{}, err
25+
}
26+
27+
return result, nil
28+
}
29+
30+
func (PXE *PXE) GetAll() ([]v1alpha1.PXE, error) {
31+
items, err := PXE.client.dynamicGetAll(PXE.resourceId)
32+
if err != nil {
33+
panic(err)
34+
}
35+
36+
var result []v1alpha1.PXE
37+
for _, item := range items {
38+
var q v1alpha1.PXE
39+
err = json.Unmarshal(item, &q)
40+
if err != nil {
41+
return nil, err
42+
}
43+
44+
result = append(result, q)
45+
}
46+
47+
return result, nil
48+
}

config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
listen: :67
1+
dhcpPort: 67
2+
pxePort: 9999
23
log:
34
level: debug
45
format: text

crd/pxe.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
kind: CustomResourceDefinition
2+
apiVersion: apiextensions.k8s.io/v1
3+
metadata:
4+
name: pxe.dhcp.xfix.org
5+
labels:
6+
app: dhcp-operator
7+
spec:
8+
group: dhcp.xfix.org
9+
names:
10+
plural: pxe
11+
singular: pxes
12+
kind: PXE
13+
listKind: PXEList
14+
scope: Cluster
15+
versions:
16+
- name: v1alpha1
17+
served: true
18+
storage: true
19+
schema:
20+
openAPIV3Schema:
21+
description: Server is the Schema for the servers API.
22+
type: object
23+
properties:
24+
apiVersion:
25+
type: string
26+
kind:
27+
type: string
28+
metadata:
29+
type: object
30+
spec:
31+
description: ServerSpec defines the desired state of Server.
32+
type: object
33+
required:
34+
- data
35+
properties:
36+
data:
37+
type: string
38+
subresources:
39+
status: {}
40+
conversion:
41+
strategy: None

examples/pool.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ spec:
1313
- 8.8.4.4
1414
domain: xfix.org
1515
lease: 1h
16-
filename: http://10.4.122.2/pxe/talos-1.4.3.ipxe
16+
filename: http://10.171.120.1:9999/pxe/k-test-worker

examples/pxe.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: dhcp.xfix.org/v1alpha1
2+
kind: PXE
3+
metadata:
4+
name: k-test-worker
5+
spec:
6+
data: |
7+
#!ipxe
8+
9+
kernel http://10.171.120.1:9999/static/talos-1.5.2-vmlinuz-amd64 slab_nomerge pti=on talos.platform=metal talos.config=http://10.171.120.1:8888/register?role=worker&token=welcome123
10+
initrd http://10.171.120.1:9999/static/talos-1.5.2-initramfs-amd64.xz
11+
boot

krolaw.go

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)