Skip to content

K8SPG-1083 improve platform detection to reduce unknown telemetry values#1655

Open
hors wants to merge 7 commits into
mainfrom
detect-more-platforms
Open

K8SPG-1083 improve platform detection to reduce unknown telemetry values#1655
hors wants to merge 7 commits into
mainfrom
detect-more-platforms

Conversation

@hors

@hors hors commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Replace CRD-based detection (which relied on optional addons being installed) with discovery API group checks and API server URL patterns.

Add detection for AKS, DOKS, OKE, ACK, NKP, Platform9, Tanzu, and Rancher alongside the existing GKE, EKS, and OpenShift detections.

CHANGE DESCRIPTION

Problem:
Short explanation of the problem.

Cause:
Short explanation of the root cause of the issue if applicable.

Solution:
Short explanation of the solution we are providing with this PR.

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported PG version?
  • Does the change support oldest and newest supported Kubernetes version?

Replace CRD-based detection (which relied on optional addons being
installed) with discovery API group checks and API server URL patterns.

Add detection for AKS, DOKS, OKE, ACK, NKP, Platform9, Tanzu, and
Rancher alongside the existing GKE, EKS, and OpenShift detections.
Copilot AI review requested due to automatic review settings June 26, 2026 11:00

Copilot AI 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.

Pull request overview

This PR updates the operator’s platform/managed-Kubernetes detection used for telemetry, moving away from CRD-based heuristics toward API discovery group checks and API server host pattern checks to reduce “unknown” platform values.

Changes:

  • Added a hasAPIGroup helper that detects platforms by checking for the presence of API groups via the discovery API.
  • Updated existing platform detection (notably GKE/EKS) to use API groups and API server host patterns rather than optional addon CRDs.
  • Added detection and telemetry labels for AKS, DOKS, OKE, ACK, NKP, Platform9, Tanzu, and Rancher.

Comment on lines +361 to +370
// hasAPIGroup returns true if the cluster exposes the given API group name.
// Uses the discovery API which is available to all authenticated users with no extra RBAC.
func hasAPIGroup(ctx context.Context, cfg *rest.Config, groupName string) bool {
client, err := discovery.NewDiscoveryClientForConfig(cfg)
assertNoError(err)

if err != nil {
return false
}
groups, err := client.ServerGroups()
if err != nil {
assertNoError(err)
return false
Comment thread cmd/postgres-operator/main.go Outdated
Comment on lines +389 to +396
func isEKS(ctx context.Context, cfg *rest.Config) bool {
log := logging.FromContext(ctx)
// EKS API server hostnames always end with .eks.amazonaws.com.
if strings.Contains(cfg.Host, ".eks.amazonaws.com") {
logging.FromContext(ctx).Info("detected EKS environment")
return true
}
return false
}
Comment thread cmd/postgres-operator/main.go Outdated
Comment on lines +470 to +493
case isTanzu(ctx, cfg):
return "tanzu"
case isRancher(ctx, cfg):
return "rancher"
Copilot AI review requested due to automatic review settings June 26, 2026 13:53
@hors hors force-pushed the detect-more-platforms branch from 44406c3 to 6cbdb1e Compare June 26, 2026 13:53

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread cmd/postgres-operator/main.go Outdated
Comment on lines 365 to +369
client, err := discovery.NewDiscoveryClientForConfig(cfg)
assertNoError(err)

if err != nil {
log.V(1).Info("platform detection: could not create discovery client", "error", err.Error())
return false
}
Comment thread cmd/postgres-operator/main.go
Comment thread cmd/postgres-operator/main.go Outdated
Comment on lines +428 to +435
func isACK(ctx context.Context, cfg *rest.Config) bool {
// ACK API server hostnames always end with .aliyuncs.com.
if strings.Contains(cfg.Host, ".aliyuncs.com") {
logging.FromContext(ctx).Info("detected ACK environment")
return true
}
return false
}

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.

I'm hesitating a little to add these without ensuring that the API group method works for them

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have tested ACK and updated the code

Comment thread cmd/postgres-operator/main.go Outdated
Comment on lines +481 to +496
case isAKS(ctx, cfg):
return "aks"
case isDOKS(ctx, cfg):
return "doks"
case isOKE(ctx, cfg):
return "oke"
case isACK(ctx, cfg):
return "ack"
case isNKP(ctx, cfg):
return "nkp"
case isPlatform9(ctx, cfg):
return "platform9"
case isTanzu(ctx, cfg):
return "tanzu"
case isRancher(ctx, cfg):
return "rancher"

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.

Maybe we can also avoid this repetition here cause every time we will have to add a function and a call here. We could have a generic logic for calling the hasAPIGroup(ctx, ...) and then iterate on the platforms that can be defined like this:

var platformProbes = []platformProbe{
	{name: "gke", label: "GKE", apiGroups: []string{"networking.gke.io"}},
	{name: "eks", label: "EKS", apiGroups: []string{"crd.k8s.amazonaws.com"}},
	{name: "aks", label: "AKS", hosts: []string{".azmk8s.io"}},....

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@hors hors force-pushed the detect-more-platforms branch from 6cbdb1e to ef39113 Compare June 29, 2026 10:14
@hors hors changed the title Improve platform detection to reduce unknown telemetry values K8SPG-1083 improve platform detection to reduce unknown telemetry values Jul 8, 2026
@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
backup-enable-disable passed 00:00:00
builtin-extensions passed 00:00:00
cert-manager-tls passed 00:00:00
custom-envs passed 00:00:00
custom-tls passed 00:00:00
database-init-sql passed 00:00:00
demand-backup passed 00:00:00
demand-backup-offline-snapshot passed 00:00:00
dynamic-configuration passed 00:00:00
finalizers passed 00:00:00
init-deploy passed 00:00:00
huge-pages passed 00:00:00
major-upgrade-14-to-15 passed 00:00:00
major-upgrade-15-to-16 passed 00:00:00
major-upgrade-16-to-17 passed 00:00:00
major-upgrade-17-to-18 passed 00:00:00
ldap passed 00:00:00
ldap-tls passed 00:00:00
monitoring passed 00:00:00
monitoring-pmm3 passed 00:00:00
one-pod passed 00:00:00
operator-self-healing passed 00:11:06
pitr passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:28:02
self-healing passed 00:00:00
sidecars passed 00:00:00
standby-pgbackrest passed 00:00:00
standby-streaming passed 00:00:00
start-from-backup passed 00:00:00
tablespaces passed 00:00:00
telemetry-transfer passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-minor passed 00:08:29
users passed 00:00:00
Summary Value
Tests Run 35/35
Job Duration 00:44:26
Total Test Time 00:47:38

commit: 610fbfe
image: perconalab/percona-postgresql-operator:PR-1655-610fbfe47

@hors hors marked this pull request as ready for review July 9, 2026 15:52
@hors hors requested review from Copilot and gkech July 9, 2026 15:52

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment on lines 373 to 377
groups, err := client.ServerGroups()
if err != nil {
assertNoError(err)
log.V(1).Info("platform detection: could not list API groups", "error", err.Error())
return false
}
if err != nil {
assertNoError(err)
if hasAPIGroup(ctx, cfg, "security.openshift.io") {
logging.FromContext(ctx).Info("detected Openshift environment")
Comment on lines +456 to +461
for _, probe := range platformProbes {
if probe.detect(ctx, cfg) {
logging.FromContext(ctx).Info("detected " + probe.label + " environment")
return probe.name
}
}
Comment on lines +433 to +435
host := strings.TrimPrefix(cfg.Host, "https://")
host = strings.TrimPrefix(host, "http://")
netConn, err := (&tls.Dialer{Config: tlsCfg}).DialContext(ctx, "tcp", host)
func detectPlatform(ctx context.Context, cfg *rest.Config) string {
switch {
case isOpenshift(ctx, cfg):
func detectPlatform(ctx context.Context, cfg *rest.Config, openShift bool) string {

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.

why don't we detect openshift in this function as well and use the return value in IsOpenshift?

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