Skip to content

Commit

Permalink
bugfix: handle default images register
Browse files Browse the repository at this point in the history
  • Loading branch information
mandochen committed Jun 5, 2023
1 parent ba0d93a commit 0962ace
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

const version = "0.6.1"
const version = "0.6.2"

var rootCmd *cobra.Command

Expand Down
24 changes: 21 additions & 3 deletions kubectl_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -191,6 +192,11 @@ func (ki *KubeImage) nodeCommands() []string {
return append([]string{"get", "nodes", "-o", nodeTemplate}, kubecfg...)
}

func (ki *KubeImage) recordImageSize(image string, size int) {
ki.imageSize[image] = size
ki.imageSize[path.Base(image)] = size
}

func (ki *KubeImage) execNodeCommand() {
process := exec.Command("kubectl", ki.nodeCommands()...)
bs, err := process.CombinedOutput()
Expand All @@ -202,17 +208,29 @@ func (ki *KubeImage) execNodeCommand() {
for _, line := range stringSplit(string(bs), "\n") {
items := stringSplit(line, ",")
switch len(items) {
case 2:
size, err := strconv.Atoi(items[1])
if err != nil {
continue
}

ki.recordImageSize(items[0], size)
parts := strings.Split(items[0], ":")
if len(parts) == 2 && parts[1] == "latest" {
ki.recordImageSize(parts[0], size)
}

case 3:
size, err := strconv.Atoi(items[2])
if err != nil {
continue
}

ki.imageSize[items[0]] = size
ki.imageSize[items[1]] = size
ki.recordImageSize(items[0], size)
ki.recordImageSize(items[1], size)
parts := strings.Split(items[1], ":")
if len(parts) == 2 && parts[1] == "latest" {
ki.imageSize[parts[0]] = size
ki.recordImageSize(parts[0], size)
}
}
}
Expand Down

0 comments on commit 0962ace

Please sign in to comment.