Waldur Site Agent OKD Plugin
This plugin enables Waldur Site Agent to manage OKD/OpenShift projects and resources, providing integration between Waldur and OKD/OpenShift clusters.
Features
- Automatic project/namespace creation for Waldur resources
- Resource quota management (CPU, memory, storage, pod limits)
- User access control through RoleBindings
- Resource usage reporting
- Project lifecycle management (create, pause, restore, delete)
Installation
Install the plugin alongside the core waldur-site-agent package:
1 2 3 4 5 | |
Configuration
Create a configuration file (see examples/okd-config.yaml for a complete example):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
Authentication Token Management
The plugin supports multiple authentication methods with automatic token refresh:
Static Token (Simple)
For testing or when manually managing tokens:
1 2 3 4 | |
Service Account Token (Production Recommended)
For production deployments with automatic token refresh:
1 2 3 4 5 6 | |
File-Based Token Refresh
When tokens are managed by external systems:
1 2 3 4 5 6 | |
OAuth Token Refresh (Future)
Framework ready for OAuth-based authentication:
1 2 3 4 5 6 7 8 9 10 | |
Waldur to OKD Object Mapping
The plugin maps Waldur organizational hierarchy to OKD/OpenShift projects and namespaces:
graph TB
subgraph "Waldur Hierarchy"
WC[Customer/Organization<br/>e.g. 'ACME Corp']
WP[Project<br/>e.g. 'Web Development']
WR[Resource/Allocation<br/>e.g. 'Production Environment']
WU[Users<br/>e.g. 'john@acme.com']
WC --> WP
WP --> WR
WC --> WU
WP --> WU
end
subgraph "OKD/OpenShift Objects"
ON[Namespace/Project<br/>waldur-alloc-prod-env]
ORQ[ResourceQuota<br/>waldur-quota]
ORB[RoleBinding<br/>waldur-users]
OSA[ServiceAccounts]
ON --> ORQ
ON --> ORB
ON --> OSA
end
subgraph "Mapping Rules"
MR1[Customer → Project Prefix]
MR2[Project → Project Metadata]
MR3[Resource → Namespace]
MR4[Users → RoleBindings]
MR5[Limits → ResourceQuota]
end
WC -.->|Prefix| ON
WP -.->|Metadata| ON
WR ==>|Creates| ON
WU -.->|Binds to| ORB
WR -.->|Sets limits| ORQ
style WR fill:#e1f5fe
style ON fill:#c8e6c9
style ORQ fill:#fff9c4
style ORB fill:#ffccbc
Object Mapping Details
1. Namespace Creation
Waldur resources are mapped to OKD namespaces with a hierarchical naming convention:
| Waldur Object | OKD Namespace Pattern | Example |
|---|---|---|
| Customer Resource | {prefix}org-{customer_slug} |
waldur-org-acme |
| Project Resource | {prefix}proj-{project_slug} |
waldur-proj-webdev |
| Allocation Resource | {prefix}alloc-{allocation_slug} |
waldur-alloc-prod-env |
2. Resource Quotas
Waldur resource limits are translated to Kubernetes ResourceQuotas:
| Waldur Component | OKD ResourceQuota Field | Example |
|---|---|---|
| CPU (Cores) | requests.cpu, limits.cpu |
4 cores |
| Memory (GB) | requests.memory, limits.memory |
16Gi |
| Storage (GB) | requests.storage |
100Gi |
| Pod Count | pods |
50 |
3. User Access Mapping
Waldur user roles are mapped to OpenShift RoleBindings:
| Waldur Role | OpenShift ClusterRole | Permissions |
|---|---|---|
| Owner | admin |
Full namespace administration |
| Manager | edit |
Create/modify resources |
| Member | view |
Read-only access |
4. Metadata and Annotations
Waldur metadata is preserved in OKD annotations:
1 2 3 4 5 6 7 8 9 10 11 12 | |
OKD/OpenShift Setup
Authentication Requirements
The plugin requires a service account token with specific permissions to manage OKD/OpenShift resources. The token must have cluster-level permissions to create and manage projects, namespaces, resource quotas, and role bindings.
Required Permissions
The service account needs the following permissions:
- Project Management: Create, delete, and modify OpenShift projects
- Namespace Management: Manage Kubernetes namespaces and their metadata
- Resource Quota Management: Create and modify resource quotas for namespace limits
- Role Binding Management: Assign users to projects with appropriate roles
- Resource Monitoring: Query resource usage and project status
1. Create Service Account
Create a service account for the Waldur Site Agent:
1 2 3 4 5 | |
2. Grant Permissions
Create a ClusterRole with necessary permissions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
Bind the role to the service account:
1 2 3 4 5 6 7 | |
3. Get Service Account Token
For Production Deployment (Recommended)
Create a long-lived token for production use:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
For Development/Testing
Create a temporary token for testing:
1 2 3 4 5 | |
Token Validation
Verify the token has correct permissions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Usage
Run the agent with your configuration:
1 | |
Supported Modes
order_process: Process orders from Waldur to create/modify OKD projectsreport: Report resource usage from OKD to Waldurmembership_sync: Synchronize user memberships between Waldur and OKDevent_process: Process events via STOMP (if configured)
Event Processing Configuration
For real-time event processing, configure STOMP settings in your configuration file:
1 2 3 4 5 6 7 8 9 10 11 12 | |
Resource Management
Quotas
Resource quotas are automatically created for each project based on Waldur resource allocations. The quotas enforce both request and limit constraints for:
- CPU cores: Managed through
requests.cpuandlimits.cpu - Memory: Managed through
requests.memoryandlimits.memory - Storage: Managed through persistent volume claims
- Pod count: Maximum number of pods in the namespace
User Access
Users from Waldur are automatically granted access to OKD projects through RoleBindings. The plugin maps Waldur roles to OpenShift ClusterRoles for fine-grained access control.
Testing
Run the plugin tests:
1 2 3 4 5 | |
Troubleshooting
Token Refresh Behavior
The plugin automatically handles token expiration and refresh:
- Automatic Detection: Monitors for 401/403 authentication errors
- Refresh Triggers: Automatically refreshes tokens before expiration (5 minutes buffer)
- Fallback Handling: Gracefully handles token refresh failures
- Retry Logic: Automatically retries failed requests with refreshed tokens
Token Refresh Flow
- Initial Request: Uses current token for API calls
- Failure Detection: Detects 401 Unauthorized responses
- Token Refresh: Invalidates current token and loads new one
- Request Retry: Retries the original request with the new token
- Error Handling: Reports refresh failures with detailed error messages
Authentication Issues
If authentication fails:
- Verify Token Validity:
1 2 3 | |
- Check Token Expiration:
1 2 | |
- Validate Service Account Permissions:
1 2 3 4 5 | |
Connection Issues
If the agent cannot connect to the OKD cluster:
- Verify the API URL is correct and accessible
- Check the service account token is valid and not expired
- For self-signed certificates, set
verify_cert: false - Ensure network connectivity to the cluster
Permission Errors
If operations fail with permission errors:
- Verify the service account has the required ClusterRole permissions
- Check the ClusterRoleBinding is correctly configured
- Ensure the token has not expired (check logs for 401 errors)
- Validate that the service account namespace exists
Token Refresh Issues
If automatic token refresh fails:
- File-based tokens: Ensure the token file path is readable and contains valid token
- Service account tokens: Verify the service account path is mounted correctly
- Static tokens: Replace expired static tokens manually
- OAuth tokens: Check OAuth configuration and refresh token validity
Debug Mode
Enable debug logging for detailed token management information:
1 2 3 4 5 | |
Diagnostics
Run diagnostics to verify configuration:
1 2 | |
Development
Plugin Structure
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Key Components
backend.py: Main plugin implementation extendingBaseBackendclient.py: OKD API client with SSL adapter and authentication integrationtoken_manager.py: Comprehensive token management system supporting:- Static tokens for testing
- File-based token refresh
- Service account token mounting
- OAuth refresh framework (future)
- Test scripts: Validation and testing utilities for development
Adding New Features
- Extend the
OkdClientclass for new API operations - Update the
OkdBackendclass to use new client methods - Add tests for new functionality
- Update configuration examples if needed
Related Plugins
Compute & HPC Plugins
- SLURM Plugin - SLURM cluster management
- MOAB Plugin - MOAB cluster management
- MUP Plugin - MUP portal integration
Container & Cloud Plugins
- Harbor Plugin - Harbor container registry management
Storage Plugins
- Croit S3 Plugin - Croit S3 storage management
- CSCS HPC Storage Plugin - CSCS HPC storage management
Accounting Plugins
- CSCS DWDI Plugin - CSCS DWDI accounting integration
Utility Plugins
- Basic Username Management Plugin - Username generation and management
License
This plugin is part of the Waldur Site Agent project and follows the same license terms.