Skip to content

Commit

Permalink
chore: rename param rsm/sts to its (#7139)
Browse files Browse the repository at this point in the history
  • Loading branch information
free6om authored Apr 23, 2024
1 parent 773ca0c commit 7daf78a
Show file tree
Hide file tree
Showing 24 changed files with 146 additions and 163 deletions.
1 change: 0 additions & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func init() {
viper.SetDefault(constant.CfgHostPortConfigMapName, "kubeblocks-host-ports")
viper.SetDefault(constant.CfgHostPortIncludeRanges, "1025-65536")
viper.SetDefault(constant.CfgHostPortExcludeRanges, "6443,10250,10257,10259,2379-2380,30000-32767")
viper.SetDefault(constant.FeatureGateReplicatedStateMachine, true)
viper.SetDefault(constant.KBDataScriptClientsImage, "apecloud/kubeblocks-datascript:latest")
viper.SetDefault(constant.KubernetesClusterDomainEnv, constant.DefaultDNSDomain)
viper.SetDefault(instanceset.MaxPlainRevisionCount, 1024)
Expand Down
12 changes: 1 addition & 11 deletions controllers/apps/cluster_status_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"time"

"golang.org/x/exp/slices"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -131,19 +130,10 @@ func getEventInvolvedObject(ctx context.Context, cli client.Client, event *corev
var err error
// If client.object interface object is used as a parameter, it will not return an error when the object is not found.
// so we should specify the object type to get the object.
switch event.InvolvedObject.Kind {
case constant.PodKind:
if event.InvolvedObject.Kind == constant.PodKind {
pod := &corev1.Pod{}
err = cli.Get(ctx, objectKey, pod, inDataContextUnspecified4C())
return pod, err
case constant.StatefulSetKind:
sts := &appsv1.StatefulSet{}
err = cli.Get(ctx, objectKey, sts, inDataContextUnspecified4C())
return sts, err
case constant.DeploymentKind:
deployment := &appsv1.Deployment{}
err = cli.Get(ctx, objectKey, deployment, inDataContextUnspecified4C())
return deployment, err
}
return nil, err
}
Expand Down
26 changes: 13 additions & 13 deletions controllers/apps/component_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,13 @@ var _ = Describe("Component Controller", func() {
clusterDefName := cluster.Spec.ClusterDefRef
componentName := cluster.Spec.ComponentSpecs[0].Name
clusterName := cluster.Name
stsName := cluster.Name + "-" + componentName
itsName := cluster.Name + "-" + componentName
pods := make([]corev1.Pod, 0)
replicasStr := strconv.Itoa(number)
for i := 0; i < number; i++ {
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: stsName + "-" + strconv.Itoa(i),
Name: itsName + "-" + strconv.Itoa(i),
Namespace: testCtx.DefaultNamespace,
Labels: map[string]string{
constant.AppManagedByLabelKey: constant.AppName,
Expand Down Expand Up @@ -524,8 +524,8 @@ var _ = Describe("Component Controller", func() {
By(fmt.Sprintf("Changing replicas to %d", updatedReplicas))
changeCompReplicas(clusterKey, int32(updatedReplicas), comp)

checkUpdatedStsReplicas := func() {
By("Checking updated sts replicas")
checkUpdatedItsReplicas := func() {
By("Checking updated its replicas")
Eventually(func() int32 {
itsList := testk8s.ListAndCheckInstanceSetWithComponent(&testCtx, clusterKey, comp.Name)
return *itsList.Items[0].Spec.Replicas
Expand Down Expand Up @@ -596,9 +596,9 @@ var _ = Describe("Component Controller", func() {
Eventually(testapps.List(&testCtx, generics.RestoreSignature, ml, client.InNamespace(clusterKey.Namespace))).Should(HaveLen(0))
}

checkUpdatedStsReplicas()
checkUpdatedItsReplicas()

By("Checking updated sts replicas' PVC and size")
By("Checking updated its replicas' PVC and size")
for _, vct := range comp.VolumeClaimTemplates {
var volumeQuantity resource.Quantity
for i := 0; i < updatedReplicas; i++ {
Expand Down Expand Up @@ -636,7 +636,7 @@ var _ = Describe("Component Controller", func() {
return
}

checkUpdatedStsReplicas()
checkUpdatedItsReplicas()

By("Checking pvcs deleting")
Eventually(func(g Gomega) {
Expand Down Expand Up @@ -866,7 +866,7 @@ var _ = Describe("Component Controller", func() {
}
}

By("mock pods/sts of component are available")
By("mock pods of component are available")
mockPods := testapps.MockInstanceSetPods(&testCtx, its, clusterObj.Name, compName)
Expect(testapps.ChangeObjStatus(&testCtx, its, func() {
testk8s.MockInstanceSetReady(its, mockPods...)
Expand Down Expand Up @@ -1749,7 +1749,7 @@ var _ = Describe("Component Controller", func() {
g.Expect(followerCount).Should(Equal(2))
}).Should(Succeed())

// trigger its to reconcile as the underlying sts is not created
// trigger its to reconcile as the underlying its is not created
Expect(testapps.GetAndChangeObj(&testCtx, client.ObjectKeyFromObject(its), func(its *workloads.InstanceSet) {
its.Annotations["time"] = time.Now().Format(time.RFC3339)
})()).Should(Succeed())
Expand Down Expand Up @@ -1844,7 +1844,7 @@ var _ = Describe("Component Controller", func() {

itsList := testk8s.ListAndCheckInstanceSet(&testCtx, clusterKey)
its := &itsList.Items[0]
By("mock pod/sts are available and wait for component enter running phase")
By("mock pod are available and wait for component enter running phase")
mockPods := testapps.MockInstanceSetPods(&testCtx, its, clusterObj.Name, compName)
Expect(testapps.ChangeObjStatus(&testCtx, its, func() {
testk8s.MockInstanceSetReady(its, mockPods...)
Expand Down Expand Up @@ -1966,11 +1966,11 @@ var _ = Describe("Component Controller", func() {
checkWorkloadGenerationAndToolsImage := func(assertion func(any, ...any) AsyncAssertion,
workloadGenerationExpected int64, oldImageCntExpected, newImageCntExpected int) {
assertion(func(g Gomega) {
sts := underlyingWorkload()
g.Expect(sts.Generation).Should(Equal(workloadGenerationExpected))
its := underlyingWorkload()
g.Expect(its.Generation).Should(Equal(workloadGenerationExpected))
oldImageCnt := 0
newImageCnt := 0
for _, c := range sts.Spec.Template.Spec.Containers {
for _, c := range its.Spec.Template.Spec.Containers {
if c.Image == oldToolsImage {
oldImageCnt += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var _ = Describe("Reconfigure RollingPolicy", func() {
Context("statefulSet rolling reconfigure policy test", func() {
It("Should success without error", func() {

// for mock sts
// for mock its
var pods []corev1.Pod
{
mockParam.Component.WorkloadType = appsv1alpha1.Stateful
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/opsrequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ var _ = Describe("OpsRequest Controller", func() {
By("Waiting for the cluster enters creating phase")
Eventually(testapps.GetClusterPhase(&testCtx, clusterKey)).Should(Equal(appsv1alpha1.CreatingClusterPhase))

By("mock pod/sts are available and wait for cluster enter running phase")
By("mock pods are available and wait for cluster enter running phase")
podName := fmt.Sprintf("%s-%s-0", clusterObj.Name, mysqlCompName)
pod := testapps.MockInstanceSetPod(&testCtx, nil, clusterObj.Name, mysqlCompName,
podName, "leader", "ReadWrite")
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/transformer_cluster_deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (t *clusterDeletionTransformer) Transform(ctx graph.TransformContext, dag *
delObjs = append(delObjs, toDeleteObjs(nonNamespacedObjs)...)

for _, o := range delObjs {
// skip the objects owned by the component and rsm controller
// skip the objects owned by the component and InstanceSet controller
if shouldSkipObjOwnedByComp(o, *cluster) || isOwnedByInstanceSet(o) {
continue
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/k8score/event_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ var _ = Describe("Event Controller", func() {
Eventually(testapps.CheckObjExists(&testCtx, client.ObjectKeyFromObject(clusterObj), &appsv1alpha1.Cluster{}, true)).Should(Succeed())

itsName := fmt.Sprintf("%s-%s", clusterObj.Name, consensusCompName)
rsm := testapps.NewInstanceSetFactory(clusterObj.Namespace, itsName, clusterObj.Name, consensusCompName).
its := testapps.NewInstanceSetFactory(clusterObj.Namespace, itsName, clusterObj.Name, consensusCompName).
SetReplicas(int32(3)).
AddContainer(corev1.Container{Name: testapps.DefaultMySQLContainerName, Image: testapps.ApeCloudMySQLImage}).
Create(&testCtx).GetObject()
Expect(testapps.GetAndChangeObj(&testCtx, client.ObjectKeyFromObject(rsm), func(tmpRSM *workloads.InstanceSet) {
tmpRSM.Spec.Roles = []workloads.ReplicaRole{
Expect(testapps.GetAndChangeObj(&testCtx, client.ObjectKeyFromObject(its), func(tmpITS *workloads.InstanceSet) {
tmpITS.Spec.Roles = []workloads.ReplicaRole{
{
Name: "leader",
IsLeader: true,
Expand Down
2 changes: 1 addition & 1 deletion controllers/k8score/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ type EventHandler interface {
var EventHandlerMap = map[string]EventHandler{}

func init() {
EventHandlerMap["rsm-event-handler"] = &instanceset.PodRoleEventHandler{}
EventHandlerMap["its-event-handler"] = &instanceset.PodRoleEventHandler{}
}
2 changes: 1 addition & 1 deletion deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ image:
##
replicaCount: 1

## MaxConcurrentReconciles for component, rsm and opsRequest controllers.
## MaxConcurrentReconciles for component, instanceSet and opsRequest controllers.
##
reconcileWorkers: ""

Expand Down
1 change: 0 additions & 1 deletion pkg/configuration/core/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func GenerateConstraintsUniqLabelKeyWithConfig(configKey string) string {
// GetInstanceCMName {{statefulset.Name}}-{{clusterVersion.Name}}-{{tpl.Name}}-"config"
func GetInstanceCMName(obj client.Object, tpl *appsv1alpha1.ComponentTemplateSpec) string {
return getInstanceCfgCMName(obj.GetName(), tpl.Name)
// return fmt.Sprintf("%s-%s-config", sts.GetName(), tpl.VolumeName)
}

// getInstanceCfgCMName configmap generation rule for configuration file.
Expand Down
4 changes: 0 additions & 4 deletions pkg/constant/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ const (
AccountPasswdForSecret = "password"
)

const (
FeatureGateReplicatedStateMachine = "REPLICATED_STATE_MACHINE" // enable rsm
)

const (
KubernetesClusterDomainEnv = "KUBERNETES_CLUSTER_DOMAIN"
DefaultDNSDomain = "cluster.local"
Expand Down
4 changes: 2 additions & 2 deletions pkg/constant/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func GenerateWorkloadNamePattern(clusterName, compName string) string {
}

// GenerateServiceNamePattern generates the service name pattern
func GenerateServiceNamePattern(rsmName string) string {
return fmt.Sprintf("%s-headless", rsmName)
func GenerateServiceNamePattern(itsName string) string {
return fmt.Sprintf("%s-headless", itsName)
}

// GeneratePodName generates the connection credential name for component.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/factory/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func BuildInstanceSet(synthesizedComp *component.SynthesizedComponent, component
return nil, err
}

// update sts.spec.volumeClaimTemplates[].metadata.labels
// update its.spec.volumeClaimTemplates[].metadata.labels
// TODO(xingran): synthesizedComp.VolumeTypes has been removed, and the following code needs to be refactored.
if len(itsObj.Spec.VolumeClaimTemplates) > 0 && len(itsObj.GetLabels()) > 0 {
for index, vct := range itsObj.Spec.VolumeClaimTemplates {
Expand Down Expand Up @@ -206,7 +206,7 @@ func setDefaultResourceLimits(its *workloads.InstanceSet) {
}
}

// BuildPersistentVolumeClaimLabels builds a pvc name label, and synchronize the labels from sts to pvc.
// BuildPersistentVolumeClaimLabels builds a pvc name label, and synchronize the labels from component to pvc.
func BuildPersistentVolumeClaimLabels(component *component.SynthesizedComponent, pvc *corev1.PersistentVolumeClaim,
pvcTplName string) {
// strict args checking.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/factory/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var _ = Describe("builder", func() {
MountPath: "/mnt/config",
}},
}
return testapps.NewInstanceSetFactory(testCtx.DefaultNamespace, "mock-sts", clusterName, mysqlCompName).
return testapps.NewInstanceSetFactory(testCtx.DefaultNamespace, "mock-its", clusterName, mysqlCompName).
AddAppNameLabel("mock-app").
AddAppInstanceLabel(clusterName).
AddAppComponentLabel(mysqlCompName).
Expand Down
Loading

0 comments on commit 7daf78a

Please sign in to comment.