Skip to content
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

Detect OpenShift version #4211

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 @@ -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