Skip to content

Commit

Permalink
feat(kollama): implemented resource limit for kollama cli
Browse files Browse the repository at this point in the history
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
  • Loading branch information
nekomeowww committed Apr 25, 2024
1 parent c464635 commit ed35340
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion internal/cli/kollama/cmd_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -227,10 +228,21 @@ func (o *CmdDeployOptions) runE(cmd *cobra.Command, args []string) error {
os.Exit(1)
}

var resourceRequirements corev1.ResourceRequirements

for _, limit := range o.resourceLimits {
parts := strings.Split(limit, "=")
if len(parts) != 2 {
return fmt.Errorf("invalid resource limit format: %s", limit)
}

resourceRequirements.Limits[corev1.ResourceName(parts[0])] = resource.MustParse(parts[1])
}

createdModelCtx, createdModelCancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer createdModelCancel()

createdModel, err := createOllamaModel(createdModelCtx, o.dynamicClient, namespace, modelName, modelImage, o.storageClass, o.pvAccessMode)
createdModel, err := createOllamaModel(createdModelCtx, o.dynamicClient, namespace, modelName, modelImage, resourceRequirements, o.storageClass, o.pvAccessMode)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion internal/cli/kollama/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func createOllamaModel(
namespace string,
name string,
image string,
resources corev1.ResourceRequirements,
storageClass string,
pvAccessMode string,
) (*ollamav1.Model, error) {
Expand All @@ -176,7 +177,8 @@ func createOllamaModel(
},
},
Spec: ollamav1.ModelSpec{
Image: image,
Image: image,
Resources: resources,
},
}
if storageClass != "" {
Expand Down

0 comments on commit ed35340

Please sign in to comment.