Skip to content

Commit

Permalink
chore: remove clusterDefName from synthesized component (#8488)
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf authored Nov 21, 2024
1 parent 33bb8c8 commit 16cc9f3
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 104 deletions.
3 changes: 0 additions & 3 deletions pkg/controller/component/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,4 @@ type SynthesizedComponent struct {
MinReadySeconds int32 `json:"minReadySeconds,omitempty"`
DisableExporter *bool `json:"disableExporter,omitempty"`
Stop *bool

// TODO(xingran): The following fields will be deprecated after KubeBlocks version 0.8.0
ClusterDefName string `json:"clusterDefName,omitempty"` // the name of the clusterDefinition
}
5 changes: 2 additions & 3 deletions pkg/controller/configuration/config_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ single_thread_memory = 294912
},
}
component = &ctrlcomp.SynthesizedComponent{
ClusterDefName: "mysql-three-node-definition",
Name: "replicasets",
Replicas: 5,
Name: "replicasets",
Replicas: 5,
VolumeClaimTemplates: []corev1.PersistentVolumeClaimTemplate{
{
ObjectMeta: metav1.ObjectMeta{
Expand Down
52 changes: 0 additions & 52 deletions pkg/controller/factory/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ import (

corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"

appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
appsv1beta1 "github.com/apecloud/kubeblocks/apis/apps/v1beta1"
dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
"github.com/apecloud/kubeblocks/pkg/common"
cfgcm "github.com/apecloud/kubeblocks/pkg/configuration/config_manager"
Expand All @@ -40,7 +38,6 @@ import (
"github.com/apecloud/kubeblocks/pkg/controller/component"
"github.com/apecloud/kubeblocks/pkg/controller/instanceset"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
dptypes "github.com/apecloud/kubeblocks/pkg/dataprotection/types"
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)

Expand Down Expand Up @@ -231,55 +228,6 @@ func GetRestoreSystemAccountPassword(annotations map[string]string, componentNam
return password
}

func BuildPVC(cluster *appsv1.Cluster,
synthesizedComp *component.SynthesizedComponent,
vct *corev1.PersistentVolumeClaimTemplate,
pvcKey types.NamespacedName,
templateName,
snapshotName string) *corev1.PersistentVolumeClaim {
pvcBuilder := builder.NewPVCBuilder(pvcKey.Namespace, pvcKey.Name).
AddLabelsInMap(constant.GetCompLabels(cluster.Name, synthesizedComp.Name)).
AddLabelsInMap(synthesizedComp.DynamicLabels).
AddLabels(constant.VolumeClaimTemplateNameLabelKey, vct.Name).
AddLabelsInMap(synthesizedComp.StaticLabels).
AddAnnotationsInMap(synthesizedComp.DynamicAnnotations).
AddAnnotationsInMap(synthesizedComp.StaticAnnotations).
SetAccessModes(vct.Spec.AccessModes).
SetResources(vct.Spec.Resources)
if vct.Spec.StorageClassName != nil {
pvcBuilder.SetStorageClass(*vct.Spec.StorageClassName)
}
if len(snapshotName) > 0 {
apiGroup := "snapshot.storage.k8s.io"
pvcBuilder.SetDataSource(corev1.TypedLocalObjectReference{
APIGroup: &apiGroup,
Kind: "VolumeSnapshot",
Name: snapshotName,
})
}
pvc := pvcBuilder.GetObject()
BuildPersistentVolumeClaimLabels(synthesizedComp, pvc, vct.Name, templateName)
return pvc
}

func BuildBackup(cluster *appsv1.Cluster,
synthesizedComp *component.SynthesizedComponent,
backupPolicyName string,
backupKey types.NamespacedName,
backupMethod string) *dpv1alpha1.Backup {
return builder.NewBackupBuilder(backupKey.Namespace, backupKey.Name).
AddLabels(dptypes.BackupMethodLabelKey, backupMethod).
AddLabels(dptypes.BackupPolicyLabelKey, backupPolicyName).
AddLabels(constant.AppManagedByLabelKey, constant.AppName).
AddLabels(constant.AppNameLabelKey, synthesizedComp.ClusterDefName).
AddLabels(constant.AppInstanceLabelKey, cluster.Name).
AddLabels(constant.AppManagedByLabelKey, constant.AppName).
AddLabels(constant.KBAppComponentLabelKey, synthesizedComp.Name).
SetBackupPolicyName(backupPolicyName).
SetBackupMethod(backupMethod).
GetObject()
}

func BuildConfigMapWithTemplate(cluster *appsv1.Cluster,
synthesizedComp *component.SynthesizedComponent,
configs map[string]string,
Expand Down
46 changes: 0 additions & 46 deletions pkg/controller/factory/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -76,25 +75,6 @@ var _ = Describe("builder", func() {
return clusterObj, compDefObj, key
}

newItsObj := func() *workloads.InstanceSet {
container := corev1.Container{
Name: "mysql",
VolumeMounts: []corev1.VolumeMount{{
Name: "mysql-config",
MountPath: "/mnt/config",
}},
}
return testapps.NewInstanceSetFactory(testCtx.DefaultNamespace, "mock-its", clusterName, mysqlCompName).
AddAppNameLabel("mock-app").
AddAppInstanceLabel(clusterName).
AddAppComponentLabel(mysqlCompName).
SetReplicas(1).AddContainer(container).
AddVolumeClaimTemplate(corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{Name: testapps.DataVolumeName},
Spec: testapps.NewPVC("1Gi"),
}).GetObject()
}

newAllFieldsSynthesizedComponent := func(compDef *appsv1.ComponentDefinition, cluster *appsv1.Cluster) *component.SynthesizedComponent {
By("assign every available fields")
comp, err := component.BuildComponent(cluster, &cluster.Spec.ComponentSpecs[0], nil, nil)
Expand All @@ -117,21 +97,6 @@ var _ = Describe("builder", func() {
}

Context("has helper function which builds specific object from cue template", func() {
It("builds PVC correctly", func() {
snapshotName := "test-snapshot-name"
its := newItsObj()
_, cluster, synthesizedComponent := newClusterObjs(nil)
pvcKey := types.NamespacedName{
Namespace: "default",
Name: "data-mysql-01-replicasets-0",
}
pvc := BuildPVC(cluster, synthesizedComponent, &synthesizedComponent.VolumeClaimTemplates[0], pvcKey, "", snapshotName)
Expect(pvc).ShouldNot(BeNil())
Expect(pvc.Spec.AccessModes).Should(Equal(its.Spec.VolumeClaimTemplates[0].Spec.AccessModes))
Expect(pvc.Spec.Resources).Should(Equal(synthesizedComponent.VolumeClaimTemplates[0].Spec.Resources))
Expect(pvc.Spec.StorageClassName).Should(Equal(synthesizedComponent.VolumeClaimTemplates[0].Spec.StorageClassName))
})

It("builds InstanceSet correctly", func() {
compDef, cluster, synthesizedComponent := newClusterObjs(nil)

Expand Down Expand Up @@ -166,17 +131,6 @@ var _ = Describe("builder", func() {
Expect(*its.Spec.MemberUpdateStrategy).Should(BeEquivalentTo(workloads.BestEffortParallelUpdateStrategy))
})

It("builds BackupJob correctly", func() {
_, cluster, synthesizedComponent := newClusterObjs(nil)
backupJobKey := types.NamespacedName{
Namespace: "default",
Name: "test-backup-job",
}
backupPolicyName := "test-backup-policy"
backupJob := BuildBackup(cluster, synthesizedComponent, backupPolicyName, backupJobKey, "snapshot")
Expect(backupJob).ShouldNot(BeNil())
})

It("builds ConfigMap with template correctly", func() {
config := map[string]string{}
_, cluster, synthesizedComponent := newClusterObjs(nil)
Expand Down

0 comments on commit 16cc9f3

Please sign in to comment.