diff --git a/pkg/components/exporter/exporter_test.go b/pkg/components/exporter/exporter_test.go index be00a77e..2b39a4d3 100644 --- a/pkg/components/exporter/exporter_test.go +++ b/pkg/components/exporter/exporter_test.go @@ -218,3 +218,40 @@ func TestSCCAllows(t *testing.T) { }) } } + +func TestSpecMethod(t *testing.T) { + + tt := []struct { + deploymentSpec v1alpha1.ExporterDeploymentSpec + method string + image string + scenario string + }{{ + deploymentSpec: v1alpha1.ExporterDeploymentSpec{}, + method: "libbpf", + scenario: "libbpf", + image: "quay.io/sustainable_computing_io/kepler:release-0.6.1" + "-libbpf", + }, { + deploymentSpec: v1alpha1.ExporterDeploymentSpec{}, + method: "bcc", + scenario: "bcc", + image: "quay.io/sustainable_computing_io/kepler:release-0.6.1", + }} + + for _, tc := range tt { + tc := tc + t.Run(tc.scenario, func(t *testing.T) { + t.Parallel() + k := v1alpha1.Kepler{ + Spec: v1alpha1.KeplerSpec{ + Exporter: v1alpha1.ExporterSpec{ + Deployment: tc.deploymentSpec, + Method: tc.method, + }, + }, + } + actual := k8s.ContainerImageFromDS(NewDaemonSet(components.Full, &k)) + assert.Equal(t, actual, tc.image) + }) + } +} diff --git a/pkg/utils/k8s/k8s.go b/pkg/utils/k8s/k8s.go index 822ed406..92b6d346 100644 --- a/pkg/utils/k8s/k8s.go +++ b/pkg/utils/k8s/k8s.go @@ -159,3 +159,7 @@ func AllowsFromSCC(SCC *secv1.SecurityContextConstraints) SCCAllows { AllowHostPorts: SCC.AllowHostPorts, } } + +func ContainerImageFromDS(ds *appsv1.DaemonSet) string { + return ds.Spec.Template.Spec.Containers[0].Image +}