mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-11 03:57:01 +00:00
chore: Added OwnerReferences during resource creation for EphemeralRunnerSet, EphemeralRunner, and EphemeralRunnerPod (#3575)
This commit is contained in:
@@ -182,3 +182,69 @@ func TestGitHubURLTrimLabelValues(t *testing.T) {
|
||||
assert.Len(t, listener.Labels[LabelKeyGitHubRepository], 0)
|
||||
})
|
||||
}
|
||||
|
||||
func TestOwnershipRelationships(t *testing.T) {
|
||||
// Create an AutoscalingRunnerSet
|
||||
autoscalingRunnerSet := v1alpha1.AutoscalingRunnerSet{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-scale-set",
|
||||
Namespace: "test-ns",
|
||||
UID: "test-autoscaling-runner-set-uid",
|
||||
Labels: map[string]string{
|
||||
LabelKeyKubernetesPartOf: labelValueKubernetesPartOf,
|
||||
LabelKeyKubernetesVersion: "0.2.0",
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
runnerScaleSetIdAnnotationKey: "1",
|
||||
AnnotationKeyGitHubRunnerGroupName: "test-group",
|
||||
AnnotationKeyGitHubRunnerScaleSetName: "test-scale-set",
|
||||
annotationKeyValuesHash: "test-hash",
|
||||
},
|
||||
},
|
||||
Spec: v1alpha1.AutoscalingRunnerSetSpec{
|
||||
GitHubConfigUrl: "https://github.com/org/repo",
|
||||
},
|
||||
}
|
||||
|
||||
// Initialize ResourceBuilder
|
||||
b := ResourceBuilder{}
|
||||
|
||||
// Create EphemeralRunnerSet
|
||||
ephemeralRunnerSet, err := b.newEphemeralRunnerSet(&autoscalingRunnerSet)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test EphemeralRunnerSet ownership
|
||||
require.Len(t, ephemeralRunnerSet.OwnerReferences, 1, "EphemeralRunnerSet should have exactly one owner reference")
|
||||
ownerRef := ephemeralRunnerSet.OwnerReferences[0]
|
||||
assert.Equal(t, autoscalingRunnerSet.GetName(), ownerRef.Name, "Owner reference name should match AutoscalingRunnerSet name")
|
||||
assert.Equal(t, autoscalingRunnerSet.GetUID(), ownerRef.UID, "Owner reference UID should match AutoscalingRunnerSet UID")
|
||||
assert.Equal(t, true, *ownerRef.Controller, "Controller flag should be true")
|
||||
assert.Equal(t, true, *ownerRef.BlockOwnerDeletion, "BlockOwnerDeletion flag should be true")
|
||||
|
||||
// Create EphemeralRunner
|
||||
ephemeralRunner := b.newEphemeralRunner(ephemeralRunnerSet)
|
||||
|
||||
// Test EphemeralRunner ownership
|
||||
require.Len(t, ephemeralRunner.OwnerReferences, 1, "EphemeralRunner should have exactly one owner reference")
|
||||
ownerRef = ephemeralRunner.OwnerReferences[0]
|
||||
assert.Equal(t, ephemeralRunnerSet.GetName(), ownerRef.Name, "Owner reference name should match EphemeralRunnerSet name")
|
||||
assert.Equal(t, ephemeralRunnerSet.GetUID(), ownerRef.UID, "Owner reference UID should match EphemeralRunnerSet UID")
|
||||
assert.Equal(t, true, *ownerRef.Controller, "Controller flag should be true")
|
||||
assert.Equal(t, true, *ownerRef.BlockOwnerDeletion, "BlockOwnerDeletion flag should be true")
|
||||
|
||||
// Create EphemeralRunnerPod
|
||||
runnerSecret := &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-secret",
|
||||
},
|
||||
}
|
||||
pod := b.newEphemeralRunnerPod(context.TODO(), ephemeralRunner, runnerSecret)
|
||||
|
||||
// Test EphemeralRunnerPod ownership
|
||||
require.Len(t, pod.OwnerReferences, 1, "EphemeralRunnerPod should have exactly one owner reference")
|
||||
ownerRef = pod.OwnerReferences[0]
|
||||
assert.Equal(t, ephemeralRunner.GetName(), ownerRef.Name, "Owner reference name should match EphemeralRunner name")
|
||||
assert.Equal(t, ephemeralRunner.GetUID(), ownerRef.UID, "Owner reference UID should match EphemeralRunner UID")
|
||||
assert.Equal(t, true, *ownerRef.Controller, "Controller flag should be true")
|
||||
assert.Equal(t, true, *ownerRef.BlockOwnerDeletion, "BlockOwnerDeletion flag should be true")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user