Skip to content

Commit cee72b9

Browse files
authored
Make controllers in volume-poollet configurable (#1425)
1 parent f04d642 commit cee72b9

File tree

2 files changed

+110
-77
lines changed
  • config/volumepoollet-broker/manager
  • poollet/volumepoollet/cmd/volumepoollet/app

2 files changed

+110
-77
lines changed

config/volumepoollet-broker/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ spec:
3838
- --volume-snapshot-downward-api-label=root-volume-snapshot-namespace=metadata.labels['downward-api.volumepoollet.ironcore.dev/volume-snapshot-root-volume-snapshot-namespace']
3939
- --volume-snapshot-downward-api-label=root-volume-snapshot-name=metadata.labels['downward-api.volumepoollet.ironcore.dev/volume-snapshot-root-volume-snapshot-name']
4040
- --volume-snapshot-downward-api-label=root-volume-snapshot-uid=metadata.labels['downward-api.volumepoollet.ironcore.dev/volume-snapshot-root-volume-snapshot-uid']
41+
- --controllers=*
4142
image: volumepoollet:latest
4243
name: manager
4344
securityContext:

poollet/volumepoollet/cmd/volumepoollet/app/app.go

Lines changed: 109 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import (
1212
"path/filepath"
1313
"time"
1414

15-
"github.com/spf13/cobra"
16-
"github.com/spf13/pflag"
17-
15+
"github.com/ironcore-dev/controller-utils/cmdutils/switches"
16+
"github.com/ironcore-dev/controller-utils/configutils"
1817
commonv1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1"
1918
ipamv1alpha1 "github.com/ironcore-dev/ironcore/api/ipam/v1alpha1"
2019
networkingv1alpha1 "github.com/ironcore-dev/ironcore/api/networking/v1alpha1"
@@ -28,8 +27,8 @@ import (
2827
"github.com/ironcore-dev/ironcore/poollet/volumepoollet/vcm"
2928
"github.com/ironcore-dev/ironcore/poollet/volumepoollet/vem"
3029
"github.com/ironcore-dev/ironcore/utils/client/config"
31-
32-
"github.com/ironcore-dev/controller-utils/configutils"
30+
"github.com/spf13/cobra"
31+
"github.com/spf13/pflag"
3332
"k8s.io/apimachinery/pkg/runtime"
3433
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3534
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -43,6 +42,11 @@ import (
4342

4443
var scheme = runtime.NewScheme()
4544

45+
const (
46+
volumeController = "volume"
47+
volumeSnapshotController = "volumesnapshot"
48+
)
49+
4650
func init() {
4751
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
4852
utilruntime.Must(storagev1alpha1.AddToScheme(scheme))
@@ -85,6 +89,8 @@ type Options struct {
8589
RelistPeriod time.Duration
8690
RelistThreshold time.Duration
8791

92+
Switches *switches.Switches
93+
8894
WatchFilterValue string
8995

9096
MaxConcurrentReconciles int
@@ -132,6 +138,18 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
132138
fs.StringVar(&o.WatchFilterValue, "watch-filter", "", "Value to filter for while watching.")
133139

134140
fs.IntVar(&o.MaxConcurrentReconciles, "max-concurrent-reconciles", 1, "Maximum number of concurrent reconciles.")
141+
142+
o.Switches = switches.New(
143+
volumeController,
144+
volumeSnapshotController,
145+
)
146+
fs.Var(o.Switches, "controllers",
147+
fmt.Sprintf("Controllers to enable. All controllers: %v. Disabled-by-default controllers: %v",
148+
o.Switches.All(),
149+
o.Switches.DisabledByDefault(),
150+
),
151+
)
152+
135153
}
136154

137155
func (o *Options) MarkFlagsRequired(cmd *cobra.Command) {
@@ -302,88 +320,102 @@ func Run(ctx context.Context, opts Options) error {
302320
if err != nil {
303321
return fmt.Errorf("error getting volume runtime version: %w", err)
304322
}
305-
volumeClassMapper := vcm.NewGeneric(volumeRuntime, vcm.GenericOptions{})
306-
if err := mgr.Add(volumeClassMapper); err != nil {
307-
return fmt.Errorf("error adding volume class mapper: %w", err)
308-
}
309-
volumeEventMapper := vem.NewVolumeEventMapper(mgr.GetClient(), volumeRuntime, mgr.GetEventRecorderFor("volume-cluster-events"), vem.VolumeEventMapperOptions{})
310-
if err := mgr.Add(volumeEventMapper); err != nil {
311-
return fmt.Errorf("error adding volume event mapper: %w", err)
312-
}
313323

314-
volumeEvents := irievent.NewGenerator(func(ctx context.Context) ([]*iri.Volume, error) {
315-
res, err := volumeRuntime.ListVolumes(ctx, &iri.ListVolumesRequest{})
316-
if err != nil {
317-
return nil, err
324+
indexer := mgr.GetFieldIndexer()
325+
326+
var volumeClassMapper vcm.VolumeClassMapper
327+
var volumeEventMapper *vem.VolumeEventMapper
328+
var volumeEvents irievent.Generator[*iri.Volume]
329+
if opts.Switches.Enabled(volumeController) {
330+
setupLog.V(1).Info("Volume controller enabled")
331+
volumeClassMapper := vcm.NewGeneric(volumeRuntime, vcm.GenericOptions{})
332+
if err := mgr.Add(volumeClassMapper); err != nil {
333+
return fmt.Errorf("error adding volume class mapper: %w", err)
334+
}
335+
volumeEventMapper = vem.NewVolumeEventMapper(mgr.GetClient(), volumeRuntime, mgr.GetEventRecorderFor("volume-cluster-events"), vem.VolumeEventMapperOptions{})
336+
if err := mgr.Add(volumeEventMapper); err != nil {
337+
return fmt.Errorf("error adding volume event mapper: %w", err)
318338
}
319-
return res.Volumes, nil
320-
}, irievent.GeneratorOptions{
321-
ChannelCapacity: opts.ChannelCapacity,
322-
RelistPeriod: opts.RelistPeriod,
323-
RelistThreshold: opts.RelistThreshold,
324-
})
325-
if err := mgr.Add(volumeEvents); err != nil {
326-
return fmt.Errorf("error adding volume event generator: %w", err)
327-
}
328-
if err := mgr.AddHealthzCheck("volume-events", volumeEvents.Check); err != nil {
329-
return fmt.Errorf("error adding volume event generator healthz check: %w", err)
330-
}
331339

332-
volumeSnapshotEvents := irievent.NewGenerator(func(ctx context.Context) ([]*iri.VolumeSnapshot, error) {
333-
res, err := volumeRuntime.ListVolumeSnapshots(ctx, &iri.ListVolumeSnapshotsRequest{})
334-
if err != nil {
335-
return nil, err
340+
volumeEvents = irievent.NewGenerator(func(ctx context.Context) ([]*iri.Volume, error) {
341+
res, err := volumeRuntime.ListVolumes(ctx, &iri.ListVolumesRequest{})
342+
if err != nil {
343+
return nil, err
344+
}
345+
return res.Volumes, nil
346+
}, irievent.GeneratorOptions{
347+
ChannelCapacity: opts.ChannelCapacity,
348+
RelistPeriod: opts.RelistPeriod,
349+
RelistThreshold: opts.RelistThreshold,
350+
})
351+
if err := mgr.Add(volumeEvents); err != nil {
352+
return fmt.Errorf("error adding volume event generator: %w", err)
353+
}
354+
if err := mgr.AddHealthzCheck("volume-events", volumeEvents.Check); err != nil {
355+
return fmt.Errorf("error adding volume event generator healthz check: %w", err)
336356
}
337-
return res.VolumeSnapshots, nil
338-
}, irievent.GeneratorOptions{
339-
ChannelCapacity: opts.ChannelCapacity,
340-
RelistPeriod: opts.RelistPeriod,
341-
RelistThreshold: opts.RelistThreshold,
342-
})
343-
if err := mgr.Add(volumeSnapshotEvents); err != nil {
344-
return fmt.Errorf("error adding volume snapshot event generator: %w", err)
345-
}
346-
if err := mgr.AddHealthzCheck("volume-snapshot-events", volumeSnapshotEvents.Check); err != nil {
347-
return fmt.Errorf("error adding volume snapshot event generator healthz check: %w", err)
348-
}
349357

350-
indexer := mgr.GetFieldIndexer()
351-
if err := storageclient.SetupVolumeSpecVolumePoolRefNameFieldIndexer(ctx, indexer); err != nil {
352-
return fmt.Errorf("error setting up %s indexer with manager: %w", storageclient.VolumeSpecVolumePoolRefNameField, err)
353-
}
354-
if err := storageclient.SetupVolumeSpecVolumeSnapshotRefNameFieldIndexer(ctx, indexer); err != nil {
355-
return fmt.Errorf("error setting up %s indexer with manager: %w", storageclient.VolumeSpecVolumeSnapshotRefNameField, err)
358+
if err := storageclient.SetupVolumeSpecVolumePoolRefNameFieldIndexer(ctx, indexer); err != nil {
359+
return fmt.Errorf("error setting up %s indexer with manager: %w", storageclient.VolumeSpecVolumePoolRefNameField, err)
360+
}
356361
}
357362

358-
onInitialized := func(ctx context.Context) error {
359-
volumeClassMapperSyncCtx, cancel := context.WithTimeout(ctx, opts.VolumeClassMapperSyncTimeout)
360-
defer cancel()
361-
362-
if err := volumeClassMapper.WaitForSync(volumeClassMapperSyncCtx); err != nil {
363-
return fmt.Errorf("error waiting for volume class mapper to sync: %w", err)
363+
var volumeSnapshotEvents irievent.Generator[*iri.VolumeSnapshot]
364+
if opts.Switches.Enabled(volumeController) {
365+
setupLog.V(1).Info("Volume Snapshot controller enabled")
366+
volumeSnapshotEvents = irievent.NewGenerator(func(ctx context.Context) ([]*iri.VolumeSnapshot, error) {
367+
res, err := volumeRuntime.ListVolumeSnapshots(ctx, &iri.ListVolumeSnapshotsRequest{})
368+
if err != nil {
369+
return nil, err
370+
}
371+
return res.VolumeSnapshots, nil
372+
}, irievent.GeneratorOptions{
373+
ChannelCapacity: opts.ChannelCapacity,
374+
RelistPeriod: opts.RelistPeriod,
375+
RelistThreshold: opts.RelistThreshold,
376+
})
377+
if err := mgr.Add(volumeSnapshotEvents); err != nil {
378+
return fmt.Errorf("error adding volume snapshot event generator: %w", err)
364379
}
365-
366-
if err := (&controllers.VolumeReconciler{
367-
EventRecorder: mgr.GetEventRecorderFor("volumes"),
368-
Client: mgr.GetClient(),
369-
Scheme: scheme,
370-
VolumeRuntime: volumeRuntime,
371-
VolumeRuntimeName: version.RuntimeName,
372-
VolumeClassMapper: volumeClassMapper,
373-
VolumePoolName: opts.VolumePoolName,
374-
DownwardAPILabels: opts.VolumeDownwardAPILabels,
375-
DownwardAPIAnnotations: opts.VolumeDownwardAPIAnnotations,
376-
WatchFilterValue: opts.WatchFilterValue,
377-
MaxConcurrentReconciles: opts.MaxConcurrentReconciles,
378-
}).SetupWithManager(mgr); err != nil {
379-
return fmt.Errorf("error setting up volume reconciler with manager: %w", err)
380+
if err := mgr.AddHealthzCheck("volume-snapshot-events", volumeSnapshotEvents.Check); err != nil {
381+
return fmt.Errorf("error adding volume snapshot event generator healthz check: %w", err)
382+
}
383+
if err := storageclient.SetupVolumeSpecVolumeSnapshotRefNameFieldIndexer(ctx, indexer); err != nil {
384+
return fmt.Errorf("error setting up %s indexer with manager: %w", storageclient.VolumeSpecVolumeSnapshotRefNameField, err)
380385
}
386+
}
381387

382-
if err := (&controllers.VolumeAnnotatorReconciler{
383-
Client: mgr.GetClient(),
384-
VolumeEvents: volumeEvents,
385-
}).SetupWithManager(mgr); err != nil {
386-
return fmt.Errorf("error setting up volume annotator reconciler with manager: %w", err)
388+
onInitialized := func(ctx context.Context) error {
389+
if opts.Switches.Enabled(volumeController) {
390+
volumeClassMapperSyncCtx, cancel := context.WithTimeout(ctx, opts.VolumeClassMapperSyncTimeout)
391+
defer cancel()
392+
393+
if err := volumeClassMapper.WaitForSync(volumeClassMapperSyncCtx); err != nil {
394+
return fmt.Errorf("error waiting for volume class mapper to sync: %w", err)
395+
}
396+
397+
if err := (&controllers.VolumeReconciler{
398+
EventRecorder: mgr.GetEventRecorderFor("volumes"),
399+
Client: mgr.GetClient(),
400+
Scheme: scheme,
401+
VolumeRuntime: volumeRuntime,
402+
VolumeRuntimeName: version.RuntimeName,
403+
VolumeClassMapper: volumeClassMapper,
404+
VolumePoolName: opts.VolumePoolName,
405+
DownwardAPILabels: opts.VolumeDownwardAPILabels,
406+
DownwardAPIAnnotations: opts.VolumeDownwardAPIAnnotations,
407+
WatchFilterValue: opts.WatchFilterValue,
408+
MaxConcurrentReconciles: opts.MaxConcurrentReconciles,
409+
}).SetupWithManager(mgr); err != nil {
410+
return fmt.Errorf("error setting up volume reconciler with manager: %w", err)
411+
}
412+
413+
if err := (&controllers.VolumeAnnotatorReconciler{
414+
Client: mgr.GetClient(),
415+
VolumeEvents: volumeEvents,
416+
}).SetupWithManager(mgr); err != nil {
417+
return fmt.Errorf("error setting up volume annotator reconciler with manager: %w", err)
418+
}
387419
}
388420

389421
if err := (&controllers.VolumeSnapshotReconciler{

0 commit comments

Comments
 (0)