rpk/registry: add context list and delete commands#29689
Conversation
15ff2c0 to
fe62753
Compare
5d14e30 to
ea25394
Compare
| type contextResponse struct { | ||
| Name string `json:"name" yaml:"name"` | ||
| } | ||
|
|
||
| // ListContexts calls cl.Contexts and translates a 404 into a message | ||
| // indicating that the Redpanda cluster does not support schema contexts. | ||
| func ListContexts(ctx context.Context, cl *sr.Client) ([]string, error) { | ||
| contexts, err := cl.Contexts(ctx) | ||
| if err != nil { | ||
| var re *sr.ResponseError | ||
| if errors.As(err, &re) && re.StatusCode == 404 { | ||
| return nil, fmt.Errorf("schema registry contexts are not supported by this cluster") | ||
| } | ||
| return nil, err | ||
| } | ||
| return contexts, nil | ||
| } |
There was a problem hiding this comment.
[food for thought, not for this PR, but maybe as a follow-up in next releases]
Would be cool to list the context, including the Mode and Compatibility that has been set. There are some other places like subject list, where we could add this as well.
There was a problem hiding this comment.
Its a good suggestion and ive updated it to show mode and compatability for context list, haven't gone deeper than that but something we can look in to
| contexts, err := ListContexts(cmd.Context(), cl.Client) | ||
| out.MaybeDie(err, "%v", err) | ||
|
|
||
| if !slices.Contains(contexts, name) { | ||
| out.Die("context %q not found", name) | ||
| } |
There was a problem hiding this comment.
Does Core makes this validation?
| schemaCtx, _ := cmd.Flags().GetString("schema-context") | ||
| skipCheck, _ := cmd.Flags().GetBool("skip-context-check") | ||
| showCtxCol := schemaCtx == "" && srcontext.CheckContextSupport(cmd.Context(), cl.Client, fs, p, skipCheck) == nil |
There was a problem hiding this comment.
What do you think of always displaying the Context column and having it empty when it is not enabled?
There was a problem hiding this comment.
oh right i think that is a bit confusing/gives the wrong impression. can be swayed but dont think its the right think to do
Add utility functions for working with schema registry contexts:
QualifySubject, ContextSubjectPrefix, StripContextQualifier,
ParseSubjectContext, and DisplayContext. These handle the
":{ctx}:{subject}" wire format used by context-qualified subjects.
Add --schema-context persistent flag to rpk registry that qualifies subject names with a context prefix for all SR operations. Existing commands (subject, schema, mode, compatibility-level) transparently use the qualified subject format when --schema-context is set. Add registry/context subpackage with list and delete subcommands, ValidateContext for flag validation, and CheckContextSupport used by list commands to show a CONTEXT column when the cluster supports contexts. The context column is hidden when --schema-context filters to a single context.
d5a6e9f to
15198c4
Compare
Add
rpk registry context listandrpk registry context deletecommandsfor managing schema registry contexts. Also add a
--schema-contextpersistent flag on the
registryparent command so all subcommands(including compatibility-level) can be scoped to a specific context.
Update compatibility-level get/set to use
cmd.Context()instead ofcontext.Background()so the schema context propagates correctly.Includes integration tests using
srfake.Backports Required
Release Notes
Features
rpk registry context listandrpk registry context deletecommands for managing schema registry contexts--schema-contextflag torpk registryto scope all registry operations to a specific contextTest Plan
subject list
--skip-context-checkdefault/.ctx1--schema-context .ctx1--skip-context-check.ctx1, no qualifier, no CONTEXT column--deleted--skip-context-check --schema-context .ctx1:.ctx1:sub-aas-issubject delete
topic-atopic-a, output showstopic-a--schema-context .ctx1--skip-context-checkmy-subject:.ctx1:my-subject, output showsmy-subject:.ctx1:my-subject:.ctx1:my-subject, output shows raw name--permanent --skip-context-check --schema-context .ctx1my-subjectschema list
--skip-context-checkdefault/.ctx1--schema-context .ctx1--skip-context-check.ctx1schemas, no CONTEXT column--skip-context-check --schema-context .ctx1schema list sub-a sub-bshows bothschema list ":.ctx1:sub-a"shows raw nameschema create
--schema file.avromy-subjectmy-subject--schema-context .ctx1--skip-context-check --schema file.avromy-subject:.ctx1:my-subject, output showsmy-subject--schema file.avro:.ctx1:my-subject:.ctx1:my-subjectschema get
--schema-version latesttopic-a--skip-context-check --schema-context .ctx1 --schema-version 1my-subject:.ctx1:my-subject, output showsmy-subject--schema-version 1:.ctx1:my-subject--id 1--skip-context-check --schema-context .ctx1 --id 2.ctx1--skip-context-check --schema-context .ctx1 --id 2my-subject:.ctx1:my-subject--skip-context-check --schema-context .ctx1 --schema file.avromy-subject--print-schema--schema-version 1 --schema-context .ctx1my-subjectschema delete
--schema-version 1topic-a--skip-context-check --schema-context .ctx1 --schema-version 1my-subjectmy-subject--schema-version 1:.ctx1:my-subject--permanent --skip-context-check --schema-context .ctx1 --schema-version 1my-subjectschema references
--schema-version 1topic-a--skip-context-check --schema-context .ctx1 --schema-version 1my-subject--schema-version 1:.ctx1:my-subjectschema check-compatibility
--schema file.avro --schema-version latesttopic-atopic-a--skip-context-check --schema-context .ctx1 --schema file.avro --schema-version latestmy-subject:.ctx1:my-subject--schema file.avro --schema-version latest:.ctx1:my-subjectcompatibility-level get
--skip-context-check --schema-context .ctx1my-subjectmy-subject--skip-context-check --schema-context .ctx1 --globalmy-subject:.ctx1:my-subjectcompatibility-level set
--level BACKWARD--skip-context-check --schema-context .ctx1 --level FULLmy-subjectmy-subject--skip-context-check --schema-context .ctx1 --level FULL --globalmy-subject--level BACKWARD:.ctx1:my-subjectmode get
--skip-context-check --schema-context .ctx1my-subjectmy-subject--skip-context-check --schema-context .ctx1 --globalmy-subject:.ctx1:my-subjectmode set
--mode READONLY--skip-context-check --schema-context .ctx1 --mode READWRITEmy-subject:.ctx1:my-subject--mode READONLY:.ctx1:my-subjectmode reset
topic-a--skip-context-check --schema-context .ctx1my-subject:.ctx1:my-subject, output showsmy-subject:.ctx1:my-subjectcontext list
.,.ctx1,.ctx2.(default only)--format json[{"name":"."},{"name":".ctx1"}]context delete
--no-confirm.ctx1--no-confirm.nope--no-confirmbadnameValidation / Edge Cases
--schema-contextwithout dot--schema-context nope--schema-contextwith colon--schema-context ".a:b"--schema-context .ctx1(admin returns false)--schema-context .ctx1(no admin)--skip-context-checkbypasses admin--schema-context .ctx1 --skip-context-check