Skip to content

Commit

Permalink
feat(telemetry) collect OpenShift version
Browse files Browse the repository at this point in the history
  • Loading branch information
rainest committed Jun 29, 2023
1 parent f381c98 commit aba1be7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/jpillora/backoff v1.0.0
github.com/kong/deck v1.22.1
github.com/kong/go-kong v0.44.0
github.com/kong/kubernetes-telemetry v0.0.6
github.com/kong/kubernetes-telemetry v0.1.0
github.com/kong/kubernetes-testing-framework v0.31.1
github.com/lithammer/dedent v1.1.0
github.com/miekg/dns v1.1.55
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ github.com/kong/deck v1.22.1 h1:zoNsewts2TxUOfj86EqlA5GuRxKcwWEhd8/vV71eFYw=
github.com/kong/deck v1.22.1/go.mod h1:PMcNms9X5MrFe3uM22tVpFQaKiHxsXEsLgwVLVKK20Y=
github.com/kong/go-kong v0.44.0 h1:1x3w/TYdJjIZ6c1j9HiYP8755c923XN2O6j3kEaUkTA=
github.com/kong/go-kong v0.44.0/go.mod h1:41Sot1N/n8UHBp+gE/6nOw3vuzoHbhMSyU/zOS7VzPE=
github.com/kong/kubernetes-telemetry v0.0.6 h1:JR1Ry69Dkzzn6x6w3Ep2Uxyd8JrLSItEICfilA7WsP0=
github.com/kong/kubernetes-telemetry v0.0.6/go.mod h1:ynIsrEEpp2j7l+SdfMtqZTjyA/uOkvOWWc7Zdrd9/88=
github.com/kong/kubernetes-telemetry v0.1.0 h1:dyDhB2SUvxVaDAxaZtLWL7JGAbkgwlCUM1P8gR/rCl0=
github.com/kong/kubernetes-telemetry v0.1.0/go.mod h1:YYG7TkKnWlHov0+pSgK0XFsg85q0EzsYWXBl6Kehnjo=
github.com/kong/kubernetes-testing-framework v0.31.1 h1:Btj4EYFnoqmE7bnMHgP2JCMDrokRu6/STT56NS2nNTk=
github.com/kong/kubernetes-testing-framework v0.31.1/go.mod h1:fHywqkfFE6KVNogM/79mkspA1br/k0Uf8rbGuJGoVQM=
github.com/kong/semver/v4 v4.0.1 h1:DIcNR8W3gfx0KabFBADPalxxsp+q/5COwIFkkhrFQ2Y=
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 @@ -123,11 +132,12 @@ func TestCreateManager(t *testing.T) {
"k8sv=v1.24.5;"+
"k8sv_semver=v1.24.5;"+
"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;"+
"mdist=all18,c1,i2,k1,km1,l3,t1;"+
"openshift_version=4.13.0;"+
"\n",
hostname,
),
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 aba1be7

Please sign in to comment.