Skip to content

Commit b9f1460

Browse files
authored
Add DownwardAPILabels support for Volume (#1317)
* Add `DownwardAPILables` support for `Volume` * address review comment
1 parent a8b7265 commit b9f1460

21 files changed

Lines changed: 146 additions & 69 deletions

File tree

broker/machinebroker/server/machine_create.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ import (
1313
"github.com/ironcore-dev/ironcore/broker/common/cleaner"
1414
machinebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/machinebroker/api/v1alpha1"
1515
"github.com/ironcore-dev/ironcore/broker/machinebroker/apiutils"
16-
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
1716
machinepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1"
17+
18+
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
19+
20+
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
1821
"github.com/ironcore-dev/ironcore/utils/maps"
1922
corev1 "k8s.io/api/core/v1"
2023
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -53,12 +56,12 @@ func (s *Server) prepareIronCoreMachineLabels(machine *iri.Machine) map[string]s
5356
labels := make(map[string]string)
5457

5558
for downwardAPILabelName, defaultLabelName := range s.brokerDownwardAPILabels {
56-
value := machine.GetMetadata().GetLabels()[machinepoolletv1alpha1.DownwardAPILabel(downwardAPILabelName)]
59+
value := machine.GetMetadata().GetLabels()[poolletutils.DownwardAPILabel(machinepoolletv1alpha1.MachineDownwardAPIPrefix, downwardAPILabelName)]
5760
if value == "" {
5861
value = machine.GetMetadata().GetLabels()[defaultLabelName]
5962
}
6063
if value != "" {
61-
labels[machinepoolletv1alpha1.DownwardAPILabel(downwardAPILabelName)] = value
64+
labels[poolletutils.DownwardAPILabel(machinepoolletv1alpha1.MachineDownwardAPIPrefix, downwardAPILabelName)] = value
6265
}
6366
}
6467

broker/machinebroker/server/machine_create_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/ironcore-dev/ironcore/broker/machinebroker/apiutils"
1010
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
1111
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
12+
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
1213
machinepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1"
1314
. "github.com/onsi/ginkgo/v2"
1415
. "github.com/onsi/gomega"
@@ -47,9 +48,9 @@ var _ = Describe("CreateMachine", func() {
4748

4849
By("inspecting the ironcore machine")
4950
Expect(ironcoreMachine.Labels).To(Equal(map[string]string{
50-
machinepoolletv1alpha1.DownwardAPILabel("root-machine-uid"): "foobar",
51-
machinebrokerv1alpha1.CreatedLabel: "true",
52-
machinebrokerv1alpha1.ManagerLabel: machinebrokerv1alpha1.MachineBrokerManager,
51+
poolletutils.DownwardAPILabel(machinepoolletv1alpha1.MachineDownwardAPIPrefix, "root-machine-uid"): "foobar",
52+
machinebrokerv1alpha1.CreatedLabel: "true",
53+
machinebrokerv1alpha1.ManagerLabel: machinebrokerv1alpha1.MachineBrokerManager,
5354
}))
5455
encodedIRIAnnotations, err := apiutils.EncodeAnnotationsAnnotation(nil)
5556
Expect(err).NotTo(HaveOccurred())

broker/volumebroker/apiutils/apiutils.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010

1111
"github.com/ironcore-dev/controller-utils/metautils"
12-
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
1312
volumebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/volumebroker/api/v1alpha1"
1413
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
1514
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -132,10 +131,6 @@ func GetAnnotationsAnnotation(o metav1.Object) (map[string]string, error) {
132131
return annotations, nil
133132
}
134133

135-
func SetVolumeManagerLabel(volume *storagev1alpha1.Volume, manager string) {
136-
metautils.SetLabel(volume, volumebrokerv1alpha1.ManagerLabel, manager)
137-
}
138-
139134
func IsManagedBy(o metav1.Object, manager string) bool {
140135
actual, ok := o.GetLabels()[volumebrokerv1alpha1.ManagerLabel]
141136
return ok && actual == manager

broker/volumebroker/cmd/volumebroker/app/app.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424
)
2525

2626
type Options struct {
27-
GetConfigOptions config.GetConfigOptions
28-
Address string
27+
GetConfigOptions config.GetConfigOptions
28+
Address string
29+
BrokerDownwardAPILabels map[string]string
2930

3031
QPS float32
3132
Burst int
@@ -38,6 +39,8 @@ type Options struct {
3839
func (o *Options) AddFlags(fs *pflag.FlagSet) {
3940
o.GetConfigOptions.BindFlags(fs)
4041
fs.StringVar(&o.Address, "address", "/var/run/iri-volumebroker.sock", "Address to listen on.")
42+
fs.StringToStringVar(&o.BrokerDownwardAPILabels, "broker-downward-api-label", nil, "The labels to broker via downward API. "+
43+
"Example is for instance to broker \"root-volume-uid\" initially obtained via \"volumepoollet.ironcore.dev/volume-uid\".")
4144

4245
fs.StringVar(&o.Namespace, "namespace", o.Namespace, "Target Kubernetes namespace to use.")
4346
fs.StringVar(&o.VolumePoolName, "volume-pool-name", o.VolumePoolName, "Name of the target volume pool to pin volumes to, if any.")
@@ -86,9 +89,10 @@ func Run(ctx context.Context, opts Options) error {
8689
}
8790

8891
srv, err := server.New(cfg, server.Options{
89-
Namespace: opts.Namespace,
90-
VolumePoolName: opts.VolumePoolName,
91-
VolumePoolSelector: opts.VolumePoolSelector,
92+
BrokerDownwardAPILabels: opts.BrokerDownwardAPILabels,
93+
Namespace: opts.Namespace,
94+
VolumePoolName: opts.VolumePoolName,
95+
VolumePoolSelector: opts.VolumePoolSelector,
9296
})
9397
if err != nil {
9498
return fmt.Errorf("error creating server: %w", err)

broker/volumebroker/server/server.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type Server struct {
4545
client client.Client
4646
idGen idgen.IDGen
4747

48+
brokerDownwardAPILabels map[string]string
49+
4850
namespace string
4951
volumePoolName string
5052
volumePoolSelector map[string]string
@@ -73,10 +75,15 @@ func (s *Server) setupCleaner(ctx context.Context, log logr.Logger, retErr *erro
7375
}
7476

7577
type Options struct {
76-
Namespace string
77-
VolumePoolName string
78-
VolumePoolSelector map[string]string
79-
IDGen idgen.IDGen
78+
// BrokerDownwardAPILabels specifies which labels to broker via downward API and what the default
79+
// label name is to obtain the value in case there is no value for the downward API.
80+
// Example usage is e.g. to broker the root UID (map "root-volume-uid" to volumepoollet's
81+
// "volumepoollet.ironcore.dev/volume-uid")
82+
BrokerDownwardAPILabels map[string]string
83+
Namespace string
84+
VolumePoolName string
85+
VolumePoolSelector map[string]string
86+
IDGen idgen.IDGen
8087
}
8188

8289
func setOptionsDefaults(o *Options) {
@@ -105,11 +112,12 @@ func New(cfg *rest.Config, opts Options) (*Server, error) {
105112
}
106113

107114
return &Server{
108-
client: c,
109-
idGen: opts.IDGen,
110-
namespace: opts.Namespace,
111-
volumePoolName: opts.VolumePoolName,
112-
volumePoolSelector: opts.VolumePoolSelector,
115+
brokerDownwardAPILabels: opts.BrokerDownwardAPILabels,
116+
client: c,
117+
idGen: opts.IDGen,
118+
namespace: opts.Namespace,
119+
volumePoolName: opts.VolumePoolName,
120+
volumePoolSelector: opts.VolumePoolSelector,
113121
}, nil
114122
}
115123

broker/volumebroker/server/server_suite_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
1818
"github.com/ironcore-dev/ironcore/broker/common/idgen"
1919
"github.com/ironcore-dev/ironcore/broker/volumebroker/server"
20+
volumepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/volumepoollet/api/v1alpha1"
2021
utilsenvtest "github.com/ironcore-dev/ironcore/utils/envtest"
2122
"github.com/ironcore-dev/ironcore/utils/envtest/apiserver"
2223
. "github.com/onsi/ginkgo/v2"
@@ -140,6 +141,9 @@ func SetupTest() (*corev1.Namespace, *server.Server) {
140141
DeferCleanup(k8sClient.Delete, volumePool)
141142

142143
newSrv, err := server.New(cfg, server.Options{
144+
BrokerDownwardAPILabels: map[string]string{
145+
"root-volume-uid": volumepoolletv1alpha1.VolumeUIDLabel,
146+
},
143147
Namespace: ns.Name,
144148
VolumePoolName: volumePool.Name,
145149
VolumePoolSelector: map[string]string{

broker/volumebroker/server/volume_create.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
volumebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/volumebroker/api/v1alpha1"
1414
"github.com/ironcore-dev/ironcore/broker/volumebroker/apiutils"
1515
iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1"
16+
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
17+
volumepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/volumepoollet/api/v1alpha1"
18+
19+
"github.com/ironcore-dev/ironcore/utils/maps"
1620
corev1 "k8s.io/api/core/v1"
1721
"k8s.io/apimachinery/pkg/api/resource"
1822
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -25,6 +29,22 @@ type AggregateIronCoreVolume struct {
2529
AccessSecret *corev1.Secret
2630
}
2731

32+
func (s *Server) prepareIronCoreVolumeLabels(volume *iri.Volume) map[string]string {
33+
labels := make(map[string]string)
34+
35+
for downwardAPILabelName, defaultLabelName := range s.brokerDownwardAPILabels {
36+
value := volume.GetMetadata().GetLabels()[poolletutils.DownwardAPILabel(volumepoolletv1alpha1.VolumeDownwardAPIPrefix, downwardAPILabelName)]
37+
if value == "" {
38+
value = volume.GetMetadata().GetLabels()[defaultLabelName]
39+
}
40+
if value != "" {
41+
labels[poolletutils.DownwardAPILabel(volumepoolletv1alpha1.VolumeDownwardAPIPrefix, downwardAPILabelName)] = value
42+
}
43+
}
44+
45+
return labels
46+
}
47+
2848
func (s *Server) getIronCoreVolumeConfig(_ context.Context, volume *iri.Volume) (*AggregateIronCoreVolume, error) {
2949
var volumePoolRef *corev1.LocalObjectReference
3050
if s.volumePoolName != "" {
@@ -55,10 +75,15 @@ func (s *Server) getIronCoreVolumeConfig(_ context.Context, volume *iri.Volume)
5575
}
5676
}
5777

78+
labels := s.prepareIronCoreVolumeLabels(volume)
79+
5880
ironcoreVolume := &storagev1alpha1.Volume{
5981
ObjectMeta: metav1.ObjectMeta{
6082
Namespace: s.namespace,
6183
Name: s.idGen.Generate(),
84+
Labels: maps.AppendMap(labels, map[string]string{
85+
volumebrokerv1alpha1.ManagerLabel: volumebrokerv1alpha1.VolumeBrokerManager,
86+
}),
6287
},
6388
Spec: storagev1alpha1.VolumeSpec{
6489
VolumeClassRef: &corev1.LocalObjectReference{Name: volume.Spec.Class},
@@ -75,7 +100,6 @@ func (s *Server) getIronCoreVolumeConfig(_ context.Context, volume *iri.Volume)
75100
if err := apiutils.SetObjectMetadata(ironcoreVolume, volume.Metadata); err != nil {
76101
return nil, err
77102
}
78-
apiutils.SetVolumeManagerLabel(ironcoreVolume, volumebrokerv1alpha1.VolumeBrokerManager)
79103

80104
return &AggregateIronCoreVolume{
81105
Volume: ironcoreVolume,

broker/volumebroker/server/volume_create_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
volumebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/volumebroker/api/v1alpha1"
1010
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
1111
iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1"
12+
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
1213
volumepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/volumepoollet/api/v1alpha1"
1314

1415
. "github.com/onsi/ginkgo/v2"
@@ -49,6 +50,7 @@ var _ = Describe("CreateVolume", func() {
4950

5051
By("inspecting the ironcore volume")
5152
Expect(ironcoreVolume.Labels).To(Equal(map[string]string{
53+
poolletutils.DownwardAPILabel(volumepoolletv1alpha1.VolumeDownwardAPIPrefix, "root-volume-uid"): "foobar",
5254
volumebrokerv1alpha1.CreatedLabel: "true",
5355
volumebrokerv1alpha1.ManagerLabel: volumebrokerv1alpha1.VolumeBrokerManager,
5456
}))

config/volumepoollet-broker/manager/manager.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ spec:
3232
args:
3333
- --health-probe-bind-address=:8081
3434
- --leader-elect
35+
- --volume-downward-api-label=root-volume-namespace=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-namespace']
36+
- --volume-downward-api-label=root-volume-name=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-name']
37+
- --volume-downward-api-label=root-volume-uid=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-uid']
3538
image: volumepoollet:latest
3639
name: manager
3740
securityContext:
@@ -62,6 +65,10 @@ spec:
6265
- /volumebroker
6366
image: volumebroker:latest
6467
name: broker
68+
args:
69+
- --broker-downward-api-label=root-volume-namespace=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-namespace']
70+
- --broker-downward-api-label=root-volume-name=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-name']
71+
- --broker-downward-api-label=root-volume-uid=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-uid']
6572
securityContext:
6673
allowPrivilegeEscalation: false
6774
livenessProbe:

poollet/bucketpoollet/controllers/bucket_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
bucketpoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/bucketpoollet/api/v1alpha1"
2121
"github.com/ironcore-dev/ironcore/poollet/bucketpoollet/bcm"
2222
"github.com/ironcore-dev/ironcore/poollet/bucketpoollet/controllers/events"
23-
poolletproviderid "github.com/ironcore-dev/ironcore/utils/poollet"
23+
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
2424

2525
ironcoreclient "github.com/ironcore-dev/ironcore/utils/client"
2626
"github.com/ironcore-dev/ironcore/utils/predicates"
@@ -441,7 +441,7 @@ func (r *BucketReconciler) updateStatus(ctx context.Context, log logr.Logger, bu
441441
base := bucket.DeepCopy()
442442
now := metav1.Now()
443443

444-
bucketID := poolletproviderid.MakeID(r.BucketRuntimeName, iriBucket.Metadata.Id)
444+
bucketID := poolletutils.MakeID(r.BucketRuntimeName, iriBucket.Metadata.Id)
445445

446446
bucket.Status.Access = access
447447
newState, err := r.convertIRIBucketState(iriBucket.Status.State)

0 commit comments

Comments
 (0)