Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxd: Update logic for project config patch #13786

Merged
merged 2 commits into from
Jul 22, 2024
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
16 changes: 8 additions & 8 deletions lxd/api_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,14 @@ func projectPatch(d *Daemon, r *http.Request) response.Response {
req.Description = project.Description
}

config, err := reqRaw.GetMap("config")
if err != nil {
req.Config = project.Config
} else {
for k, v := range project.Config {
_, ok := config[k]
if !ok {
config[k] = v
// Perform config patch
req.Config = util.CopyConfig(project.Config)
patches, err := reqRaw.GetMap("config")
if err == nil {
for k, v := range patches {
strVal, ok := v.(string)
if ok {
req.Config[k] = strVal
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/suites/projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ test_projects_crud() {
lxc project show foo | grep -q 'features.images: "true"'
lxc project get foo "features.profiles" | grep -q 'true'

# Set a limit
lxc project set foo limits.containers 10
lxc project show foo | grep -q 'limits.containers: "10"'

# Trying to create a project with the same name fails
! lxc project create foo || false

Expand All @@ -37,6 +41,13 @@ test_projects_crud() {
lxc project show bar| sed 's/^description:.*/description: "Bar project"/' | lxc project edit bar
lxc project show bar | grep -q "description: Bar project"

# Edit the project config via PATCH. Existing key/value pairs should remain or be updated.
lxc query -X PATCH -d '{\"config\" : {\"limits.memory\":\"5GiB\",\"features.images\":\"false\"}}' /1.0/projects/bar
lxc project show bar | grep -q 'limits.memory: 5GiB'
lxc project show bar | grep -q 'features.images: "false"'
lxc project show bar | grep -q 'features.profiles: "true"'
lxc project show bar | grep -q 'limits.containers: "10"'

# Create a second project
lxc project create foo

Expand Down
Loading