@@ -12,12 +12,14 @@ import (
1212 rm "cloud.google.com/go/resourcemanager/apiv3"
1313 rmpb "cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb"
1414 "cloud.google.com/go/storage"
15+ "github.com/statisticsnorway/ssbucketeer/internal/template"
1516 "google.golang.org/api/iterator"
1617 appsv1 "k8s.io/api/apps/v1"
1718 batchv1 "k8s.io/api/batch/v1"
1819 corev1 "k8s.io/api/core/v1"
1920 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021 "k8s.io/apimachinery/pkg/types"
22+ "k8s.io/utils/ptr"
2123 ctrl "sigs.k8s.io/controller-runtime"
2224 "sigs.k8s.io/controller-runtime/pkg/client"
2325 klog "sigs.k8s.io/controller-runtime/pkg/log"
@@ -50,6 +52,13 @@ type StatefulsetMutator struct {
5052 ADCGroupEnvName string
5153
5254 GroupConfigs AccessGroupConfigs
55+
56+ SharedBucketTemplate template.AnonymousTemplate [SharedBucketTemplateData ]
57+ }
58+
59+ type SharedBucketSpec struct {
60+ Team string `json:"team"`
61+ ShortName string `json:"sharedBucket"`
5362}
5463
5564func (m * StatefulsetMutator ) SetupWithManager (mgr ctrl.Manager ) {
@@ -120,6 +129,12 @@ func (m *StatefulsetMutator) Handle(ctx context.Context, req admission.Request)
120129 }
121130 }
122131
132+ if sharedBuckets , ok := sfs .Annotations [mountSharedBucketsAnnotation ]; ok {
133+ if err := m .addSharedBuckets (bucketMounts , sharedBuckets ); err != nil {
134+ log .Error (err , "failed to add shared buckets" )
135+ }
136+ }
137+
123138 // TODO: Use Dapla Team API for this?
124139 if sfs .Annotations [mountStandardBucketsAnnotation ] == "true" {
125140 if err := m .addStandardBuckets (ctx , team , * groupConfig , bucketMounts ); err != nil {
@@ -167,7 +182,7 @@ func getServiceContainer(pod *corev1.PodTemplateSpec, name string) *corev1.Conta
167182
168183func (m * StatefulsetMutator ) launchIamProbe (ctx context.Context , sfs * appsv1.StatefulSet ) error {
169184 sfs .Annotations [iamProbeStatus ] = fmt .Sprintf ("%s%d" , iamProbeRunningPrefix , * sfs .Spec .Replicas )
170- sfs .Spec .Replicas = ptr [int32 ](0 )
185+ sfs .Spec .Replicas = ptr. To [int32 ](0 )
171186
172187 probeJob := & batchv1.Job {
173188 ObjectMeta : metav1.ObjectMeta {
@@ -178,8 +193,8 @@ func (m *StatefulsetMutator) launchIamProbe(ctx context.Context, sfs *appsv1.Sta
178193 },
179194 },
180195 Spec : batchv1.JobSpec {
181- ActiveDeadlineSeconds : ptr [int64 ](300 ),
182- TTLSecondsAfterFinished : ptr [int32 ](0 ),
196+ ActiveDeadlineSeconds : ptr. To [int64 ](300 ),
197+ TTLSecondsAfterFinished : ptr. To [int32 ](0 ),
183198 Template : corev1.PodTemplateSpec {
184199 ObjectMeta : metav1.ObjectMeta {
185200 Annotations : map [string ]string {
@@ -257,7 +272,7 @@ func (m *StatefulsetMutator) addStandardBuckets(ctx context.Context, team string
257272
258273 projectName , err := gc .ProjectTemplate .Execute (ProjectTemplateData {TeamName : team , Stage : m .Stage })
259274 if err != nil {
260- return fmt .Errorf ("execute template %s: %w" , gc .ProjectTemplate .template . Name (), err )
275+ return fmt .Errorf ("execute template %s: %w" , gc .ProjectTemplate .Name (), err )
261276 }
262277
263278 projectIt := m .Projects .SearchProjects (ctx , & rmpb.SearchProjectsRequest {
@@ -291,6 +306,28 @@ func (m *StatefulsetMutator) addStandardBuckets(ctx context.Context, team string
291306 return nil
292307}
293308
309+ func (m * StatefulsetMutator ) addSharedBuckets (bucketMounts map [string ]string , sharedBuckets string ) error {
310+ bucketSpecs := []SharedBucketSpec {}
311+
312+ if err := json .Unmarshal ([]byte (sharedBuckets ), & bucketSpecs ); err != nil {
313+ return err
314+ }
315+
316+ for _ , bucket := range bucketSpecs {
317+ mountPoint := fmt .Sprintf ("shared/%s/%s" , bucket .Team , bucket .ShortName )
318+ bucket , err := m .SharedBucketTemplate .Execute (SharedBucketTemplateData {
319+ TeamName : bucket .Team ,
320+ BucketShortName : bucket .ShortName ,
321+ Stage : m .Stage ,
322+ })
323+ if err != nil {
324+ return err
325+ }
326+ bucketMounts [mountPoint ] = bucket
327+ }
328+ return nil
329+ }
330+
294331func ensurePodAnnotations (podTemplate * corev1.PodTemplateSpec ) {
295332 if podTemplate .Annotations == nil {
296333 podTemplate .Annotations = make (map [string ]string , 2 )
0 commit comments