Skip to content

Commit e5ec6dd

Browse files
committed
Include workload pool specs in chart values
It's useful for any virtual cluster chart to be able to create objects based on the workload pool specs, which aren't otherwise processed by the controller. This only really makes sense in the context of #248 (which made the vcluster chart a subchart, leaving room for the _parent_ chart to have its own templates).
1 parent af3a975 commit e5ec6dd

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

pkg/provisioners/helmapplications/virtualcluster/provisioner.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package virtualcluster
1919
import (
2020
"context"
2121
"crypto/sha256"
22+
"errors"
2223
"fmt"
2324

2425
"github.com/prometheus/client_golang/prometheus"
@@ -43,6 +44,10 @@ var (
4344
})
4445
)
4546

47+
var (
48+
errNoVKCInContext = errors.New("no VirtualKubernetesCluster in context")
49+
)
50+
4651
//nolint:gochecknoinits
4752
func init() {
4853
metrics.Registry.MustRegister(durationMetric)
@@ -84,7 +89,13 @@ func (p *Provisioner) Values(ctx context.Context, version unikornv1core.Semantic
8489
// and the cost is "what you use", we'll need to worry about billing, so it may
8590
// be prudent to add organization, project and cluster labels to pods.
8691
// We use SNI to demutiplex at the ingress to the correct vcluster instance.
87-
hostname := p.ReleaseName(ctx) + "." + p.domain
92+
vkc, ok := application.FromContext(ctx).(*unikornv1.VirtualKubernetesCluster)
93+
if !ok {
94+
return nil, errNoVKCInContext
95+
}
96+
97+
releaseName := p.ReleaseName(ctx)
98+
hostname := releaseName + "." + p.domain
8899

89100
// Allow users to actually hit the cluster.
90101
ingress := map[string]any{
@@ -185,7 +196,21 @@ func (p *Provisioner) Values(ctx context.Context, version unikornv1core.Semantic
185196
"policies": policies,
186197
"sync": sync,
187198
"exportKubeConfig": kubeConfig,
199+
"workloadPools": workloadPoolsAsValues(vkc),
188200
}
189201

190202
return values, nil
191203
}
204+
205+
func workloadPoolsAsValues(vkc *unikornv1.VirtualKubernetesCluster) []any {
206+
pools := make([]any, len(vkc.Spec.WorkloadPools))
207+
for i, pool := range vkc.Spec.WorkloadPools {
208+
pools[i] = map[string]any{
209+
"name": pool.Name,
210+
"replicas": pool.Replicas,
211+
"flavorId": pool.FlavorID,
212+
}
213+
}
214+
215+
return pools
216+
}

0 commit comments

Comments
 (0)