Skip to content

Commit

Permalink
Merge branch 'main' into support/remove-rsm-to-its-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
free6om committed Oct 8, 2024
2 parents 94f0b79 + 5dfe1c5 commit ffd3735
Show file tree
Hide file tree
Showing 51 changed files with 199 additions and 383 deletions.
33 changes: 20 additions & 13 deletions apis/operations/v1alpha1/opsrequest_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
"strings"

"github.com/pkg/errors"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -75,15 +75,15 @@ func (r *OpsRequest) Validate(ctx context.Context,
cluster *appsv1.Cluster,
needCheckClusterPhase bool) error {
if needCheckClusterPhase {
if err := r.validateClusterPhase(cluster); err != nil {
if err := r.ValidateClusterPhase(cluster); err != nil {
return err
}
}
return r.validateOps(ctx, k8sClient, cluster)
return r.ValidateOps(ctx, k8sClient, cluster)
}

// validateClusterPhase validates whether the current cluster state supports the OpsRequest
func (r *OpsRequest) validateClusterPhase(cluster *appsv1.Cluster) error {
// ValidateClusterPhase validates whether the current cluster state supports the OpsRequest
func (r *OpsRequest) ValidateClusterPhase(cluster *appsv1.Cluster) error {
opsBehaviour := OpsRequestBehaviourMapper[r.Spec.Type]
// if the OpsType has no cluster phases, ignore it
if len(opsBehaviour.FromClusterPhases) == 0 {
Expand All @@ -95,29 +95,36 @@ func (r *OpsRequest) validateClusterPhase(cluster *appsv1.Cluster) error {
// validate whether existing the same type OpsRequest
var (
opsRequestValue string
opsRecorder []OpsRecorder
opsRecorders []OpsRecorder
ok bool
)
if opsRequestValue, ok = cluster.Annotations[opsRequestAnnotationKey]; ok {
// opsRequest annotation value in cluster to map
if err := json.Unmarshal([]byte(opsRequestValue), &opsRecorder); err != nil {
if err := json.Unmarshal([]byte(opsRequestValue), &opsRecorders); err != nil {
return err
}
}
// check if the opsRequest can be executed in the current cluster.
if slices.Contains(opsBehaviour.FromClusterPhases, cluster.Status.Phase) {
return nil
}
var opsRecord *OpsRecorder
for _, v := range opsRecorders {
if v.Name == r.Name {
opsRecord = &v
break
}
}
// check if this opsRequest needs to verify cluster phase before opsRequest starts running.
needCheck := len(opsRecorder) == 0 || (opsRecorder[0].Name == r.Name && opsRecorder[0].InQueue)
if !needCheck {
return nil
needCheck := len(opsRecorders) == 0 || (opsRecord != nil && !opsRecord.InQueue)
if needCheck {
return fmt.Errorf("OpsRequest.spec.type=%s is forbidden when Cluster.status.phase=%s", r.Spec.Type, cluster.Status.Phase)
}
return fmt.Errorf("OpsRequest.spec.type=%s is forbidden when Cluster.status.phase=%s", r.Spec.Type, cluster.Status.Phase)
return nil
}

// validateOps validates ops attributes
func (r *OpsRequest) validateOps(ctx context.Context,
// ValidateOps validates ops attributes
func (r *OpsRequest) ValidateOps(ctx context.Context,
k8sClient client.Client,
cluster *appsv1.Cluster) error {
// Check whether the corresponding attribute is legal according to the operation type
Expand Down
1 change: 0 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func init() {
viper.SetDefault(constant.CfgKBReconcileWorkers, 8)
viper.SetDefault(constant.FeatureGateIgnoreConfigTemplateDefaultMode, false)
viper.SetDefault(constant.FeatureGateInPlacePodVerticalScaling, false)
viper.SetDefault(constant.FeatureGateNoRSMEnv, false)
}

type flagName string
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ package apps
import (
"encoding/json"
"fmt"
"slices"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/sethvargo/go-password/password"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/cluster_status_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package apps

import (
"fmt"
"slices"

"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/clusterdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ package apps
import (
"context"
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/componentdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"fmt"
"hash/fnv"
"reflect"
"slices"
"strings"

"github.com/pkg/errors"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down
6 changes: 3 additions & 3 deletions controllers/apps/configuration/reconfigure_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ func (param *reconfigureParams) maxRollingReplicas() int32 {
if isPercentage {
r = int32(math.Floor(float64(v) * float64(replicas) / 100))
} else {
r = util.Safe2Int32(util.Min(v, param.getTargetReplicas()))
r = util.Safe2Int32(min(v, param.getTargetReplicas()))
}
return util.Max(r, defaultRolling)
return max(r, defaultRolling)
}

func (param *reconfigureParams) getTargetReplicas() int {
Expand All @@ -195,7 +195,7 @@ func (param *reconfigureParams) getTargetReplicas() int {

func (param *reconfigureParams) podMinReadySeconds() int32 {
minReadySeconds := param.SynthesizedComponent.MinReadySeconds
return util.Max(minReadySeconds, viper.GetInt32(constant.PodMinReadySecondsEnv))
return max(minReadySeconds, viper.GetInt32(constant.PodMinReadySecondsEnv))
}

func RegisterPolicy(policy appsv1alpha1.UpgradePolicy, action reconfigurePolicy) {
Expand Down
3 changes: 1 addition & 2 deletions controllers/apps/configuration/rolling_upgrade_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1alpha1 "github.com/apecloud/kubeblocks/apis/apps/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/configuration/util"
"github.com/apecloud/kubeblocks/pkg/constant"
podutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
Expand Down Expand Up @@ -151,7 +150,7 @@ func markDynamicCursor(pods []corev1.Pod, podsStats *componentPodStats, configKe
podsStats.updated[pod.Name] = pod
}

podWindows.begin = util.Max[int](podWindows.end-int(rollingReplicas), 0)
podWindows.begin = max(podWindows.end-int(rollingReplicas), 0)
for i := podWindows.begin; i < podWindows.end; i++ {
pod := &pods[i]
if podutil.IsMatchConfigVersion(pod, configKey, currentVersion) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/transformer_cluster_backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ package apps
import (
"encoding/json"
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/gengo/examples/set-gen/sets"
Expand Down
12 changes: 7 additions & 5 deletions controllers/apps/transformer_cluster_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package apps

import (
"slices"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -113,8 +115,8 @@ var _ = Describe("cluster service transformer test", func() {
graphCli := transCtx.Client.(model.GraphClient)
objs := graphCli.FindAll(dag, &corev1.Service{})
Expect(len(objs)).Should(Equal(len(reader.objs)))
slices.SortFunc(objs, func(a, b client.Object) bool {
return a.GetName() < b.GetName()
slices.SortFunc(objs, func(a, b client.Object) int {
return strings.Compare(a.GetName(), b.GetName())
})
for i := 0; i < len(reader.objs); i++ {
svc := objs[i].(*corev1.Service)
Expand Down Expand Up @@ -149,8 +151,8 @@ var _ = Describe("cluster service transformer test", func() {

for i := 0; i < len(transCtx.Cluster.Spec.Services); i++ {
svc := objs[i].(*corev1.Service)
slices.SortFunc(svc.Spec.Ports, func(a, b corev1.ServicePort) bool { return a.Name < b.Name })
slices.SortFunc(expectedPorts, func(a, b corev1.ServicePort) bool { return a.Name < b.Name })
slices.SortFunc(svc.Spec.Ports, func(a, b corev1.ServicePort) int { return strings.Compare(a.Name, b.Name) })
slices.SortFunc(expectedPorts, func(a, b corev1.ServicePort) int { return strings.Compare(a.Name, b.Name) })
Expect(svc.Spec.Ports).Should(Equal(expectedPorts))
Expect(graphCli.IsAction(dag, svc, model.ActionUpdatePtr())).Should(BeTrue())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package apps

import (
"slices"
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
15 changes: 8 additions & 7 deletions controllers/apps/transformer_component_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ package apps

import (
"fmt"
"slices"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -133,8 +134,8 @@ var _ = Describe(" component service transformer test", func() {
graphCli := transCtx.Client.(model.GraphClient)
objs := graphCli.FindAll(dag, &corev1.Service{})
Expect(len(objs)).Should(Equal(int(transCtx.SynthesizeComponent.Replicas)))
slices.SortFunc(objs, func(a, b client.Object) bool {
return a.GetName() < b.GetName()
slices.SortFunc(objs, func(a, b client.Object) int {
return strings.Compare(a.GetName(), b.GetName())
})
for i := int32(0); i < transCtx.SynthesizeComponent.Replicas; i++ {
svc := objs[i].(*corev1.Service)
Expand All @@ -160,8 +161,8 @@ var _ = Describe(" component service transformer test", func() {
graphCli := transCtx.Client.(model.GraphClient)
objs := graphCli.FindAll(dag, &corev1.Service{})
Expect(len(objs)).Should(Equal(int(transCtx.SynthesizeComponent.Replicas)))
slices.SortFunc(objs, func(a, b client.Object) bool {
return a.GetName() < b.GetName()
slices.SortFunc(objs, func(a, b client.Object) int {
return strings.Compare(a.GetName(), b.GetName())
})
for i := int32(0); i < transCtx.SynthesizeComponent.Replicas; i++ {
svc := objs[i].(*corev1.Service)
Expand All @@ -188,8 +189,8 @@ var _ = Describe(" component service transformer test", func() {
graphCli := transCtx.Client.(model.GraphClient)
objs := graphCli.FindAll(dag, &corev1.Service{})
Expect(len(objs)).Should(Equal(int(replicas)))
slices.SortFunc(objs, func(a, b client.Object) bool {
return a.GetName() < b.GetName()
slices.SortFunc(objs, func(a, b client.Object) int {
return strings.Compare(a.GetName(), b.GetName())
})
for i := int32(0); i < replicas; i++ {
svc := objs[i].(*corev1.Service)
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/transformer_component_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"errors"
"fmt"
"reflect"
"slices"
"strings"

"github.com/spf13/viper"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down
6 changes: 3 additions & 3 deletions controllers/dataprotection/log_collection_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ package dataprotection
import (
"context"
"fmt"
"slices"
"strings"

"github.com/spf13/viper"
"golang.org/x/exp/slices"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -136,8 +136,8 @@ func (r *LogCollectionReconciler) collectErrorLogs(reqCtx intctrlutil.RequestCtx
return "", nil
}
// sort pod with oldest creation place front
slices.SortFunc(podList.Items, func(a, b corev1.Pod) bool {
return !b.CreationTimestamp.Before(&(a.CreationTimestamp))
slices.SortFunc(podList.Items, func(a, b corev1.Pod) int {
return b.CreationTimestamp.Compare(a.CreationTimestamp.Time)
})
oldestPod := podList.Items[0]
clientset, err := corev1client.NewForConfig(r.RestConfig)
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/volumepopulator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ package dataprotection
import (
"context"
"fmt"
"slices"
"strings"

vsv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
"golang.org/x/exp/slices"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package experimental

import (
"slices"
"time"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down
2 changes: 1 addition & 1 deletion controllers/experimental/reconciler_update_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package experimental

import (
"fmt"
"slices"
"strings"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
6 changes: 3 additions & 3 deletions controllers/extensions/addon_controller_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
"strings"
"time"

"github.com/Masterminds/semver/v3"
ctrlerihandler "github.com/authzed/controller-idioms/handler"
"golang.org/x/exp/slices"
v1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -1101,8 +1101,8 @@ func logFailedJobPodToCondError(ctx context.Context, stageCtx *stageCtx, addon *
}

// sort pod with latest creation place front
slices.SortFunc(podList.Items, func(a, b corev1.Pod) bool {
return b.CreationTimestamp.Before(&(a.CreationTimestamp))
slices.SortFunc(podList.Items, func(a, b corev1.Pod) int {
return b.CreationTimestamp.Compare(a.CreationTimestamp.Time)
})

podsloop:
Expand Down
2 changes: 1 addition & 1 deletion controllers/operations/opsrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"context"
"math"
"reflect"
"slices"
"strings"
"time"

"golang.org/x/exp/slices"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion controllers/operations/opsrequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ package operations
import (
"fmt"
"reflect"
"slices"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

snapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down
Loading

0 comments on commit ffd3735

Please sign in to comment.