Skip to content

Commit

Permalink
update phase names (#99)
Browse files Browse the repository at this point in the history
* fix, update phase names

* fix, chage label prepare and complete
  • Loading branch information
shaofan-hs authored Sep 27, 2023
1 parent dcfcfa7 commit f33fdc7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions apis/apps/v1alpha1/well_known_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ const (

PodPreCheckLabelPrefix = "pre-check.podopslifecycle.kusionstack.io" // indicate a pod is in pre-check phase
PodPreCheckedLabelPrefix = "pre-checked.podopslifecycle.kusionstack.io" // indicate a pod has finished pre-check phase
PodPrepareLabelPrefix = "prepare.podopslifecycle.kusionstack.io" // indicate a pod is in prepare phase
PodPreparingLabelPrefix = "preparing.podopslifecycle.kusionstack.io" // indicate a pod is preparing for operation
PodOperateLabelPrefix = "operate.podopslifecycle.kusionstack.io" // indicate a pod is in operate phase
PodOperatedLabelPrefix = "operated.podopslifecycle.kusionstack.io" // indicate a pod has finished operate phase
PodPostCheckLabelPrefix = "post-check.podopslifecycle.kusionstack.io" // indicate a pod is in post-check phase
PodPostCheckedLabelPrefix = "post-checked.podopslifecycle.kusionstack.io" // indicate a pod has finished post-check phase
PodCompleteLabelPrefix = "complete.podopslifecycle.kusionstack.io" // indicate a pod has finished all phases
PodCompletingLabelPrefix = "completing.podopslifecycle.kusionstack.io" // indicate a pod is completing operation

PodServiceAvailableLabel = "podopslifecycle.kusionstack.io/service-available" // indicate a pod is available to serve
PodDeletionIndicationLabelKey = "podopslifecycle.kusionstack.io/to-delete" // users can use this label to indicate a pod to delete
Expand All @@ -47,6 +47,6 @@ const (

var (
WellKnownLabelPrefixesWithID = []string{PodOperatingLabelPrefix, PodOperationTypeLabelPrefix, PodPreCheckLabelPrefix, PodPreCheckedLabelPrefix,
PodPrepareLabelPrefix, PodDoneOperationTypeLabelPrefix, PodUndoOperationTypeLabelPrefix, PodOperateLabelPrefix, PodOperatedLabelPrefix, PodPostCheckLabelPrefix,
PodPostCheckedLabelPrefix, PodCompleteLabelPrefix}
PodPreparingLabelPrefix, PodDoneOperationTypeLabelPrefix, PodUndoOperationTypeLabelPrefix, PodOperateLabelPrefix, PodOperatedLabelPrefix, PodPostCheckLabelPrefix,
PodPostCheckedLabelPrefix, PodCompletingLabelPrefix}
)
4 changes: 2 additions & 2 deletions apis/apps/v1alpha1/well_known_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ const (

// well known variables
const (
PodOpsLifecyclePreTrafficOffStage = "PreTrafficOff"
PodOpsLifecyclePreTrafficOnStage = "PreTrafficOn"
PodOpsLifecyclePreCheckStage = "PreCheck"
PodOpsLifecyclePostCheckStage = "PostCheck"
)
20 changes: 10 additions & 10 deletions pkg/controllers/podopslifecycle/podopslifecycle_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
var labels map[string]string
if state.InStageAndPassed() {
switch state.Stage {
case v1alpha1.PodOpsLifecyclePreTrafficOffStage:
labels, err = r.preTrafficOffStage(pod, idToLabelsMap)
case v1alpha1.PodOpsLifecyclePreTrafficOnStage:
labels, err = r.preTrafficOnStage(pod, idToLabelsMap)
case v1alpha1.PodOpsLifecyclePreCheckStage:
labels, err = r.preCheckStage(pod, idToLabelsMap)
case v1alpha1.PodOpsLifecyclePostCheckStage:
labels, err = r.postCheckStage(pod, idToLabelsMap)
}
}
if err != nil {
Expand All @@ -163,8 +163,8 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
}

expected := map[string]bool{
v1alpha1.PodPrepareLabelPrefix: false, // set readiness gate to false, traffic off
v1alpha1.PodCompleteLabelPrefix: true, // set readiness gate to true, traffic on
v1alpha1.PodPreparingLabelPrefix: false, // set readiness gate to false, traffic off
v1alpha1.PodCompletingLabelPrefix: true, // set readiness gate to true, traffic on
}
for _, labels := range idToLabelsMap {
for k, v := range expected {
Expand Down Expand Up @@ -286,7 +286,7 @@ func (r *ReconcilePodOpsLifecycle) setServiceReadiness(pod *corev1.Pod, isReady
return true, fmt.Sprintf("update service readiness gate to: %s", string(status))
}

func (r *ReconcilePodOpsLifecycle) preTrafficOffStage(pod *corev1.Pod, idToLabelsMap map[string]map[string]string) (labels map[string]string, err error) {
func (r *ReconcilePodOpsLifecycle) preCheckStage(pod *corev1.Pod, idToLabelsMap map[string]map[string]string) (labels map[string]string, err error) {
labels = map[string]string{}
currentTime := strconv.FormatInt(time.Now().Unix(), 10)
for k, v := range idToLabelsMap {
Expand All @@ -309,7 +309,7 @@ func (r *ReconcilePodOpsLifecycle) preTrafficOffStage(pod *corev1.Pod, idToLabel
return
}

func (r *ReconcilePodOpsLifecycle) preTrafficOnStage(pod *corev1.Pod, idToLabelsMap map[string]map[string]string) (labels map[string]string, err error) {
func (r *ReconcilePodOpsLifecycle) postCheckStage(pod *corev1.Pod, idToLabelsMap map[string]map[string]string) (labels map[string]string, err error) {
labels = map[string]string{}
currentTime := strconv.FormatInt(time.Now().Unix(), 10)
for k := range idToLabelsMap {
Expand Down Expand Up @@ -353,11 +353,11 @@ func (r *ReconcilePodOpsLifecycle) addLabels(ctx context.Context, pod *corev1.Po
}

func (r *ReconcilePodOpsLifecycle) initPodTransitionRuleManager() {
r.podTransitionRuleManager.RegisterStage(v1alpha1.PodOpsLifecyclePreTrafficOffStage, func(po client.Object) bool {
r.podTransitionRuleManager.RegisterStage(v1alpha1.PodOpsLifecyclePreCheckStage, func(po client.Object) bool {
labels := po.GetLabels()
return labels != nil && labelHasPrefix(labels, v1alpha1.PodPreCheckLabelPrefix)
})
r.podTransitionRuleManager.RegisterStage(v1alpha1.PodOpsLifecyclePreTrafficOnStage, func(po client.Object) bool {
r.podTransitionRuleManager.RegisterStage(v1alpha1.PodOpsLifecyclePostCheckStage, func(po client.Object) bool {
labels := po.GetLabels()
return labels != nil && labelHasPrefix(labels, v1alpha1.PodPostCheckLabelPrefix)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var _ = Describe("podopslifecycle controller", func() {
Labels: map[string]string{
v1alpha1.ControlledByKusionStackLabelKey: "true",
fmt.Sprintf("%s/%s", v1alpha1.PodOperatingLabelPrefix, id): timestamp,
fmt.Sprintf("%s/%s", v1alpha1.PodPrepareLabelPrefix, id): timestamp,
fmt.Sprintf("%s/%s", v1alpha1.PodPreparingLabelPrefix, id): timestamp,
},
},
Spec: podSpec,
Expand Down Expand Up @@ -205,9 +205,9 @@ var _ = Describe("podopslifecycle controller", func() {
Name: "test",
Namespace: "default",
Labels: map[string]string{
v1alpha1.ControlledByKusionStackLabelKey: "true",
fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, id): timestamp,
fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, id): timestamp,
v1alpha1.ControlledByKusionStackLabelKey: "true",
fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, id): timestamp,
fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, id): timestamp,
},
},
Spec: podSpec,
Expand Down Expand Up @@ -264,9 +264,9 @@ var _ = Describe("podopslifecycle controller", func() {
Expect(err).NotTo(HaveOccurred())

pod.ObjectMeta.Labels = map[string]string{
v1alpha1.ControlledByKusionStackLabelKey: "true",
fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, id): timestamp,
fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, id): timestamp,
v1alpha1.ControlledByKusionStackLabelKey: "true",
fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, id): timestamp,
fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, id): timestamp,
}
err = mgr.GetClient().Update(context.Background(), pod)
Expect(err).NotTo(HaveOccurred())
Expand Down
16 changes: 8 additions & 8 deletions pkg/webhook/server/generic/pod/opslifecycle/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
v1alpha1.PodOperationTypeLabelPrefix,
v1alpha1.PodPreCheckLabelPrefix,
v1alpha1.PodPreCheckedLabelPrefix,
v1alpha1.PodPrepareLabelPrefix,
v1alpha1.PodPreparingLabelPrefix,
v1alpha1.PodOperateLabelPrefix} {

delete(newPod.Labels, fmt.Sprintf("%s/%s", v, id))
Expand All @@ -76,16 +76,16 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
operatingCount++

if _, ok := labels[v1alpha1.PodPreCheckedLabelPrefix]; ok { // pre-checked
_, hasPrepare := labels[v1alpha1.PodPrepareLabelPrefix]
_, hasPrepare := labels[v1alpha1.PodPreparingLabelPrefix]
_, hasOperate := labels[v1alpha1.PodOperateLabelPrefix]

if !hasPrepare && !hasOperate {
delete(newPod.Labels, v1alpha1.PodServiceAvailableLabel)

lc.addLabelWithTime(newPod, fmt.Sprintf("%s/%s", v1alpha1.PodPrepareLabelPrefix, id)) // prepare
lc.addLabelWithTime(newPod, fmt.Sprintf("%s/%s", v1alpha1.PodPreparingLabelPrefix, id)) // prepare
} else if !hasOperate {
if ready, _ := lc.readyToUpgrade(newPod); ready {
delete(newPod.Labels, fmt.Sprintf("%s/%s", v1alpha1.PodPrepareLabelPrefix, id))
delete(newPod.Labels, fmt.Sprintf("%s/%s", v1alpha1.PodPreparingLabelPrefix, id))

lc.addLabelWithTime(newPod, fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, id)) // operate
}
Expand All @@ -98,8 +98,8 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
}

if _, ok := labels[v1alpha1.PodPostCheckedLabelPrefix]; ok { // post-checked
if _, ok := labels[v1alpha1.PodCompleteLabelPrefix]; !ok {
lc.addLabelWithTime(newPod, fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, id)) // complete
if _, ok := labels[v1alpha1.PodCompletingLabelPrefix]; !ok {
lc.addLabelWithTime(newPod, fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, id)) // complete
}
}

Expand All @@ -109,7 +109,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
if _, ok := labels[v1alpha1.PodOperatedLabelPrefix]; ok {
operatedCount++
}
if _, ok := labels[v1alpha1.PodCompleteLabelPrefix]; ok { // complete
if _, ok := labels[v1alpha1.PodCompletingLabelPrefix]; ok { // complete
completeCount++
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
v1alpha1.PodDoneOperationTypeLabelPrefix,
v1alpha1.PodPostCheckLabelPrefix,
v1alpha1.PodPostCheckedLabelPrefix,
v1alpha1.PodCompleteLabelPrefix} {
v1alpha1.PodCompletingLabelPrefix} {

delete(newPod.Labels, fmt.Sprintf("%s/%s", v, id))
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/webhook/server/generic/pod/opslifecycle/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func TestMutating(t *testing.T) {
fmt.Sprintf("%s/%s", v1alpha1.PodPreCheckedLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodOperationPermissionLabelPrefix, "upgrade"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodPrepareLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPreparingLabelPrefix, "123"): "1402144848",
},

readyToUpgrade: readyToUpgradeReturnFalse,
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestMutating(t *testing.T) {
fmt.Sprintf("%s/%s", v1alpha1.PodPreCheckedLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodOperationPermissionLabelPrefix, "replace"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodPrepareLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPreparingLabelPrefix, "456"): "1402144848",
},
readyToUpgrade: readyToUpgradeReturnFalse,
},
Expand All @@ -246,7 +246,7 @@ func TestMutating(t *testing.T) {
fmt.Sprintf("%s/%s", v1alpha1.PodPreCheckedLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodOperationPermissionLabelPrefix, "upgrade"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodPrepareLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPreparingLabelPrefix, "123"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodOperatingLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodOperationTypeLabelPrefix, "456"): "replace",
Expand All @@ -273,7 +273,7 @@ func TestMutating(t *testing.T) {
fmt.Sprintf("%s/%s", v1alpha1.PodPreCheckedLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodOperationPermissionLabelPrefix, "upgrade"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodPrepareLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPreparingLabelPrefix, "123"): "1402144848",
},
},

Expand Down Expand Up @@ -371,15 +371,15 @@ func TestMutating(t *testing.T) {
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckedLabelPrefix, "123"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, "123"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodOperatedLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodDoneOperationTypeLabelPrefix, "456"): "upgrade",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckedLabelPrefix, "456"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, "456"): "1402144848",
},
},

Expand All @@ -391,15 +391,15 @@ func TestMutating(t *testing.T) {
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckedLabelPrefix, "123"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, "123"): "1402144848",
},
expectedLabels: map[string]string{
fmt.Sprintf("%s/%s", v1alpha1.PodOperatedLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodDoneOperationTypeLabelPrefix, "123"): "upgrade",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckedLabelPrefix, "123"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, "123"): "1402144848",
},
},

Expand All @@ -412,15 +412,15 @@ func TestMutating(t *testing.T) {
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckedLabelPrefix, "123"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, "123"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, "123"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodOperatedLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodDoneOperationTypeLabelPrefix, "456"): "upgrade",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodPostCheckedLabelPrefix, "456"): "1402144848",

fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, "456"): "1402144848",
fmt.Sprintf("%s/%s", v1alpha1.PodCompletingLabelPrefix, "456"): "1402144848",
},
expectedLabels: map[string]string{},
},
Expand Down

0 comments on commit f33fdc7

Please sign in to comment.