diff --git a/container_manager/volume.go b/container_manager/volume.go index eae75f211f..d2b5548995 100644 --- a/container_manager/volume.go +++ b/container_manager/volume.go @@ -47,14 +47,14 @@ func (m Manager) CreateNFSVolume(name string, nfsServer string, nfsPath string, } // CreateCIFSVolume : Create a new CIFS volume, return id of the volume -func (m Manager) CreateCIFSVolume(name string, cifsHost string, cifsShare string, username string, password string, fileMode string, dirMode string) error { +func (m Manager) CreateCIFSVolume(name string, cifsHost string, cifsShare string, username string, password string, fileMode string, dirMode string, uid int, gid int) error { _, err := m.client.VolumeCreate(m.ctx, volume.CreateOptions{ Name: name, Driver: "local", DriverOpts: map[string]string{ "type": "cifs", "device": cifsShare, - "o": fmt.Sprintf("addr=%s,username=%s,password=%s,file_mode=%s,dir_mode=%s", cifsHost, username, password, fileMode, dirMode), + "o": fmt.Sprintf("addr=%s,username=%s,password=%s,file_mode=%s,dir_mode=%s,uid=%d,gid=%d", cifsHost, username, password, fileMode, dirMode, uid, gid), }, }) if err != nil { diff --git a/swiftwave_service/core/pv.operations.go b/swiftwave_service/core/pv.operations.go index 9ae11e4087..b7b9b7608e 100644 --- a/swiftwave_service/core/pv.operations.go +++ b/swiftwave_service/core/pv.operations.go @@ -110,7 +110,7 @@ func (persistentVolume *PersistentVolume) Create(ctx context.Context, db gorm.DB } else if persistentVolume.Type == PersistentVolumeTypeNFS { err = dockerManager.CreateNFSVolume(persistentVolume.Name, persistentVolume.NFSConfig.Host, persistentVolume.NFSConfig.Path, persistentVolume.NFSConfig.Version) } else if persistentVolume.Type == PersistentVolumeTypeCIFS { - err = dockerManager.CreateCIFSVolume(persistentVolume.Name, persistentVolume.CIFSConfig.Host, persistentVolume.CIFSConfig.Share, persistentVolume.CIFSConfig.Username, persistentVolume.CIFSConfig.Password, persistentVolume.CIFSConfig.FileMode, persistentVolume.CIFSConfig.DirMode) + err = dockerManager.CreateCIFSVolume(persistentVolume.Name, persistentVolume.CIFSConfig.Host, persistentVolume.CIFSConfig.Share, persistentVolume.CIFSConfig.Username, persistentVolume.CIFSConfig.Password, persistentVolume.CIFSConfig.FileMode, persistentVolume.CIFSConfig.DirMode, persistentVolume.CIFSConfig.Uid, persistentVolume.CIFSConfig.Gid) } else { transaction.Rollback() return errors.New("invalid persistentVolume type") diff --git a/swiftwave_service/core/types.go b/swiftwave_service/core/types.go index b111c928fc..ea0b0bc9eb 100644 --- a/swiftwave_service/core/types.go +++ b/swiftwave_service/core/types.go @@ -221,6 +221,8 @@ type CIFSConfig struct { Password string `json:"password"` FileMode string `json:"file_mode"` DirMode string `json:"dir_mode"` + Uid int `json:"uid" gorm:"default:0"` + Gid int `json:"gid" gorm:"default:0"` } var RequiredServerDependencies = []string{ diff --git a/swiftwave_service/db/migrations/20240603064438_add_uid_gid_in_cifs_pv.down.sql b/swiftwave_service/db/migrations/20240603064438_add_uid_gid_in_cifs_pv.down.sql new file mode 100644 index 0000000000..534d871f3f --- /dev/null +++ b/swiftwave_service/db/migrations/20240603064438_add_uid_gid_in_cifs_pv.down.sql @@ -0,0 +1,2 @@ +-- reverse: modify "persistent_volumes" table +ALTER TABLE "public"."persistent_volumes" DROP COLUMN "cifs_config_gid", DROP COLUMN "cifs_config_uid"; diff --git a/swiftwave_service/db/migrations/20240603064438_add_uid_gid_in_cifs_pv.up.sql b/swiftwave_service/db/migrations/20240603064438_add_uid_gid_in_cifs_pv.up.sql new file mode 100644 index 0000000000..536dd5c9b9 --- /dev/null +++ b/swiftwave_service/db/migrations/20240603064438_add_uid_gid_in_cifs_pv.up.sql @@ -0,0 +1,2 @@ +-- modify "persistent_volumes" table +ALTER TABLE "public"."persistent_volumes" ADD COLUMN "cifs_config_uid" bigint NULL DEFAULT 0, ADD COLUMN "cifs_config_gid" bigint NULL DEFAULT 0; diff --git a/swiftwave_service/db/migrations/atlas.sum b/swiftwave_service/db/migrations/atlas.sum index 6bba9e1c7b..90e7f2650b 100644 --- a/swiftwave_service/db/migrations/atlas.sum +++ b/swiftwave_service/db/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:uWOZFcgvAkjaJFKBWZ0tpLG7pEJDVeWMzZGbyVkS4lI= +h1:ats7Dhdc37WkTpGvkMFA0GlEzBlFmXB3EBwYk6vd+c8= 20240413191732_init.down.sql h1:HoitObGwuKF/akF4qg3dol2FfNTLCEuf6wHYDuCez8I= 20240413191732_init.up.sql h1:USKdQx/yTz1KJ0+mDwYGhKm3WzX7k+I9+6B6SxImwaE= 20240414051823_server_custom_ssh_port_added.down.sql h1:IC1DFQBQceTPTRdZOo5/WqytH+ZbgcKrQuMCkhArF/0= @@ -21,3 +21,5 @@ h1:uWOZFcgvAkjaJFKBWZ0tpLG7pEJDVeWMzZGbyVkS4lI= 20240520174246_added_cpu_time_in_stats.up.sql h1:8yIHQVQWTbjR6AuLOUGGOivEhGPqTNu9gBu7iSsqReE= 20240602144400_add_application_resource_limit_and_reserve.down.sql h1:byOYWw5WRJjPjBiF72JAu2q1XUMUL0BkWbLPchienF4= 20240602144400_add_application_resource_limit_and_reserve.up.sql h1:Qs5+63C2xrVKbRjDAQ+/Aw0x9JVj7c0Msli1Fv5c48Q= +20240603064438_add_uid_gid_in_cifs_pv.down.sql h1:EVlD++5wMSaSGQA4gPMyZiBaOjVvm/QURa1t4RwdIwQ= +20240603064438_add_uid_gid_in_cifs_pv.up.sql h1:eJqHJ0QQxzz21//f3iU9hvVavHxbPoUrKPGt914/0Ik= diff --git a/swiftwave_service/graphql/generated.go b/swiftwave_service/graphql/generated.go index e955758126..25d7875005 100644 --- a/swiftwave_service/graphql/generated.go +++ b/swiftwave_service/graphql/generated.go @@ -109,9 +109,11 @@ type ComplexityRoot struct { CIFSConfig struct { DirMode func(childComplexity int) int FileMode func(childComplexity int) int + Gid func(childComplexity int) int Host func(childComplexity int) int Password func(childComplexity int) int Share func(childComplexity int) int + UID func(childComplexity int) int Username func(childComplexity int) int } @@ -905,6 +907,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.CIFSConfig.FileMode(childComplexity), true + case "CIFSConfig.gid": + if e.complexity.CIFSConfig.Gid == nil { + break + } + + return e.complexity.CIFSConfig.Gid(childComplexity), true + case "CIFSConfig.host": if e.complexity.CIFSConfig.Host == nil { break @@ -926,6 +935,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.CIFSConfig.Share(childComplexity), true + case "CIFSConfig.uid": + if e.complexity.CIFSConfig.UID == nil { + break + } + + return e.complexity.CIFSConfig.UID(childComplexity), true + case "CIFSConfig.username": if e.complexity.CIFSConfig.Username == nil { break @@ -6771,6 +6787,94 @@ func (ec *executionContext) fieldContext_CIFSConfig_dir_mode(_ context.Context, return fc, nil } +func (ec *executionContext) _CIFSConfig_uid(ctx context.Context, field graphql.CollectedField, obj *model.CIFSConfig) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CIFSConfig_uid(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.UID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CIFSConfig_uid(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CIFSConfig", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CIFSConfig_gid(ctx context.Context, field graphql.CollectedField, obj *model.CIFSConfig) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CIFSConfig_gid(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Gid, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CIFSConfig_gid(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CIFSConfig", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _Dependency_name(ctx context.Context, field graphql.CollectedField, obj *model.Dependency) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Dependency_name(ctx, field) if err != nil { @@ -14112,6 +14216,10 @@ func (ec *executionContext) fieldContext_PersistentVolume_cifsConfig(_ context.C return ec.fieldContext_CIFSConfig_file_mode(ctx, field) case "dir_mode": return ec.fieldContext_CIFSConfig_dir_mode(ctx, field) + case "uid": + return ec.fieldContext_CIFSConfig_uid(ctx, field) + case "gid": + return ec.fieldContext_CIFSConfig_gid(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type CIFSConfig", field.Name) }, @@ -22739,7 +22847,7 @@ func (ec *executionContext) unmarshalInputCIFSConfigInput(ctx context.Context, o asMap[k] = v } - fieldsInOrder := [...]string{"host", "share", "username", "password", "file_mode", "dir_mode"} + fieldsInOrder := [...]string{"host", "share", "username", "password", "file_mode", "dir_mode", "uid", "gid"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -22788,6 +22896,20 @@ func (ec *executionContext) unmarshalInputCIFSConfigInput(ctx context.Context, o return it, err } it.DirMode = data + case "uid": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("uid")) + data, err := ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + it.UID = data + case "gid": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("gid")) + data, err := ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + it.Gid = data } } @@ -24288,6 +24410,16 @@ func (ec *executionContext) _CIFSConfig(ctx context.Context, sel ast.SelectionSe if out.Values[i] == graphql.Null { out.Invalids++ } + case "uid": + out.Values[i] = ec._CIFSConfig_uid(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "gid": + out.Values[i] = ec._CIFSConfig_gid(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } diff --git a/swiftwave_service/graphql/graphql_object_mapper.go b/swiftwave_service/graphql/graphql_object_mapper.go index ede8f9501d..9046944b7b 100644 --- a/swiftwave_service/graphql/graphql_object_mapper.go +++ b/swiftwave_service/graphql/graphql_object_mapper.go @@ -121,6 +121,8 @@ func persistentVolumeToGraphqlObject(record *core.PersistentVolume) *model.Persi Password: record.CIFSConfig.Password, FileMode: record.CIFSConfig.FileMode, DirMode: record.CIFSConfig.DirMode, + UID: record.CIFSConfig.Uid, + Gid: record.CIFSConfig.Gid, }, } } @@ -144,6 +146,8 @@ func persistentVolumeInputToDatabaseObject(record *model.PersistentVolumeInput) Password: record.CifsConfig.Password, FileMode: record.CifsConfig.FileMode, DirMode: record.CifsConfig.DirMode, + Uid: record.CifsConfig.UID, + Gid: record.CifsConfig.Gid, } } return &core.PersistentVolume{ diff --git a/swiftwave_service/graphql/model/models_gen.go b/swiftwave_service/graphql/model/models_gen.go index 4c2b0c5800..607ad98637 100644 --- a/swiftwave_service/graphql/model/models_gen.go +++ b/swiftwave_service/graphql/model/models_gen.go @@ -91,6 +91,8 @@ type CIFSConfig struct { Password string `json:"password"` FileMode string `json:"file_mode"` DirMode string `json:"dir_mode"` + UID int `json:"uid"` + Gid int `json:"gid"` } type CIFSConfigInput struct { @@ -100,6 +102,8 @@ type CIFSConfigInput struct { Password string `json:"password"` FileMode string `json:"file_mode"` DirMode string `json:"dir_mode"` + UID int `json:"uid"` + Gid int `json:"gid"` } type CustomSSLInput struct { diff --git a/swiftwave_service/graphql/schema/cifs_config.graphqls b/swiftwave_service/graphql/schema/cifs_config.graphqls index a365939c0e..6f774132e6 100644 --- a/swiftwave_service/graphql/schema/cifs_config.graphqls +++ b/swiftwave_service/graphql/schema/cifs_config.graphqls @@ -5,6 +5,8 @@ type CIFSConfig { password: String! file_mode: String! dir_mode: String! + uid: Int! + gid: Int! } input CIFSConfigInput { @@ -14,4 +16,6 @@ input CIFSConfigInput { password: String! file_mode: String! dir_mode: String! + uid: Int! + gid: Int! } \ No newline at end of file diff --git a/swiftwave_service/worker/process_setup_server_request.go b/swiftwave_service/worker/process_setup_server_request.go index 10ac9eed47..4c9f1936e9 100644 --- a/swiftwave_service/worker/process_setup_server_request.go +++ b/swiftwave_service/worker/process_setup_server_request.go @@ -245,7 +245,7 @@ func (m Manager) setupServerHelper(request SetupServerRequest, ctx context.Conte } else if persistentVolume.Type == core.PersistentVolumeTypeNFS { err = dockerClient.CreateNFSVolume(persistentVolume.Name, persistentVolume.NFSConfig.Host, persistentVolume.NFSConfig.Path, persistentVolume.NFSConfig.Version) } else if persistentVolume.Type == core.PersistentVolumeTypeCIFS { - err = dockerClient.CreateCIFSVolume(persistentVolume.Name, persistentVolume.CIFSConfig.Host, persistentVolume.CIFSConfig.Share, persistentVolume.CIFSConfig.Username, persistentVolume.CIFSConfig.Password, persistentVolume.CIFSConfig.FileMode, persistentVolume.CIFSConfig.DirMode) + err = dockerClient.CreateCIFSVolume(persistentVolume.Name, persistentVolume.CIFSConfig.Host, persistentVolume.CIFSConfig.Share, persistentVolume.CIFSConfig.Username, persistentVolume.CIFSConfig.Password, persistentVolume.CIFSConfig.FileMode, persistentVolume.CIFSConfig.DirMode, persistentVolume.CIFSConfig.Uid, persistentVolume.CIFSConfig.Gid) } if err != nil { logText += "Failed to add persistent volume " + persistentVolume.Name + "\n"