test/e2e: Improve kubectl subresource e2e test

We now get structured output using jsonpath for the
name and version fields of the node object and then
compare the outputs.

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
This commit is contained in:
Madhav Jivrajani 2023-03-15 17:27:34 +05:30
parent 8decaf3ae7
commit 88b498f23e

View File

@ -2048,26 +2048,19 @@ metadata:
framework.ExpectNoError(err) framework.ExpectNoError(err)
gomega.Expect(nodes.Items).ToNot(gomega.BeEmpty()) gomega.Expect(nodes.Items).ToNot(gomega.BeEmpty())
node := nodes.Items[0] node := nodes.Items[0]
ginkgo.By(fmt.Sprintf("calling kubectl get nodes %s", node.Name))
outBuiltIn := e2ekubectl.RunKubectlOrDie("", "get", "nodes", node.Name)
ginkgo.By(fmt.Sprintf("calling kubectl get nodes %s --subresource=status", node.Name))
outStatusSubresource := e2ekubectl.RunKubectlOrDie("", "get", "nodes", node.Name, "--subresource=status")
// Avoid comparing values of fields that might end up // Avoid comparing values of fields that might end up
// changing between the two invocations of kubectl. // changing between the two invocations of kubectl. We
requiredOutput := [][]string{ // compare the name and version fields.
{"NAME"}, ginkgo.By(fmt.Sprintf("calling kubectl get nodes %s", node.Name))
{"STATUS"}, outBuiltIn := e2ekubectl.RunKubectlOrDie("", "get", "nodes", node.Name,
{"ROLES"}, "--output=jsonpath='{.metadata.name}{.status.nodeInfo.kubeletVersion}'",
{"AGE"}, )
{"VERSION"}, ginkgo.By(fmt.Sprintf("calling kubectl get nodes %s --subresource=status", node.Name))
{node.Name}, // check for NAME outStatusSubresource := e2ekubectl.RunKubectlOrDie("", "get", "nodes", node.Name,
{""}, // avoid comparing STATUS "--output=jsonpath='{.metadata.name}{.status.nodeInfo.kubeletVersion}'",
{""}, // avoid comparing ROLES "--subresource=status",
{""}, // avoid comparing AGE )
{node.Status.NodeInfo.KubeletVersion}, // check for VERSION gomega.Expect(outBuiltIn).To(gomega.Equal(outStatusSubresource))
}
checkOutput(outBuiltIn, requiredOutput)
checkOutput(outStatusSubresource, requiredOutput)
}) })
}) })
}) })