Repository navigation
feat(crdmanager): create ServiceMonitor and PodMonitor CRDs when missing - #435
Conversation
|
Blocking: add envtest coverage for the ownership check ( The unit tests use the fake client and hand-build The repo already runs envtest from
|
|
A client-side Please also return false when the CRD has the annotation |
|
Non-blocking: drop The chart runs a single operator replica, so this feature doesn't need leader election, and nothing passes the flag. Please remove The package doc also says "Run only in the elected leader", which isn't true as shipped. Suggest: "Safe with more than one operator pod (for example during a rolling upgrade): only a missing CRD is created, and AlreadyExists counts as success." |
589d3de to
6021cb0
Compare
Added an envtest suite in
Each failing case is reconciled 3 times, with zero writes and exactly one |
Done: |
Removed |
db22a08 to
6a22ec0
Compare
Adds an opt-in controller that creates the monitoring.coreos.com/v1 ServiceMonitor and PodMonitor CRDs when they do not exist, so SM/PM scraping works without a manual CRD install. - Add pkg/crdmanager with the prometheus-operator v0.92.0 CRDs embedded, matching the client version in go.mod - Create a missing CRD with field manager amazon-cloudwatch-agent-operator, label cloudwatch.aws.amazon.com/crd-managed-by and annotations crd-applied-version and crd-applied-generation - Never update, patch or delete an existing CRD; evaluate an ownership check and log plus emit an Event once when the CRD is not the operator's - Treat a CRD as not the operator's when it carries another tool's markers (kubectl.kubernetes.io/last-applied-configuration, meta.helm.sh/release-name, app.kubernetes.io/managed-by) - Recreate a managed CRD after it is deleted, and treat AlreadyExists on create as success, so concurrent operator pods are safe - Watch CRD metadata only, filtered to the two names, and enqueue both names at start - Add --manage-prometheus-crds (default false) - Add RBAC for customresourcedefinitions get, list, watch and create, and regenerate config/rbac/role.yaml - Add unit tests and an envtest suite that runs the ownership check against a real API server
6a22ec0 to
5707da1
Compare
AshuSrv
left a comment
There was a problem hiding this comment.
Let's fix the tests if they are flaky.
Adds an opt-in controller (
--manage-prometheus-crds, off by default) that creates themonitoring.coreos.com/v1ServiceMonitor and PodMonitor CRDs when they don't exist, so SM/PM scraping works with no manual CRD install.go.mod. A unit test fails if they drift apart.amazon-cloudwatch-agent-operator, labelcloudwatch.aws.amazon.com/crd-managed-by, and annotationscrd-applied-versionandcrd-applied-generation. Sets no owner reference.kubectl.kubernetes.io/last-applied-configuration,meta.helm.sh/release-nameorapp.kubernetes.io/managed-by. A client-sidekubectl applyor Helm--take-ownershipwith identical content changes no spec field and no generation, so only these markers show it.customresourcedefinitionsget,list,watchandcreate, with noupdate,patchordelete.Testing
Unit tests for the ownership check, create path, step-back and version pinning, and an envtest suite that runs the reconciler and the ownership check against a real API server (
pkg/crdmanager/envtest_test.go):generation1,amazon-cloudwatch-agent-operatoris the onlyspecfield manager, ownership check passesgenerationunchanged, ownership check passesgeneration2, ownership check failsoperator.prometheus.io/versionchangeslast-applied-configuration)generationunchanged, no extraspecmanager, ownership check fails on the markerresourceVersionunchanged, exactly onePrometheusCRDNotManagedEventWith the marker check disabled, the client-side apply and Helm cases fail.
golangci-lintis clean.On EKS 1.35 with aws-observability/helm-charts#406:
helm uninstall.Related: aws-observability/helm-charts#406, aws/amazon-cloudwatch-agent-test#773
Merge order
--manage-prometheus-crdswhenotelPrometheusMonitor.enabledis true. That switch is off by default, so Updated Release Notes for 3.7.0 #406 can merge before this releases. Turning scraping on requires an operator image that includes this PR; older images reject the unknown flag at startup.PR Checklist
makepasses locally (build, unit tests, lint) -make teststops atgenerate→crdocbecausefybrik.iois unreachable from my network. I ran the target's remaining steps directly:make fmt vet envtestpasses, with no changes to files in this PR.go teston the target's package list, with envtest 1.33, passes 32/32 packages, including the newpkg/crdmanager.mainpasses 31/31 on the same machine.golangci-lintreports 0 issues.make manifestsregenerates only the newcustomresourcedefinitionsrule inconfig/rbac/role.yaml.PR BuildandOperator Integration Testare waiting for a maintainer to approve workflow runs from a fork.TestServiceMonitorPodMonitorCRDsCreatedByOperator,TestOperatorManagesPrometheusCRDs).pkg/crdmanager/reconciler_test.go(unit) andpkg/crdmanager/envtest_test.go(real API server).--manage-prometheus-crdsis set; the new flag defaults tofalse. The manager ClusterRole inconfig/rbac/role.yamlgains cluster-widecreateoncustomresourcedefinitions(plusget,list,watch). Kubernetes cannot limitcreateto specific names, so this needs security review.