Skip to content

Commit

Permalink
Moves interactions with kicDriver's bin inside oci driver package
Browse files Browse the repository at this point in the history
  • Loading branch information
x7upLime committed Dec 6, 2022
1 parent 0ed0966 commit 2c68b45
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/drivers/kic/oci/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package oci

import (
"os/exec"
"strings"

"k8s.io/minikube/pkg/minikube/image"
)

// ToDriverCache
// calls OCIBIN's load command at specified path:
// loads the archived container image at provided PATH.
func ArchiveToDriverCache(ociBin, path string) (string, error) {
_, err := runCmd(exec.Command(ociBin, "load", "-i", path))
return "", err
}

// IsInCache
// searches in OCIBIN's cache for the IMG; returns true if found. no error handling
func IsImageInCache(ociBin, img string) (bool) {
res, err := runCmd(exec.Command(ociBin, "images", "--format", "{{.Repository}}:{{.Tag}}@{{.Digest}}"))
if err != nil {
// only the docker binary seems to have this issue..
// the docker.io/ substring is cut from the output and formatting doesn't help
if ociBin == Docker {
img = image.TrimDockerIO(img)
}

if strings.Contains(res.Stdout.String(), img){
return true
}
}

return false
}
11 changes: 11 additions & 0 deletions pkg/drivers/kic/oci/download.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package oci

import (
"os/exec"
"bytes"
)

func PullImage(ociBin, img string) (bytes.Buffer, error) {
res, err := runCmd(exec.Command(ociBin, "pull", "--quiet", img))
return res.Stdout, err
}

0 comments on commit 2c68b45

Please sign in to comment.