From b9b06c8532aad8589569f848474d7636b2cd9c6a Mon Sep 17 00:00:00 2001
From: Erik Schubert
Date: Mon, 22 Jul 2024 13:29:30 +0200
Subject: [PATCH] Pass `serverLabels` from `MachineClass` to `ServerClaim` (#5)
Also remove network and root disk configuration
---
docs/provider-spec.md | 97 +--------------------------
pkg/api/v1alpha1/provider.go | 20 +-----
pkg/api/validation/validation.go | 12 ----
pkg/api/validation/validation_test.go | 40 +----------
pkg/metal/create_machine.go | 4 +-
pkg/metal/create_machine_test.go | 14 +---
pkg/metal/testing/testing.go | 7 +-
7 files changed, 14 insertions(+), 180 deletions(-)
diff --git a/docs/provider-spec.md b/docs/provider-spec.md
index ad91e9f..58b6ca9 100644
--- a/docs/provider-spec.md
+++ b/docs/provider-spec.md
@@ -72,47 +72,6 @@ If the key is empty, the DefaultIgnitionKey will be used as fallback.
-rootDisk
- |
-
-
-
-RootDisk
-
-
- |
-
- RootDisk defines the root disk properties of the Machine.
- |
-
-
-
-networkName
- |
-
-
-string
-
- |
-
- NetworkName is the Network to be used for the Machine’s NetworkInterface.
- |
-
-
-
-prefixName
- |
-
-
-string
-
- |
-
- PrefixName is the parent Prefix from which an IP should be allocated for the Machine’s NetworkInterface.
- |
-
-
-
labels
|
@@ -139,67 +98,17 @@ map[string]string
DnsServers is a list of DNS resolvers which should be configured on the host.
|
-
-
-
-
-RootDisk
-
-
-(Appears on:
-ProviderSpec)
-
-
-
RootDisk defines the root disk properties of the Machine.
-
-
-
-
-Field |
-Type |
-Description |
-
-
-
-
-
-size
- |
-
-
-
-k8s.io/apimachinery/pkg/api/resource.Quantity
-
-
- |
-
- Size defines the volume size of the root disk.
- |
-
-
-
-volumeClassName
- |
-
-
-string
-
- |
-
- VolumeClassName defines which volume class to use for the root disk.
- |
-
-volumePoolName
+serverLabels
|
-string
+map[string]string
|
- VolumePoolName defines on which VolumePool a Volume should be scheduled.
+ServerLabels are passed to the ServerClaim to find a server with certain properties
|
diff --git a/pkg/api/v1alpha1/provider.go b/pkg/api/v1alpha1/provider.go
index 631d6d8..3b98eca 100644
--- a/pkg/api/v1alpha1/provider.go
+++ b/pkg/api/v1alpha1/provider.go
@@ -5,8 +5,6 @@ package v1alpha1
import (
"net/netip"
-
- "k8s.io/apimachinery/pkg/api/resource"
)
const (
@@ -28,24 +26,10 @@ type ProviderSpec struct {
// IgnitionSecretKey is optional key field used to identify the ignition content in the Secret
// If the key is empty, the DefaultIgnitionKey will be used as fallback.
IgnitionSecretKey string `json:"ignitionSecretKey,omitempty"`
- // RootDisk defines the root disk properties of the Machine.
- RootDisk *RootDisk `json:"rootDisk,omitempty"`
- // NetworkName is the Network to be used for the Machine's NetworkInterface.
- NetworkName string `json:"networkName"`
- // PrefixName is the parent Prefix from which an IP should be allocated for the Machine's NetworkInterface.
- PrefixName string `json:"prefixName"`
// Labels are used to tag resources which the MCM creates, so they can be identified later.
Labels map[string]string `json:"labels,omitempty"`
// DnsServers is a list of DNS resolvers which should be configured on the host.
DnsServers []netip.Addr `json:"dnsServers,omitempty"`
-}
-
-// RootDisk defines the root disk properties of the Machine.
-type RootDisk struct {
- // Size defines the volume size of the root disk.
- Size resource.Quantity `json:"size"`
- // VolumeClassName defines which volume class to use for the root disk.
- VolumeClassName string `json:"volumeClassName"`
- // VolumePoolName defines on which VolumePool a Volume should be scheduled.
- VolumePoolName string `json:"volumePoolName,omitempty"`
+ // ServerLabels are passed to the ServerClaim to find a server with certain properties
+ ServerLabels map[string]string `json:"serverLabels,omitempty"`
}
diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go
index fd88463..5ab1832 100644
--- a/pkg/api/validation/validation.go
+++ b/pkg/api/validation/validation.go
@@ -39,22 +39,10 @@ func validateSecret(secret *corev1.Secret, fldPath *field.Path) field.ErrorList
func validateMachineClassSpec(spec *v1alpha1.ProviderSpec, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList
- if spec.RootDisk != nil && spec.RootDisk.VolumeClassName == "" {
- allErrs = append(allErrs, field.Required(fldPath.Child("rootDisk").Child("volumeClassName"), "volumeClassName is required"))
- }
-
if spec.Image == "" {
allErrs = append(allErrs, field.Required(fldPath.Child("image"), "image is required"))
}
- if spec.NetworkName == "" {
- allErrs = append(allErrs, field.Required(fldPath.Child("networkName"), "networkName is required"))
- }
-
- if spec.PrefixName == "" {
- allErrs = append(allErrs, field.Required(fldPath.Child("prefixName"), "prefixName is required"))
- }
-
for i, ip := range spec.DnsServers {
if !netip.Addr.IsValid(ip) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("dnsServers").Index(i), ip, "ip is invalid"))
diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go
index 502a853..9a96201 100644
--- a/pkg/api/validation/validation_test.go
+++ b/pkg/api/validation/validation_test.go
@@ -25,17 +25,13 @@ var _ = Describe("Machine", func() {
Expect(errList).To(match)
},
Entry("no secret",
- &v1alpha1.ProviderSpec{
- RootDisk: &v1alpha1.RootDisk{},
- },
+ &v1alpha1.ProviderSpec{},
nil,
fldPath,
ContainElement(field.Required(fldPath.Child("spec.secretRef"), "secretRef is required")),
),
Entry("no userData in secret",
- &v1alpha1.ProviderSpec{
- RootDisk: &v1alpha1.RootDisk{},
- },
+ &v1alpha1.ProviderSpec{},
&corev1.Secret{
Data: map[string][]byte{
"userData": nil,
@@ -46,44 +42,14 @@ var _ = Describe("Machine", func() {
),
Entry("no image",
&v1alpha1.ProviderSpec{
- Image: "",
- RootDisk: &v1alpha1.RootDisk{},
+ Image: "",
},
&corev1.Secret{},
fldPath,
ContainElement(field.Required(fldPath.Child("spec.image"), "image is required")),
),
- Entry("no volumeclass name",
- &v1alpha1.ProviderSpec{
- RootDisk: &v1alpha1.RootDisk{
- VolumeClassName: "",
- },
- },
- &corev1.Secret{},
- fldPath,
- ContainElement(field.Required(fldPath.Child("spec.rootDisk.volumeClassName"), "volumeClassName is required")),
- ),
- Entry("no network name",
- &v1alpha1.ProviderSpec{
- NetworkName: "",
- RootDisk: &v1alpha1.RootDisk{},
- },
- &corev1.Secret{},
- fldPath,
- ContainElement(field.Required(fldPath.Child("spec.networkName"), "networkName is required")),
- ),
- Entry("no prefix name",
- &v1alpha1.ProviderSpec{
- PrefixName: "",
- RootDisk: &v1alpha1.RootDisk{},
- },
- &corev1.Secret{},
- fldPath,
- ContainElement(field.Required(fldPath.Child("spec.prefixName"), "prefixName is required")),
- ),
Entry("invalid dns server ip",
&v1alpha1.ProviderSpec{
- RootDisk: &v1alpha1.RootDisk{},
DnsServers: []netip.Addr{invalidIP},
},
&corev1.Secret{},
diff --git a/pkg/metal/create_machine.go b/pkg/metal/create_machine.go
index 58be610..33e7a64 100644
--- a/pkg/metal/create_machine.go
+++ b/pkg/metal/create_machine.go
@@ -104,9 +104,7 @@ func (d *metalDriver) applyServerClaim(ctx context.Context, req *driver.CreateMa
Spec: metalv1alpha1.ServerClaimSpec{
Power: "On",
ServerSelector: &metav1.LabelSelector{
- MatchLabels: map[string]string{
- "instance-type": req.MachineClass.NodeTemplate.InstanceType,
- },
+ MatchLabels: providerSpec.ServerLabels,
MatchExpressions: nil,
},
IgnitionSecretRef: &corev1.LocalObjectReference{Name: ignitionSecret.Name},
diff --git a/pkg/metal/create_machine_test.go b/pkg/metal/create_machine_test.go
index 2915420..3ed0aac 100644
--- a/pkg/metal/create_machine_test.go
+++ b/pkg/metal/create_machine_test.go
@@ -74,17 +74,9 @@ var _ = Describe("CreateMachine", func() {
HaveField("Spec.Power", metalv1alpha1.PowerOn),
HaveField("Spec.ServerSelector", &metav1.LabelSelector{
MatchLabels: map[string]string{
- "instance-type": "foo",
- }}),
- // Power: "On",
- // ServerSelector: &metav1.LabelSelector{
- // MatchLabels: map[string]string{
- // "instance-type": req.MachineClass.NodeTemplate.InstanceType,
- // },
- // MatchExpressions: nil,
- //},
- // IgnitionSecretRef: &corev1.LocalObjectReference{Name: ignitionSecret.Name},
- // Image: providerSpec.Image,
+ "instance-type": "bar",
+ },
+ }),
))
By("ensuring that the ignition secret has been created")
diff --git a/pkg/metal/testing/testing.go b/pkg/metal/testing/testing.go
index c2d2b35..1d91e18 100644
--- a/pkg/metal/testing/testing.go
+++ b/pkg/metal/testing/testing.go
@@ -13,11 +13,8 @@ var (
},
"machineClassName": "foo",
"machinePoolName": "foo",
- "networkName": "my-network",
- "prefixName": "my-prefix",
- "rootDisk": map[string]string{
- "volumeClassName": "foo",
- "size": "10Gi",
+ "serverLabels": map[string]string{
+ "instance-type": "bar",
},
"ignitionSecret": map[string]string{
"name": "foo",