Skip to content

Commit

Permalink
Merge pull request #248 from grycap/dev-slangarita
Browse files Browse the repository at this point in the history
Improvements on mounted volumes
  • Loading branch information
catttam authored Jul 25, 2024
2 parents 32e85ae + a98d86e commit 53a298a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
25 changes: 24 additions & 1 deletion pkg/handlers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func MakeCreateHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand

// Check service values and set defaults
checkValues(&service, cfg)

// Check if users in allowed_users have a MinIO associated user
minIOAdminClient, _ := utils.MakeMinIOAdminClient(cfg)

Expand Down Expand Up @@ -98,6 +97,10 @@ func MakeCreateHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand
break
}
}
} else {
if len(cfg.OIDCGroups) != 0 {
c.String(http.StatusBadRequest, fmt.Sprintln("service must be part of one of the following VO: ", cfg.OIDCGroups))
}
}

if len(service.AllowedUsers) > 0 {
Expand Down Expand Up @@ -417,6 +420,26 @@ func createBuckets(service *types.Service, cfg *types.Config, minIOAdminClient *
return fmt.Errorf("error creating bucket %s: %v", splitPath[0], err)
}
}
if !isUpdate {
if !isAdminUser {
if len(allowed_users) == 0 {
err = minIOAdminClient.AddServiceToAllUsersGroup(splitPath[0])
if err != nil {
return fmt.Errorf("error adding service %s to all users group: %v", splitPath[0], err)
}
} else {
err = minIOAdminClient.CreateServiceGroup(splitPath[0])
if err != nil {
return fmt.Errorf("error creating service group for bucket %s: %v", splitPath[0], err)
}

err = minIOAdminClient.UpdateUsersInGroup(allowed_users, splitPath[0], false)
if err != nil {
return err
}
}
}
}
// Create folder(s)
if len(splitPath) == 2 {
// Add "/" to the end of the key in order to create a folder
Expand Down
8 changes: 8 additions & 0 deletions pkg/handlers/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ func MakeDeleteHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand
minIOAdminClient.UpdateUsersInGroup(users, bucket[0], true)
}

if service.Mount.Path != "" {
path := strings.Trim(service.Mount.Path, " /")
// Split buckets and folders from path
bucket := strings.SplitN(path, "/", 2)
var users []string
minIOAdminClient.UpdateUsersInGroup(users, bucket[0], true)
}

// Disable input notifications
if err := disableInputNotifications(service.GetMinIOWebhookARN(), service.Input, service.StorageProviders.MinIO[types.DefaultProvider]); err != nil {
log.Printf("Error disabling MinIO input notifications for service \"%s\": %v\n", service.Name, err)
Expand Down
10 changes: 2 additions & 8 deletions pkg/types/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
autos "k8s.io/api/autoscaling/v1"
v1 "k8s.io/api/core/v1"
net "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
Expand All @@ -53,7 +52,7 @@ An exposed service can be of to types:

// CreateExpose creates all the kubernetes components
func CreateExpose(service Service, kubeClientset kubernetes.Interface, cfg *Config) error {
ExposeLogger.Printf("Creating exposed service: \n%v\n", service)
//ExposeLogger.Printf("Creating exposed service: \n%v\n", service)
err := createDeployment(service, kubeClientset, cfg)
if err != nil {
return fmt.Errorf("error creating deployment for exposed service '%s': %v", service.Name, err)
Expand Down Expand Up @@ -254,11 +253,6 @@ func getPodTemplateSpec(service Service, cfg *Config) v1.PodTemplateSpec {
ContainerPort: int32(service.Expose.APIPort),
},
}
podSpec.Containers[i].Resources = v1.ResourceRequirements{
Requests: v1.ResourceList{
"cpu": *resource.NewMilliQuantity(500, resource.DecimalSI),
},
}
podSpec.Containers[i].VolumeMounts[0].ReadOnly = false
if service.Expose.DefaultCommand {
podSpec.Containers[i].Command = nil
Expand Down Expand Up @@ -516,7 +510,7 @@ func getIngressSpec(service Service, kubeClientset kubernetes.Interface, cfg *Co
}
annotation := map[string]string{
"nginx.ingress.kubernetes.io/rewrite-target": rewriteOption,
"kubernetes.io/ingress.class": "nginx",
"spec.ingressClassName": "nginx",
"nginx.ingress.kubernetes.io/use-regex": "true",
}
if service.Expose.SetAuth {
Expand Down
1 change: 1 addition & 0 deletions pkg/types/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ done`
ephemeralVolumeMount = "/tmpfolder"
)

// SetMount Creates the sidecar container that mounts the source volume onto the pod volume
func SetMount(podSpec *v1.PodSpec, service Service, cfg *Config) {
podSpec.Containers = append(podSpec.Containers, sidecarPodSpec(service))
termination := int64(5)
Expand Down
2 changes: 1 addition & 1 deletion ui

0 comments on commit 53a298a

Please sign in to comment.