Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progressing deployment state #570

Merged
merged 10 commits into from
Sep 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion cyclops-ctrl/cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook"

"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/auth"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/handler"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/modulecontroller"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/prometheus"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/telemetry"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template/cache"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template/render"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient"

cyclopsv1alpha1 "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1"
)
Expand Down
1 change: 0 additions & 1 deletion cyclops-ctrl/internal/controller/sse/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ func (s *Server) Resources(ctx *gin.Context) {
}
}
})

}
2 changes: 1 addition & 1 deletion cyclops-ctrl/internal/controller/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/gin-gonic/gin"
json "github.com/json-iterator/go"

"github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/mapper"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/models/dto"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/telemetry"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/template"
"github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient"
)

type Templates struct {
Expand Down
6 changes: 3 additions & 3 deletions cyclops-ctrl/internal/models/dto/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Deployment struct {
Namespace string `json:"namespace"`
Replicas int `json:"replicas"`
Pods []Pod `json:"pods"`
Status bool `json:"status"`
Status string `json:"status"`
Deleted bool `json:"deleted"`
}

Expand Down Expand Up @@ -69,7 +69,7 @@ type DaemonSet struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Pods []Pod `json:"pods"`
Status bool `json:"status"`
Status string `json:"status"`
Deleted bool `json:"deleted"`
}

Expand Down Expand Up @@ -257,7 +257,7 @@ type StatefulSet struct {
Namespace string `json:"namespace"`
Replicas int `json:"replicas"`
Pods []Pod `json:"pods"`
Status bool `json:"status"`
Status string `json:"status"`
Deleted bool `json:"deleted"`
}

Expand Down
2 changes: 1 addition & 1 deletion cyclops-ctrl/internal/models/helm/helmschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Property struct {
FileExtension string `json:"fileExtension"`
Reference string `json:"$ref"`
Definitions map[string]Property `json:"$defs"`
Immutable bool `json:"immutable"`
Immutable bool `json:"immutable"`

// number validation
Minimum *float64 `json:"minimum"`
Expand Down
6 changes: 3 additions & 3 deletions cyclops-ctrl/pkg/cluster/k8sclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ func (k *KubernetesClient) mapDeployment(group, version, kind, name, namespace s
Namespace: deployment.Namespace,
Replicas: int(*deployment.Spec.Replicas),
Pods: pods,
Status: getDeploymentStatus(pods),
Status: getDeploymentStatus(deployment),
}, nil
}

Expand All @@ -655,7 +655,7 @@ func (k *KubernetesClient) mapDaemonSet(group, version, kind, name, namespace st
Name: daemonSet.Name,
Namespace: daemonSet.Namespace,
Pods: pods,
Status: getDaemonSetStatus(pods),
Status: getDaemonSetStatus(daemonSet),
}, nil
}

Expand All @@ -678,7 +678,7 @@ func (k *KubernetesClient) mapStatefulSet(group, version, kind, name, namespace
Namespace: namespace,
Replicas: int(*statefulset.Spec.Replicas),
Pods: pods,
Status: getDeploymentStatus(pods),
Status: getStatefulSetStatus(statefulset),
}, nil
}

Expand Down
103 changes: 60 additions & 43 deletions cyclops-ctrl/pkg/cluster/k8sclient/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import (
)

const (
statusUnknown = "unknown"
statusHealthy = "healthy"
statusUnhealthy = "unhealthy"
statusUnknown = "unknown"
statusHealthy = "healthy"
statusUnhealthy = "unhealthy"
statusProgressing = "progressing"
)

func (k *KubernetesClient) ListModules() ([]cyclopsv1alpha1.Module, error) {
moduleList, err := k.moduleset.Modules(cyclopsNamespace).List(metav1.ListOptions{})

return moduleList, err
}

Expand Down Expand Up @@ -241,6 +242,10 @@ func (k *KubernetesClient) GetModuleResourcesHealth(name string) (string, error)

resourcesWithHealth += len(deployments.Items)
for _, item := range deployments.Items {
if isProgressing(item.Status.Conditions) {
return statusProgressing, nil
}

if item.Generation != item.Status.ObservedGeneration ||
item.Status.Replicas != item.Status.UpdatedReplicas ||
item.Status.UnavailableReplicas != 0 {
Expand Down Expand Up @@ -370,13 +375,7 @@ func (k *KubernetesClient) getResourceStatus(o unstructured.Unstructured) (strin
return statusUnknown, err
}

if deployment.Generation == deployment.Status.ObservedGeneration &&
deployment.Status.Replicas == deployment.Status.UpdatedReplicas &&
deployment.Status.UnavailableReplicas == 0 {
return statusHealthy, nil
}

return statusUnhealthy, nil
return getDeploymentStatus(deployment), nil
}

if isStatefulSet(o.GroupVersionKind().Group, o.GroupVersionKind().Version, o.GetKind()) {
Expand All @@ -385,13 +384,7 @@ func (k *KubernetesClient) getResourceStatus(o unstructured.Unstructured) (strin
return statusUnknown, err
}

if statefulset.Generation == statefulset.Status.ObservedGeneration &&
statefulset.Status.Replicas == statefulset.Status.UpdatedReplicas &&
statefulset.Status.Replicas == statefulset.Status.AvailableReplicas {
return statusHealthy, nil
}

return statusUnhealthy, nil
return getStatefulSetStatus(statefulset), nil
}

if isDaemonSet(o.GroupVersionKind().Group, o.GroupVersionKind().Version, o.GetKind()) {
Expand All @@ -400,13 +393,7 @@ func (k *KubernetesClient) getResourceStatus(o unstructured.Unstructured) (strin
return statusUnknown, err
}

if daemonset.Generation == daemonset.Status.ObservedGeneration &&
daemonset.Status.UpdatedNumberScheduled == daemonset.Status.DesiredNumberScheduled &&
daemonset.Status.NumberUnavailable == 0 {
return statusHealthy, nil
}

return statusUnhealthy, nil
return getDaemonSetStatus(daemonset), nil
}

if isPersistentVolumeClaims(o.GroupVersionKind().Group, o.GroupVersionKind().Version, o.GetKind()) {
Expand Down Expand Up @@ -769,32 +756,38 @@ func containerStatus(status apiv1.ContainerStatus) dto.ContainerStatus {
}
}

func getDeploymentStatus(pods []dto.Pod) bool {
for _, pod := range pods {
for _, container := range pod.Containers {
if !container.Status.Running {
return false
}
}
func getDeploymentStatus(deployment *appsv1.Deployment) string {
if isProgressing(deployment.Status.Conditions) {
return statusProgressing
}

return true
if deployment.Generation == deployment.Status.ObservedGeneration &&
deployment.Status.Replicas == deployment.Status.UpdatedReplicas &&
deployment.Status.UnavailableReplicas == 0 {
return statusHealthy
}

return statusUnhealthy
}

func getDaemonSetStatus(pods []dto.Pod) bool {
if len(pods) == 0 {
return false
func getStatefulSetStatus(statefulset *appsv1.StatefulSet) string {
if statefulset.Generation == statefulset.Status.ObservedGeneration &&
statefulset.Status.Replicas == statefulset.Status.UpdatedReplicas &&
statefulset.Status.Replicas == statefulset.Status.AvailableReplicas {
return statusHealthy
}

for _, pod := range pods {
for _, container := range pod.Containers {
if !container.Status.Running {
return false
}
}
return statusUnhealthy
}

func getDaemonSetStatus(daemonset *appsv1.DaemonSet) string {
if daemonset.Generation == daemonset.Status.ObservedGeneration &&
daemonset.Status.UpdatedNumberScheduled == daemonset.Status.DesiredNumberScheduled &&
daemonset.Status.NumberUnavailable == 0 {
return statusHealthy
}

return true
return statusUnhealthy
}

func getPodStatus(containers []dto.Container) bool {
Expand All @@ -806,3 +799,27 @@ func getPodStatus(containers []dto.Container) bool {

return true
}

func isProgressing(conditions []appsv1.DeploymentCondition) bool {
progressingReason := ""
availableReason := ""

for _, condition := range conditions {
if condition.Type == appsv1.DeploymentProgressing {
if condition.Status == "False" {
return false
}

progressingReason = condition.Reason
}

if condition.Type == appsv1.DeploymentAvailable {
availableReason = condition.Reason
}
}

return availableReason == "MinimumReplicasAvailable" &&
(progressingReason == "NewReplicaSetCreated" ||
progressingReason == "FoundNewReplicaSet" ||
progressingReason == "ReplicaSetUpdated")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button, notification } from "antd";
import axios from "axios";
import React from "react";
import { mapResponseError } from "../../../utils/api/errors";
import { UndoOutlined } from "@ant-design/icons";

interface Props {
group: string;
Expand Down Expand Up @@ -51,6 +52,7 @@ export const RestartButton = ({
handleRestart(group, version, kind, name, namespace);
}}
>
<UndoOutlined />
Restart
</Button>
);
Expand Down
Loading
Loading