Skip to content

Commit 150bdf5

Browse files
committed
Allow sandboxclaim's metadata to be passed to the sandbox
1 parent 4b0d016 commit 150bdf5

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

extensions/controllers/sandboxclaim_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ func (r *SandboxClaimReconciler) createSandbox(ctx context.Context, claim *exten
250250
logger.Info("creating sandbox from template", "template", template.Name)
251251
sandbox := &v1alpha1.Sandbox{
252252
ObjectMeta: metav1.ObjectMeta{
253-
Namespace: claim.Namespace,
254-
Name: claim.Name,
253+
Namespace: claim.Namespace,
254+
Name: claim.Name,
255+
Labels: claim.Labels,
256+
Annotations: claim.Annotations,
255257
},
256258
}
257259
sandbox.Spec.PodTemplate = template.Spec.PodTemplate

extensions/controllers/sandboxclaim_controller_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,22 @@ func TestSandboxClaimReconcile(t *testing.T) {
109109
},
110110
}
111111

112+
claimWithMetadata := claim.DeepCopy()
113+
claimWithMetadata.Labels = map[string]string{
114+
"test-label": "test-value",
115+
}
116+
claimWithMetadata.Annotations = map[string]string{
117+
"test-annotation": "test-annotation-value",
118+
}
119+
112120
testCases := []struct {
113121
name string
114122
existingObjects []client.Object
115123
expectSandbox bool
116124
expectError bool
117-
expectedCondition metav1.Condition
125+
expectedCondition metav1.Condition
126+
expectedLabels map[string]string
127+
expectedAnnotations map[string]string
118128
}{
119129
{
120130
name: "sandbox is created when a claim is made",
@@ -184,6 +194,23 @@ func TestSandboxClaimReconcile(t *testing.T) {
184194
Message: "Sandbox is ready",
185195
},
186196
},
197+
{
198+
name: "sandbox is created with labels and annotations from claim",
199+
existingObjects: []client.Object{template, claimWithMetadata},
200+
expectSandbox: true,
201+
expectedCondition: metav1.Condition{
202+
Type: string(sandboxv1alpha1.SandboxConditionReady),
203+
Status: metav1.ConditionFalse,
204+
Reason: "SandboxNotReady",
205+
Message: "Sandbox is not ready",
206+
},
207+
expectedLabels: map[string]string{
208+
"test-label": "test-value",
209+
},
210+
expectedAnnotations: map[string]string{
211+
"test-annotation": "test-annotation-value",
212+
},
213+
},
187214
}
188215

189216
for _, tc := range testCases {
@@ -221,6 +248,16 @@ func TestSandboxClaimReconcile(t *testing.T) {
221248
if diff := cmp.Diff(sandbox.Spec.PodTemplate.Spec, template.Spec.PodTemplate.Spec); diff != "" {
222249
t.Errorf("unexpected sandbox spec:\n%s", diff)
223250
}
251+
if tc.expectedLabels != nil {
252+
if diff := cmp.Diff(tc.expectedLabels, sandbox.Labels); diff != "" {
253+
t.Errorf("unexpected sandbox labels:\n%s", diff)
254+
}
255+
}
256+
if tc.expectedAnnotations != nil {
257+
if diff := cmp.Diff(tc.expectedAnnotations, sandbox.Annotations); diff != "" {
258+
t.Errorf("unexpected sandbox annotations:\n%s", diff)
259+
}
260+
}
224261
}
225262

226263
var updatedClaim extensionsv1alpha1.SandboxClaim

0 commit comments

Comments
 (0)