-
Notifications
You must be signed in to change notification settings - Fork 531
fix/target-allocator: check CRDs availability in the cluster #4118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a changelog, fix the lint and add a test. Thanks!
for _, group := range apiGroups { | ||
if group.Name == "monitoring.coreos.com" { | ||
for _, version := range group.Versions { | ||
resources, err := dcl.ServerResourcesForGroupVersion(version.GroupVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we'll need to update the TA's permissions in order for this to work https://github.com/open-telemetry/opentelemetry-operator/blob/main/apis/v1beta1/targetallocator_rbac.go#L18
serviceMonitorAvailable, err := checkCRDAvailability(dcl, "servicemonitors") | ||
if err != nil { | ||
return nil, err | ||
logger.Warn("Failed to check ServiceMonitor availability", "error", err) | ||
} else if serviceMonitorAvailable { | ||
serviceMonitorInformers, err2 := informers.NewInformersForResource(factory, monitoringv1.SchemeGroupVersion.WithResource(monitoringv1.ServiceMonitorName)) | ||
if err2 != nil { | ||
return nil, err2 | ||
} | ||
informersMap[monitoringv1.ServiceMonitorName] = serviceMonitorInformers | ||
} else { | ||
logger.Warn("ServiceMonitor CRD not available, skipping informer") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this a helper method? I also wonder if we should just return a no-op informer which may simplify where we actually get the instances below. What do you think?
@@ -1303,3 +1304,38 @@ func sanitizeScrapeConfigsForTest(scs []*promconfig.ScrapeConfig) { | |||
sc.MetricRelabelConfigs = nil | |||
} | |||
} | |||
|
|||
// getTestInformers creates informers for testing without CRD availability checks. | |||
func getTestInformers(factory informers.FactoriesForNamespaces) (map[string]*informers.ForResource, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add new tests in here as well as in e2e to verify this works as expected?
Description:
target-allocator: check CRDs availability in the cluster before querying them in order to prevent an unhandled error
Link to tracking Issue(s):
Testing:
tested on local k8s cluster to ensure the error is gone