ROX-33584: Migrate cert monitor to controller-runtime#2624
ROX-33584: Migrate cert monitor to controller-runtime#2624
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kovayur The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
internal/certmonitor/certmonitor.go
Outdated
| ) | ||
|
|
||
| // Config represents the certificate monitor configuration | ||
| type Config struct { |
There was a problem hiding this comment.
I see that the Config is still reference by the CertMonitor struct, but is not referenced by any of it's code.
The labelselectors are hardcoded in the constructur for the cache, with no way to influence the cache from an outside package.
We should either remove that config or make the CertMonitor actually use it.
There was a problem hiding this comment.
You are right. I missed that. It's deleted now.
| "time" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| "github.com/stackrox/acs-fleet-manager/fleetshard/pkg/fleetshardmetrics" |
There was a problem hiding this comment.
A lot of test code deleted here. I'm not sure what it was testing exactly, didn't look to deep.
The remaining tests seems to verify package internal methods, but not that the overall CertMonitor is working like expected.
I would expect a test with sample secrets with rhacs.redhat.com/tls=true label and without it, starting the CertMonitor, then verify the metrics for matching labels show up. Then deleting a secrets, verifying it disappears from the metrics.
There was a problem hiding this comment.
Most of the deleted tests were dedicated to the config validation and client side filtering which I removed.
I couldn't find a way to cover server-side filtering with unit tests. Perhaps I could add e2e tests or integration tests with envtest that starts a real etcd + API server, but I believe that would be overkill. Instead, I'd rely on controller-runtime to handle the filtering.
There was a problem hiding this comment.
I'll timebox an integration test implementation with envtest and see how it goes.
There was a problem hiding this comment.
Actually, I though it would be a simple fakeclient test at first, but you're right it isn't straight forward.
I'd also be fine if you'd get the cache options in a extra function and tests that as a unit tests.
So in essence we're testing that we're configuring controller-runtime correctly, and leave the rest to controller-runtime.
Something like:
func certMonitorCacheOptions() ctrlcache.Options {
syncPeriod := syncPeriod
return ctrlcache.Options{
ByObject: map[client.Object]ctrlcache.ByObject{
&corev1.Secret{}: {
Label: labels.SelectorFromSet(labels.Set{
tlsSecretLabel: "true",
}),
},
},
DefaultLabelSelector: labels.Nothing(),
SyncPeriod: &syncPeriod,
}
}
Then test:
func TestCertMonitorCacheOptions(t *testing.T) {
opts := certMonitorCacheOptions()
// Verify label selector matches labeled secrets
selector := opts.ByObject[&corev1.Secret{}].Label
labeled := labels.Set{"rhacs.redhat.com/tls": "true"}
unlabeled := labels.Set{"other": "label"}
assert.True(t, selector.Matches(labeled))
assert.False(t, selector.Matches(unlabeled))
// Verify default selector rejects everything
assert.False(t, opts.DefaultLabelSelector.Matches(labels.Set{}))
}
ae82fc1 to
8ff7fd3
Compare
8ff7fd3 to
3653fdb
Compare
|
@kovayur: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Description
rhacs.redhat.com/tlsto filter only stackrox TLS secretsChecklist (Definition of Done)
Test manualROX-12345: ...Test manual
TODO: Add manual testing efforts