Skip to content

Commit

Permalink
Merge pull request #13 from Cdayz/fix-mistakes-after-local-testing
Browse files Browse the repository at this point in the history
Fix mistakes after local testing
  • Loading branch information
Cdayz authored Mar 2, 2024
2 parents 0ea121b + b7fd108 commit c642d6a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@ You can install this operator by installing it through [Helm Chart](./charts/k8s
When operator installed in cluster you can simply create resources like this:

```yaml
apiVersion: v1
apiVersion: images.cdayz.k8s.extensions/v1
kind: PrePullImage
metadata:
name: my-cool-image-pre-pull
namespace: my-namespace
spec:
image: "gcr.io/my-cool-image"
nodeSelector: {} # You can specify selectors for pre-pull only on particular nodes
```
Or you can specify `nodeSelector` to pre-pull image only on particular nodes.

```yaml
apiVersion: images.cdayz.k8s.extensions/v1
kind: PrePullImage
metadata:
name: my-cool-image-pre-pull
namespace: my-namespace
spec:
image: "gcr.io/my-cool-image"
nodeSelector:
ssd: "true"
feature.nvidia-runtime: "true"
...
```

This operator automatically will create a `DaemonSet` for create pre-pulling pods on every existing node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ spec:
type: object
required:
- image
- nodeSelector
type: object
status:
description: PrePullImageStatus defines the observed state of PrePullImage
Expand Down
6 changes: 3 additions & 3 deletions charts/k8s-image-pre-puller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ pre_pull_image_reconciller:
memory: 25Mi
pre_pull_container:
command: ['/bin/sh']
args: ['-c', 'exit 0']
args: ['-c', 'echo OK']
resources:
limits:
cpu: 25m
memory: 25Mi
cpu: 100m
memory: 250Mi
requests:
cpu: 25m
memory: 25Mi
8 changes: 8 additions & 0 deletions internal/controller/prepullimage_reconciller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"slices"
"strconv"
"strings"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -30,6 +31,8 @@ const (

PodNamePrefix = "image-pre-puller-"
DaemonSetNamePrefix = "image-pre-puller-"

BuiltinKubernetesTaintKeyPrefix = "node.kubernetes.io"
)

var MaxUnavailablePodsOfDaemonSetDuringRollingUpdate = intstr.FromString("100%")
Expand Down Expand Up @@ -342,6 +345,11 @@ func (r *prePullImageReconciller) getTolerationsByNodeSelector(ctx context.Conte
tolerationMap := map[string]corev1.Toleration{}
for _, item := range nodes.Items {
for _, taint := range item.Spec.Taints {
if strings.HasPrefix(taint.Key, BuiltinKubernetesTaintKeyPrefix) {
// WARN: we should avoid to add tolerations for builtin taints
continue
}

key := taint.ToString()

if _, ok := tolerationMap[key]; !ok {
Expand Down
48 changes: 48 additions & 0 deletions local/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
logger:
system: k8s-image-pre-puller
level: info

metrics:
path: /metrics
port: 9090

pprof:
enable: true
port: 8085

health:
port: 8080
liveness_path: /alive
readiness_path: /ready

leader_election:
instance_id: k8s-image-pre-puller-local
lock_name: k8s-image-pre-puller-lock
lock_namespace: default

worker_count: 10
resync_period: 5m
pre_pull_image_reconciller:
main_container:
name: main
image: busybox
command: ["/bin/sh"]
args: ["-c", "sleep inf"]
resources:
limits:
cpu: 25m
memory: 25Mi
requests:
cpu: 25m
memory: 25Mi
pre_pull_container:
command: ["/bin/sh"]
args: ["-c", "echo OK"]
resources:
limits:
cpu: 100m
memory: 256Mi
requests:
cpu: 25m
memory: 25Mi
image_pull_secret_names: []

0 comments on commit c642d6a

Please sign in to comment.