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
5 changes: 0 additions & 5 deletions broker/bucketbroker/apiutils/apiutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"

"github.com/ironcore-dev/controller-utils/metautils"
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
bucketbrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/bucketbroker/api/v1alpha1"
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -128,10 +127,6 @@ func GetAnnotationsAnnotation(o metav1.Object) (map[string]string, error) {
return annotations, nil
}

func SetBucketManagerLabel(bucket *storagev1alpha1.Bucket, manager string) {
metautils.SetLabel(bucket, bucketbrokerv1alpha1.ManagerLabel, manager)
}

func IsManagedBy(o metav1.Object, manager string) bool {
actual, ok := o.GetLabels()[bucketbrokerv1alpha1.ManagerLabel]
return ok && actual == manager
Expand Down
14 changes: 9 additions & 5 deletions broker/bucketbroker/cmd/bucketbroker/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
)

type Options struct {
GetConfigOptions config.GetConfigOptions
Address string
GetConfigOptions config.GetConfigOptions
Address string
BrokerDownwardAPILabels map[string]string

QPS float32
Burst int
Expand All @@ -38,6 +39,8 @@ type Options struct {
func (o *Options) AddFlags(fs *pflag.FlagSet) {
o.GetConfigOptions.BindFlags(fs)
fs.StringVar(&o.Address, "address", "/var/run/iri-bucketbroker.sock", "Address to listen on.")
fs.StringToStringVar(&o.BrokerDownwardAPILabels, "broker-downward-api-label", nil, "The labels to broker via downward API."+
"Example: broker 'root-bucket-uid' from 'bucketpoollet.ironcore.dev/bucket-uid'.")

fs.StringVar(&o.Namespace, "namespace", o.Namespace, "Target Kubernetes namespace to use.")
fs.StringVar(&o.BucketPoolName, "bucket-pool-name", o.BucketPoolName, "Name of the target bucket pool to pin buckets to, if any.")
Expand Down Expand Up @@ -86,9 +89,10 @@ func Run(ctx context.Context, opts Options) error {
}

srv, err := server.New(cfg, server.Options{
Namespace: opts.Namespace,
BucketPoolName: opts.BucketPoolName,
BucketPoolSelector: opts.BucketPoolSelector,
BrokerDownwardAPILabels: opts.BrokerDownwardAPILabels,
Namespace: opts.Namespace,
BucketPoolName: opts.BucketPoolName,
BucketPoolSelector: opts.BucketPoolSelector,
})
if err != nil {
return fmt.Errorf("error creating server: %w", err)
Expand Down
24 changes: 23 additions & 1 deletion broker/bucketbroker/server/bucket_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
bucketbrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/bucketbroker/api/v1alpha1"
"github.com/ironcore-dev/ironcore/broker/bucketbroker/apiutils"
iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"
bucketpoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/bucketpoollet/api/v1alpha1"
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"
"github.com/ironcore-dev/ironcore/utils/maps"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -22,17 +25,37 @@ type AggregateIronCoreBucket struct {
AccessSecret *corev1.Secret
}

func (s *Server) prepareIronCoreBucketLabels(bucket *iri.Bucket) map[string]string {
labels := make(map[string]string)

for downwardAPILabelName, defaultLabelName := range s.brokerDownwardAPILabels {
value := bucket.GetMetadata().GetLabels()[poolletutils.DownwardAPILabel(bucketpoolletv1alpha1.BucketDownwardAPIPrefix, downwardAPILabelName)]
if value == "" {
value = bucket.GetMetadata().GetLabels()[defaultLabelName]
}
if value != "" {
labels[poolletutils.DownwardAPILabel(bucketpoolletv1alpha1.BucketDownwardAPIPrefix, downwardAPILabelName)] = value
}
}

return labels
}

func (s *Server) getIronCoreBucketConfig(_ context.Context, bucket *iri.Bucket) (*AggregateIronCoreBucket, error) {
var bucketPoolRef *corev1.LocalObjectReference
if s.bucketPoolName != "" {
bucketPoolRef = &corev1.LocalObjectReference{
Name: s.bucketPoolName,
}
}
labels := s.prepareIronCoreBucketLabels(bucket)
ironcoreBucket := &storagev1alpha1.Bucket{
ObjectMeta: metav1.ObjectMeta{
Namespace: s.namespace,
Name: s.generateID(),
Labels: maps.AppendMap(labels, map[string]string{
bucketbrokerv1alpha1.ManagerLabel: bucketbrokerv1alpha1.BucketBrokerManager,
}),
},
Spec: storagev1alpha1.BucketSpec{
BucketClassRef: &corev1.LocalObjectReference{Name: bucket.Spec.Class},
Expand All @@ -43,7 +66,6 @@ func (s *Server) getIronCoreBucketConfig(_ context.Context, bucket *iri.Bucket)
if err := apiutils.SetObjectMetadata(ironcoreBucket, bucket.Metadata); err != nil {
return nil, err
}
apiutils.SetBucketManagerLabel(ironcoreBucket, bucketbrokerv1alpha1.BucketBrokerManager)

return &AggregateIronCoreBucket{
Bucket: ironcoreBucket,
Expand Down
2 changes: 2 additions & 0 deletions broker/bucketbroker/server/bucket_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1"
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
bucketpoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/bucketpoollet/api/v1alpha1"
poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -46,6 +47,7 @@ var _ = Describe("CreateBucket", func() {

By("inspecting the ironcore bucket")
Expect(ironcoreBucket.Labels).To(Equal(map[string]string{
poolletutils.DownwardAPILabel(bucketpoolletv1alpha1.BucketDownwardAPIPrefix, "root-bucket-uid"): "foobar",
bucketbrokerv1alpha1.CreatedLabel: "true",
bucketbrokerv1alpha1.ManagerLabel: bucketbrokerv1alpha1.BucketBrokerManager,
}))
Expand Down
22 changes: 15 additions & 7 deletions broker/bucketbroker/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Server struct {
client client.Client
iri.UnimplementedBucketRuntimeServer

brokerDownwardAPILabels map[string]string

namespace string
bucketPoolName string
bucketPoolSelector map[string]string
Expand Down Expand Up @@ -90,9 +92,14 @@ func (s *Server) setupCleaner(ctx context.Context, log logr.Logger, retErr *erro
}

type Options struct {
Namespace string
BucketPoolName string
BucketPoolSelector map[string]string
// BrokerDownwardAPILabels specifies which labels to broker via downward API and what the default
// label name is to obtain the value in case there is no value for the downward API.
// Example usage is e.g. to broker the root UID (map "root-bucket-uid" to bucketpoollet's
// "bucketpoollet.ironcore.dev/bucket-uid")
BrokerDownwardAPILabels map[string]string
Namespace string
BucketPoolName string
BucketPoolSelector map[string]string
}

func setOptionsDefaults(o *Options) {
Expand All @@ -118,10 +125,11 @@ func New(cfg *rest.Config, opts Options) (*Server, error) {
}

return &Server{
client: c,
namespace: opts.Namespace,
bucketPoolName: opts.BucketPoolName,
bucketPoolSelector: opts.BucketPoolSelector,
brokerDownwardAPILabels: opts.BrokerDownwardAPILabels,
client: c,
namespace: opts.Namespace,
bucketPoolName: opts.BucketPoolName,
bucketPoolSelector: opts.BucketPoolSelector,
}, nil
}

Expand Down
4 changes: 4 additions & 0 deletions broker/bucketbroker/server/server_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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/bucketbroker/server"
bucketpoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/bucketpoollet/api/v1alpha1"
utilsenvtest "github.com/ironcore-dev/ironcore/utils/envtest"
"github.com/ironcore-dev/ironcore/utils/envtest/apiserver"
. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -138,6 +139,9 @@ func SetupTest() (*corev1.Namespace, *storagev1alpha1.BucketPool, *server.Server
BucketPoolSelector: map[string]string{
"pool": "test-pool",
},
BrokerDownwardAPILabels: map[string]string{
"root-bucket-uid": bucketpoolletv1alpha1.BucketUIDLabel,
},
})
Expect(err).NotTo(HaveOccurred())
*srv = *newSrv
Expand Down
7 changes: 7 additions & 0 deletions config/bucketpoollet-broker/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ spec:
args:
- --health-probe-bind-address=:8081
- --leader-elect
- --bucket-downward-api-label=root-bucket-namespace=metadata.labels['downward-api.bucketpoollet.ironcore.dev/root-bucket-namespace']
- --bucket-downward-api-label=root-bucket-name=metadata.labels['downward-api.bucketpoollet.ironcore.dev/root-bucket-name']
- --bucket-downward-api-label=root-bucket-uid=metadata.labels['downward-api.bucketpoollet.ironcore.dev/root-bucket-uid']
image: bucketpoollet:latest
name: manager
securityContext:
Expand Down Expand Up @@ -62,6 +65,10 @@ spec:
- /bucketbroker
image: bucketbroker:latest
name: broker
args:
- --broker-downward-api-label=root-bucket-namespace=bucketpoollet.ironcore.dev/root-bucket-namespace
- --broker-downward-api-label=root-bucket-name=bucketpoollet.ironcore.dev/root-bucket-name
- --broker-downward-api-label=root-bucket-uid=bucketpoollet.ironcore.dev/root-bucket-uid
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
Expand Down
6 changes: 3 additions & 3 deletions config/volumepoollet-broker/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ spec:
image: volumebroker:latest
name: broker
args:
- --broker-downward-api-label=root-volume-namespace=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-namespace']
- --broker-downward-api-label=root-volume-name=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-name']
- --broker-downward-api-label=root-volume-uid=metadata.labels['downward-api.volumepoollet.ironcore.dev/root-volume-uid']
- --broker-downward-api-label=root-volume-namespace=volumepoollet.ironcore.dev/root-volume-namespace
- --broker-downward-api-label=root-volume-name=volumepoollet.ironcore.dev/root-volume-name
- --broker-downward-api-label=root-volume-uid=volumepoollet.ironcore.dev/root-volume-uid
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
Expand Down
3 changes: 3 additions & 0 deletions poollet/bucketpoollet/api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ const (

FieldOwner = "bucketpoollet.ironcore.dev/field-owner"
BucketFinalizer = "bucketpoollet.ironcore.dev/bucket"

// DownwardAPIPrefix is the prefix for any downward label.
BucketDownwardAPIPrefix = "downward-api.bucketpoollet.ironcore.dev/"
)
3 changes: 3 additions & 0 deletions poollet/bucketpoollet/bem/bem_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const (
apiServiceTimeout = 5 * time.Minute

controllerManagerService = "controller-manager"

fooDownwardAPILabel = "custom-downward-api-label"
fooAnnotation = "foo"
)

func TestControllers(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion poollet/bucketpoollet/bem/bem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ var _ = Describe("BucketEventMapper", func() {
BucketRuntimeName: fakebucket.FakeRuntimeName,
BucketClassMapper: bucketClassMapper,
BucketPoolName: bp.Name,
}).SetupWithManager(k8sManager)).To(Succeed())
DownwardAPILabels: map[string]string{
fooDownwardAPILabel: fmt.Sprintf("metadata.annotations['%s']", fooAnnotation),
}}).SetupWithManager(k8sManager)).To(Succeed())

mgrCtx, cancel := context.WithCancel(context.Background())
DeferCleanup(cancel)
Expand Down
4 changes: 4 additions & 0 deletions poollet/bucketpoollet/cmd/bucketpoollet/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type Options struct {
LeaderElectionKubeconfig string
ProbeAddr string

BucketDownwardAPILabels map[string]string
BucketDownwardAPIAnnotations map[string]string
BucketPoolName string
ProviderID string
BucketRuntimeEndpoint string
Expand Down Expand Up @@ -97,6 +99,8 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.LeaderElectionNamespace, "leader-election-namespace", "", "Namespace to do leader election in.")
fs.StringVar(&o.LeaderElectionKubeconfig, "leader-election-kubeconfig", "", "Path pointing to a kubeconfig to use for leader election.")

fs.StringToStringVar(&o.BucketDownwardAPILabels, "bucket-downward-api-label", o.BucketDownwardAPILabels, "Downward-API labels to set on the IRI bucket.")
fs.StringToStringVar(&o.BucketDownwardAPIAnnotations, "bucket-downward-api-annotations", o.BucketDownwardAPIAnnotations, "Downward-API annotations to set on the IRI bucket.")
fs.StringVar(&o.BucketPoolName, "bucket-pool-name", o.BucketPoolName, "Name of the bucket pool to announce / watch")
fs.StringVar(&o.ProviderID, "provider-id", "", "Provider id to announce on the bucket pool.")
fs.StringVar(&o.BucketRuntimeEndpoint, "bucket-runtime-endpoint", o.BucketRuntimeEndpoint, "Endpoint of the remote bucket runtime service.")
Expand Down
27 changes: 21 additions & 6 deletions poollet/bucketpoollet/controllers/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/kubectl/pkg/util/fieldpath"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -50,18 +51,28 @@ type BucketReconciler struct {

BucketClassMapper bcm.BucketClassMapper

DownwardAPILabels map[string]string
DownwardAPIAnnotations map[string]string

BucketPoolName string
WatchFilterValue string

MaxConcurrentReconciles int
}

func (r *BucketReconciler) iriBucketLabels(bucket *storagev1alpha1.Bucket) map[string]string {
return map[string]string{
func (r *BucketReconciler) iriBucketLabels(bucket *storagev1alpha1.Bucket) (map[string]string, error) {
labels := map[string]string{
bucketpoolletv1alpha1.BucketUIDLabel: string(bucket.UID),
bucketpoolletv1alpha1.BucketNamespaceLabel: bucket.Namespace,
bucketpoolletv1alpha1.BucketNameLabel: bucket.Name,
}
for downwardAPILabelName, fieldPath := range r.DownwardAPILabels {
value, err := fieldpath.ExtractFieldPathAsString(bucket, fieldPath)
if err == nil && value != "" {
labels[poolletutils.DownwardAPILabel(bucketpoolletv1alpha1.BucketDownwardAPIPrefix, downwardAPILabelName)] = value
}
}
return labels, nil
}

func (r *BucketReconciler) iriBucketAnnotations(_ *storagev1alpha1.Bucket) map[string]string {
Expand Down Expand Up @@ -226,11 +237,15 @@ func getIRIBucketClassCapabilities(bucketClass *storagev1alpha1.BucketClass) *ir
}
}

func (r *BucketReconciler) prepareIRIBucketMetadata(bucket *storagev1alpha1.Bucket) *irimeta.ObjectMetadata {
func (r *BucketReconciler) prepareIRIBucketMetadata(bucket *storagev1alpha1.Bucket, errs []error) (*irimeta.ObjectMetadata, []error) {
labels, err := r.iriBucketLabels(bucket)
if err != nil {
errs = append(errs, fmt.Errorf("error preparing iri bucket labels: %w", err))
}
return &irimeta.ObjectMetadata{
Labels: r.iriBucketLabels(bucket),
Labels: labels,
Annotations: r.iriBucketAnnotations(bucket),
}
}, errs
}

func (r *BucketReconciler) prepareIRIBucketClass(ctx context.Context, bucket *storagev1alpha1.Bucket, bucketClassName string) (string, bool, error) {
Expand Down Expand Up @@ -270,7 +285,7 @@ func (r *BucketReconciler) prepareIRIBucket(ctx context.Context, log logr.Logger
ok = false
}

metadata := r.prepareIRIBucketMetadata(bucket)
metadata, errs := r.prepareIRIBucketMetadata(bucket, errs)

if len(errs) > 0 {
return nil, false, fmt.Errorf("error(s) preparing iri bucket: %v", errs)
Expand Down
2 changes: 1 addition & 1 deletion poollet/volumepoollet/controllers/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func getIRIVolumeClassCapabilities(volumeClass *storagev1alpha1.VolumeClass) *ir
func (r *VolumeReconciler) prepareIRIVolumeMetadata(volume *storagev1alpha1.Volume, errs []error) (*irimeta.ObjectMetadata, []error) {
labels, err := r.iriVolumeLabels(volume)
if err != nil {
errs = append(errs, fmt.Errorf("error preparing iri machine labels: %w", err))
errs = append(errs, fmt.Errorf("error preparing iri volume labels: %w", err))
}
return &irimeta.ObjectMetadata{
Labels: labels,
Expand Down
Loading