Skip to content

Commit

Permalink
feat(kollama): added two new options
Browse files Browse the repository at this point in the history
Signed-off-by: Neko Ayaka <[email protected]>
  • Loading branch information
nekomeowww committed Apr 20, 2024
1 parent fc8d464 commit 9615b42
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
31 changes: 25 additions & 6 deletions internal/cli/kollama/cmd_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ type CmdDeployOptions struct {
dynamicClient dynamic.Interface
discoveryClient discovery.DiscoveryInterface

modelImage string
expose bool
serviceType string
serviceName string
nodePort int32
modelImage string
expose bool
serviceType string
serviceName string
nodePort int32
storageClass string
pvAccessMode string

genericiooptions.IOStreams
}
Expand Down Expand Up @@ -140,19 +142,36 @@ func NewCmdDeploy(streams genericiooptions.IOStreams) *cobra.Command {
"image name (will be pulled from registry.ollama.ai/library/<model name> by "+
"default if no registry is specified), the tag will be latest.",
)

cmd.Flags().StringVarP(&o.storageClass, "storage-class", "", "", ""+
"Storage class to use for the model's persistent volume claim. If not specified, "+
"the default storage class will be used.",
)

cmd.Flags().StringVarP(&o.pvAccessMode, "pv-access-mode", "", "", ""+
"Access mode for the model's persistent volume for image store StatefulSet. If not "+
"specified, the access mode will be ReadWriteOnce. If you are deploying models "+
"into default deployed kind and k3s clusters, you should keep it as ReadWriteOnce. "+
"If you are deploying models into a custom cluster, you can set it to ReadWriteMany "+
"if storage class supports it.",
)

cmd.Flags().BoolVar(&o.expose, "expose", false, ""+
"Whether to expose the model through a service for external access and makes it "+
"easy to interact with the model. By default, --expose will create a NodePort "+
"service. Use --expose=LoadBalancer to create a LoadBalancer service",
)

cmd.Flags().StringVar(&o.serviceType, "service-type", "", ""+
"Type of the service to expose the model. If not specified, the service will be "+
"exposed as NodePort. Use LoadBalancer to expose the service as LoadBalancer.",
)

cmd.Flags().StringVar(&o.serviceName, "service-name", "", ""+
"Name of the service to expose the model. If not specified, the model name will "+
"be used as the service name with -nodeport as the suffix for NodePort.",
)

cmd.Flags().Int32Var(&o.nodePort, "node-port", 0, ""+
"NodePort to expose the model. If not specified, a random port will be assigned."+
"Only valid when --expose is set to true, and --service-type is set to NodePort.",
Expand Down Expand Up @@ -203,7 +222,7 @@ func (o *CmdDeployOptions) runE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}

createdModel, err := createOllamaModel(ctx, o.dynamicClient, namespace, modelName, modelImage)
createdModel, err := createOllamaModel(ctx, o.dynamicClient, namespace, modelName, modelImage, o.storageClass, o.pvAccessMode)
if err != nil {
return err
}
Expand Down
19 changes: 18 additions & 1 deletion internal/cli/kollama/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/samber/lo"
"github.com/spf13/cobra"

ollamav1 "github.com/nekomeowww/ollama-operator/api/ollama/v1"
Expand Down Expand Up @@ -131,7 +132,15 @@ func getImage(cmd *cobra.Command, args []string) (string, error) {
return modelImage, nil
}

func createOllamaModel(ctx context.Context, dynamicClient dynamic.Interface, namespace string, name string, image string) (*ollamav1.Model, error) {
func createOllamaModel(
ctx context.Context,
dynamicClient dynamic.Interface,
namespace string,
name string,
image string,
storageClass string,
pvAccessMode string,
) (*ollamav1.Model, error) {
model := &ollamav1.Model{
TypeMeta: metav1.TypeMeta{
APIVersion: schemaGroupVersion.String(),
Expand All @@ -147,6 +156,14 @@ func createOllamaModel(ctx context.Context, dynamicClient dynamic.Interface, nam
Image: image,
},
}
if storageClass != "" {
model.Spec.StorageClassName = lo.ToPtr(storageClass)
}
if pvAccessMode != "" {
model.Spec.PersistentVolume = &ollamav1.ModelPersistentVolumeSpec{
AccessMode: lo.ToPtr(corev1.PersistentVolumeAccessMode(pvAccessMode)),
}
}

unstructuredObj, err := Unstructured(model)
if err != nil {
Expand Down

0 comments on commit 9615b42

Please sign in to comment.