mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
fix the image name parsing panic
Signed-off-by: 24sama <jacksama@foxmail.com>
This commit is contained in:
parent
b5990f4298
commit
77cc90cffd
|
|
@ -156,6 +156,9 @@ func (s *SaveImages) Execute(runtime connector.Runtime) error {
|
|||
return errors.Wrapf(errors.WithStack(err), "mkdir %s failed", dirName)
|
||||
}
|
||||
for _, image := range s.Manifest.Spec.Images {
|
||||
if err := validateImageName(image); err != nil {
|
||||
return err
|
||||
}
|
||||
imageFullName := strings.Split(image, "/")
|
||||
repo := imageFullName[0]
|
||||
auth := new(registry.DockerRegistryEntry)
|
||||
|
|
@ -171,8 +174,8 @@ func (s *SaveImages) Execute(runtime connector.Runtime) error {
|
|||
variant = "-" + variant
|
||||
}
|
||||
// Ex:
|
||||
// oci:./kubekey/artifact/images:kubesphere:kube-apiserver-amd64:v1.21.5
|
||||
// oci:./kubekey/artifact/images:kubesphere:kube-apiserver-arm-v7:v1.21.5
|
||||
// oci:./kubekey/artifact/images:kubesphere:kube-apiserver:v1.21.5-amd64
|
||||
// oci:./kubekey/artifact/images:kubesphere:kube-apiserver:v1.21.5-arm-v7
|
||||
destName := fmt.Sprintf("oci:%s:%s:%s-%s%s", dirName, imageFullName[1], imageFullName[2], arch, variant)
|
||||
logger.Log.Infof("Source: %s", srcName)
|
||||
logger.Log.Infof("Destination: %s", destName)
|
||||
|
|
|
|||
|
|
@ -18,12 +18,15 @@ package images
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containers/image/v5/types"
|
||||
manifesttypes "github.com/estesp/manifest-tool/v2/pkg/types"
|
||||
"github.com/kubesphere/kubekey/cmd/kk/pkg/core/logger"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"strings"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/kubesphere/kubekey/cmd/kk/pkg/core/logger"
|
||||
)
|
||||
|
||||
var defaultUserAgent = "kubekey"
|
||||
|
|
@ -167,3 +170,14 @@ func NewManifestSpec(image string, entries []manifesttypes.ManifestEntry) manife
|
|||
Manifests: srcImages,
|
||||
}
|
||||
}
|
||||
|
||||
func validateImageName(imageFullName string) error {
|
||||
image := strings.Split(imageFullName, "/")
|
||||
if len(image) != 3 {
|
||||
return errors.Errorf("image %s is invalid, only the format \"registry/namespace/name:tag\" is supported", imageFullName)
|
||||
}
|
||||
if len(strings.Split(image[2], ":")) != 2 {
|
||||
return errors.Errorf("image %s is invalid, only the format \"registry/namespace/name:tag\" is supported", imageFullName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue