Skip to content

Commit

Permalink
feat: added uid, gid in cifs config (#701)
Browse files Browse the repository at this point in the history
(cherry picked from commit 233af09)
  • Loading branch information
tanmoysrt authored and mergify[bot] committed Jun 3, 2024
1 parent fbb560d commit decc215
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 6 deletions.
4 changes: 2 additions & 2 deletions container_manager/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion swiftwave_service/core/pv.operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions swiftwave_service/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- reverse: modify "persistent_volumes" table
ALTER TABLE "public"."persistent_volumes" DROP COLUMN "cifs_config_gid", DROP COLUMN "cifs_config_uid";
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion swiftwave_service/db/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
134 changes: 133 additions & 1 deletion swiftwave_service/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions swiftwave_service/graphql/graphql_object_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand All @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions swiftwave_service/graphql/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions swiftwave_service/graphql/schema/cifs_config.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type CIFSConfig {
password: String!
file_mode: String!
dir_mode: String!
uid: Int!
gid: Int!
}

input CIFSConfigInput {
Expand All @@ -14,4 +16,6 @@ input CIFSConfigInput {
password: String!
file_mode: String!
dir_mode: String!
uid: Int!
gid: Int!
}
2 changes: 1 addition & 1 deletion swiftwave_service/worker/process_setup_server_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit decc215

Please sign in to comment.