Skip to content

Commit

Permalink
feat(liqoctl): flag runtimeclass command create virtualnode
Browse files Browse the repository at this point in the history
  • Loading branch information
fra98 committed Jan 7, 2025
1 parent d839604 commit db8c2b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion pkg/liqo-controller-manager/offloading/forge/virtualnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func VirtualNode(name, namespace string) *offloadingv1beta1.VirtualNode {

// MutateVirtualNode mutates a VirtualNode resource.
func MutateVirtualNode(ctx context.Context, cl client.Client, virtualNode *offloadingv1beta1.VirtualNode,
remoteClusterID liqov1beta1.ClusterID, opts *VirtualNodeOptions, createNode, disableNetworkCheck *bool) error {
remoteClusterID liqov1beta1.ClusterID, opts *VirtualNodeOptions, createNode, disableNetworkCheck *bool, runtimeClassName *string) error {
// VirtualNode metadata
if virtualNode.ObjectMeta.Labels == nil {
virtualNode.ObjectMeta.Labels = make(map[string]string)
Expand Down Expand Up @@ -89,6 +89,13 @@ func MutateVirtualNode(ctx context.Context, cl client.Client, virtualNode *offlo
virtualNode.Spec.IngressClasses = opts.IngressClasses
virtualNode.Spec.LoadBalancerClasses = opts.LoadBalancerClasses

if runtimeClassName != nil && *runtimeClassName != "" {
if virtualNode.Spec.OffloadingPatch == nil {
virtualNode.Spec.OffloadingPatch = &offloadingv1beta1.OffloadingPatch{}
}
virtualNode.Spec.OffloadingPatch.RuntimeClassName = runtimeClassName
}

if len(opts.NodeSelector) > 0 {
if virtualNode.Spec.OffloadingPatch == nil {
virtualNode.Spec.OffloadingPatch = &offloadingv1beta1.OffloadingPatch{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *VirtualNodeCreatorReconciler) Reconcile(ctx context.Context, req ctrl.R
virtualNode.Spec.VkOptionsTemplateRef)

if err := forge.MutateVirtualNode(ctx, r.Client,
virtualNode, identity.Spec.ClusterID, vnOpts, nil, nil); err != nil {
virtualNode, identity.Spec.ClusterID, vnOpts, nil, nil, nil); err != nil {
return err
}
if virtualNode.Labels == nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/liqoctl/rest/virtualnode/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (o *Options) Create(ctx context.Context, options *rest.CreateOptions) *cobr
[]string{}, "The load balancer classes offered by the remote cluster. The first one will be used as default")
cmd.Flags().StringToStringVar(&o.labels, "labels", map[string]string{}, "The labels to be added to the virtual node")
cmd.Flags().StringToStringVar(&o.nodeSelector, "node-selector", map[string]string{}, "The node selector to be applied to offloaded pods")
cmd.Flags().StringVar(&o.runtimeClassName, "runtime-class-name", "", "The runtimeClass the pods should have on the target remote cluster")

runtime.Must(cmd.MarkFlagRequired("remote-cluster-id"))

Expand Down Expand Up @@ -166,7 +167,7 @@ func (o *Options) handleCreate(ctx context.Context) error {
virtualNode := forge.VirtualNode(opts.Name, tenantNamespace)
if _, err := resource.CreateOrUpdate(ctx, opts.CRClient, virtualNode, func() error {
return forge.MutateVirtualNode(ctx, opts.CRClient,
virtualNode, o.remoteClusterID.GetClusterID(), vnOpts, &o.createNode, &o.disableNetworkCheck)
virtualNode, o.remoteClusterID.GetClusterID(), vnOpts, &o.createNode, &o.disableNetworkCheck, &o.runtimeClassName)
}); err != nil {
s.Fail("Unable to create virtual node: ", output.PrettyErr(err))
return err
Expand Down Expand Up @@ -301,7 +302,7 @@ func (o *Options) output(ctx context.Context, name, namespace string, vnOpts *fo

virtualNode := forge.VirtualNode(name, namespace)
if err := forge.MutateVirtualNode(ctx, opts.CRClient,
virtualNode, o.remoteClusterID.GetClusterID(), vnOpts, &o.createNode, &o.disableNetworkCheck); err != nil {
virtualNode, o.remoteClusterID.GetClusterID(), vnOpts, &o.createNode, &o.disableNetworkCheck, &o.runtimeClassName); err != nil {
return err
}

Expand Down
1 change: 1 addition & 0 deletions pkg/liqoctl/rest/virtualnode/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Options struct {
loadBalancerClasses []string
labels map[string]string
nodeSelector map[string]string
runtimeClassName string
}

var _ rest.API = &Options{}
Expand Down

0 comments on commit db8c2b6

Please sign in to comment.