Skip to content

Commit

Permalink
fix: update UpdateGroupData method to support creating group data if …
Browse files Browse the repository at this point in the history
…it doesn't exist
  • Loading branch information
alexlovelltroy committed Dec 19, 2024
1 parent e519ed2 commit a097b29
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/cloud-init-server/group_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (h CiHandler) UpdateGroupHandler(w http.ResponseWriter, r *http.Request) {
}

// update group key-value data
err = h.store.UpdateGroupData(groupName, data)
err = h.store.UpdateGroupData(groupName, data, true)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
6 changes: 5 additions & 1 deletion internal/memstore/ciMemStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ func (m *MemStore) GetGroupData(groupName string) (cistore.GroupData, error) {
}

// UpdateGroupData is similar to AddGroupData but only works if the group exists
func (m *MemStore) UpdateGroupData(groupName string, groupData cistore.GroupData) error {
func (m *MemStore) UpdateGroupData(groupName string, groupData cistore.GroupData, create bool) error {
m.GroupsMutex.RLock()
defer m.GroupsMutex.RUnlock()
if create {
m.Groups[groupName] = groupData
return nil
}

_, ok := m.Groups[groupName]
if ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cistore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Store interface {
GetGroups() map[string]GroupData
AddGroupData(groupName string, groupData GroupData) error
GetGroupData(groupName string) (GroupData, error)
UpdateGroupData(groupName string, groupData GroupData) error
UpdateGroupData(groupName string, groupData GroupData, create bool) error
RemoveGroupData(groupName string) error
// Extended Instance Information API
GetInstanceInfo(nodeName string) (OpenCHAMIInstanceInfo, error)
Expand Down

0 comments on commit a097b29

Please sign in to comment.