-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add instance template public api (#7707)
Signed-off-by: Liang Deng <[email protected]> (cherry picked from commit 6e30e0b)
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package instanceset | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1alpha1" | ||
) | ||
|
||
// TODO: remove these after extract the Schema of the API types from Kubeblocks into a separate Go package. | ||
|
||
// InstanceSetExt serves as a Public Struct, | ||
// used as the type for the input parameters of BuildInstanceTemplateExts. | ||
type InstanceSetExt struct { | ||
Its *workloads.InstanceSet | ||
InstanceTemplates []*workloads.InstanceTemplate | ||
} | ||
|
||
// InstanceTemplateExt serves as a Public Struct, | ||
// used as the type for the construction results returned by BuildInstanceTemplateExts. | ||
type InstanceTemplateExt struct { | ||
Name string | ||
Replicas int32 | ||
corev1.PodTemplateSpec | ||
VolumeClaimTemplates []corev1.PersistentVolumeClaim | ||
} | ||
|
||
// BuildInstanceTemplateExts serves as a Public API, through which users can obtain InstanceTemplateExt objects | ||
// processed by the buildInstanceTemplateExts function. | ||
// Its main purpose is to acquire the PodTemplate rendered by InstanceTemplate. | ||
func BuildInstanceTemplateExts(itsExt *InstanceSetExt) []*InstanceTemplateExt { | ||
itsExts := buildInstanceTemplateExts(&instanceSetExt{ | ||
its: itsExt.Its, | ||
instanceTemplates: itsExt.InstanceTemplates, | ||
}) | ||
var instanceTemplateExts []*InstanceTemplateExt | ||
for _, itsExt := range itsExts { | ||
instanceTemplateExts = append(instanceTemplateExts, (*InstanceTemplateExt)(itsExt)) | ||
} | ||
return instanceTemplateExts | ||
} | ||
|
||
// BuildInstanceTemplates serves as a Public API, allowing users to construct InstanceTemplates. | ||
// The constructed InstanceTemplates can be used as part of the input for BuildInstanceTemplateExts. | ||
func BuildInstanceTemplates(totalReplicas int32, instances []workloads.InstanceTemplate, instancesCompressed *corev1.ConfigMap) []*workloads.InstanceTemplate { | ||
return buildInstanceTemplates(totalReplicas, instances, instancesCompressed) | ||
} |