Feat: support rollout controller for StatefulSet (#1969)

* Feat: support rollout controller for StatefulSet

* Feat: support one statefulset in rollout

* Feat: add tests for StatefulSet rollout controller

* Fix: correct workload-deleting error

* Feat: remove advanced sts
This commit is contained in:
whichxjy
2021-09-28 11:46:30 +08:00
committed by GitHub
parent 22bf2e4c3a
commit 811c783a00
8 changed files with 858 additions and 26 deletions
@@ -155,15 +155,21 @@ func PrepareWorkloadForRollout(rolloutComp string) WorkloadOption {
"kind", assembledWorkload.GetKind(), "instance name", assembledWorkload.GetName())
return nil
}
} else if assembledWorkload.GroupVersionKind().Group == appsv1.GroupName &&
assembledWorkload.GetKind() == reflect.TypeOf(appsv1.Deployment{}).Name() {
err := pv.SetBool(deploymentDisablePath, true)
if err != nil {
return err
}
if assembledWorkload.GroupVersionKind().Group == appsv1.GroupName {
switch assembledWorkload.GetKind() {
case reflect.TypeOf(appsv1.Deployment{}).Name():
if err := pv.SetBool(deploymentDisablePath, true); err != nil {
return err
}
klog.InfoS("we render a deployment assembledWorkload.paused on the first time",
"kind", assembledWorkload.GetKind(), "instance name", assembledWorkload.GetName())
return nil
case reflect.TypeOf(appsv1.StatefulSet{}).Name():
// TODO: Pause StatefulSet here.
return nil
}
klog.InfoS("we render a deployment assembledWorkload.paused on the first time",
"kind", assembledWorkload.GetKind(), "instance name", assembledWorkload.GetName())
return nil
}
klog.InfoS("we encountered an unknown resource, we don't know how to prepare it",
@@ -49,17 +49,26 @@ func RolloutWorkloadName(rolloutComp string) assemble.WorkloadOption {
// we hard code the behavior depends on the workload group/kind for now. The only in-place upgradable resources
// we support is cloneset/statefulset for now. We can easily add more later.
supportInplaceUpgrade := false
if w.GroupVersionKind().Group == v1alpha1.GroupVersion.Group {
if w.GetKind() == reflect.TypeOf(v1alpha1.CloneSet{}).Name() ||
w.GetKind() == reflect.TypeOf(v1alpha1.StatefulSet{}).Name() {
// we use the component name alone for those resources that do support in-place upgrade
klog.InfoS("we reuse the component name for resources that support in-place upgrade",
"GVK", w.GroupVersionKind(), "instance name", w.GetName())
// assemble use component name as workload name by default
// so no need to re-set name
return nil
if w.GetKind() == reflect.TypeOf(v1alpha1.CloneSet{}).Name() {
supportInplaceUpgrade = true
}
} else if w.GroupVersionKind().Group == appsv1.GroupName {
if w.GetKind() == reflect.TypeOf(appsv1.StatefulSet{}).Name() {
supportInplaceUpgrade = true
}
}
if supportInplaceUpgrade {
// we use the component name alone for those resources that do support in-place upgrade
klog.InfoS("we reuse the component name for resources that support in-place upgrade",
"GVK", w.GroupVersionKind(), "instance name", w.GetName())
// assemble use component name as workload name by default
// so no need to re-set name
return nil
}
// we assume that the rest of the resources do not support in-place upgrade
compRevName := w.GetLabels()[oam.LabelAppComponentRevision]
w.SetName(compRevName)
@@ -82,7 +91,7 @@ func HandleReplicas(ctx context.Context, rolloutComp string, c client.Client) as
// we hard code here, but we can easily support more types of workload by add more cases logic in switch
var replicasFieldPath string
switch u.GetKind() {
case reflect.TypeOf(v1alpha1.CloneSet{}).Name(), reflect.TypeOf(appsv1.Deployment{}).Name():
case reflect.TypeOf(v1alpha1.CloneSet{}).Name(), reflect.TypeOf(appsv1.Deployment{}).Name(), reflect.TypeOf(appsv1.StatefulSet{}).Name():
replicasFieldPath = "spec.replicas"
default:
klog.Errorf("rollout meet a workload we cannot support yet", "Kind", u.GetKind(), "name", u.GetName())