Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cazorla19
Copy link

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

@cazorla19 cazorla19 requested a review from a team as a code owner June 18, 2025 14:19
Copy link

linux-foundation-easycla bot commented Jun 18, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Contributor

@iblancasa iblancasa left a 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)
Copy link
Contributor

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

Comment on lines +232 to 243
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")
}
Copy link
Contributor

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) {
Copy link
Contributor

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?

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.

target-allocator doesn't check if CRDs exist before querying them
3 participants