Skip to content

Commit

Permalink
Pass serverLabels from MachineClass to ServerClaim (#5)
Browse files Browse the repository at this point in the history
Also remove network and root disk configuration
  • Loading branch information
Nuckal777 authored Jul 22, 2024
1 parent 2544d61 commit b9b06c8
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 180 deletions.
97 changes: 3 additions & 94 deletions docs/provider-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,6 @@ If the key is empty, the DefaultIgnitionKey will be used as fallback.</p>
</tr>
<tr>
<td>
<code>rootDisk</code>
</td>
<td>
<em>
<a href="#?id=%23settings.gardener.cloud%2fv1alpha1.RootDisk">
RootDisk
</a>
</em>
</td>
<td>
<p>RootDisk defines the root disk properties of the Machine.</p>
</td>
</tr>
<tr>
<td>
<code>networkName</code>
</td>
<td>
<em>
string
</em>
</td>
<td>
<p>NetworkName is the Network to be used for the Machine&rsquo;s NetworkInterface.</p>
</td>
</tr>
<tr>
<td>
<code>prefixName</code>
</td>
<td>
<em>
string
</em>
</td>
<td>
<p>PrefixName is the parent Prefix from which an IP should be allocated for the Machine&rsquo;s NetworkInterface.</p>
</td>
</tr>
<tr>
<td>
<code>labels</code>
</td>
<td>
Expand All @@ -139,67 +98,17 @@ map[string]string
<p>DnsServers is a list of DNS resolvers which should be configured on the host.</p>
</td>
</tr>
</tbody>
</table>
<br>
<h3 id="settings.gardener.cloud/v1alpha1.RootDisk">
<b>RootDisk</b>
</h3>
<p>
(<em>Appears on:</em>
<a href="#?id=%23settings.gardener.cloud%2fv1alpha1.ProviderSpec">ProviderSpec</a>)
</p>
<p>
<p>RootDisk defines the root disk properties of the Machine.</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>size</code>
</td>
<td>
<em>
<a href="#?id=https%3a%2f%2fpkg.go.dev%2fk8s.io%2fapimachinery%2fpkg%2fapi%2fresource%23Quantity">
k8s.io/apimachinery/pkg/api/resource.Quantity
</a>
</em>
</td>
<td>
<p>Size defines the volume size of the root disk.</p>
</td>
</tr>
<tr>
<td>
<code>volumeClassName</code>
</td>
<td>
<em>
string
</em>
</td>
<td>
<p>VolumeClassName defines which volume class to use for the root disk.</p>
</td>
</tr>
<tr>
<td>
<code>volumePoolName</code>
<code>serverLabels</code>
</td>
<td>
<em>
string
map[string]string
</em>
</td>
<td>
<p>VolumePoolName defines on which VolumePool a Volume should be scheduled.</p>
<p>ServerLabels are passed to the ServerClaim to find a server with certain properties</p>
</td>
</tr>
</tbody>
Expand Down
20 changes: 2 additions & 18 deletions pkg/api/v1alpha1/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package v1alpha1

import (
"net/netip"

"k8s.io/apimachinery/pkg/api/resource"
)

const (
Expand All @@ -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"`
}
12 changes: 0 additions & 12 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
40 changes: 3 additions & 37 deletions pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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{},
Expand Down
4 changes: 1 addition & 3 deletions pkg/metal/create_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
14 changes: 3 additions & 11 deletions pkg/metal/create_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 2 additions & 5 deletions pkg/metal/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b9b06c8

Please sign in to comment.