Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions internal/k8s/cluster/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,11 @@ func (p *EKSProvider) ListClusters(ctx context.Context) ([]ClusterInfo, error) {
if err != nil {
// Include basic info even if full details fail
clusters = append(clusters, ClusterInfo{
Name: name,
Type: ClusterTypeEKS,
Status: "unknown",
Region: p.region,
Name: name,
Type: ClusterTypeEKS,
Status: "unknown",
NormalizedStatus: ClusterStatusUnknown,
Region: p.region,
})
continue
}
Expand All @@ -502,6 +503,7 @@ func (p *EKSProvider) GetCluster(ctx context.Context, clusterName string) (*Clus
Name: cluster.Name,
Type: ClusterTypeEKS,
Status: cluster.Status,
NormalizedStatus: NormalizeEKSStatus(cluster.Status),
KubernetesVersion: cluster.Version,
Endpoint: cluster.Endpoint,
Region: p.region,
Expand Down
2 changes: 2 additions & 0 deletions internal/k8s/cluster/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func (p *GKEProvider) ListClusters(ctx context.Context) ([]ClusterInfo, error) {
Name: c.Name,
Type: ClusterTypeGKE,
Status: c.Status,
NormalizedStatus: NormalizeGKEStatus(c.Status),
KubernetesVersion: c.CurrentMasterVersion,
Endpoint: c.Endpoint,
Region: c.Location,
Expand Down Expand Up @@ -366,6 +367,7 @@ func (p *GKEProvider) GetCluster(ctx context.Context, clusterName string) (*Clus
Name: cluster.Name,
Type: ClusterTypeGKE,
Status: cluster.Status,
NormalizedStatus: NormalizeGKEStatus(cluster.Status),
KubernetesVersion: cluster.CurrentMasterVersion,
Endpoint: cluster.Endpoint,
Region: cluster.Location,
Expand Down
117 changes: 107 additions & 10 deletions internal/k8s/cluster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,31 @@ type ClusterType string
const (
ClusterTypeEKS ClusterType = "eks"
ClusterTypeGKE ClusterType = "gke"
ClusterTypeAKS ClusterType = "aks"
ClusterTypeKubeadm ClusterType = "kubeadm"
ClusterTypeKops ClusterType = "kops"
ClusterTypeK3s ClusterType = "k3s"
ClusterTypeExisting ClusterType = "existing"
)

// ClusterStatus represents the normalized status of a cluster
type ClusterStatus string

const (
// ClusterStatusReady indicates the cluster is ready and operational
ClusterStatusReady ClusterStatus = "ready"
// ClusterStatusCreating indicates the cluster is being created
ClusterStatusCreating ClusterStatus = "creating"
// ClusterStatusUpdating indicates the cluster is being updated
ClusterStatusUpdating ClusterStatus = "updating"
// ClusterStatusDeleting indicates the cluster is being deleted
ClusterStatusDeleting ClusterStatus = "deleting"
// ClusterStatusError indicates the cluster is in an error state
ClusterStatusError ClusterStatus = "error"
// ClusterStatusUnknown indicates the cluster status could not be determined
ClusterStatusUnknown ClusterStatus = "unknown"
)

// NodeInfo contains information about a cluster node
type NodeInfo struct {
Name string `json:"name"`
Expand All @@ -30,16 +49,17 @@ type NodeInfo struct {

// ClusterInfo contains cluster details
type ClusterInfo struct {
Name string `json:"name"`
Type ClusterType `json:"type"`
Status string `json:"status"`
KubernetesVersion string `json:"kubernetes_version"`
Endpoint string `json:"endpoint"`
ControlPlaneNodes []NodeInfo `json:"control_plane_nodes,omitempty"`
WorkerNodes []NodeInfo `json:"worker_nodes,omitempty"`
CreatedAt time.Time `json:"created_at"`
Region string `json:"region,omitempty"`
VPCID string `json:"vpc_id,omitempty"`
Name string `json:"name"`
Type ClusterType `json:"type"`
Status string `json:"status"`
NormalizedStatus ClusterStatus `json:"normalized_status"`
KubernetesVersion string `json:"kubernetes_version"`
Endpoint string `json:"endpoint"`
ControlPlaneNodes []NodeInfo `json:"control_plane_nodes,omitempty"`
WorkerNodes []NodeInfo `json:"worker_nodes,omitempty"`
CreatedAt time.Time `json:"created_at"`
Region string `json:"region,omitempty"`
VPCID string `json:"vpc_id,omitempty"`
}

// HealthStatus represents cluster health
Expand Down Expand Up @@ -246,3 +266,80 @@ type ErrInvalidConfiguration struct {
func (e *ErrInvalidConfiguration) Error() string {
return "invalid cluster configuration: " + e.Message
}

// NormalizeEKSStatus converts EKS-specific status to normalized ClusterStatus
func NormalizeEKSStatus(status string) ClusterStatus {
switch status {
case "ACTIVE":
return ClusterStatusReady
case "CREATING":
return ClusterStatusCreating
case "UPDATING":
return ClusterStatusUpdating
case "DELETING":
return ClusterStatusDeleting
case "FAILED":
return ClusterStatusError
case "PENDING":
return ClusterStatusCreating
default:
return ClusterStatusUnknown
}
}

// NormalizeGKEStatus converts GKE-specific status to normalized ClusterStatus
func NormalizeGKEStatus(status string) ClusterStatus {
switch status {
case "RUNNING":
return ClusterStatusReady
case "PROVISIONING":
return ClusterStatusCreating
case "RECONCILING":
return ClusterStatusUpdating
case "STOPPING":
return ClusterStatusDeleting
case "ERROR":
return ClusterStatusError
case "DEGRADED":
return ClusterStatusError
case "STATUS_UNSPECIFIED":
return ClusterStatusUnknown
default:
return ClusterStatusUnknown
}
}

// NormalizeAKSStatus converts AKS-specific status to normalized ClusterStatus
func NormalizeAKSStatus(provisioningState string) ClusterStatus {
switch provisioningState {
case "Succeeded":
return ClusterStatusReady
case "Creating":
return ClusterStatusCreating
case "Updating":
return ClusterStatusUpdating
case "Deleting":
return ClusterStatusDeleting
case "Failed":
return ClusterStatusError
case "Canceled":
return ClusterStatusError
default:
return ClusterStatusUnknown
}
}

// IsReady returns true if the cluster is in a ready state
func (s ClusterStatus) IsReady() bool {
return s == ClusterStatusReady
}

// IsTransitioning returns true if the cluster is in a transitional state
func (s ClusterStatus) IsTransitioning() bool {
return s == ClusterStatusCreating || s == ClusterStatusUpdating || s == ClusterStatusDeleting
}

// IsError returns true if the cluster is in an error state
func (s ClusterStatus) IsError() bool {
return s == ClusterStatusError
}
Loading