NamespacedResource class extends the base Resource class to provide namespace-aware functionality.
Overview
Most Kubernetes resources are namespaced, meaning they exist within a namespace scope and are isolated from resources in other namespaces. Common examples include Pods, Deployments, Services, ConfigMaps, and Secrets.NamespacedResource Class
TheNamespacedResource class is defined in /home/daytona/workspace/source/ocp_resources/resource.py:1598 and provides:
- Namespace requirement enforcement
- Namespace-aware API operations
- Automatic namespace handling from YAML/dict inputs
Creating Namespaced Resources
Basic Creation
From YAML with Namespace
Override Namespace from YAML
Common Namespaced Resources
Here are the most commonly used namespaced resources:Workload Resources
Configuration Resources
Network Resources
Storage Resources
RBAC Resources
Querying Namespaced Resources
Get Resources in Specific Namespace
Get Resources Across All Namespaces
Get Single Resource
Namespace Management
Check Resource Namespace
Ensure Namespace Exists
Create Multiple Resources in Same Namespace
Differences from Cluster Resources
Namespace Requirement
Namespace Requirement
Namespaced Resources: Require Cluster Resources: No namespace parameter
namespace parameterAPI Operations
API Operations
Namespaced Resources: API calls include namespaceCluster Resources: API calls are cluster-wide
Deletion Scope
Deletion Scope
Namespaced Resources: Deleted with namespace or individuallyCluster Resources: Only individually deleted
RBAC Scope
RBAC Scope
Namespaced Resources: Can use namespace-scoped RBAC (Role/RoleBinding)Cluster Resources: Require cluster-scoped RBAC (ClusterRole/ClusterRoleBinding)
Common Patterns
Pattern 1: Create App with Multiple Resources
Pattern 2: Resource with Namespace Context
Pattern 3: Batch Resource Creation
Troubleshooting
Missing Namespace Error
Namespace Not Found
Check Namespace Before Creating Resource
Best Practices
Always Specify Namespace
Explicitly provide the namespace parameter for all namespaced resources to avoid confusion.
Use Namespace Context Managers
When creating multiple resources in the same namespace, use context managers for automatic cleanup.
Verify Namespace Exists
Check if the namespace exists before creating resources in it, or create it as part of your setup.
Label Your Resources
Use consistent labels across resources in a namespace for easier querying and management.
Next Steps
Context Managers
Learn about automatic resource lifecycle management
Resource Class
Understand the base Resource class
Working with Pods
Complete guide to working with pods
Working with Deployments
Manage deployments and replicas