* Copyright (c) 2025 Bocloud Technologies Co., Ltd.
* installer is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain n copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
******************************************************************/
package build
import (
"fmt"
"os"
"path"
"gopkg.in/yaml.v3"
"gopkg.openfuyao.cn/bkeadm/utils"
"gopkg.openfuyao.cn/bkeadm/utils/log"
)
type BuildConfig struct {
Registry registry `yaml:"registry"`
OpenFuyaoVersion string `yaml:"openFuyaoVersion"`
KubernetesVersion string `yaml:"kubernetesVersion"`
EtcdVersion string `yaml:"etcdVersion"`
ContainerdVersion string `yaml:"containerdVersion"`
Repos []Repo `yaml:"repos"`
Rpms []Rpm `yaml:"rpms"`
Debs []Deb `yaml:"debs"`
Files []File `yaml:"files"`
Patches []File `yaml:"patches"`
Charts []File `yaml:"charts"`
}
type registry struct {
ImageAddress string `yaml:"imageAddress"`
Architecture []string `yaml:"architecture"`
}
type Repo struct {
Architecture []string `yaml:"architecture"`
NeedDownload bool `yaml:"needDownload"`
IsKubernetes bool `yaml:"isKubernetes"`
SubImages []SubImage `yaml:"subImages"`
}
type SubImage struct {
SourceRepo string `yaml:"sourceRepo"`
TargetRepo string `yaml:"targetRepo"`
ImageTrack string `yaml:"imageTrack"`
SkipTLSVerify *bool `yaml:"skipTLSVerify"`
Images []Image `yaml:"images"`
}
type Image struct {
Name string `json:"name" yaml:"name"`
UsedPodInfo []PodInfo `json:"usedPodInfo" yaml:"usedPodInfo"`
Tag []string `json:"tag" yaml:"tag"`
}
type PodInfo struct {
PodPrefix string `json:"podPrefix" yaml:"podPrefix"`
NameSpace string `json:"namespace" yaml:"namespace"`
}
Centos/7/amd64/docker-ce/*
*/
type Rpm struct {
Address string `yaml:"address"`
System []string `yaml:"system"`
SystemVersion []string `yaml:"systemVersion"`
SystemArchitecture []string `yaml:"systemArchitecture"`
Directory []string `yaml:"directory"`
}
Centos/7/amd64/docker-ce/*
*/
type Deb struct {
Address string `yaml:"address"`
System []string `yaml:"system"`
SystemVersion []string `yaml:"systemVersion"`
SystemArchitecture []string `yaml:"systemArchitecture"`
Directory []string `yaml:"directory"`
}
type File struct {
Address string `yaml:"address"`
Files []FileInfo `yaml:"files"`
}
type FileInfo struct {
FileName string `yaml:"fileName"`
FileAlias string `yaml:"fileAlias"`
}
func (o *Options) Config() {
cfg := o.buildConfig()
b, err := yaml.Marshal(cfg)
if err != nil {
log.Errorf("Description Failed to parse the configuration file %v", err)
return
}
curPath, err := os.Getwd()
if err != nil {
log.Warnf("Failed to get current working directory: %v", err)
}
err = os.WriteFile(path.Join(curPath, "build.yaml"), b, utils.DefaultFilePermission)
if err != nil {
log.Errorf("Failed to write the configuration file. Procedure %v", err)
return
}
fmt.Println("The sample file is generated in the current directory and is called build.yaml")
}
func (o *Options) buildConfig() BuildConfig {
return BuildConfig{
Registry: registry{
ImageAddress: fmt.Sprintf("registry.bocloud.com/kubernetes/%s", utils.DefaultLocalImageRegistry),
Architecture: []string{"amd64"},
},
Repos: []Repo{
{
Architecture: []string{"amd64"},
NeedDownload: true,
SubImages: []SubImage{
{
SourceRepo: "registry.bocloud.com/kubernetes",
TargetRepo: "kubernetes",
Images: []Image{
{Name: "registry", Tag: []string{"2.8.1"}},
{Name: "nginx_yum_repo", Tag: []string{"1.23.0-alpine"}},
{Name: "chartmuseum", Tag: []string{"0.15.0"}},
{Name: "nfs-server-alpine", Tag: []string{"0.9.0"}},
{Name: "k3s", Tag: []string{"v1.25.7-k3s1"}},
{Name: "mirrored-pause", Tag: []string{"3.6"}},
},
},
},
},
},
Rpms: []Rpm{
{
Address: "http://127.0.0.1:40080/",
System: []string{"CentOS"},
SystemVersion: []string{"7"},
SystemArchitecture: []string{"amd64"},
Directory: []string{"docker-ce"},
},
},
Files: []File{
{
Address: "http://127.0.0.1:40080/files/",
Files: []FileInfo{
{"bkeadm_linux_amd64", ""},
{"containerd-1.7.14-linux-amd64.tar.gz", ""},
{"charts.tar.gz", ""},
{"nfsshare.tar.gz", ""},
{"kubectl-v1.23.17-amd64", ""},
{"cni-plugins-linux-amd64-v1.2.0.tgz", ""},
},
},
},
}
}