- Add comprehensive database migrations (001-024) for schema evolution - Enhance API schema with expanded type definitions and resolvers - Add new middleware: audit logging, rate limiting, MFA enforcement, security, tenant auth - Implement new services: AI optimization, billing, blockchain, compliance, marketplace - Add adapter layer for cloud integrations (Cloudflare, Kubernetes, Proxmox, storage) - Update Crossplane provider with enhanced VM management capabilities - Add comprehensive test suite for API endpoints and services - Update frontend components with improved GraphQL subscriptions and real-time updates - Enhance security configurations and headers (CSP, CORS, etc.) - Update documentation and configuration files - Add new CI/CD workflows and validation scripts - Implement design system improvements and UI enhancements
105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
package virtualmachine
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// ErrorCategory represents a categorized error with appropriate condition type and reason
|
|
type ErrorCategory struct {
|
|
Type string
|
|
Reason string
|
|
}
|
|
|
|
// categorizeError categorizes errors into appropriate types for better handling
|
|
func categorizeError(errorStr string) ErrorCategory {
|
|
errorStr = strings.ToLower(errorStr)
|
|
|
|
// API not implemented errors
|
|
if strings.Contains(errorStr, "501") ||
|
|
strings.Contains(errorStr, "not implemented") ||
|
|
strings.Contains(errorStr, "importdisk") {
|
|
return ErrorCategory{
|
|
Type: "APINotSupported",
|
|
Reason: "ImportDiskAPINotImplemented",
|
|
}
|
|
}
|
|
|
|
// Configuration errors (non-retryable without manual intervention)
|
|
if strings.Contains(errorStr, "cannot get provider config") ||
|
|
strings.Contains(errorStr, "cannot get credentials") ||
|
|
strings.Contains(errorStr, "cannot find site") ||
|
|
strings.Contains(errorStr, "cannot create proxmox client") {
|
|
return ErrorCategory{
|
|
Type: "ConfigurationError",
|
|
Reason: "InvalidConfiguration",
|
|
}
|
|
}
|
|
|
|
// Quota errors
|
|
if strings.Contains(errorStr, "quota") ||
|
|
strings.Contains(errorStr, "exceeded") {
|
|
return ErrorCategory{
|
|
Type: "QuotaExceeded",
|
|
Reason: "ResourceQuotaExceeded",
|
|
}
|
|
}
|
|
|
|
// Node health errors
|
|
if strings.Contains(errorStr, "node") &&
|
|
(strings.Contains(errorStr, "unhealthy") ||
|
|
strings.Contains(errorStr, "not reachable") ||
|
|
strings.Contains(errorStr, "offline")) {
|
|
return ErrorCategory{
|
|
Type: "NodeUnhealthy",
|
|
Reason: "NodeHealthCheckFailed",
|
|
}
|
|
}
|
|
|
|
// Image/Storage errors
|
|
if strings.Contains(errorStr, "image") &&
|
|
(strings.Contains(errorStr, "not found") ||
|
|
strings.Contains(errorStr, "cannot find")) {
|
|
return ErrorCategory{
|
|
Type: "ImageNotFound",
|
|
Reason: "ImageNotFoundInStorage",
|
|
}
|
|
}
|
|
|
|
// Lock file errors
|
|
if strings.Contains(errorStr, "lock") ||
|
|
strings.Contains(errorStr, "timeout") {
|
|
return ErrorCategory{
|
|
Type: "LockError",
|
|
Reason: "LockFileTimeout",
|
|
}
|
|
}
|
|
|
|
// Network/Connection errors (retryable)
|
|
if strings.Contains(errorStr, "network") ||
|
|
strings.Contains(errorStr, "connection") ||
|
|
strings.Contains(errorStr, "timeout") ||
|
|
strings.Contains(errorStr, "502") ||
|
|
strings.Contains(errorStr, "503") {
|
|
return ErrorCategory{
|
|
Type: "NetworkError",
|
|
Reason: "TransientNetworkFailure",
|
|
}
|
|
}
|
|
|
|
// Generic creation failure
|
|
if strings.Contains(errorStr, "cannot create vm") ||
|
|
strings.Contains(errorStr, "failed to create") {
|
|
return ErrorCategory{
|
|
Type: "CreationFailed",
|
|
Reason: "VMCreationFailed",
|
|
}
|
|
}
|
|
|
|
// Default: generic failure
|
|
return ErrorCategory{
|
|
Type: "Failed",
|
|
Reason: "UnknownError",
|
|
}
|
|
}
|
|
|