Skip to content

Collect Kubernetes distribution platform and version #1651

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

Merged
merged 24 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adjust collector and platform tests
  • Loading branch information
bjee19 committed Mar 13, 2024
commit 9e9bcb793675e74a2cbaebc45689570a32bf9661
104 changes: 71 additions & 33 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ var _ = Describe("Collector", Ordered, func() {
}
}

mergeListCallsWithBase := func(f listCallsFunc) listCallsFunc {
return func(
ctx context.Context,
object client.ObjectList,
option ...client.ListOption,
) error {
err := baseListCalls(ctx, object, option...)
Expect(err).ToNot(HaveOccurred())

return f(ctx, object, option...)
}
}

Describe("Normal case", func() {
When("collecting telemetry data", func() {
It("collects all fields", func() {
Expand Down Expand Up @@ -340,7 +353,26 @@ var _ = Describe("Collector", Ordered, func() {
})
})

Describe("clusterID collector", func() {
Describe("cluster information collector", func() {
When("collecting cluster platform", func() {
When("it encounters an error while collecting data", func() {
It("should error if the kubernetes client errored when getting the NamespaceList", func() {
expectedError := errors.New("failed to get NamespaceList")
k8sClientReader.ListCalls(mergeListCallsWithBase(
func(_ context.Context, object client.ObjectList, _ ...client.ListOption) error {
switch object.(type) {
case *v1.NamespaceList:
return expectedError
}
return nil
}))

_, err := dataCollector.Collect(ctx)
Expect(err).To(MatchError(expectedError))
})
})
})

When("collecting clusterID data", func() {
When("it encounters an error while collecting data", func() {
It("should error if the kubernetes client errored when getting the namespace", func() {
Expand All @@ -359,6 +391,34 @@ var _ = Describe("Collector", Ordered, func() {
})
})
})

When("collecting cluster version data", func() {
When("the kubelet version is missing", func() {
It("should be report 'unknown'", func() {
nodes := &v1.NodeList{
Items: []v1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Name: "node1",
},
Spec: v1.NodeSpec{
ProviderID: "k3s://ip-172-16-0-210",
},
},
},
}

k8sClientReader.ListCalls(createListCallsFunc(nodes))
expData.ClusterVersion = "unknown"
expData.ClusterPlatform = "k3s"

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(expData).To(Equal(data))
})
})
})
})

Describe("node count collector", func() {
Expand All @@ -383,9 +443,17 @@ var _ = Describe("Collector", Ordered, func() {

Expect(err).To(MatchError(expectedError))
})

It("should error on kubernetes client api errors", func() {
expectedError := errors.New("there was an error getting NodeList")
k8sClientReader.ListReturns(expectedError)
expectedError := errors.New("failed to get NodeList")
k8sClientReader.ListCalls(
func(_ context.Context, object client.ObjectList, _ ...client.ListOption) error {
switch object.(type) {
case *v1.NodeList:
return expectedError
}
return nil
})

_, err := dataCollector.Collect(ctx)
Expect(err).To(MatchError(expectedError))
Expand All @@ -394,36 +462,6 @@ var _ = Describe("Collector", Ordered, func() {
})
})

Describe("cluster version collector", func() {
When("collecting cluster version data", func() {
When("the kubelet version is missing", func() {
It("should be report 'unknown'", func() {
nodes := &v1.NodeList{
Items: []v1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Name: "node1",
},
Spec: v1.NodeSpec{
ProviderID: "k3s://ip-172-16-0-210",
},
},
},
}

k8sClientReader.ListCalls(createListCallsFunc(nodes))
expData.ClusterVersion = "unknown"
expData.ClusterPlatform = "k3s"

data, err := dataCollector.Collect(ctx)

Expect(err).To(BeNil())
Expect(expData).To(Equal(data))
})
})
})
})

Describe("NGF resource count collector", func() {
var (
graph1 *graph.Graph
Expand Down
17 changes: 15 additions & 2 deletions internal/mode/static/telemetry/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestGetPlatform(t *testing.T) {
},
},
expectedPlatform: "rancher",
name: "rancher platform",
name: "rancher platform on k3s",
},
{
node: &v1.Node{
Expand All @@ -94,7 +94,20 @@ func TestGetPlatform(t *testing.T) {
},
namespaces: &v1.NamespaceList{},
expectedPlatform: "openshift",
name: "openshift platform",
name: "openshift platform on k3s",
},
{
node: &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"node.openshift.io/os_id": "test"},
},
Spec: v1.NodeSpec{
ProviderID: "aws://test-data/us-central1-c/test-data",
},
},
namespaces: &v1.NamespaceList{},
expectedPlatform: "openshift",
name: "openshift platform on aws",
},
{
node: &v1.Node{
Expand Down