Skip to content

Commit

Permalink
test(provider): merge additional labels into pod template (#49)
Browse files Browse the repository at this point in the history
should resolve #28: tests merging additional labels into pod template
via `podTemplateSpec` of provider-config.
  • Loading branch information
rafalgalaw committed May 16, 2024
1 parent 246acd7 commit ec8785a
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 0 deletions.
151 changes: 151 additions & 0 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,157 @@ func TestCreateInstance(t *testing.T) {
runtimeObjects: []runtime.Object{},
err: nil,
},
{
name: "Valid bootstrapParams and merge pod template spec with additional labels",
config: &config.ProviderConfig{
KubeConfigPath: "",
RunnerNamespace: "runner",
PodTemplate: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"foo": "bar",
"foo1": "bar2",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{},
},
},
},
bootstrapParams: params.BootstrapInstance{
Name: instanceName,
PoolID: poolID,
Flavor: "small",
RepoURL: "https://github.com/testorg",
InstanceToken: "test-token",
MetadataURL: "https://metadata.test",
CallbackURL: "https://callback.test/status",
Image: "localhost:5000/runner:ubuntu-22.04",
OSType: "linux",
OSArch: "arm64",
Labels: []string{"road-runner", "linux", "arm64", "kubernetes"},
JitConfigEnabled: true,
},
expectedProviderInstance: params.ProviderInstance{
ProviderID: providerID,
Name: instanceName,
OSType: "linux",
OSName: "",
OSVersion: "",
OSArch: "arm64",
Status: "running",
},
expectedPodInstance: &corev1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: providerID,
Namespace: "runner",
Labels: map[string]string{
spec.GarmInstanceNameLabel: instanceName,
spec.GarmFlavorLabel: "small",
spec.GarmOSArchLabel: "arm64",
spec.GarmOSTypeLabel: "linux",
spec.GarmPoolIDLabel: "ddce45e7-1bbb-4ecd-92cb-c733372b5cde",
spec.GarmControllerIDLabel: controllerID,
spec.GarmRunnerGroupLabel: "",
"foo": "bar",
"foo1": "bar2",
},
},
Spec: corev1.PodSpec{
Volumes: []corev1.Volume{
{
Name: "runner",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: "",
SizeLimit: nil,
},
},
},
},
RestartPolicy: corev1.RestartPolicyNever,
Containers: []corev1.Container{
{
Name: "runner",
Image: "localhost:5000/runner:ubuntu-22.04",
Env: []corev1.EnvVar{
{
Name: "RUNNER_ORG",
Value: "testorg",
},
{
Name: "RUNNER_REPO",
Value: "",
},
{
Name: "RUNNER_ENTERPRISE",
Value: "",
},
{
Name: "RUNNER_GROUP",
Value: "",
},
{
Name: "RUNNER_NAME",
Value: instanceName,
},
{
Name: "RUNNER_LABELS",
Value: "road-runner,linux,arm64,kubernetes",
},
{
Name: "RUNNER_WORKDIR",
Value: "/runner/_work/",
},
{
Name: "GITHUB_URL",
Value: "https://github.com",
},
{
Name: "RUNNER_EPHEMERAL",
Value: "true",
},
{
Name: "RUNNER_TOKEN",
Value: "dummy",
},
{
Name: "METADATA_URL",
Value: "https://metadata.test",
},
{
Name: "BEARER_TOKEN",
Value: "test-token",
},
{
Name: "CALLBACK_URL",
Value: "https://callback.test/status",
},
{
Name: "JIT_CONFIG_ENABLED",
Value: "true",
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "runner",
ReadOnly: false,
MountPath: "/runner",
},
},
ImagePullPolicy: "Always",
Resources: corev1.ResourceRequirements{},
},
},
},
},
runtimeObjects: []runtime.Object{},
err: nil,
},
{
name: "Valid bootstrapParams and custom flavors",
config: &config.ProviderConfig{
Expand Down
29 changes: 29 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/mercedes-benz/garm-provider-k8s/pkg/config"
)
Expand Down Expand Up @@ -179,6 +180,34 @@ podTemplate:
- test -f /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
`,
wantError: false,
},
{
name: "valid configuration with additional pod labels",
expected: config.ProviderConfig{
KubeConfigPath: "/path/to/kubeconfig",
RunnerNamespace: "runner",
PodTemplate: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"foo": "bar",
"foo1": "bar2",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{},
},
},
},
config: `
kubeConfigPath: "/path/to/kubeconfig"
runnerNamespace: "runner"
podTemplate:
metadata:
labels:
foo: bar
foo1: bar2
`,
wantError: false,
},
Expand Down

0 comments on commit ec8785a

Please sign in to comment.