Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor image pulling logic to support different pull commands, fix crictl pull failure #2485

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions cmd/kk/pkg/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,30 @@ func (images *Images) PullImages(runtime connector.Runtime, kubeConf *common.Kub

host := runtime.RemoteHost()

for _, image := range images.Images {
switch {
case host.IsRole(common.Master) && image.Group == kubekeyapiv1alpha2.Master && image.Enable,
host.IsRole(common.Worker) && image.Group == kubekeyapiv1alpha2.Worker && image.Enable,
(host.IsRole(common.Master) || host.IsRole(common.Worker)) && image.Group == kubekeyapiv1alpha2.K8s && image.Enable,
host.IsRole(common.ETCD) && image.Group == kubekeyapiv1alpha2.Etcd && image.Enable:

logger.Log.Messagef(host.GetName(), "downloading image: %s", image.ImageName())
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("env PATH=$PATH %s pull %s --platform %s", pullCmd, image.ImageName(), host.GetArch()), false); err != nil {
return errors.Wrap(err, "pull image failed")
}
default:
continue
}

}
return nil
for _, image := range images.Images {
switch {
case host.IsRole(common.Master) && image.Group == kubekeyapiv1alpha2.Master && image.Enable,
host.IsRole(common.Worker) && image.Group == kubekeyapiv1alpha2.Worker && image.Enable,
(host.IsRole(common.Master) || host.IsRole(common.Worker)) && image.Group == kubekeyapiv1alpha2.K8s && image.Enable,
host.IsRole(common.ETCD) && image.Group == kubekeyapiv1alpha2.Etcd && image.Enable:

logger.Log.Messagef(host.GetName(), "downloading image: %s", image.ImageName())

var pullCommand string
if pullCmd == "crictl" {
pullCommand = fmt.Sprintf("env PATH=$PATH %s pull %s", pullCmd, image.ImageName())
} else {
pullCommand = fmt.Sprintf("env PATH=$PATH %s pull %s --platform %s", pullCmd, image.ImageName(), host.GetArch())
}

if _, err := runtime.GetRunner().SudoCmd(pullCommand, false); err != nil {
return errors.Wrap(err, "pull image failed")
}
default:
continue
}
}
return nil
}

// DefaultRegistry is used to get default registry address.
Expand Down