Skip to content

Commit

Permalink
feat: add instance template public api (#7707)
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Deng <[email protected]>
(cherry picked from commit 6e30e0b)
  • Loading branch information
YTGhost authored and free6om committed Jul 3, 2024
1 parent 2ae1ab5 commit 22ce3ff
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pkg/controller/instanceset/instance_template_util.go
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)
}

0 comments on commit 22ce3ff

Please sign in to comment.