Skip to content

Commit

Permalink
Feat: add workload status to rollout status (openkruise#145)
Browse files Browse the repository at this point in the history
Signed-off-by: machine3 <[email protected]>
  • Loading branch information
machine3 committed Jul 5, 2023
1 parent f25f8a5 commit 1fdc44b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
18 changes: 18 additions & 0 deletions api/v1alpha1/rollout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ type RolloutStatus struct {

// observedGeneration is the most recent generation observed for this Rollout.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// WorkloadStatus describes the state of the workload.
// +optional
WorkloadStatus *WorkloadStatus `json:"workloadStatus,omitempty"`
// Canary describes the state of the canary rollout
// +optional
CanaryStatus *CanaryStatus `json:"canaryStatus,omitempty"`
Expand Down Expand Up @@ -259,6 +262,21 @@ const (
TerminatingReasonCompleted = "Completed"
)

type WorkloadStatus struct {
// WorkloadState is the state of the workload.
WorkloadState WorkloadState `json:"workloadState,omitempty"`
// Replicas is the number of desired replicas.
Replicas int32 `json:"replicas,omitempty"`
}

type WorkloadState string

const (
WorkloadStateNormal WorkloadState = "Normal"
WorkloadStateIgnore WorkloadState = "Ignore"
WorkloadStateNotFound WorkloadState = "NotFound"
)

// CanaryStatus status fields that only pertain to the canary rollout
type CanaryStatus struct {
// observedWorkloadGeneration is the most recent generation observed for this Rollout ref workload generation.
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions config/crd/bases/rollouts.kruise.io_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ spec:
description: BlueGreenStatus *BlueGreenStatus `json:"blueGreenStatus,omitempty"`
Phase is the rollout phase.
type: string
workloadStatus:
description: WorkloadStatus describes the state of the workload.
properties:
replicas:
description: Replicas is the number of desired replicas.
format: int32
type: integer
workloadState:
description: WorkloadState is the state of the workload.
type: string
type: object
type: object
type: object
served: true
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/rollout/rollout_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r
ObservedGeneration: rollout.Generation,
Phase: v1alpha1.RolloutPhaseInitial,
Message: "Workload Not Found",
WorkloadStatus: &v1alpha1.WorkloadStatus{
WorkloadState: v1alpha1.WorkloadStateNotFound,
},
}
klog.Infof("rollout(%s/%s) workload not found, and reset status be Initial", rollout.Namespace, rollout.Name)
return false, newStatus, nil
Expand All @@ -72,6 +75,13 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r
return true, nil, nil
}

// update workload status
if newStatus.WorkloadStatus == nil {
newStatus.WorkloadStatus = &v1alpha1.WorkloadStatus{}
}
newStatus.WorkloadStatus.WorkloadState = v1alpha1.WorkloadStateNormal
newStatus.WorkloadStatus.Replicas = workload.Replicas

// update workload generation to canaryStatus.ObservedWorkloadGeneration
// rollout is a target ref bypass, so there needs to be a field to identify the rollout execution process or results,
// which version of deployment is targeted, ObservedWorkloadGeneration that is to compare with the workload generation
Expand Down

0 comments on commit 1fdc44b

Please sign in to comment.