Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *Server) getIronCoreNetworkInterfaceConfig(iriNIC *iri.NetworkInterface)
var preparedNicLabels, preparedNetworkLabels map[string]string
attributes := iriNIC.GetAttributes()
if attributes != nil {
preparedNicLabels, preparedNetworkLabels, err = s.prepareLabelsFromAttributes(iriNIC.GetAttributes())
preparedNicLabels, preparedNetworkLabels, err = s.prepareLabelsFromAttributes(attributes)
if err != nil {
return nil, err
}
Expand All @@ -63,13 +63,13 @@ func (s *Server) prepareLabelsFromAttributes(attrs map[string]string) (map[strin

if nicLabelsString, ok := attrs[machinepoolletv1alpha1.NICLabelsAttributeKey]; ok {
if err := json.Unmarshal([]byte(nicLabelsString), &nicLabels); err != nil {
return nil, nil, fmt.Errorf("error unmarshaling labels: %w", err)
return nil, nil, fmt.Errorf("error unmarshaling NIC labels: %w", err)
}
}

if networkLabelsString, ok := attrs[machinepoolletv1alpha1.NetworkLabelsAttributeKey]; ok {
if err := json.Unmarshal([]byte(networkLabelsString), &networkLabels); err != nil {
return nil, nil, fmt.Errorf("error unmarshaling labels: %w", err)
return nil, nil, fmt.Errorf("error unmarshaling network labels: %w", err)
}
}
preparedNicLabels := brokerutils.PrepareDownwardAPILabels(nicLabels, s.brokerDownwardAPILabels, machinepoolletv1alpha1.MachineDownwardAPIPrefix)
Expand Down
37 changes: 34 additions & 3 deletions broker/machinebroker/server/machine_volume_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package server

import (
"context"
"encoding/json"
"fmt"

"github.com/go-logr/logr"
Expand All @@ -13,8 +14,12 @@ import (
corev1alpha1 "github.com/ironcore-dev/ironcore/api/core/v1alpha1"
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
"github.com/ironcore-dev/ironcore/broker/common/cleaner"
brokerutils "github.com/ironcore-dev/ironcore/broker/common/utils"
machinebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/machinebroker/api/v1alpha1"
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
machinepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1"

utilsmaps "github.com/ironcore-dev/ironcore/utils/maps"
metautils "github.com/ironcore-dev/ironcore/utils/meta"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -27,6 +32,7 @@ type IronCoreVolumeConfig struct {
Device string
EmptyDisk *IronCoreVolumeEmptyDiskConfig
Remote *IronCoreVolumeRemoteConfig
Labels map[string]string
}

type IronCoreVolumeEmptyDiskConfig struct {
Expand Down Expand Up @@ -68,15 +74,40 @@ func (s *Server) getIronCoreVolumeConfig(volume *iri.Volume) (*IronCoreVolumeCon
default:
return nil, fmt.Errorf("unrecognized volume %#v", volume)
}

labels, err := s.prepareLabels(volume.Connection)
if err != nil {
return nil, err
}
return &IronCoreVolumeConfig{
Name: volume.Name,
Device: volume.Device,
EmptyDisk: emptyDisk,
Remote: remote,
Labels: labels,
}, nil
}

func (s *Server) prepareLabels(conn *iri.VolumeConnection) (map[string]string, error) {
attrs := conn.GetAttributes()
if attrs == nil {
return nil, nil
}
return s.prepareVolumeLabelsFromAttributes(attrs)
}

func (s *Server) prepareVolumeLabelsFromAttributes(attrs map[string]string) (map[string]string, error) {
var labels map[string]string

if labelsString, ok := attrs[machinepoolletv1alpha1.VolumeLabelsAttributeKey]; ok {
if err := json.Unmarshal([]byte(labelsString), &labels); err != nil {
return nil, fmt.Errorf("error unmarshaling volume labels: %w", err)
}
}
preparedVolumeLabels := brokerutils.PrepareDownwardAPILabels(labels, s.brokerDownwardAPILabels, machinepoolletv1alpha1.MachineDownwardAPIPrefix)

return preparedVolumeLabels, nil
}

func (s *Server) createIronCoreVolume(
ctx context.Context,
log logr.Logger,
Expand Down Expand Up @@ -121,9 +152,9 @@ func (s *Server) createIronCoreVolume(
Annotations: map[string]string{
commonv1alpha1.ManagedByAnnotation: machinebrokerv1alpha1.MachineBrokerManager,
},
Labels: map[string]string{
Labels: utilsmaps.AppendMap(cfg.Labels, map[string]string{
machinebrokerv1alpha1.ManagerLabel: machinebrokerv1alpha1.MachineBrokerManager,
},
}),
},
Spec: storagev1alpha1.VolumeSpec{
ClaimRef: s.optionalLocalUIDReference(optIronCoreMachine),
Expand Down
13 changes: 13 additions & 0 deletions broker/machinebroker/server/machine_volume_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ package server_test
import (
computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1"
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
machinebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/machinebroker/api/v1alpha1"
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
machinepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
Expand Down Expand Up @@ -37,6 +40,9 @@ var _ = Describe("AttachVolume", func() {
machineID := createMachineRes.Machine.Metadata.Id

By("attaching a volume")
labels := map[string]string{
machinepoolletv1alpha1.VolumeUIDLabel: "bar",
}
Expect(srv.AttachVolume(ctx, &iri.AttachVolumeRequest{
MachineId: machineID,
Volume: &iri.Volume{
Expand All @@ -46,6 +52,7 @@ var _ = Describe("AttachVolume", func() {
Driver: "ceph",
Handle: "mycephvolume",
Attributes: map[string]string{
machinepoolletv1alpha1.VolumeLabelsAttributeKey: string(mustMarshalJSON(labels)),
"foo": "bar",
},
SecretData: map[string][]byte{
Expand Down Expand Up @@ -86,10 +93,16 @@ var _ = Describe("AttachVolume", func() {
"Driver": Equal("ceph"),
"Handle": Equal("mycephvolume"),
"VolumeAttributes": Equal(map[string]string{
machinepoolletv1alpha1.VolumeLabelsAttributeKey: string(mustMarshalJSON(labels)),
"foo": "bar",
}),
})))

Expect(volume.Labels).To(Equal(map[string]string{
poolletutils.DownwardAPILabel(machinepoolletv1alpha1.MachineDownwardAPIPrefix, "root-volume-uid"): "bar",
machinebrokerv1alpha1.ManagerLabel: machinebrokerv1alpha1.MachineBrokerManager,
}))

By("inspecting the effective storage resource is set for volume")
Expect(volume.Status.Resources.Storage().String()).Should(Equal("2k"))

Expand Down
1 change: 1 addition & 0 deletions broker/machinebroker/server/server_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func SetupTest() (*corev1.Namespace, *server.Server) {
BaseURL: baseURL,
BrokerDownwardAPILabels: map[string]string{
"root-machine-uid": machinepoolletv1alpha1.MachineUIDLabel,
"root-volume-uid": machinepoolletv1alpha1.VolumeUIDLabel,
"root-nic-uid": machinepoolletv1alpha1.NetworkInterfaceUIDLabel,
"root-network-uid": machinepoolletv1alpha1.NetworkUIDLabel,
},
Expand Down
6 changes: 6 additions & 0 deletions config/machinepoollet-broker/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ spec:
- --machine-downward-api-label=root-machine-namespace=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-machine-namespace']
- --machine-downward-api-label=root-machine-name=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-machine-name']
- --machine-downward-api-label=root-machine-uid=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-machine-uid']
- --volume-downward-api-label=root-volume-namespace=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-volume-namespace']
- --volume-downward-api-label=root-volume-name=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-volume-name']
- --volume-downward-api-label=root-volume-uid=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-volume-uid']
- --nic-downward-api-label=root-nic-namespace=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-nic-namespace']
- --nic-downward-api-label=root-nic-name=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-nic-name']
- --nic-downward-api-label=root-nic-uid=metadata.labels['downward-api.machinepoollet.ironcore.dev/root-nic-uid']
Expand Down Expand Up @@ -86,6 +89,9 @@ spec:
- --broker-downward-api-label=root-machine-namespace=machinepoollet.ironcore.dev/machine-namespace
- --broker-downward-api-label=root-machine-name=machinepoollet.ironcore.dev/machine-name
- --broker-downward-api-label=root-machine-uid=machinepoollet.ironcore.dev/machine-uid
- --broker-downward-api-label=root-volume-namespace=machinepoollet.ironcore.dev/volume-namespace
- --broker-downward-api-label=root-volume-name=machinepoollet.ironcore.dev/volume-name
- --broker-downward-api-label=root-volume-uid=machinepoollet.ironcore.dev/volume-uid
- --broker-downward-api-label=root-nic-namespace=machinepoollet.ironcore.dev/nic-namespace
- --broker-downward-api-label=root-nic-name=machinepoollet.ironcore.dev/nic-name
- --broker-downward-api-label=root-nic-uid=machinepoollet.ironcore.dev/nic-uid
Expand Down
5 changes: 5 additions & 0 deletions poollet/machinepoollet/api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const (
MachineNamespaceLabel = "machinepoollet.ironcore.dev/machine-namespace"
MachineNameLabel = "machinepoollet.ironcore.dev/machine-name"

VolumeUIDLabel = "machinepoollet.ironcore.dev/volume-uid"
VolumeNamespaceLabel = "machinepoollet.ironcore.dev/volume-namespace"
VolumeNameLabel = "machinepoollet.ironcore.dev/volume-name"

NetworkInterfaceUIDLabel = "machinepoollet.ironcore.dev/nic-uid"
NetworkInterfaceNamespaceLabel = "machinepoollet.ironcore.dev/nic-namespace"
NetworkInterfaceNameLabel = "machinepoollet.ironcore.dev/nic-name"
Expand All @@ -25,6 +29,7 @@ const (

NICLabelsAttributeKey = "rawNICLabels"
NetworkLabelsAttributeKey = "rawNetworkLabels"
VolumeLabelsAttributeKey = "rawVolumeLabels"

MachineGenerationAnnotation = "machinepoollet.ironcore.dev/machine-generation"
IRIMachineGenerationAnnotation = "machinepoollet.ironcore.dev/irimachine-generation"
Expand Down
8 changes: 8 additions & 0 deletions poollet/machinepoollet/cmd/machinepoollet/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ type Options struct {
MachineDownwardAPILabels map[string]string
MachineDownwardAPIAnnotations map[string]string

VolumeDownwardAPILabels map[string]string
VolumeDownwardAPIAnnotations map[string]string

NicDownwardAPILabels map[string]string
NicDownwardAPIAnnotations map[string]string

Expand Down Expand Up @@ -126,10 +129,13 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.MachinePoolName, "machine-pool-name", o.MachinePoolName, "Name of the machine pool to announce / watch")
fs.StringToStringVar(&o.MachineDownwardAPILabels, "machine-downward-api-label", o.MachineDownwardAPILabels, "Downward-API labels to set on the iri machine.")
fs.StringToStringVar(&o.MachineDownwardAPIAnnotations, "machine-downward-api-annotation", o.MachineDownwardAPIAnnotations, "Downward-API annotations to set on the iri machine.")
fs.StringToStringVar(&o.VolumeDownwardAPILabels, "volume-downward-api-label", o.VolumeDownwardAPILabels, "Downward-API labels to set on the iri volume.")
fs.StringToStringVar(&o.VolumeDownwardAPIAnnotations, "volume-downward-api-annotation", o.VolumeDownwardAPIAnnotations, "Downward-API annotations to set on the iri volume.")
fs.StringToStringVar(&o.NicDownwardAPILabels, "nic-downward-api-label", o.NicDownwardAPILabels, "Downward-API labels to set on the iri nic.")
fs.StringToStringVar(&o.NicDownwardAPIAnnotations, "nic-downward-api-annotation", o.NicDownwardAPIAnnotations, "Downward-API annotations to set on the iri nic.")
fs.StringToStringVar(&o.NetworkDownwardAPILabels, "network-downward-api-label", o.NetworkDownwardAPILabels, "Downward-API labels to set on the iri network.")
fs.StringToStringVar(&o.NetworkDownwardAPIAnnotations, "network-downward-api-annotation", o.NetworkDownwardAPIAnnotations, "Downward-API annotations to set on the iri network.")

fs.StringVar(&o.ProviderID, "provider-id", "", "Provider id to announce on the machine pool.")
fs.StringVar(&o.MachineRuntimeEndpoint, "machine-runtime-endpoint", o.MachineRuntimeEndpoint, "Endpoint of the remote machine runtime service.")
fs.DurationVar(&o.MachineRuntimeSocketDiscoveryTimeout, "machine-runtime-socket-discovery-timeout", 20*time.Second, "Timeout for discovering the machine runtime socket.")
Expand Down Expand Up @@ -430,6 +436,8 @@ func Run(ctx context.Context, opts Options) error {
MachinePoolName: opts.MachinePoolName,
MachineDownwardAPILabels: opts.MachineDownwardAPILabels,
MachineDownwardAPIAnnotations: opts.MachineDownwardAPIAnnotations,
VolumeDownwardAPILabels: opts.VolumeDownwardAPILabels,
VolumeDownwardAPIAnnotations: opts.VolumeDownwardAPIAnnotations,
NicDownwardAPILabels: opts.NicDownwardAPILabels,
NicDownwardAPIAnnotations: opts.NicDownwardAPIAnnotations,
NetworkDownwardAPILabels: opts.NetworkDownwardAPILabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func SetupTest() (*corev1.Namespace, *computev1alpha1.MachinePool, *computev1alp
MachineDownwardAPILabels: map[string]string{
fooDownwardAPILabel: fmt.Sprintf("metadata.annotations['%s']", fooAnnotation),
},
VolumeDownwardAPILabels: map[string]string{
fooDownwardAPILabel: fmt.Sprintf("metadata.annotations['%s']", fooAnnotation),
"root-volume-uid": "metadata.uid",
},
NicDownwardAPILabels: map[string]string{
fooDownwardAPILabel: fmt.Sprintf("metadata.annotations['%s']", fooAnnotation),
"root-nic-uid": "metadata.uid",
Expand Down
3 changes: 3 additions & 0 deletions poollet/machinepoollet/controllers/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ type MachineReconciler struct {
NicDownwardAPILabels map[string]string
NicDownwardAPIAnnotations map[string]string

VolumeDownwardAPILabels map[string]string
VolumeDownwardAPIAnnotations map[string]string

NetworkDownwardAPILabels map[string]string
NetworkDownwardAPIAnnotations map[string]string

Expand Down
Loading
Loading