adm/frostfsid: Add 'set-kv' #1634
No reviewers
Labels
No labels
P0
P1
P2
P3
badger
frostfs-adm
frostfs-cli
frostfs-ir
frostfs-lens
frostfs-node
good first issue
triage
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-node#1634
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "achuprov/frostfs-node:feat/frostfs_adm_add_set-kv"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add:
Signed-off-by: Alexander Chuprov a.chuprov@yadro.com
@ -403,6 +433,48 @@ func frostfsidRemoveSubjectFromGroup(cmd *cobra.Command, _ []string) {
commonCmd.ExitOnErr(cmd, "remove subject from group error: %w", err)
}
const disable = "disable"
You don't need to introduce the constant. You've already got
disableFlag
. So, feel free to use it incmd.Flags().GetBool(disable)
:)Thanks, fixed
@ -406,0 +465,4 @@
commonCmd.ExitOnErr(cmd, "init contract client: %w", err)
method, args := ffsid.roCli.SetSubjectKVCall(subjectAddress, key, value)
if ok, _ := cmd.Flags().GetBool(disable); ok {
I can't figure out what is going on in this part. Why do you set a key to subject's KV storage and then remove it if
disable
flag is set? I checked the contract's method anddeleteSubjectKV
literally means deletion but not disabling.So, we need to make
frostfsidSetKV
free from deletion and introducefrostfsidDeleteKV
and not usedisable
.frostfsidSetKV
is responsible for setting but not "disabling" (when it deletes in fact) :)IMHO, by default, the
FrostFS ID KV
storage does not contain any options. When we add a key, these options are enabled. This means that deleting an option disables it.There are no "options" that are enabled or disabled, there are keys and values, which (according to contract) we can
set
anddelete
.626a7ae344
todbc2495589
@ -406,0 +447,4 @@
key, _ := cmd.Flags().GetString(keyFlag)
value, _ := cmd.Flags().GetString(valueFlag)
for wellKnownKey, flagInfo := range wellKnownFlags {
Please, let's have 2 separate commands:
set-kv
anddelete-kv
.The
--disable
flag has a wrong name and thisfor
loop should not be executed if we want to delete kv.done
@ -406,0 +448,4 @@
value, _ := cmd.Flags().GetString(valueFlag)
for wellKnownKey, flagInfo := range wellKnownFlags {
if ok, _ := cmd.Flags().GetBool(wellKnownKey); ok {
This logic should be reverted: we have key and we should check whether it is well-known.
You iterate over all well-known keys and check whether a key is present.
Another problem is that you silently ignore previous key value, the flags should be marked as mutually exclusive.
fixed
adm/frostfsid: Add 'set-kv'to WIP: adm/frostfsid: Add 'set-kv'dbc2495589
toa94f6e2711
@ -0,0 +7,4 @@
"github.com/spf13/pflag"
)
func AutoCompleteFlags(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
@fyrchik What do you think about creating a task to add
AutoCompleteFlags
to all cmd commands?I think it provides little value but significantly increases mental overhead when reading the code.
Ok, deleted
AutoCompleteFlags
.a94f6e2711
to8528ddb16d
WIP: adm/frostfsid: Add 'set-kv'to adm/frostfsid: Add 'set-kv'@ -406,0 +481,4 @@
}
if key == "" {
commonCmd.ExitOnErr(cmd, "", errors.New("key can't be empty"))
Let's avoid using
can't
andfailed
in error messages. I used to use them too but actually that's unnecessary.I'd consider just
empty key
. Andfailed to set
->set key: %w
,failed to delete
->delete key: %w
fixed
@ -239,0 +267,4 @@
frostfsidSetKVCmd.Flags().String(keyFlag, "", keyDescFlag)
frostfsidSetKVCmd.Flags().String(valueFlag, "", valueDescFlag)
frostfsidSetKVCmd.ValidArgsFunction = commonflags.AutoCompleteFlags
Why do we need this line? Its seems generic and unrelated to the "well-known" keys.
@ -406,0 +474,4 @@
value, _ := cmd.Flags().GetString(valueFlag)
for wellKnownKey, wellKnownValue := range wellKnownFlags {
if key == wellKnownKey && value == "" {
Empty value almost always is an error, because we forgot.
Let's remove this "wellKnownValue" logic.
removed
8528ddb16d
to8d0b741d37
8d0b741d37
to2be7c21568
2be7c21568
tob504078794
b504078794
to076952f4c7