mirror of
https://github.com/labring/sealos.git
synced 2026-09-24 15:46:19 +08:00
imagecrbuilder better code (#2334)
* add imageCrdBuilder split some function to make the logic clear fit new buildah implement add image id arch and size read * add some imgeCrdBuilder change add CheckLoginStatus() to check wheather push image should appen ReadOrBuildAppConfig() add logic when user didn't write any image config add Image base info read such as image size image arch ... delete action content read now sealos push args is allow to be one or two ,when one ,this arg is both dst and src.when args has two , the secend is dest. * use config.GetAllCredentials to place CheckLoginStatus in imagecrdbuilder * change some func name to better understand add Success and Faild output * add some comment write ReadOrBuildImageCRFile better
This commit is contained in:
@@ -59,7 +59,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
//Read Content Output
|
||||
//Read Content Success Output
|
||||
SuccessCreateContainer = "Success create container"
|
||||
SuccessReadOrBuildImageCROutput = "Success get image cr"
|
||||
SuccessReadImageInfoOutput = "Success read image Info"
|
||||
@@ -69,7 +69,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
//Read Content Output
|
||||
//Read Content Failed Output
|
||||
FailCreateContainer = "Fail to create container"
|
||||
FailReadOrBuildImageCROutput = "Fail to get image cr"
|
||||
FailReadImageInfoOutput = "Fail to read image Info"
|
||||
@@ -255,22 +255,19 @@ func (icb *ImageCRBuilder) ReadOrBuildImageCRFile(MountPoint string) (string, er
|
||||
if err = icb.ImageCRParse(c); err != nil {
|
||||
return FailReadOrBuildImageCROutput, fmt.Errorf("read ImageCR err : %v", err)
|
||||
}
|
||||
} else {
|
||||
//if app base config not find
|
||||
//image name which contains "/" and ":" couldn't be used in meta name
|
||||
MetaName := strings.Replace(icb.GetClearImagename(), ":", ".", -1)
|
||||
MetaName = strings.Replace(MetaName, "/", ".", -1)
|
||||
c := imagev1.Image{
|
||||
TypeMeta: metav1.TypeMeta{Kind: ImagehubKind, APIVersion: filepath.Join(ImagehubGroup, ImagehubVersion)},
|
||||
ObjectMeta: metav1.ObjectMeta{Name: MetaName},
|
||||
Spec: imagev1.ImageSpec{Name: imagev1.ImageName(icb.GetClearImagename())},
|
||||
Status: imagev1.ImageStatus{},
|
||||
}
|
||||
icb.ImageCR = &c
|
||||
}
|
||||
//if app base config not find
|
||||
//image name which contains "/" and ":" couldn't be used in meta name
|
||||
MetaName := strings.Replace(icb.GetClearImagename(), ":", ".", -1)
|
||||
MetaName = strings.Replace(MetaName, "/", ".", -1)
|
||||
// replace image cr spec and matename by imagename
|
||||
icb.ImageCR.TypeMeta = metav1.TypeMeta{Kind: ImagehubKind, APIVersion: filepath.Join(ImagehubGroup, ImagehubVersion)}
|
||||
icb.ImageCR.ObjectMeta.Name = MetaName
|
||||
icb.ImageCR.Spec.Name = imagev1.ImageName(icb.GetClearImagename())
|
||||
return SuccessReadOrBuildImageCROutput, nil
|
||||
}
|
||||
|
||||
// ImageCRParse parse image cr yaml file ot an image cr obj
|
||||
func (icb *ImageCRBuilder) ImageCRParse(c []byte) error {
|
||||
cr := imagev1.Image{}
|
||||
_, _, err := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(c, nil, &cr)
|
||||
@@ -282,6 +279,7 @@ func (icb *ImageCRBuilder) ImageCRParse(c []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReadReadme gen image cr detail info: Readme
|
||||
func (icb *ImageCRBuilder) ReadReadme(MountPoint string) (string, error) {
|
||||
if file.IsExist(filepath.Join(MountPoint, READMEpath)) {
|
||||
c, err := file.ReadAll(filepath.Join(MountPoint, READMEpath))
|
||||
@@ -293,6 +291,7 @@ func (icb *ImageCRBuilder) ReadReadme(MountPoint string) (string, error) {
|
||||
return SuccessReadReadmeOutput, nil
|
||||
}
|
||||
|
||||
// ReadInspectInfo gen image cr detail info: Id, Arch and Size
|
||||
func (icb *ImageCRBuilder) ReadInspectInfo(MountPoint string) (string, error) {
|
||||
realImpl, err := New("")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user