├── .github └── workflows │ ├── docker-image.yml │ └── go.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── cmd ├── copy │ └── main.go ├── operator │ └── main.go └── sleep │ └── main.go ├── go.mod ├── go.sum ├── internal ├── controller │ ├── images.go │ ├── images_test.go │ └── main.go └── prefetcher │ └── daemonset.go ├── main.go └── manifest.yaml /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Docker Image CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | tags: 7 | - v* 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - name: Prepare 16 | id: prepare 17 | run: | 18 | DOCKER_IMAGE=averagemarcus/kube-image-prefetch 19 | DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x 20 | 21 | VERSION=latest 22 | if [[ $GITHUB_REF == refs/tags/* ]]; then 23 | VERSION=${GITHUB_REF#refs/tags/} 24 | fi 25 | 26 | TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" 27 | if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then 28 | TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" 29 | fi 30 | 31 | echo ::set-output name=tags::${TAGS} 32 | echo ::set-output name=platforms::${DOCKER_PLATFORMS} 33 | 34 | - name: Set up Docker Buildx 35 | uses: crazy-max/ghaction-docker-buildx@v3 36 | 37 | - name: Cache Docker layers 38 | uses: actions/cache@v2 39 | id: cache 40 | with: 41 | path: /tmp/.buildx-cache 42 | key: ${{ runner.os }}-buildx-${{ github.sha }} 43 | restore-keys: | 44 | ${{ runner.os }}-buildx- 45 | 46 | - name: Docker Buildx (build) 47 | run: | 48 | docker buildx build \ 49 | --cache-from "type=local,src=/tmp/.buildx-cache" \ 50 | --cache-to "type=local,dest=/tmp/.buildx-cache" \ 51 | --platform ${{ steps.prepare.outputs.platforms }} \ 52 | --output "type=image,push=false" \ 53 | ${{ steps.prepare.outputs.tags }} \ 54 | . 55 | 56 | - name: Docker Login 57 | env: 58 | DOCKER_USERNAME: averagemarcus 59 | DOCKER_PASSWORD: ${{ secrets.DOCKER_TOKEN }} 60 | run: | 61 | echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin 62 | 63 | - name: Docker Buildx (push) 64 | run: | 65 | docker buildx build \ 66 | --cache-from "type=local,src=/tmp/.buildx-cache" \ 67 | --cache-to "type=local,dest=/tmp/.buildx-cache" \ 68 | --platform ${{ steps.prepare.outputs.platforms }} \ 69 | --output "type=image,push=true" \ 70 | ${{ steps.prepare.outputs.tags }} \ 71 | . 72 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | name: Build 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Set up Go 1.x 15 | uses: actions/setup-go@v2 16 | with: 17 | go-version: ^1.13 18 | id: go 19 | - name: Check out code into the Go module directory 20 | uses: actions/checkout@v2 21 | with: 22 | fetch-depth: 0 23 | - name: Get dependencies 24 | run: | 25 | go get -v -t -d ./... 26 | if [ -f Gopkg.toml ]; then 27 | curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh 28 | dep ensure 29 | fi 30 | - name: Build 31 | run: go build -v . 32 | - name: Test 33 | run: go test -v . 34 | - name: Run golangci-lint 35 | run: | 36 | go get -u golang.org/x/lint/golint 37 | golint -set_exit_status ./... 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Git ### 2 | # Created by git for backups. To disable backups in Git: 3 | # $ git config --global mergetool.keepBackup false 4 | *.orig 5 | 6 | # Created by git when using merge tools for conflicts 7 | *.BACKUP.* 8 | *.BASE.* 9 | *.LOCAL.* 10 | *.REMOTE.* 11 | *_BACKUP_*.txt 12 | *_BASE_*.txt 13 | *_LOCAL_*.txt 14 | *_REMOTE_*.txt 15 | 16 | ### Go ### 17 | # Binaries for programs and plugins 18 | *.exe 19 | *.exe~ 20 | *.dll 21 | *.so 22 | *.dylib 23 | 24 | # Test binary, built with `go test -c` 25 | *.test 26 | 27 | # Output of the go coverage tool, specifically when used with LiteIDE 28 | *.out 29 | 30 | # Dependency directories (remove the comment below to include it) 31 | # vendor/ 32 | 33 | ### Go Patch ### 34 | /vendor/ 35 | /Godeps/ 36 | 37 | ### Node ### 38 | # Logs 39 | logs 40 | *.log 41 | npm-debug.log* 42 | yarn-debug.log* 43 | yarn-error.log* 44 | lerna-debug.log* 45 | 46 | # Diagnostic reports (https://nodejs.org/api/report.html) 47 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 48 | 49 | # Runtime data 50 | pids 51 | *.pid 52 | *.seed 53 | *.pid.lock 54 | 55 | # Directory for instrumented libs generated by jscoverage/JSCover 56 | lib-cov 57 | 58 | # Coverage directory used by tools like istanbul 59 | coverage 60 | *.lcov 61 | 62 | # nyc test coverage 63 | .nyc_output 64 | 65 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 66 | .grunt 67 | 68 | # Bower dependency directory (https://bower.io/) 69 | bower_components 70 | 71 | # node-waf configuration 72 | .lock-wscript 73 | 74 | # Compiled binary addons (https://nodejs.org/api/addons.html) 75 | build/Release 76 | 77 | # Dependency directories 78 | node_modules/ 79 | jspm_packages/ 80 | 81 | # TypeScript v1 declaration files 82 | typings/ 83 | 84 | # TypeScript cache 85 | *.tsbuildinfo 86 | 87 | # Optional npm cache directory 88 | .npm 89 | 90 | # Optional eslint cache 91 | .eslintcache 92 | 93 | # Optional REPL history 94 | .node_repl_history 95 | 96 | # Output of 'npm pack' 97 | *.tgz 98 | 99 | # Yarn Integrity file 100 | .yarn-integrity 101 | 102 | # dotenv environment variables file 103 | .env 104 | .env.test 105 | 106 | # parcel-bundler cache (https://parceljs.org/) 107 | .cache 108 | 109 | # next.js build output 110 | .next 111 | 112 | # nuxt.js build output 113 | .nuxt 114 | 115 | # rollup.js default build output 116 | dist/ 117 | 118 | # Storybook build outputs 119 | .out 120 | .storybook-out 121 | 122 | # vuepress build output 123 | .vuepress/dist 124 | 125 | # Serverless directories 126 | .serverless/ 127 | 128 | # FuseBox cache 129 | .fusebox/ 130 | 131 | # DynamoDB Local files 132 | .dynamodb/ 133 | 134 | # Temporary folders 135 | tmp/ 136 | temp/ 137 | 138 | # VSCode 139 | .vscode/* 140 | !.vscode/settings.json 141 | !.vscode/tasks.json 142 | !.vscode/launch.json 143 | !.vscode/extensions.json 144 | *.code-workspace 145 | .history/ 146 | 147 | # MacOS 148 | # General 149 | .DS_Store 150 | .AppleDouble 151 | .LSOverride 152 | 153 | # Thumbnails 154 | ._* 155 | 156 | # Files that might appear in the root of a volume 157 | .DocumentRevisions-V100 158 | .fseventsd 159 | .Spotlight-V100 160 | .TemporaryItems 161 | .Trashes 162 | .VolumeIcon.icns 163 | .com.apple.timemachine.donotpresent 164 | 165 | # Directories potentially created on remote AFP share 166 | .AppleDB 167 | .AppleDesktop 168 | Network Trash Folder 169 | Temporary Items 170 | .apdisk 171 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.14 as builder 2 | 3 | ARG TARGETPLATFORM 4 | ARG BUILDPLATFORM 5 | ARG TARGETOS 6 | ARG TARGETARCH 7 | 8 | WORKDIR /app/ 9 | ADD . . 10 | RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o kube-image-prefetch main.go 11 | 12 | FROM --platform=${TARGETPLATFORM:-linux/amd64} scratch 13 | WORKDIR /app/ 14 | COPY --from=builder /app/kube-image-prefetch /app/kube-image-prefetch 15 | ENTRYPOINT ["/app/kube-image-prefetch"] 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2020 - present Marcus Noble 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 | OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := default 2 | 3 | IMAGE ?= averagemarcus/kube-image-prefetch:latest 4 | 5 | export DOCKER_CLI_EXPERIMENTAL=enabled 6 | 7 | .PHONY: test # Run all tests, linting and format checks 8 | test: lint check-format run-tests 9 | 10 | .PHONY: lint # Perform lint checks against code 11 | lint: 12 | @go vet && golint -set_exit_status ./... 13 | 14 | .PHONY: check-format # Checks code formatting and returns a non-zero exit code if formatting errors found 15 | check-format: 16 | @gofmt -e -l . 17 | 18 | .PHONY: format # Performs automatic format fixes on all code 19 | format: 20 | @gofmt -s -w . 21 | 22 | .PHONY: run-tests # Runs all tests 23 | run-tests: 24 | @go test ./... 25 | 26 | .PHONY: fetch-deps # Fetch all project dependencies 27 | fetch-deps: 28 | @go mod tidy 29 | 30 | .PHONY: build # Build the project 31 | build: lint check-format fetch-deps 32 | @go build -o kube-image-prefetch main.go 33 | 34 | .PHONY: docker-build # Build the docker image 35 | docker-build: 36 | @docker buildx create --use --name=crossplat --node=crossplat && \ 37 | docker buildx build \ 38 | --output "type=docker,push=false" \ 39 | --tag $(IMAGE) \ 40 | . 41 | 42 | .PHONY: docker-publish # Push the docker image to the remote registry 43 | docker-publish: 44 | @docker buildx create --use --name=crossplat --node=crossplat && \ 45 | docker buildx build \ 46 | --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x \ 47 | --output "type=image,push=true" \ 48 | --tag $(IMAGE) \ 49 | . 50 | 51 | .PHONY: run # Run the application 52 | run: 53 | @go run main.go 54 | 55 | .PHONY: help # Show this list of commands 56 | help: 57 | @echo "kube-image-prefetch" 58 | @echo "Usage: make [target]" 59 | @echo "" 60 | @echo "target description" | expand -t20 61 | @echo "-----------------------------------" 62 | @grep '^.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1 \2/' | expand -t20 63 | 64 | default: test 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kube-image-prefetch 2 | 3 | > Pre-pull all images, on all nodes, within a Kubernetes cluster 4 | 5 | ## Features 6 | 7 | * Pull all images used by deployments in the cluster on all nodes 8 | * Watch for new, changed or removed deployments and pre-fetch images on all nodes 9 | * Ignore deployments with annotation `kube-image-prefetch/ignore: "true"` 10 | * Ignore specific containers with annotation `kube-image-prefetch/ignore-containers: "container-name"`. Multiple containers within a pod can be specified as a comma separated list. 11 | 12 | ## Install 13 | 14 | ```sh 15 | kubectl apply -f https://raw.githubusercontent.com/AverageMarcus/kube-image-prefetch/master/manifest.yaml 16 | ``` 17 | 18 | ## Building from source 19 | 20 | With Docker: 21 | 22 | ```sh 23 | make docker-build 24 | ``` 25 | 26 | Standalone: 27 | 28 | ```sh 29 | make build 30 | ``` 31 | 32 | ## Contributing 33 | 34 | If you find a bug or have an idea for a new feature please [raise an issue](https://github.com/AverageMarcus/kube-image-prefetch/issues/new) to discuss it. 35 | 36 | Pull requests are welcomed but please try and follow similar code style as the rest of the project and ensure all tests and code checkers are passing. 37 | 38 | Thank you 💙 39 | 40 | ## License 41 | 42 | See [LICENSE](LICENSE) 43 | -------------------------------------------------------------------------------- /cmd/copy/main.go: -------------------------------------------------------------------------------- 1 | package copy 2 | 3 | import ( 4 | "io" 5 | "os" 6 | ) 7 | 8 | // Run triggers the copy of this binary to the provided destination 9 | func Run(dest string) error { 10 | original, err := os.Open(os.Args[0]) 11 | if err != nil { 12 | return err 13 | } 14 | defer original.Close() 15 | 16 | new, err := os.Create(dest) 17 | if err != nil { 18 | return err 19 | } 20 | defer new.Close() 21 | 22 | _, err = io.Copy(new, original) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | return os.Chmod(dest, 0777) 28 | } 29 | -------------------------------------------------------------------------------- /cmd/operator/main.go: -------------------------------------------------------------------------------- 1 | package operator 2 | 3 | import ( 4 | "os" 5 | 6 | appsv1 "k8s.io/api/apps/v1" 7 | corev1 "k8s.io/api/core/v1" 8 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 | "k8s.io/apimachinery/pkg/types" 10 | "k8s.io/client-go/kubernetes" 11 | "k8s.io/client-go/rest" 12 | "k8s.io/client-go/tools/clientcmd" 13 | "k8s.io/utils/pointer" 14 | 15 | "kube-image-prefetch/internal/controller" 16 | "kube-image-prefetch/internal/prefetcher" 17 | ) 18 | 19 | const ( 20 | namespace = "default" 21 | name = "kube-image-prefetch" 22 | image = "averagemarcus/kube-image-prefetch:latest" 23 | ) 24 | 25 | // Run triggers the operator to watch deployments and update the prefetcher daemonset 26 | func Run() error { 27 | clientset, err := getClient() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | ds, err := clientset.AppsV1().DaemonSets(namespace).Get(name, metav1.GetOptions{}) 33 | if err != nil { 34 | ds = prefetcher.CreateDaemonSet(getSelfOwnerReference(clientset)...) 35 | ds, err = clientset.AppsV1().DaemonSets(namespace).Create(ds) 36 | if err != nil { 37 | return err 38 | } 39 | } 40 | 41 | imageChan := make(chan controller.Images, 1) 42 | controller.Start(clientset, imageChan) 43 | 44 | toPrefetch := map[string]controller.Images{} 45 | for { 46 | img := <-imageChan 47 | 48 | if img.Images == nil { 49 | delete(toPrefetch, img.ID) 50 | } else { 51 | toPrefetch[img.ID] = img 52 | } 53 | 54 | images := []string{} 55 | pullSecrets := []corev1.LocalObjectReference{} 56 | 57 | for _, v := range toPrefetch { 58 | images = append(images, v.Images...) 59 | pullSecrets = append(pullSecrets, v.PullSecrets...) 60 | } 61 | 62 | ds, _ = clientset.AppsV1().DaemonSets(namespace).Get(name, metav1.GetOptions{}) 63 | ds, err = clientset.AppsV1().DaemonSets(namespace).Patch(name, types.JSONPatchType, prefetcher.GeneratePatch(dedupe(images), pullSecrets)) 64 | if err != nil { 65 | return err 66 | } 67 | } 68 | } 69 | 70 | func getClient() (*kubernetes.Clientset, error) { 71 | config, err := rest.InClusterConfig() 72 | if err != nil { 73 | kubeconfigPath := os.Getenv("KUBECONFIG") 74 | if kubeconfigPath == "" { 75 | kubeconfigPath = os.Getenv("HOME") + "/.kube/config" 76 | } 77 | config, err = clientcmd.BuildConfigFromFlags("", kubeconfigPath) 78 | } 79 | 80 | return kubernetes.NewForConfig(config) 81 | } 82 | 83 | func dedupe(a []string) []string { 84 | tempMap := map[string]bool{} 85 | dest := []string{} 86 | 87 | for _, obj := range a { 88 | if !tempMap[obj] { 89 | tempMap[obj] = true 90 | dest = append(dest, obj) 91 | } 92 | } 93 | 94 | return dest 95 | } 96 | 97 | func getSelfOwnerReference(clientset *kubernetes.Clientset) []metav1.OwnerReference { 98 | ownerReference := []metav1.OwnerReference{} 99 | 100 | self, err := clientset.AppsV1().Deployments("kube-system").Get("kube-image-prefetch-manager", metav1.GetOptions{}) 101 | if err != nil { 102 | return ownerReference 103 | } 104 | 105 | ownerReference = append(ownerReference, metav1.OwnerReference{ 106 | APIVersion: appsv1.SchemeGroupVersion.Identifier(), 107 | Kind: "Deployment", 108 | Name: self.ObjectMeta.Name, 109 | UID: self.ObjectMeta.UID, 110 | Controller: pointer.BoolPtr(true), 111 | }) 112 | 113 | return ownerReference 114 | } 115 | -------------------------------------------------------------------------------- /cmd/sleep/main.go: -------------------------------------------------------------------------------- 1 | package sleep 2 | 3 | import ( 4 | "os" 5 | "os/signal" 6 | "syscall" 7 | ) 8 | 9 | // Run triggers a sleep function that waits until a term/kill signal is received 10 | func Run() error { 11 | c := make(chan os.Signal, 1) 12 | signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL) 13 | <-c 14 | 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module kube-image-prefetch 2 | 3 | go 1.13 4 | 5 | require ( 6 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect 7 | golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect 8 | k8s.io/api v0.17.0 9 | k8s.io/apimachinery v0.17.0 10 | k8s.io/client-go v0.17.0 11 | k8s.io/utils v0.0.0-20200720150651-0bdb4ca86cbc 12 | ) 13 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= 5 | github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= 6 | github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= 7 | github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= 8 | github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= 9 | github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= 10 | github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= 11 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 12 | github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= 13 | github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= 14 | github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= 15 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 16 | github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 17 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 18 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 19 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 20 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 21 | github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= 22 | github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= 23 | github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= 24 | github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= 25 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 26 | github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 27 | github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg= 28 | github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= 29 | github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= 30 | github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= 31 | github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= 32 | github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= 33 | github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I= 34 | github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= 35 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 36 | github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 h1:LbsanbbD6LieFkXbj9YNNBupiGHJgFeLpO0j0Fza1h8= 37 | github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 38 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 39 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 40 | github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 41 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 42 | github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= 43 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 44 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 45 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 46 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 47 | github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= 48 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 49 | github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= 50 | github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= 51 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 52 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 53 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 54 | github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= 55 | github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 56 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 57 | github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k= 58 | github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= 59 | github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= 60 | github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= 61 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 62 | github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= 63 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 64 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 65 | github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q= 66 | github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= 67 | github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 68 | github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok= 69 | github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 70 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 71 | github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= 72 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 73 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 74 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 75 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 76 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 77 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 78 | github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= 79 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 80 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 81 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 82 | github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 83 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 84 | github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= 85 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 86 | github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= 87 | github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= 88 | github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 89 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 90 | github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 91 | github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= 92 | github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= 93 | github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= 94 | github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 95 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 96 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 97 | github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= 98 | github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 99 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 100 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 101 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 102 | github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 103 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 104 | github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 105 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 106 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 107 | golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 108 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= 109 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 110 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0= 111 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 112 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 113 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 114 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 115 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 116 | golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 117 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 118 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 119 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 120 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 121 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 122 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 123 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 124 | golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI= 125 | golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 126 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 127 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 128 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 129 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= 130 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 131 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 132 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 133 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 134 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 135 | golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 136 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 137 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 138 | golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 139 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 140 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 141 | golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 h1:ng0gs1AKnRRuEMZoTLLlbOd+C17zUDepwGQBb/n+JVg= 142 | golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 143 | golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 144 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 145 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 146 | golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= 147 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 148 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 149 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 150 | golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s= 151 | golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 152 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 153 | golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 154 | golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 155 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 156 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 157 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 158 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 159 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 160 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 161 | google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c= 162 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 163 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 164 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 165 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 166 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 167 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 168 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 169 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 170 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 171 | gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= 172 | gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= 173 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 174 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 175 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 176 | gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= 177 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 178 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 179 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 180 | k8s.io/api v0.17.0 h1:H9d/lw+VkZKEVIUc8F3wgiQ+FUXTTr21M87jXLU7yqM= 181 | k8s.io/api v0.17.0/go.mod h1:npsyOePkeP0CPwyGfXDHxvypiYMJxBWAMpQxCaJ4ZxI= 182 | k8s.io/apimachinery v0.17.0 h1:xRBnuie9rXcPxUkDizUsGvPf1cnlZCFu210op7J7LJo= 183 | k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg= 184 | k8s.io/client-go v0.17.0 h1:8QOGvUGdqDMFrm9sD6IUFl256BcffynGoe80sxgTEDg= 185 | k8s.io/client-go v0.17.0/go.mod h1:TYgR6EUHs6k45hb6KWjVD6jFZvJV4gHDikv/It0xz+k= 186 | k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= 187 | k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= 188 | k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= 189 | k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= 190 | k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= 191 | k8s.io/klog/v2 v2.0.0 h1:Foj74zO6RbjjP4hBEKjnYtjjAhGg4jNynUdYF6fJrok= 192 | k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= 193 | k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= 194 | k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= 195 | k8s.io/utils v0.0.0-20200720150651-0bdb4ca86cbc h1:GiXZzevctVRRBh56shqcqB9s9ReWMU6GTsFyE2RCFJQ= 196 | k8s.io/utils v0.0.0-20200720150651-0bdb4ca86cbc/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= 197 | sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= 198 | sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= 199 | sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= 200 | -------------------------------------------------------------------------------- /internal/controller/images.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "strings" 5 | 6 | appsv1 "k8s.io/api/apps/v1" 7 | ) 8 | 9 | func getImages(dp appsv1.Deployment) []string { 10 | images := []string{} 11 | 12 | ignoreDP := dp.ObjectMeta.Annotations["kube-image-prefetch/ignore"] 13 | if ignoreDP == "true" { 14 | return images 15 | } 16 | 17 | ignoreContainersStr := dp.ObjectMeta.Annotations["kube-image-prefetch/ignore-containers"] 18 | ignoreContainers := strings.Split(ignoreContainersStr, ",") 19 | 20 | for _, container := range append(dp.Spec.Template.Spec.InitContainers, dp.Spec.Template.Spec.Containers...) { 21 | if !contains(ignoreContainers, container.Name) { 22 | images = append(images, container.Image) 23 | } 24 | } 25 | 26 | return images 27 | } 28 | 29 | func contains(arr []string, str string) bool { 30 | for _, c := range arr { 31 | if strings.TrimSpace(strings.ToLower(str)) == strings.TrimSpace(strings.ToLower(c)) { 32 | return true 33 | } 34 | } 35 | return false 36 | } 37 | -------------------------------------------------------------------------------- /internal/controller/images_test.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "testing" 5 | "reflect" 6 | 7 | appsv1 "k8s.io/api/apps/v1" 8 | corev1 "k8s.io/api/core/v1" 9 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 | ) 11 | 12 | func TestGetImages_SingleImage(t *testing.T) { 13 | dp := appsv1.Deployment{ 14 | ObjectMeta: v1.ObjectMeta{ 15 | Name: "test-deployment", 16 | }, 17 | Spec: appsv1.DeploymentSpec{ 18 | Template: corev1.PodTemplateSpec{ 19 | Spec: corev1.PodSpec{ 20 | Containers: []corev1.Container{ 21 | corev1.Container{ 22 | Name: "container-1", 23 | Image: "image:1", 24 | }, 25 | }, 26 | }, 27 | }, 28 | }, 29 | } 30 | 31 | expected := []string{"image:1"} 32 | actual := getImages(dp) 33 | 34 | if ! reflect.DeepEqual(expected, actual) { 35 | t.Errorf("Unexpected images returned - %v", actual) 36 | } 37 | } 38 | 39 | func TestGetImages_MultipleImage(t *testing.T) { 40 | dp := appsv1.Deployment{ 41 | ObjectMeta: v1.ObjectMeta{ 42 | Name: "test-deployment", 43 | }, 44 | Spec: appsv1.DeploymentSpec{ 45 | Template: corev1.PodTemplateSpec{ 46 | Spec: corev1.PodSpec{ 47 | Containers: []corev1.Container{ 48 | corev1.Container{ 49 | Name: "container-1", 50 | Image: "image:1", 51 | }, 52 | corev1.Container{ 53 | Name: "container-2", 54 | Image: "image:2", 55 | }, 56 | }, 57 | }, 58 | }, 59 | }, 60 | } 61 | 62 | expected := []string{"image:1","image:2"} 63 | actual := getImages(dp) 64 | 65 | if ! reflect.DeepEqual(expected, actual) { 66 | t.Errorf("Unexpected images returned - %v", actual) 67 | } 68 | } 69 | 70 | func TestGetImages_InitContainers(t *testing.T) { 71 | dp := appsv1.Deployment{ 72 | ObjectMeta: v1.ObjectMeta{ 73 | Name: "test-deployment", 74 | }, 75 | Spec: appsv1.DeploymentSpec{ 76 | Template: corev1.PodTemplateSpec{ 77 | Spec: corev1.PodSpec{ 78 | InitContainers: []corev1.Container{ 79 | corev1.Container{ 80 | Name: "initcontainer-1", 81 | Image: "initimage:1", 82 | }, 83 | }, 84 | Containers: []corev1.Container{ 85 | corev1.Container{ 86 | Name: "container-1", 87 | Image: "image:1", 88 | }, 89 | }, 90 | }, 91 | }, 92 | }, 93 | } 94 | 95 | expected := []string{"initimage:1","image:1"} 96 | actual := getImages(dp) 97 | 98 | if ! reflect.DeepEqual(expected, actual) { 99 | t.Errorf("Unexpected images returned - %v", actual) 100 | } 101 | } 102 | 103 | func TestGetImages_IgnoreDeployment(t *testing.T) { 104 | dp := appsv1.Deployment{ 105 | ObjectMeta: v1.ObjectMeta{ 106 | Name: "test-deployment", 107 | Annotations: map[string]string{ 108 | "kube-image-prefetch/ignore": "true", 109 | }, 110 | }, 111 | Spec: appsv1.DeploymentSpec{ 112 | Template: corev1.PodTemplateSpec{ 113 | Spec: corev1.PodSpec{ 114 | InitContainers: []corev1.Container{ 115 | corev1.Container{ 116 | Name: "initcontainer-1", 117 | Image: "initimage:1", 118 | }, 119 | }, 120 | Containers: []corev1.Container{ 121 | corev1.Container{ 122 | Name: "container-1", 123 | Image: "image:1", 124 | }, 125 | }, 126 | }, 127 | }, 128 | }, 129 | } 130 | 131 | expected := []string{} 132 | actual := getImages(dp) 133 | 134 | if ! reflect.DeepEqual(expected, actual) { 135 | t.Errorf("Unexpected images returned - %v", actual) 136 | } 137 | } 138 | 139 | func TestGetImages_IgnoreContainer(t *testing.T) { 140 | dp := appsv1.Deployment{ 141 | ObjectMeta: v1.ObjectMeta{ 142 | Name: "test-deployment", 143 | Annotations: map[string]string{ 144 | "kube-image-prefetch/ignore-containers": "initcontainer-1", 145 | }, 146 | }, 147 | Spec: appsv1.DeploymentSpec{ 148 | Template: corev1.PodTemplateSpec{ 149 | Spec: corev1.PodSpec{ 150 | InitContainers: []corev1.Container{ 151 | corev1.Container{ 152 | Name: "initcontainer-1", 153 | Image: "initimage:1", 154 | }, 155 | }, 156 | Containers: []corev1.Container{ 157 | corev1.Container{ 158 | Name: "container-1", 159 | Image: "image:1", 160 | }, 161 | }, 162 | }, 163 | }, 164 | }, 165 | } 166 | 167 | expected := []string{"image:1"} 168 | actual := getImages(dp) 169 | 170 | if ! reflect.DeepEqual(expected, actual) { 171 | t.Errorf("Unexpected images returned - %v", actual) 172 | } 173 | } 174 | 175 | func TestGetImages_IgnoreMultipleContainer(t *testing.T) { 176 | dp := appsv1.Deployment{ 177 | ObjectMeta: v1.ObjectMeta{ 178 | Name: "test-deployment", 179 | Annotations: map[string]string{ 180 | "kube-image-prefetch/ignore-containers": "initcontainer-1,container-1", 181 | }, 182 | }, 183 | Spec: appsv1.DeploymentSpec{ 184 | Template: corev1.PodTemplateSpec{ 185 | Spec: corev1.PodSpec{ 186 | InitContainers: []corev1.Container{ 187 | corev1.Container{ 188 | Name: "initcontainer-1", 189 | Image: "initimage:1", 190 | }, 191 | }, 192 | Containers: []corev1.Container{ 193 | corev1.Container{ 194 | Name: "container-1", 195 | Image: "image:1", 196 | }, 197 | }, 198 | }, 199 | }, 200 | }, 201 | } 202 | 203 | expected := []string{} 204 | actual := getImages(dp) 205 | 206 | if ! reflect.DeepEqual(expected, actual) { 207 | t.Errorf("Unexpected images returned - %v", actual) 208 | } 209 | } 210 | 211 | func TestGetImages_IgnoreContainerSpaces(t *testing.T) { 212 | dp := appsv1.Deployment{ 213 | ObjectMeta: v1.ObjectMeta{ 214 | Name: "test-deployment", 215 | Annotations: map[string]string{ 216 | "kube-image-prefetch/ignore-containers": "initcontainer-1, container-1", 217 | }, 218 | }, 219 | Spec: appsv1.DeploymentSpec{ 220 | Template: corev1.PodTemplateSpec{ 221 | Spec: corev1.PodSpec{ 222 | InitContainers: []corev1.Container{ 223 | corev1.Container{ 224 | Name: "initcontainer-1", 225 | Image: "initimage:1", 226 | }, 227 | }, 228 | Containers: []corev1.Container{ 229 | corev1.Container{ 230 | Name: "container-1", 231 | Image: "image:1", 232 | }, 233 | }, 234 | }, 235 | }, 236 | }, 237 | } 238 | 239 | expected := []string{} 240 | actual := getImages(dp) 241 | 242 | if ! reflect.DeepEqual(expected, actual) { 243 | t.Errorf("Unexpected images returned - %v", actual) 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /internal/controller/main.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "time" 5 | 6 | appsv1 "k8s.io/api/apps/v1" 7 | corev1 "k8s.io/api/core/v1" 8 | "k8s.io/apimachinery/pkg/util/wait" 9 | coreinformers "k8s.io/client-go/informers" 10 | "k8s.io/client-go/kubernetes" 11 | "k8s.io/client-go/tools/cache" 12 | "k8s.io/client-go/util/workqueue" 13 | ) 14 | 15 | const ( 16 | maxRetries = 5 17 | 18 | createdAction = "created" 19 | updatedAction = "updated" 20 | deletedAction = "deleted" 21 | ) 22 | 23 | // Worker is used to process the events from the informer 24 | type Worker struct { 25 | queue workqueue.RateLimitingInterface 26 | informer cache.SharedIndexInformer 27 | imageChan chan Images 28 | } 29 | 30 | // Event contains the key associated with the event and the action of the event 31 | type Event struct { 32 | Key string 33 | Action string 34 | } 35 | 36 | // Images encapsulates the images and image pull secrets for each deployment 37 | type Images struct { 38 | ID string 39 | Images []string 40 | PullSecrets []corev1.LocalObjectReference 41 | } 42 | 43 | // Start creates the informers and responds to changes 44 | func Start(clientset kubernetes.Interface, imageChan chan Images) { 45 | queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()) 46 | 47 | coreInformers := coreinformers.NewSharedInformerFactory(clientset, 0) 48 | 49 | deploymentInformer := coreInformers.Apps().V1().Deployments().Informer() 50 | deploymentInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ 51 | AddFunc: func(obj interface{}) { 52 | key, _ := cache.MetaNamespaceKeyFunc(obj) 53 | queue.Add(Event{ 54 | Key: key, 55 | Action: createdAction, 56 | }) 57 | }, 58 | UpdateFunc: func(old, new interface{}) { 59 | key, _ := cache.MetaNamespaceKeyFunc(new) 60 | queue.Add(Event{ 61 | Key: key, 62 | Action: updatedAction, 63 | }) 64 | }, 65 | DeleteFunc: func(obj interface{}) { 66 | key, _ := cache.MetaNamespaceKeyFunc(obj) 67 | queue.Add(Event{ 68 | Key: key, 69 | Action: deletedAction, 70 | }) 71 | }, 72 | }) 73 | 74 | w := &Worker{ 75 | informer: deploymentInformer, 76 | queue: queue, 77 | imageChan: imageChan, 78 | } 79 | stopCh := make(chan struct{}) 80 | go w.Run(stopCh) 81 | } 82 | 83 | // Run triggers the worker to start processing informer events 84 | func (w *Worker) Run(stopCh <-chan struct{}) { 85 | defer w.queue.ShutDown() 86 | go w.informer.Run(stopCh) 87 | wait.Until(w.runWorker, time.Second, stopCh) 88 | } 89 | 90 | func (w *Worker) runWorker() { 91 | for w.processNextItem() { 92 | // continue looping 93 | } 94 | } 95 | 96 | func (w *Worker) processNextItem() bool { 97 | newEvent, quit := w.queue.Get() 98 | if quit { 99 | return false 100 | } 101 | defer w.queue.Done(newEvent) 102 | 103 | err := w.processItem(newEvent.(Event)) 104 | if err == nil { 105 | // No error, reset the ratelimit counters 106 | w.queue.Forget(newEvent) 107 | } else if w.queue.NumRequeues(newEvent) < maxRetries { 108 | w.queue.AddRateLimited(newEvent) 109 | } else { 110 | w.queue.Forget(newEvent) 111 | } 112 | 113 | return true 114 | } 115 | 116 | func (w *Worker) processItem(newEvent Event) error { 117 | obj, _, err := w.informer.GetIndexer().GetByKey(newEvent.Key) 118 | if err != nil { 119 | return err 120 | } 121 | 122 | switch newEvent.Action { 123 | case createdAction: 124 | fallthrough 125 | case updatedAction: 126 | dp := obj.(*appsv1.Deployment) 127 | images := getImages(*dp) 128 | if len(images) > 0 { 129 | w.imageChan <- Images{ 130 | ID: newEvent.Key, 131 | Images: images, 132 | PullSecrets: dp.Spec.Template.Spec.ImagePullSecrets, 133 | } 134 | return nil 135 | } 136 | fallthrough 137 | case deletedAction: 138 | w.imageChan <- Images{ 139 | ID: newEvent.Key, 140 | Images: nil, 141 | PullSecrets: nil, 142 | } 143 | } 144 | return nil 145 | } 146 | -------------------------------------------------------------------------------- /internal/prefetcher/daemonset.go: -------------------------------------------------------------------------------- 1 | package prefetcher 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | 7 | appsv1 "k8s.io/api/apps/v1" 8 | corev1 "k8s.io/api/core/v1" 9 | "k8s.io/apimachinery/pkg/api/resource" 10 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 11 | ) 12 | 13 | const ( 14 | namespace = "default" 15 | name = "kube-image-prefetch" 16 | image = "averagemarcus/kube-image-prefetch:latest" 17 | ) 18 | 19 | // ContainerPatch is a JSON Patch for the Containers property 20 | type ContainerPatch struct { 21 | Op string `json:"op"` 22 | Path string `json:"path"` 23 | Value []corev1.Container `json:"value"` 24 | } 25 | 26 | // PullSecretsPatch is a JSON Patch for the PullSecrets property 27 | type PullSecretsPatch struct { 28 | Op string `json:"op"` 29 | Path string `json:"path"` 30 | Value []corev1.LocalObjectReference `json:"value"` 31 | } 32 | 33 | // CreateDaemonSet generates a new DaemonSet for kube-image-prefetch 34 | func CreateDaemonSet(ownerReference ...metav1.OwnerReference) *appsv1.DaemonSet { 35 | labels := map[string]string{ 36 | "app": name, 37 | } 38 | 39 | ds := &appsv1.DaemonSet{ 40 | ObjectMeta: metav1.ObjectMeta{ 41 | Name: name, 42 | Labels: labels, 43 | OwnerReferences: ownerReference, 44 | }, 45 | Spec: appsv1.DaemonSetSpec{ 46 | Selector: &metav1.LabelSelector{ 47 | MatchLabels: labels, 48 | }, 49 | Template: corev1.PodTemplateSpec{ 50 | ObjectMeta: metav1.ObjectMeta{ 51 | Labels: labels, 52 | }, 53 | Spec: corev1.PodSpec{ 54 | InitContainers: []corev1.Container{{ 55 | Name: "init", 56 | Image: image, 57 | ImagePullPolicy: corev1.PullAlways, 58 | Args: []string{ 59 | "-command", "copy", 60 | "-dest", "/mount/sleep", 61 | }, 62 | VolumeMounts: []corev1.VolumeMount{{ 63 | Name: "share", 64 | MountPath: "/mount", 65 | }}, 66 | }}, 67 | Containers: []corev1.Container{ 68 | { 69 | Name: "pending", 70 | Image: image, 71 | ImagePullPolicy: corev1.PullIfNotPresent, 72 | Command: []string{"/mount/sleep"}, 73 | Args: []string{"-command", "sleep"}, 74 | Resources: corev1.ResourceRequirements{ 75 | Limits: corev1.ResourceList{ 76 | corev1.ResourceCPU: resource.MustParse("1m"), 77 | corev1.ResourceMemory: resource.MustParse("10M"), 78 | }, 79 | }, 80 | }, 81 | }, 82 | ImagePullSecrets: []corev1.LocalObjectReference{}, 83 | Volumes: []corev1.Volume{{ 84 | Name: "share", 85 | VolumeSource: corev1.VolumeSource{ 86 | EmptyDir: &corev1.EmptyDirVolumeSource{}, 87 | }, 88 | }}, 89 | }, 90 | }, 91 | }, 92 | } 93 | 94 | return ds 95 | } 96 | 97 | // GeneratePatch creates the JSON Patch for the provided images and pull secrets 98 | func GeneratePatch(images []string, pullSecrets []corev1.LocalObjectReference) []byte { 99 | containers := []corev1.Container{} 100 | for i, img := range images { 101 | containers = append(containers, buildPrefetchContainer(img, i)) 102 | } 103 | 104 | payload, _ := json.Marshal([]interface{}{ 105 | ContainerPatch{ 106 | Op: "replace", 107 | Path: "/spec/template/spec/containers", 108 | Value: containers, 109 | }, 110 | PullSecretsPatch{ 111 | Op: "replace", 112 | Path: "/spec/template/spec/imagePullSecrets", 113 | Value: pullSecrets, 114 | }, 115 | }) 116 | return payload 117 | } 118 | 119 | func buildPrefetchContainer(img string, index int) corev1.Container { 120 | return corev1.Container{ 121 | Name: fmt.Sprintf("prefetch-%d", index), 122 | Image: img, 123 | ImagePullPolicy: corev1.PullIfNotPresent, 124 | Command: []string{"/mount/sleep"}, 125 | Args: []string{"-command", "sleep"}, 126 | VolumeMounts: []corev1.VolumeMount{{ 127 | Name: "share", 128 | MountPath: "/mount", 129 | }}, 130 | Resources: corev1.ResourceRequirements{ 131 | Limits: corev1.ResourceList{ 132 | corev1.ResourceCPU: resource.MustParse("1m"), 133 | corev1.ResourceMemory: resource.MustParse("10M"), 134 | }, 135 | }, 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "strings" 6 | 7 | "kube-image-prefetch/cmd/copy" 8 | "kube-image-prefetch/cmd/operator" 9 | "kube-image-prefetch/cmd/sleep" 10 | ) 11 | 12 | func main() { 13 | command := flag.String("command", "operator", "The operation to perform [one of 'copy', 'sleep' or 'operator']") 14 | dest := flag.String("dest", "/mount/sleep", "The location to copy the binary to when command is 'copy'") 15 | flag.Parse() 16 | 17 | switch strings.ToLower(*command) { 18 | case "copy": 19 | if err := copy.Run(*dest); err != nil { 20 | panic(err) 21 | } 22 | case "sleep": 23 | if err := sleep.Run(); err != nil { 24 | panic(err) 25 | } 26 | default: 27 | if err := operator.Run(); err != nil { 28 | panic(err) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /manifest.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRole 3 | metadata: 4 | name: kube-image-prefetch 5 | rules: 6 | - apiGroups: 7 | - apps 8 | resources: 9 | - deployments 10 | verbs: 11 | - get 12 | - watch 13 | - list 14 | - apiGroups: 15 | - apps 16 | resources: 17 | - daemonsets 18 | resourceNames: 19 | - kube-image-prefetch 20 | verbs: 21 | - get 22 | - update 23 | - patch 24 | - apiGroups: 25 | - apps 26 | resources: 27 | - daemonsets 28 | verbs: 29 | - create 30 | --- 31 | apiVersion: rbac.authorization.k8s.io/v1 32 | kind: ClusterRoleBinding 33 | metadata: 34 | name: kube-image-prefetch 35 | subjects: 36 | - kind: ServiceAccount 37 | name: kube-image-prefetch 38 | namespace: kube-system 39 | roleRef: 40 | kind: ClusterRole 41 | name: kube-image-prefetch 42 | apiGroup: rbac.authorization.k8s.io 43 | --- 44 | apiVersion: v1 45 | kind: ServiceAccount 46 | metadata: 47 | name: kube-image-prefetch 48 | namespace: kube-system 49 | --- 50 | apiVersion: apps/v1 51 | kind: Deployment 52 | metadata: 53 | name: kube-image-prefetch-manager 54 | namespace: kube-system 55 | spec: 56 | replicas: 1 57 | selector: 58 | matchLabels: 59 | app: kube-image-prefetch-manager 60 | template: 61 | metadata: 62 | labels: 63 | app: kube-image-prefetch-manager 64 | spec: 65 | serviceAccountName: kube-image-prefetch 66 | containers: 67 | - name: kube-image-prefetch 68 | image: averagemarcus/kube-image-prefetch:latest 69 | imagePullPolicy: Always 70 | --------------------------------------------------------------------------------