Skip to content

admin/smb: add more flexible generic resource types#1223

Merged
mergify[bot] merged 4 commits into
ceph:masterfrom
phlogistonjohn:jjm-smb-flex
Feb 18, 2026
Merged

admin/smb: add more flexible generic resource types#1223
mergify[bot] merged 4 commits into
ceph:masterfrom
phlogistonjohn:jjm-smb-flex

Conversation

@phlogistonjohn

Copy link
Copy Markdown
Collaborator

The concrete Cluster, Share, etc. types are all nice and useful but with a rapidly evolving smb mgr module are bound to be perpetually out of date. Add a new GenericResource type that is a thin layer over the JSON input/output of the smb mgr module so that bleeding-edge or experimental features can still be manipulated somewhat easily through this go-ceph library.

An example workflow might involve creating concrete Cluster and Share instances and filling in the common fields the usual way, then converting them into generic resources to set experimental branch fields on the Shares via the generic Values map before submitting them to the mgr via the Apply method.

Methods to convert to and from the more concrete types (Cluster, Share, etc) exist specifically to help enable this workflow. New methods to ShowOpts allow requesting that the library return GenericResource instances when querying the mgr.

Thus the generic resource type can be used as a stop-gap or longer any time the go-ceph admin/smb package doesn't support some resource fields that the mgr module does.

Checklist

  • Added tests for features and functional changes
  • Public functions and types are documented
  • Standard formatting is applied to Go code
  • Is this a new API? Added a new file that begins with //go:build ceph_preview
  • Ran make api-update to record new APIs

New or infrequent contributors may want to review the go-ceph Developer's Guide including the section on how we track API Status and the API Stability Plan.

The go-ceph project uses mergify. View the mergify command guide for information on how to interact with mergify. Add a comment with @Mergifyio rebase to rebase your PR when github indicates that the PR is out of date with the base branch.

@phlogistonjohn phlogistonjohn force-pushed the jjm-smb-flex branch 2 times, most recently from 9b0791b to c4cd261 Compare January 26, 2026 12:25
@phlogistonjohn phlogistonjohn added the API This PR includes a change to the public API of a go-ceph package label Jan 26, 2026
Comment thread common/admin/smb/generic.go Outdated
Comment thread common/admin/smb/generic.go Outdated
Comment thread common/admin/smb/generic.go Outdated
Comment thread common/admin/smb/generic.go Outdated
Comment thread common/admin/smb/generic.go Outdated
Comment thread common/admin/smb/generic.go Outdated
Comment thread common/admin/smb/generic.go Outdated
@phlogistonjohn

Copy link
Copy Markdown
Collaborator Author

Well, it looks like I fouled up the changes to the Convert function somehow.

Comment thread common/admin/smb/generic.go Outdated
@phlogistonjohn phlogistonjohn force-pushed the jjm-smb-flex branch 2 times, most recently from b35fdca to 71a62eb Compare February 12, 2026 18:38
When running the Show function to get resources from the server add a
private field that can be used to customize how the unmarshaling is
done. This will be used in a future change to support generic smb
resource types.

Because this new field is private this does not need to be part of
a preview API. Accessor functions that manipulate it in the future will.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
The concrete Cluster, Share, etc. types are all nice and useful but
with a rapidly evolving smb mgr module are bound to be perpetually
out of date. Add a new GenericResource type that is a thin layer
over the JSON input/output of the smb mgr module so that bleeding-edge
or experimental features can still be manipulated somewhat easily
through this go-ceph library.

An example workflow might involve creating concrete Cluster and Share
instances and filling in the common fields the usual way, then
converting them into generic resources to set experimental branch
fields on the Shares via the generic Values map before submitting
them to the mgr via the Apply method.

Methods to convert to and from the more concrete types (Cluster, Share,
etc) exist specifically to help enable this workflow.  New methods to
ShowOpts allow requesting that the library return GenericResourc
instances when querying the mgr.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>

@anoopcs9 anoopcs9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks.

@ansiwen ansiwen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really oversee if certain things are safe or not, so I just left some questions. Otherwise LGTM.

func (t TopIdentityKind) Identity(m map[string]any) ResourceRef {
return ResourceID{
ResourceType: getResourceType(m),
ID: m[t.IDKey].(string),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it guaranteed by business-logic, that this key exists in the map?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't its not a valid resource. The server always produces a resource with an id field of form and if you try to construct a Generic Resource from scratch and don't set up an id it will be invalid. If that means this function panics I am OK with that because it is a programmer error.

)

func getResourceType(m map[string]any) ResourceType {
return ResourceType(m[ResourceTypeKey].(string))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure: collisions with "resrouce_type" are not possible?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can manually mangle "resource_type" but then it won't pass validation.

// Data is stored in the Values map and metadata used to identify the
// resource is provided by the IDKind field.
type GenericResource struct {
Values map[string]any

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this "any"? Is this an external dependency?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not predict that the values in the top-level map are strings, ints, lists of strings, lists of maps of strings, etc.
As long as we can round-trip between JSON we really can work with any type here so I used any which is the newer way to express a map of string to any type.

@ansiwen

ansiwen commented Feb 18, 2026

Copy link
Copy Markdown
Collaborator

Approved, remove the label to merge.

@mergify mergify Bot added the queued label Feb 18, 2026
@mergify mergify Bot merged commit 3101a57 into ceph:master Feb 18, 2026
26 of 28 checks passed
@mergify

mergify Bot commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

Rule: default


  • Entered queue2026-02-18 18:15 UTC
  • Checks passed · in-place
  • Merged2026-02-18 18:15 UTC · at 67b400b82400dd92172c539dec4331921ead8949

This pull request spent 7 seconds in the queue, with no time running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of [🛡 GitHub branch protection]:
    • check-success = test-suite (pacific)
    • check-neutral = test-suite (pacific)
    • check-skipped = test-suite (pacific)
  • any of [🛡 GitHub branch protection]:
    • check-success = test-suite (quincy)
    • check-neutral = test-suite (quincy)
    • check-skipped = test-suite (quincy)
  • any of [🛡 GitHub branch protection]:
    • check-success = test-suite (reef)
    • check-neutral = test-suite (reef)
    • check-skipped = test-suite (reef)
  • any of [🛡 GitHub branch protection]:
    • check-success = test-suite (squid)
    • check-neutral = test-suite (squid)
    • check-skipped = test-suite (squid)

@mergify mergify Bot removed the queued label Feb 18, 2026
@phlogistonjohn phlogistonjohn deleted the jjm-smb-flex branch February 18, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API This PR includes a change to the public API of a go-ceph package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants