Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #231 from sofastack/liushuo_0.6_fix
Browse files Browse the repository at this point in the history
Liushuo 0.6 fix
  • Loading branch information
lvjing2 authored Nov 2, 2023
2 parents 865d251 + e74ff9e commit 58b9f33
Show file tree
Hide file tree
Showing 20 changed files with 533 additions and 364 deletions.
1 change: 1 addition & 0 deletions module-controller/api/v1alpha1/module_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ModuleStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=md

// Module is the Schema for the modules API
type Module struct {
Expand Down
6 changes: 5 additions & 1 deletion module-controller/api/v1alpha1/moduledeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ type ReleaseStatus struct {
// +optional
OriginalDeltaReplicas int32 `json:"originalDeltaReplicas,omitempty"`

// The phase current release reach
// The phase current whole release reach
// +optional
Progress ReleaseProgress `json:"progress,omitempty"`

// the phase current batch release reach
BatchProgress ReleaseProgress `json:"batchProgress,omitempty"`

// Last time the release transitioned from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`

Expand Down Expand Up @@ -198,6 +201,7 @@ type ModuleDeploymentStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=mddeploy

// ModuleDeployment is the Schema for the moduledeployments API
type ModuleDeployment struct {
Expand Down
1 change: 1 addition & 0 deletions module-controller/api/v1alpha1/modulereplicaset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type ModuleReplicaSetStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=mdrs

// ModuleReplicaSet is the Schema for the modulereplicasets API
type ModuleReplicaSet struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spec:
kind: ModuleDeployment
listKind: ModuleDeploymentList
plural: moduledeployments
shortNames:
- mddeploy
singular: moduledeployment
scope: Namespaced
versions:
Expand Down Expand Up @@ -224,6 +226,9 @@ spec:
type: integer
releaseStatus:
properties:
batchProgress:
description: the phase current batch release reach
type: string
currentBatch:
description: Records the current batch serial number.
format: int32
Expand All @@ -241,7 +246,7 @@ spec:
format: int32
type: integer
progress:
description: The phase current release reach
description: The phase current whole release reach
type: string
realBatchCount:
description: Records the real batch count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spec:
kind: ModuleReplicaSet
listKind: ModuleReplicaSetList
plural: modulereplicasets
shortNames:
- mdrs
singular: modulereplicaset
scope: Namespaced
versions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spec:
kind: Module
listKind: ModuleList
plural: modules
shortNames:
- md
singular: module
scope: Namespaced
versions:
Expand Down
28 changes: 14 additions & 14 deletions module-controller/internal/controller/module_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func (r *ModuleReconciler) parseModuleInstanceStatus(ctx context.Context, module
module.Status.Status = moduleInstanceStatus
module.Status.LastTransitionTime = metav1.Now()
log.Log.Info(fmt.Sprintf("%s%s", "module status change to ", moduleInstanceStatus), "moduleName", module.Name)
err := r.Status().Update(ctx, module)
err := utils.UpdateStatus(r.Client, ctx, module)
if err != nil {
return ctrl.Result{}, err
return ctrl.Result{}, utils.Error(err, "update module status failed")
}
return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (r *ModuleReconciler) cleanLabelAndFinalizer(ctx context.Context, module *v
// remove finalizer
log.Log.Info("start clean module install finalizer", "moduleName", module.Spec.Module.Name, "module", module.Name)
utils.RemoveFinalizer(&module.ObjectMeta, finalizer.AllocatePodFinalizer)
err := r.Client.Update(ctx, module)
err := utils.UpdateResource(r.Client, ctx, module)
if err != nil {
return utils.Error(err, "failed to clean module install finalizer", "moduleName", module.Spec.Module.Name, "module", module.Name)
}
Expand All @@ -268,7 +268,7 @@ func (r *ModuleReconciler) cleanLabelAndFinalizer(ctx context.Context, module *v
pod.Labels[label.ModuleInstanceCount] = strconv.Itoa(count - 1)
}
}
err = r.Client.Update(ctx, pod)
err = utils.UpdateResource(r.Client, ctx, pod)
if err != nil {
return err
}
Expand All @@ -285,9 +285,9 @@ func (r *ModuleReconciler) handlePendingModuleInstance(ctx context.Context, modu
module.Status.Status = v1alpha1.ModuleInstanceStatusPrepare
module.Status.LastTransitionTime = metav1.Now()
log.Log.Info(fmt.Sprintf("%s%s", "module status change to ", v1alpha1.ModuleInstanceStatusPrepare), "moduleName", module.Name)
err := r.Status().Update(ctx, module)
err := utils.UpdateStatus(r.Client, ctx, module)
if err != nil {
return ctrl.Result{}, err
return ctrl.Result{}, utils.Error(err, "update module status from pending to prepare failed")
}
return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -325,7 +325,7 @@ func (r *ModuleReconciler) handlePendingModuleInstance(ctx context.Context, modu
return ctrl.Result{RequeueAfter: requeueAfter}, nil
}
UpdatePodLabelBeforeInstallModule(pod, module.Spec.Module.Name)
err = r.Client.Update(ctx, &pod)
err = utils.UpdateResource(r.Client, ctx, &pod)
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -344,7 +344,7 @@ func (r *ModuleReconciler) handlePendingModuleInstance(ctx context.Context, modu
}
module.SetOwnerReferences(owner)
utils.AddFinalizer(&module.ObjectMeta, finalizer.AllocatePodFinalizer)
err = r.Client.Update(ctx, module)
err = utils.UpdateResource(r.Client, ctx, module)
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -358,9 +358,9 @@ func (r *ModuleReconciler) handlePrepareModuleInstance(ctx context.Context, modu
module.Status.Status = v1alpha1.ModuleInstanceStatusUpgrading
module.Status.LastTransitionTime = metav1.Now()
log.Log.Info(fmt.Sprintf("%s%s", "module status change to ", v1alpha1.ModuleInstanceStatusUpgrading), "moduleName", module.Name)
err := r.Status().Update(ctx, module)
err := utils.UpdateStatus(r.Client, ctx, module)
if err != nil {
return ctrl.Result{}, err
return ctrl.Result{}, utils.Error(err, "update module from prepare to upgrading failed")
}
return ctrl.Result{}, nil
}
Expand All @@ -383,9 +383,9 @@ func (r *ModuleReconciler) handleUpgradingModuleInstance(ctx context.Context, mo
module.Status.Status = v1alpha1.ModuleInstanceStatusCompleting
module.Status.LastTransitionTime = metav1.Now()
log.Log.Info(fmt.Sprintf("%s%s", "module status change to ", v1alpha1.ModuleInstanceStatusCompleting), "moduleName", module.Name)
err = r.Status().Update(ctx, module)
err = utils.UpdateStatus(r.Client, ctx, module)
if err != nil {
return ctrl.Result{}, err
return ctrl.Result{}, utils.Error(err, "update module from upgrading to completing failed")
}
return ctrl.Result{}, nil
}
Expand All @@ -397,9 +397,9 @@ func (r *ModuleReconciler) handleCompletingModuleInstance(ctx context.Context, m
module.Status.Status = v1alpha1.ModuleInstanceStatusAvailable
module.Status.LastTransitionTime = metav1.Now()
log.Log.Info(fmt.Sprintf("%s%s", "module status change to ", v1alpha1.ModuleInstanceStatusAvailable), "moduleName", module.Name)
err := r.Status().Update(ctx, module)
err := utils.UpdateStatus(r.Client, ctx, module)
if err != nil {
return ctrl.Result{}, err
return ctrl.Result{}, utils.Error(err, "update module from completing to available failed")
}
return ctrl.Result{}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

var _ = Describe("Module Controller", func() {

const timeout = time.Second * 30
const interval = time.Second * 3
moduleName := "test-module-name"
Expand Down Expand Up @@ -78,7 +79,7 @@ var _ = Describe("Module Controller", func() {
module.Labels[label.ModuleReplicasetLabel] = moduleReplicaSetName
module.Labels[label.ModuleNameLabel] = "test-module"
utils.AddFinalizer(&module.ObjectMeta, finalizer.AllocatePodFinalizer)
moduleReplicaSet := prepareModuleReplicaSet(namespaceName, moduleReplicaSetName)
moduleReplicaSet := prepareModuleReplicaSet(namespaceName, moduleReplicaSetName, "")
moduleReplicaSet.Spec.Template.Spec.Module.Url = updateModuleUrl
Expect(k8sClient.Create(context.TODO(), &moduleReplicaSet)).Should(Succeed())
Expect(k8sClient.Update(context.TODO(), &module)).Should(Succeed())
Expand Down
Loading

0 comments on commit 58b9f33

Please sign in to comment.