Skip to content

util: cache the controller publish secret - #5497

Merged
mergify[bot] merged 1 commit into
ceph:develfrom
black-dragon74:cache-ctrl-pub-secret
Sep 15, 2025
Merged

mergify[bot] merged 1 commit into
ceph:develfrom
black-dragon74:cache-ctrl-pub-secret

Conversation

@black-dragon74

Copy link
Copy Markdown
Member

Describe what this PR does

This patch introduces a caching mechanism based on the shared informers for ControllerPublish secrets.

Is there anything that requires special attention

Do you have any questions?

  • Should we watch for all namespaces?
  • Is the default cache re-sync interval of 10 minutes ideal?

Comment thread internal/util/k8s/secrets.go Outdated

@Rakshith-R Rakshith-R left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just a small nit,
please open the pr for review

Comment thread internal/util/k8s/secrets.go Outdated
@black-dragon74
black-dragon74 marked this pull request as ready for review September 3, 2025 14:33
@Rakshith-R
Rakshith-R requested a review from nixpanic September 3, 2025 14:54
@black-dragon74
black-dragon74 force-pushed the cache-ctrl-pub-secret branch 2 times, most recently from c9aa5ae to c1d7017 Compare September 4, 2025 09:43
Comment thread internal/util/k8s/secrets.go Outdated
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/tools/cache"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

controller-runtime is very large, I don't think you need it here.

The signals package is only used for this:

			<-signals.SetupSignalHandler().Done()

I think you can just write an empty struct to the channel too?

<-struct{}{}

Or, consider replacing stopCh chan struct{} by stopCh chan bool and write <-true or something to it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The idea was to avoid leaking the unclosed channel. Handled it via signal.Notify.

"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

type cachedSecret struct {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why introduce this type, and not use the Kubernetes Secret type?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To avoid iterating, casting and copying secret.Data

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess nothing uses secret.StringData, but only the base64 encoded values?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

map[string][]byte vs map[string]string. While storing in cache we iterate over the bytes and cast them to string. Storing them like that is more convenient as the code elsewhere expects a map[string]string

Comment thread internal/util/k8s/secrets.go Outdated
Comment thread internal/util/k8s/secrets.go Outdated
Comment thread internal/util/k8s/secrets.go Outdated
@nixpanic

nixpanic commented Sep 4, 2025

Copy link
Copy Markdown
Member

Do you have any questions?

* Should we watch for all namespaces?

Only the namespaces+secrets that are requested. There will be many Secrets in a Kubernetes cluster, we definitely should not cache all of them. Even all Secrets in the namespace where Ceph-CSI is deployed may be way too much. We also don't want auditing to fire alarms when Ceph-CSI is caching secrets it would not use.

* Is the default cache re-sync interval of 10 minutes ideal?

A non-changeable default is never ideal. For some users it will be fine, others may want/need to tune it. Ideally there is an option to adjust the behavior.

Comment thread internal/util/k8s/secrets.go Outdated

@nixpanic nixpanic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, just a few nits that should be corrected. The OOP change would be nice, but isn't absolutely required.

"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

type cachedSecret struct {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess nothing uses secret.StringData, but only the base64 encoded values?

Comment thread internal/util/k8s/secrets.go Outdated
Comment thread internal/util/k8s/secrets.go Outdated
Comment thread internal/util/k8s/secrets.go

@nixpanic nixpanic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Just waiting for a response on the outstanding questions/comments.

Comment thread internal/util/k8s/secrets.go Outdated
input := fmt.Sprintf("%s/%s", ns, name)
h := sha256.Sum256([]byte(input))

// Only use 16bytes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand that the code only uses 16 bytes. The comment should better explain why only 16 bytes should be used. Is there no issue with potential abbreviated-hash-collisions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a comment. For a cache key, 128bits is collision is improbable until order of 10^9 entries. We'd be good with more than a billion entries.

}

// secretCache is a thread safe cache for secrets.
// /!\ The `cache` must be read/modified with the lock held.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just wondering why you decided to use sync.RWMutex and not sync.Map. Can you explain that a little?

@black-dragon74 black-dragon74 Sep 11, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sync.Map is not strongly typed and would require type casting.

@Rakshith-R Rakshith-R left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks !

@Rakshith-R

Copy link
Copy Markdown
Contributor

@Mergifyio rebase

This patch introduces a caching mechanism based on the
shared informers for ControllerPublish secrets.

Signed-off-by: Niraj Yadav <[email protected]>
@mergify

mergify Bot commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

rebase

✅ Branch has been successfully rebased

@iPraveenParihar iPraveenParihar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@iPraveenParihar

Copy link
Copy Markdown
Contributor

/test ci/centos/mini-e2e/k8s-1.33

@iPraveenParihar

Copy link
Copy Markdown
Contributor

@Mergifyio rebase

@mergify

mergify Bot commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

rebase

☑️ Nothing to do, the required conditions are not met

Details
  • any of:
    • #commits > 1 [📌 rebase requirement]
    • #commits-behind > 0 [📌 rebase requirement]
    • -linear-history [📌 rebase requirement]
  • -closed [📌 rebase requirement]
  • -conflict [📌 rebase requirement]
  • queue-position = -1 [📌 rebase requirement]

@iPraveenParihar

Copy link
Copy Markdown
Contributor

@Mergifyio queue

@mergify

mergify Bot commented Sep 12, 2025 •

Copy link
Copy Markdown
Contributor

queue

🛑 The pull request has been removed from the queue default

Details

The merge conditions cannot be satisfied due to failing checks.

You can take a look at Queue: Embarked in merge queue check runs for more details about the failure.

@mergify

mergify Bot commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

This pull request has been removed from the queue for the following reason: checks failed.

The merge conditions cannot be satisfied due to failing checks:

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@iPraveenParihar

Copy link
Copy Markdown
Contributor

@Mergifyio queue

@mergify

mergify Bot commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

queue

🛑 The pull request has been removed from the queue default

Details

The merge conditions cannot be satisfied due to failing checks.

You can take a look at Queue: Embarked in merge queue check runs for more details about the failure.

@iPraveenParihar iPraveenParihar added the ok-to-test Label to trigger E2E tests label Sep 12, 2025
@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.32

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-cephfs

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.31

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.32

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/upgrade-tests-rbd

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.31

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.32

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.33

@ceph-csi-bot

Copy link
Copy Markdown
Collaborator

/test ci/centos/mini-e2e/k8s-1.31

@ceph-csi-bot ceph-csi-bot removed the ok-to-test Label to trigger E2E tests label Sep 12, 2025
@iPraveenParihar

Copy link
Copy Markdown
Contributor

https://github.com/Mergifyio queue

@mergify

mergify Bot commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

queue

🛑 The pull request has been removed from the queue default

Details

The merge conditions cannot be satisfied due to failing checks.

You can take a look at Queue: Embarked in merge queue check runs for more details about the failure.

@iPraveenParihar

Copy link
Copy Markdown
Contributor

@Mergifyio refresh

@mergify

mergify Bot commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

refresh

✅ Pull request refreshed

@mergify
mergify Bot merged commit 8c80d56 into ceph:devel Sep 15, 2025
37 of 38 checks passed
black-dragon74 added a commit to black-dragon74/ceph-csi-operator that referenced this pull request Nov 26, 2025
This patch adds watch and list RBACs to clusterroles for
CephFS and RBD nodeplugin.

This is to comply with the enhancement at: ceph/ceph-csi#5497

Signed-off-by: Niraj Yadav <[email protected]>
black-dragon74 added a commit to black-dragon74/ceph-csi-operator that referenced this pull request Nov 26, 2025
This patch adds watch and list RBACs to clusterroles for
CephFS and RBD nodeplugin.

This is to comply with the enhancement at: ceph/ceph-csi#5497

Signed-off-by: Niraj Yadav <[email protected]>
black-dragon74 added a commit to black-dragon74/ceph-csi-operator that referenced this pull request Nov 27, 2025
This patch adds watch and list RBACs to clusterroles for
CephFS and RBD nodeplugin.

This is to comply with the enhancement at: ceph/ceph-csi#5497

Signed-off-by: Niraj Yadav <[email protected]>
(cherry picked from commit 0308496)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants