Skip to content

Commit 1c13aa8

Browse files
committed
fix: compute domain template name
1 parent 18ec42f commit 1c13aa8

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

internal/compute-domain-controller/computedomain_controller.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (r *ComputeDomainReconciler) handleDeletion(ctx context.Context, domain *co
116116
}
117117

118118
func (r *ComputeDomainReconciler) ensureResourceClaimTemplates(ctx context.Context, domain *computedomainv1beta1.ComputeDomain) error {
119-
return r.ensureTemplate(ctx, domain, domain.Name, consts.ComputeDomainWorkloadDeviceClass, "workload")
119+
return r.ensureTemplate(ctx, domain, templateName(domain), consts.ComputeDomainWorkloadDeviceClass, "workload")
120120
}
121121

122122
func (r *ComputeDomainReconciler) getAllocationMode(domain *computedomainv1beta1.ComputeDomain) string {
@@ -204,7 +204,7 @@ func (r *ComputeDomainReconciler) ensureTemplate(
204204

205205
func (r *ComputeDomainReconciler) deleteResourceClaimTemplates(ctx context.Context, domain *computedomainv1beta1.ComputeDomain) error {
206206
template := &resourceapi.ResourceClaimTemplate{}
207-
key := client.ObjectKey{Namespace: domain.Namespace, Name: domain.Name}
207+
key := client.ObjectKey{Namespace: domain.Namespace, Name: templateName(domain)}
208208
if err := r.Get(ctx, key, template); err != nil {
209209
if apierrors.IsNotFound(err) {
210210
return nil
@@ -322,3 +322,11 @@ func (r *ComputeDomainReconciler) statusEqual(current computedomainv1beta1.Compu
322322
}
323323
return true
324324
}
325+
326+
func templateName(domain *computedomainv1beta1.ComputeDomain) string {
327+
templateName := domain.Name
328+
if domain.Spec.Channel != nil {
329+
templateName = domain.Spec.Channel.ResourceClaimTemplate.Name
330+
}
331+
return templateName
332+
}

internal/compute-domain-controller/computedomain_controller_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ func TestComputeDomainReconciler_Reconcile(t *testing.T) {
5656
Namespace: "default",
5757
UID: "test-uid",
5858
},
59+
Spec: computedomainv1beta1.ComputeDomainSpec{
60+
Channel: &computedomainv1beta1.ComputeDomainChannelSpec{
61+
ResourceClaimTemplate: computedomainv1beta1.ComputeDomainResourceClaimTemplate{
62+
Name: "test-template-name",
63+
},
64+
},
65+
},
5966
},
6067
expectedWorkloadTemplate: true,
6168
expectedFinalizer: true,
@@ -69,11 +76,18 @@ func TestComputeDomainReconciler_Reconcile(t *testing.T) {
6976
DeletionTimestamp: &metav1.Time{Time: time.Now()},
7077
Finalizers: []string{consts.ComputeDomainFinalizer},
7178
},
79+
Spec: computedomainv1beta1.ComputeDomainSpec{
80+
Channel: &computedomainv1beta1.ComputeDomainChannelSpec{
81+
ResourceClaimTemplate: computedomainv1beta1.ComputeDomainResourceClaimTemplate{
82+
Name: "test-template-name",
83+
},
84+
},
85+
},
7286
},
7387
existingObjects: []client.Object{
7488
&resourceapi.ResourceClaimTemplate{
7589
ObjectMeta: metav1.ObjectMeta{
76-
Name: "test-domain",
90+
Name: "test-template-name",
7791
Namespace: "default",
7892
Labels: map[string]string{
7993
consts.ComputeDomainTemplateLabel: "test-domain",
@@ -128,7 +142,7 @@ func TestComputeDomainReconciler_Reconcile(t *testing.T) {
128142

129143
workloadTemplate := &resourceapi.ResourceClaimTemplate{}
130144
err = fakeClient.Get(context.Background(), types.NamespacedName{
131-
Name: "test-domain",
145+
Name: test.computeDomain.Spec.Channel.ResourceClaimTemplate.Name,
132146
Namespace: "default",
133147
}, workloadTemplate)
134148
// Check ResourceClaimTemplates

test/integration/compute_domain_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var _ = Describe("Compute Domain Controller Integration Tests", func() {
4242
manifestPath := "manifests/compute-domain-basic.yaml"
4343
namespace := "compute-domain-test-compute-domain-basic"
4444
computeDomainName := "test-domain"
45+
templateName := "test-domain-template"
4546

4647
setupTest(manifestPath, namespace, &testNamespaces)
4748

@@ -55,13 +56,13 @@ var _ = Describe("Compute Domain Controller Integration Tests", func() {
5556
// Wait for ResourceClaimTemplate to be created by the controller
5657
Eventually(func() error {
5758
_, err := kubeClient.ResourceV1().ResourceClaimTemplates(namespace).Get(
58-
context.Background(), computeDomainName, metav1.GetOptions{})
59+
context.Background(), templateName, metav1.GetOptions{})
5960
return err
6061
}).WithTimeout(30 * time.Second).Should(Succeed())
6162

6263
// Verify ResourceClaimTemplate details
6364
rct, err := kubeClient.ResourceV1().ResourceClaimTemplates(namespace).Get(
64-
context.Background(), computeDomainName, metav1.GetOptions{})
65+
context.Background(), templateName, metav1.GetOptions{})
6566
Expect(err).NotTo(HaveOccurred())
6667

6768
// Check that it has the correct labels

test/integration/manifests/compute-domain-basic.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ spec:
1515
channel:
1616
allocationMode: Single
1717
resourceClaimTemplate:
18-
name: test-domain
18+
name: test-domain-template

0 commit comments

Comments
 (0)