MCPcopy
hub / github.com/apecloud/kubeblocks / BuildInstanceSet

Function BuildInstanceSet

pkg/controller/factory/builder.go:48–107  ·  view source on GitHub ↗

BuildInstanceSet builds an InstanceSet object from SynthesizedComponent.

(synthesizedComp *component.SynthesizedComponent, componentDef *kbappsv1.ComponentDefinition)

Source from the content-addressed store, hash-verified

46
47// BuildInstanceSet builds an InstanceSet object from SynthesizedComponent.
48func BuildInstanceSet(synthesizedComp *component.SynthesizedComponent, componentDef *kbappsv1.ComponentDefinition) (*workloads.InstanceSet, error) {
49 var (
50 compDefName = synthesizedComp.CompDefName
51 namespace = synthesizedComp.Namespace
52 clusterName = synthesizedComp.ClusterName
53 compName = synthesizedComp.Name
54 )
55
56 itsName := constant.GenerateWorkloadNamePattern(clusterName, compName)
57 itsBuilder := builder.NewInstanceSetBuilder(namespace, itsName).
58 // priority: static < dynamic < built-in
59 AddLabelsInMap(synthesizedComp.StaticLabels).
60 AddLabelsInMap(synthesizedComp.DynamicLabels).
61 AddLabelsInMap(constant.GetCompLabels(clusterName, compName)).
62 AddAnnotations(constant.KubeBlocksGenerationKey, synthesizedComp.Generation).
63 AddAnnotations(constant.CRDAPIVersionAnnotationKey, workloads.GroupVersion.String()).
64 AddAnnotationsInMap(map[string]string{
65 constant.AppComponentLabelKey: compDefName,
66 constant.KBAppServiceVersionKey: synthesizedComp.ServiceVersion,
67 }).
68 AddAnnotationsInMap(synthesizedComp.StaticAnnotations).
69 AddAnnotationsInMap(getMonitorAnnotations(synthesizedComp, componentDef)).
70 SetTemplate(getTemplate(synthesizedComp)).
71 SetSelectorMatchLabel(constant.GetCompLabels(clusterName, compName)).
72 SetReplicas(synthesizedComp.Replicas).
73 SetVolumeClaimTemplates(defaultVolumeClaimTemplates(synthesizedComp)...).
74 SetPVCRetentionPolicy(&synthesizedComp.PVCRetentionPolicy).
75 SetMinReadySeconds(synthesizedComp.MinReadySeconds).
76 SetInstances(getInstanceTemplates(synthesizedComp)).
77 SetOfflineInstances(synthesizedComp.OfflineInstances).
78 SetRoles(synthesizedComp.Roles).
79 SetPodManagementPolicy(getPodManagementPolicy(synthesizedComp)).
80 SetParallelPodManagementConcurrency(getParallelPodManagementConcurrency(synthesizedComp)).
81 SetPodUpdatePolicy(synthesizedComp.PodUpdatePolicy).
82 SetPodUpgradePolicy(synthesizedComp.PodUpgradePolicy).
83 SetInstanceUpdateStrategy(getInstanceUpdateStrategy(synthesizedComp)).
84 SetMemberUpdateStrategy(getMemberUpdateStrategy(synthesizedComp)).
85 SetLifecycleActions(synthesizedComp.LifecycleActions).
86 SetTemplateVars(synthesizedComp.TemplateVars)
87
88 if common.IsCompactMode(synthesizedComp.Annotations) {
89 itsBuilder.AddAnnotations(constant.FeatureReconciliationInCompactModeAnnotationKey,
90 synthesizedComp.Annotations[constant.FeatureReconciliationInCompactModeAnnotationKey])
91 }
92
93 itsObj := itsBuilder.GetObject()
94
95 // update its.spec.volumeClaimTemplates[].metadata.labels
96 // TODO(xingran): synthesizedComp.VolumeTypes has been removed, and the following code needs to be refactored.
97 if len(itsObj.Spec.VolumeClaimTemplates) > 0 && len(itsObj.GetLabels()) > 0 {
98 for index, vct := range itsObj.Spec.VolumeClaimTemplates {
99 BuildPersistentVolumeClaimLabels(synthesizedComp, &vct, vct.Name, "")
100 itsObj.Spec.VolumeClaimTemplates[index] = vct
101 }
102 }
103
104 setDefaultResourceLimits(itsObj)
105

Callers 3

TransformMethod · 0.92
builder_test.goFile · 0.85

Calls 15

NewInstanceSetBuilderFunction · 0.92
GetCompLabelsFunction · 0.92
IsCompactModeFunction · 0.92
getMonitorAnnotationsFunction · 0.85
getTemplateFunction · 0.85
getPodManagementPolicyFunction · 0.85
setDefaultResourceLimitsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…