Skip to content

Include workload pool specs in chart values #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/provisioners/helmapplications/virtualcluster/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package virtualcluster
import (
"context"
"crypto/sha256"
"errors"
"fmt"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -44,6 +45,10 @@ var (
})
)

var (
errNoVKCInContext = errors.New("no VirtualKubernetesCluster in context")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is a type assertion error rather than it being totally missing... 😄 Hmm, I wonder why this isn't error checked like everything else. I'm in core are the moment, may even add in some generic magic to do the assert for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's true. It's also possible that it's missing, and one error could cover both those cases, since the outcome is the same. There's a few dynamically-scoped variables like this, which must be present for correct operation. It might even be better to have a generically-typed context wrapper, something like:

type ProvisionerContext[T client.Object] struct {
  Subject T
  context.Context
}

but, then you have to make sure any context.WithCancel does the right thing (which you can, if you type all the context arguments accurately), ... faff.

)

//nolint:gochecknoinits
func init() {
metrics.Registry.MustRegister(durationMetric)
Expand Down Expand Up @@ -116,6 +121,11 @@ func (p *Provisioner) Values(ctx context.Context, version unikornv1core.Semantic
// and the cost is "what you use", we'll need to worry about billing, so it may
// be prudent to add organization, project and cluster labels to pods.
// We use SNI to demutiplex at the ingress to the correct vcluster instance.
vkc, ok := application.FromContext(ctx).(*unikornv1.VirtualKubernetesCluster)
if !ok {
return nil, errNoVKCInContext
}

releaseName := p.ReleaseName(ctx)
hostname := releaseName + "." + p.Options.Domain

Expand Down Expand Up @@ -193,7 +203,21 @@ func (p *Provisioner) Values(ctx context.Context, version unikornv1core.Semantic
"exportKubeConfig": kubeConfig,
"sync": sync,
},
"workloadPools": workloadPoolsAsValues(vkc),
}

return values, nil
}

func workloadPoolsAsValues(vkc *unikornv1.VirtualKubernetesCluster) []any {
pools := make([]any, len(vkc.Spec.WorkloadPools))
for i, pool := range vkc.Spec.WorkloadPools {
pools[i] = map[string]any{
"name": pool.Name,
"replicas": pool.Replicas,
"flavorId": pool.FlavorID,
}
}

return pools
}
Loading