Skip to content

Commit 63b5999

Browse files
committed
Ensure that ResourceClaim / ComputeDomain namespace are the same
Signed-off-by: Kevin Klues <[email protected]>
1 parent ad7d20a commit 63b5999

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cmd/compute-domain-kubelet-plugin/computedomain.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,22 @@ func (m *ComputeDomainManager) GetNodeIPs(ctx context.Context, cdUID string) ([]
265265
return ips, nil
266266
}
267267

268+
func (m *ComputeDomainManager) AssertComputeDomainNamespace(ctx context.Context, claimNamespace, cdUID string) error {
269+
cd, err := m.GetComputeDomain(ctx, cdUID)
270+
if err != nil {
271+
return fmt.Errorf("error getting ComputeDomain: %w", err)
272+
}
273+
if cd == nil {
274+
return fmt.Errorf("ComputeDomain not found: %s", cdUID)
275+
}
276+
277+
if cd.Namespace != claimNamespace {
278+
return fmt.Errorf("the ResourceClaim's namespace is different than the ComputeDomain's namespace")
279+
}
280+
281+
return nil
282+
}
283+
268284
func (m *ComputeDomainManager) AddNodeLabel(ctx context.Context, cdUID string) error {
269285
node, err := m.config.clientsets.Core.CoreV1().Nodes().Get(ctx, m.config.flags.nodeName, metav1.GetOptions{})
270286
if err != nil {

cmd/compute-domain-kubelet-plugin/device_state.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ func (s *DeviceState) applyComputeDomainChannelConfig(ctx context.Context, confi
378378
// Create any necessary ComputeDomain channels and gather their CDI container edits.
379379
for _, r := range results {
380380
channel := s.allocatable[r.Device].Channel
381+
if err := s.computeDomainManager.AssertComputeDomainNamespace(ctx, claim.Namespace, config.DomainID); err != nil {
382+
return nil, fmt.Errorf("error asserting ComputeDomain's namespace: %w", err)
383+
}
381384
if err := s.computeDomainManager.AddNodeLabel(ctx, config.DomainID); err != nil {
382385
return nil, fmt.Errorf("error adding Node label for ComputeDomain: %w", err)
383386
}

0 commit comments

Comments
 (0)