Skip to content

Commit

Permalink
feat(telemetry) collect OpenShift version (#4211)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainest committed Jun 30, 2023
1 parent 263b35b commit 4f933ab
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Adding a new version? You'll need three changes:
if a configuration error prevents the controller from sending the latest
configuration.
[#4205](https://github.com/Kong/kubernetes-ingress-controller/pull/4205)
- Telemetry reports now include the OpenShift version, if any.
[#4211](https://github.com/Kong/kubernetes-ingress-controller/pull/4211)

### Changed

Expand Down
44 changes: 43 additions & 1 deletion internal/manager/telemetry/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ import (
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

const (
// openShiftVersionPodNamespace is a namespace expected to contain pods whose environment includes OpenShift version
// information.
openShiftVersionPodNamespace = "openshift-apiserver-operator"
// openShiftVersionPodApp is a value for the "app" label to select pods whose environment includes OpenShift version
// information.
openShiftVersionPodApp = "openshift-apiserver-operator"
)

type mockGatewaysCounter int

func (m mockGatewaysCounter) GatewayClientsCount() int {
Expand Down Expand Up @@ -122,8 +131,9 @@ func TestCreateManager(t *testing.T) {
"k8s_provider=UNKNOWN;"+
"k8sv=v1.24.5;"+
"k8sv_semver=v1.24.5;"+
"openshift_version=4.13.0;"+
"k8s_nodes_count=4;"+
"k8s_pods_count=10;"+
"k8s_pods_count=11;"+
"k8s_services_count=18;"+
"kinm=c3,l2,l3,l4;"+
"mdep=i3,k3,km3,l3,t3;"+
Expand Down Expand Up @@ -576,5 +586,37 @@ func prepareObjects(pod k8stypes.NamespacedName) []runtime.Object {
},
},
},

&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: openShiftVersionPodNamespace,
},
Spec: corev1.NamespaceSpec{},
},
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: openShiftVersionPodNamespace,
Name: openShiftVersionPodApp + "-85c4c6dbb7-zbrkm",
Labels: map[string]string{
"app": openShiftVersionPodApp,
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "worker",
Env: []corev1.EnvVar{
{
// this is hardcoded here. the upstream const in telemetry lives inside an internal package and
// doesn't make sense to stick elsewhere. this is, however, only in a test, and it will be obvious if
// we break it. not ideal, but only requires some additional busywork to fix if we change upstream.
Name: "OPERATOR_IMAGE_VERSION",
Value: "4.13.0",
},
},
},
},
},
},
}
}
3 changes: 3 additions & 0 deletions test/envtest/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ func verifyTelemetryReport(t *testing.T, k8sVersion *version.Info, report string
}
}

// this expected report OMITS openshift_version, whereas manager/telemetry.TestCreateManager includes it.
// the resources created for this test do not include the OpenShift namespace+pod combo, as expected for
// non-OpenShift clusters. output for non-OpenShift clusters should not include an OpenShift version.
expectedReport := fmt.Sprintf(
"<14>"+
"signal=kic-ping;"+
Expand Down

0 comments on commit 4f933ab

Please sign in to comment.