Skip to content

Commit

Permalink
fix(ollama-operator): align labels
Browse files Browse the repository at this point in the history
Signed-off-by: Neko Ayaka <[email protected]>
  • Loading branch information
nekomeowww committed Apr 25, 2024
1 parent 3a31e6c commit b541d40
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 34 deletions.
13 changes: 6 additions & 7 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { text } from 'stream/consumers'
import { defineConfig } from 'vitepress'
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'

Expand Down Expand Up @@ -101,9 +100,9 @@ export default defineConfig({
{
text: 'Getting started',
items: [
{ text: '1. Install Ollama Operator', link: '/pages/en/guide/getting-started/' },
{ text: '2. Deploy models through CLI', link: '/pages/en/guide/getting-started/cli' },
{ text: '3. Deploy models through CRD', link: '/pages/en/guide/getting-started/crd' },
{ text: 'Install Ollama Operator', link: '/pages/en/guide/getting-started/' },
{ text: 'Deploy models through CLI', link: '/pages/en/guide/getting-started/cli' },
{ text: 'Deploy models through CRD', link: '/pages/en/guide/getting-started/crd' },
]
},
{ text: 'Supported models', link: '/pages/en/guide/supported-models' },
Expand Down Expand Up @@ -192,9 +191,9 @@ export default defineConfig({
{
text: '快速上手',
items: [
{ text: '1. 安装 Ollama Operator', link: '/pages/zh-CN/guide/getting-started/' },
{ text: '2. 通过 CLI 部署模型', link: '/pages/zh-CN/guide/getting-started/cli' },
{ text: '3. 通过 CRD 部署模型', link: '/pages/zh-CN/guide/getting-started/crd' },
{ text: '安装 Ollama Operator', link: '/pages/zh-CN/guide/getting-started/' },
{ text: '通过 CLI 部署模型', link: '/pages/zh-CN/guide/getting-started/cli' },
{ text: '通过 CRD 部署模型', link: '/pages/zh-CN/guide/getting-started/crd' },
]
},
{ text: '支持模型', link: '/pages/zh-CN/guide/supported-models' },
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/en/references/cli/commands/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ Your can read more here: [Schedule GPUs | Kubernetes](https://kubernetes.io/docs
Of course you can, with the [`kubectl set resources`](https://kubernetes.io/zh-cn/docs/reference/kubectl/generated/kubectl_set/kubectl_set_resources/) command, you can change the resource limit:

```shell
kubectl set resources deployment -l model.ollama.ayaka.io=<model name> --limits cpu=4
kubectl set resources deployment -l model.ollama.ayaka.io/name=<model name> --limits cpu=4
```

For memory limits:

```shell
kubectl set resources deployment -l model.ollama.ayaka.io=<model name> --limits memory=8Gi
kubectl set resources deployment -l model.ollama.ayaka.io/name=<model name> --limits memory=8Gi
```

:::
Expand Down Expand Up @@ -193,7 +193,7 @@ If not specified, the service will be exposed as [`NodePort`](https://kubernetes
::: tip To understand how many Services are associated to [`Model`](/pages/en/references/crd/model)...

```shell
kubectl get svc --selector model.ollama.ayaka.io
kubectl get svc --selector ollama.ayaka.io/type=model
```

:::
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/en/references/cli/commands/expose.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If not specified, the service will be exposed as [`NodePort`](https://kubernetes
::: tip To understand how many Services are associated to models...

```shell
kubectl get svc --selector model.ollama.ayaka.io
kubectl get svc --selector ollama.ayaka.io/type=model
```

:::
Expand All @@ -67,7 +67,7 @@ If not specified, the service will be exposed as [`NodePort`](https://kubernetes
::: tip To understand how many Services are associated to [`Model`](/pages/en/references/crd/model)...

```shell
kubectl get svc --selector model.ollama.ayaka.io
kubectl get svc --selector ollama.ayaka.io/type=model
```

:::
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/zh-CN/references/cli/commands/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ resources:
当然可以,用 [`kubectl set resources`](https://kubernetes.io/zh-cn/docs/reference/kubectl/generated/kubectl_set/kubectl_set_resources/) 命令来可以更改资源限制:

```shell
kubectl set resources deployment -l model.ollama.ayaka.io=<model name> --limits cpu=4
kubectl set resources deployment -l model.ollama.ayaka.io/name=<model name> --limits cpu=4
```

改内存限制:

```shell
kubectl set resources deployment -l model.ollama.ayaka.io=<model name> --limits memory=8Gi
kubectl set resources deployment -l model.ollama.ayaka.io/name=<model name> --limits memory=8Gi
```

:::
Expand Down Expand Up @@ -207,7 +207,7 @@ kollama deploy phi --expose --service-type=NodePort
::: tip 了解有多少服务与 [`Model`](/pages/zh-CN/references/crd/model) 相关联...

```shell
kubectl get svc --selector model.ollama.ayaka.io
kubectl get svc --selector ollama.ayaka.io/type=model
```

:::
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/zh-CN/references/cli/commands/expose.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ kollama deploy phi --expose --service-type=NodePort
::: tip 了解有多少服务与 [`Model`](/pages/zh-CN/references/crd/model) 相关联...

```shell
kubectl get svc --selector model.ollama.ayaka.io
kubectl get svc --selector ollama.ayaka.io/type=model
```

:::
Expand Down
14 changes: 6 additions & 8 deletions pkg/model/image_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func EnsureImageStorePVCCreated(
ObjectMeta: metav1.ObjectMeta{
Name: ImageStorePVCName,
Namespace: namespace,
Labels: ImageStoreLabels(ImageStoreStatefulSetName),
Labels: ImageStoreLabels(),
Annotations: ModelAnnotations(ImageStoreStatefulSetName, true),
},
Spec: corev1.PersistentVolumeClaimSpec{
Expand Down Expand Up @@ -144,19 +144,17 @@ func EnsureImageStoreStatefulSetCreated(
ObjectMeta: metav1.ObjectMeta{
Name: ImageStoreStatefulSetName,
Namespace: namespace,
Labels: ImageStoreLabels(ImageStoreStatefulSetName),
Labels: ImageStoreLabels(),
Annotations: ModelAnnotations(ImageStoreStatefulSetName, true),
},
Spec: appsv1.StatefulSetSpec{
Replicas: lo.ToPtr(int32(1)),
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": ImageStoreStatefulSetName,
},
MatchLabels: ImageStoreLabels(),
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: ImageStoreLabels(ImageStoreStatefulSetName),
Labels: ImageStoreLabels(),
Annotations: ModelAnnotations(ImageStoreStatefulSetName, true),
},
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -254,7 +252,7 @@ func EnsureImageStoreServiceCreated(
ObjectMeta: metav1.ObjectMeta{
Name: ImageStoreStatefulSetName,
Namespace: namespace,
Labels: ImageStoreLabels(ImageStoreStatefulSetName),
Labels: ImageStoreLabels(),
Annotations: ModelAnnotations(ImageStoreStatefulSetName, true),
OwnerReferences: []metav1.OwnerReference{{
APIVersion: "apps/v1",
Expand All @@ -274,7 +272,7 @@ func EnsureImageStoreServiceCreated(
TargetPort: intstr.FromInt(11434),
},
},
Selector: ImageStoreLabels(ImageStoreStatefulSetName),
Selector: ImageStoreLabels(),
},
}

Expand Down
16 changes: 6 additions & 10 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,20 @@ func ModelAppName(name string) string {
func ModelLabels(name string) map[string]string {
return map[string]string{
"app": ModelAppName(name),
"model.ollama.ayaka.io": name,
"model.ollama.ayaka.io/type": "model",
"ollama.ayaka.io/type": "model",
"model.ollama.ayaka.io/name": name,
}
}

func ImageStoreLabels(name string) map[string]string {
func ImageStoreLabels() map[string]string {
return map[string]string{
"app": "ollama-image-store",
"model.ollama.ayaka.io": name,
"model.ollama.ayaka.io/type": "image-store",
"app": "ollama-image-store",
"ollama.ayaka.io/type": "image-store",
}
}

func ModelAnnotations(name string, imageStore bool) map[string]string {
return map[string]string{
"model.ollama.ayaka.io/name": name,
"model.ollama.ayaka.io/type": lo.Ternary(imageStore, "image-store", "model"),
}
return map[string]string{}
}

func getDeployment(ctx context.Context, c client.Client, namespace string, name string) (*appsv1.Deployment, error) {
Expand Down

0 comments on commit b541d40

Please sign in to comment.