refactor: change "contants" to "constants" (#1142)

This commit is contained in:
Mercurio
2022-06-21 13:41:40 +08:00
committed by GitHub
parent 500a23f228
commit d24d09f16a
42 changed files with 137 additions and 137 deletions
+5 -5
View File
@@ -20,7 +20,7 @@ import (
"os"
"path"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/ipvs"
@@ -40,7 +40,7 @@ func NewStaticPodCmd() *cobra.Command {
}
// check route for host
cmd.AddCommand(NewLvscareCmd())
cmd.PersistentFlags().StringVar(&staticPodPath, "path", contants.KubernetesEtcStaticPod, "default kubernetes static pod path")
cmd.PersistentFlags().StringVar(&staticPodPath, "path", constants.KubernetesEtcStaticPod, "default kubernetes static pod path")
return cmd
}
@@ -58,7 +58,7 @@ func NewLvscareCmd() *cobra.Command {
}
},
Run: func(cmd *cobra.Command, args []string) {
fileName := fmt.Sprintf("%s.%s", name, contants.YamlFileSuffix)
fileName := fmt.Sprintf("%s.%s", name, constants.YamlFileSuffix)
yaml, err := ipvs.LvsStaticPodYaml(vip, masters, image, name)
if err != nil {
logger.Error(err)
@@ -83,8 +83,8 @@ func NewLvscareCmd() *cobra.Command {
}
// manually to set host via gateway
cmd.Flags().StringVar(&vip, "vip", "10.103.97.2:6443", "default vip IP")
cmd.Flags().StringVar(&name, "name", contants.LvsCareStaticPodName, "generator lvscare static pod name")
cmd.Flags().StringVar(&image, "image", contants.DefaultLvsCareImage, "generator lvscare static pod image")
cmd.Flags().StringVar(&name, "name", constants.LvsCareStaticPodName, "generator lvscare static pod name")
cmd.Flags().StringVar(&image, "image", constants.DefaultLvsCareImage, "generator lvscare static pod image")
cmd.Flags().StringSliceVar(&masters, "masters", []string{}, "generator masters addrs")
cmd.Flags().BoolVar(&printBool, "print", false, "is print yaml")
return cmd
+7 -7
View File
@@ -18,7 +18,7 @@ import (
"fmt"
"os"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/sirupsen/logrus"
@@ -53,21 +53,21 @@ func init() {
cobra.OnInitialize(onBootOnDie)
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logger")
rootCmd.PersistentFlags().StringVar(&clusterRootDir, "clusterRootDir", contants.DefaultClusterRootfsDir, "cluster root directory")
rootCmd.PersistentFlags().StringVar(&clusterRootDir, "cluster-root", constants.DefaultClusterRootfsDir, "cluster root directory")
}
func onBootOnDie() {
contants.DefaultClusterRootfsDir = clusterRootDir
constants.DefaultClusterRootfsDir = clusterRootDir
var rootDirs = []string{
contants.LogPath(),
contants.DataPath(),
contants.Workdir(),
constants.LogPath(),
constants.DataPath(),
constants.Workdir(),
}
if err := file.MkDirs(rootDirs...); err != nil {
logger.Error(err)
panic(1)
}
logger.CfgAndFile(debug, contants.LogPath(), "sealos", false)
logger.CfgAndFile(debug, constants.LogPath(), "sealos", false)
setupLogrus()
}
+4 -4
View File
@@ -61,8 +61,8 @@ create a cluster with custom environment variables:
`
var runArgs *apply.RunArgs
func newInitCmd() *cobra.Command {
var initCmd = &cobra.Command{
func newRunCmd() *cobra.Command {
var runCmd = &cobra.Command{
Use: "run",
Short: "Simplest way to run your kubernets HA cluster",
Long: `sealos run labring/kubernetes:v1.24.0 --masters [arg] --nodes [arg]`,
@@ -78,12 +78,12 @@ func newInitCmd() *cobra.Command {
logger.Info(contact)
},
}
return initCmd
return runCmd
}
func init() {
runArgs = &apply.RunArgs{}
runCmd := newInitCmd()
runCmd := newRunCmd()
rootCmd.AddCommand(runCmd)
runCmd.Flags().StringVarP(&runArgs.Masters, "masters", "m", "", "set Count or IPList to masters")
runCmd.Flags().StringVarP(&runArgs.Nodes, "nodes", "n", "", "set Count or IPList to nodes")
@@ -26,7 +26,7 @@ import (
"github.com/labring/sealos/pkg/client-go/kubernetes"
"github.com/labring/sealos/pkg/clusterfile"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"k8s.io/apimachinery/pkg/version"
)
@@ -34,7 +34,7 @@ func NewDefaultApplier(cluster *v2.Cluster, images []string) (Interface, error)
if cluster.Name == "" {
return nil, fmt.Errorf("cluster name cannot be empty")
}
cFile := clusterfile.NewClusterFile(contants.Clusterfile(cluster.Name))
cFile := clusterfile.NewClusterFile(constants.Clusterfile(cluster.Name))
_ = cFile.Process()
return &Applier{
ClusterDesired: cluster,
@@ -48,7 +48,7 @@ func NewDefaultScaleApplier(current, cluster *v2.Cluster) (Interface, error) {
if cluster.Name == "" {
return nil, fmt.Errorf("cluster name cannot be empty")
}
cFile := clusterfile.NewClusterFile(contants.Clusterfile(cluster.Name))
cFile := clusterfile.NewClusterFile(constants.Clusterfile(cluster.Name))
return &Applier{
ClusterDesired: cluster,
ClusterFile: cFile,
@@ -66,7 +66,7 @@ type Applier struct {
}
func (c *Applier) Apply() error {
clusterPath := contants.Clusterfile(c.ClusterDesired.Name)
clusterPath := constants.Clusterfile(c.ClusterDesired.Name)
if c.ClusterDesired.CreationTimestamp.IsZero() {
if err := c.initCluster(); err != nil {
return err
+3 -3
View File
@@ -33,7 +33,7 @@ import (
"github.com/labring/sealos/pkg/image/types"
"github.com/labring/sealos/pkg/runtime"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/yaml"
)
@@ -92,7 +92,7 @@ func (c *CreateProcessor) CheckImageType(cluster *v2.Cluster) error {
imageTypes := sets.NewString()
for _, oci := range ociList {
if oci.Config.Labels != nil {
imageTypes.Insert(oci.Config.Labels[contants.ImageTypeKey])
imageTypes.Insert(oci.Config.Labels[constants.ImageTypeKey])
} else {
imageTypes.Insert(string(v2.AppImage))
}
@@ -174,7 +174,7 @@ func (c *CreateProcessor) Join(cluster *v2.Cluster) error {
if err != nil {
return err
}
return yaml.MarshalYamlToFile(contants.Clusterfile(cluster.Name), cluster)
return yaml.MarshalYamlToFile(constants.Clusterfile(cluster.Name), cluster)
}
func (c *CreateProcessor) RunGuest(cluster *v2.Cluster) error {
+3 -3
View File
@@ -28,7 +28,7 @@ import (
"github.com/labring/sealos/pkg/image/types"
"github.com/labring/sealos/pkg/runtime"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
fileutil "github.com/labring/sealos/pkg/utils/file"
)
@@ -104,8 +104,8 @@ func (d DeleteProcessor) UnMountImage(cluster *v2.Cluster) error {
}
func (d DeleteProcessor) CleanFS(cluster *v2.Cluster) error {
workDir := contants.ClusterDir(cluster.Name)
dataDir := contants.NewData(cluster.Name).Homedir()
workDir := constants.ClusterDir(cluster.Name)
dataDir := constants.NewData(cluster.Name).Homedir()
return fileutil.CleanFiles(workDir, dataDir)
}
+2 -2
View File
@@ -35,7 +35,7 @@ import (
"github.com/labring/sealos/pkg/image"
"github.com/labring/sealos/pkg/image/types"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
)
var ForceOverride bool
@@ -113,7 +113,7 @@ func (c *InstallProcessor) PreProcess(cluster *v2.Cluster) error {
imageTypes := sets.NewString()
for _, oci := range ociList {
if oci.Config.Labels != nil {
imageTypes.Insert(oci.Config.Labels[contants.ImageTypeKey])
imageTypes.Insert(oci.Config.Labels[constants.ImageTypeKey])
} else {
imageTypes.Insert(string(v2.AppImage))
}
+3 -3
View File
@@ -18,7 +18,7 @@ import (
"github.com/labring/sealos/pkg/image/types"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/confirm"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/maps"
"github.com/labring/sealos/pkg/utils/strings"
@@ -80,8 +80,8 @@ func OCIToImageMount(mount *v2.MountImage, imgService types.Service) error {
mount.Cmd = newCMDs
mount.Labels = oci[0].Config.Labels
imageType := v2.AppImage
if mount.Labels[contants.ImageTypeKey] != "" {
imageType = v2.ImageType(mount.Labels[contants.ImageTypeKey])
if mount.Labels[constants.ImageTypeKey] != "" {
imageType = v2.ImageType(mount.Labels[constants.ImageTypeKey])
}
mount.Type = imageType
}
+2 -2
View File
@@ -27,7 +27,7 @@ import (
"github.com/labring/sealos/pkg/image/types"
"github.com/labring/sealos/pkg/runtime"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/yaml"
"golang.org/x/sync/errgroup"
@@ -149,7 +149,7 @@ func (c *ScaleProcessor) PreProcess(cluster *v2.Cluster) error {
return err
}
if c.IsScaleUp {
clusterPath := contants.Clusterfile(cluster.Name)
clusterPath := constants.Clusterfile(cluster.Name)
if err = yaml.MarshalYamlToFile(clusterPath, cluster); err != nil {
return err
}
+2 -2
View File
@@ -18,7 +18,7 @@ import (
"github.com/labring/sealos/pkg/apply/applydrivers"
"github.com/labring/sealos/pkg/clusterfile"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
fileutil "github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/yaml"
@@ -27,7 +27,7 @@ import (
func NewApplierFromResetArgs(args *ResetArgs) (applydrivers.Interface, error) {
var cluster *v2.Cluster
clusterPath := contants.Clusterfile(args.ClusterName)
clusterPath := constants.Clusterfile(args.ClusterName)
if fileutil.IsExist(clusterPath) {
clusterFile := clusterfile.NewClusterFile(clusterPath)
err := clusterFile.Process()
+2 -2
View File
@@ -23,7 +23,7 @@ import (
"github.com/labring/sealos/pkg/apply/applydrivers"
"github.com/labring/sealos/pkg/clusterfile"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
fileutil "github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/iputils"
"github.com/labring/sealos/pkg/utils/logger"
@@ -38,7 +38,7 @@ type ClusterArgs struct {
func NewApplierFromArgs(imageName []string, args *RunArgs) (applydrivers.Interface, error) {
var cluster *v2.Cluster
clusterPath := contants.Clusterfile(args.ClusterName)
clusterPath := constants.Clusterfile(args.ClusterName)
if !fileutil.IsExist(clusterPath) {
cluster = initCluster(args.ClusterName)
} else {
+2 -2
View File
@@ -26,7 +26,7 @@ import (
"github.com/labring/sealos/pkg/apply/applydrivers"
"github.com/labring/sealos/pkg/clusterfile"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
fileutil "github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/iputils"
strings2 "github.com/labring/sealos/pkg/utils/strings"
@@ -36,7 +36,7 @@ import (
func NewScaleApplierFromArgs(scaleArgs *ScaleArgs, flag string) (applydrivers.Interface, error) {
var cluster *v2.Cluster
var curr *v2.Cluster
clusterPath := contants.Clusterfile(scaleArgs.ClusterName)
clusterPath := constants.Clusterfile(scaleArgs.ClusterName)
if !fileutil.IsExist(clusterPath) {
cluster = initCluster(scaleArgs.ClusterName)
curr = cluster
+2 -2
View File
@@ -22,7 +22,7 @@ import (
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -48,7 +48,7 @@ func (n *ClusterChecker) Check(cluster *v2.Cluster, phase string) error {
}
// checker if all the node is ready
data := contants.NewData(cluster.Name)
data := constants.NewData(cluster.Name)
c, err := kubernetes.NewKubernetesClient(data.AdminFile(), cluster.GetMaster0IPAPIServer())
if err != nil {
return err
+2 -2
View File
@@ -20,7 +20,7 @@ import (
"os"
"text/template"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -51,7 +51,7 @@ func (n *NodeChecker) Check(cluster *v2.Cluster, phase string) error {
return nil
}
// checker if all the node is ready
data := contants.NewData(cluster.Name)
data := constants.NewData(cluster.Name)
c, err := kubernetes.NewKubernetesClient(data.AdminFile(), cluster.GetMaster0IPAPIServer())
if err != nil {
return err
+2 -2
View File
@@ -19,7 +19,7 @@ import (
"github.com/labring/sealos/pkg/runtime"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/decode"
fileutil "github.com/labring/sealos/pkg/utils/file"
)
@@ -68,7 +68,7 @@ func (c *ClusterFile) DecodeCluster(data []byte) error {
}
func (c *ClusterFile) DecodeConfigs(data []byte) error {
configs, err := decode.CRDForBytes(data, contants.Config)
configs, err := decode.CRDForBytes(data, constants.Config)
if err != nil {
return err
}
+6 -6
View File
@@ -22,7 +22,7 @@ import (
"github.com/labring/sealos/pkg/runtime"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
yaml2 "github.com/labring/sealos/pkg/utils/yaml"
k8sV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -32,7 +32,7 @@ import (
var ErrClusterNotExist = fmt.Errorf("no cluster exist")
func GetDefaultClusterName() (string, error) {
files, err := ioutil.ReadDir(contants.Workdir())
files, err := ioutil.ReadDir(constants.Workdir())
if err != nil {
return "", err
}
@@ -57,7 +57,7 @@ func GetClusterFromName(clusterName string) (cluster *v2.Cluster, err error) {
return nil, err
}
}
clusterFile := contants.Clusterfile(clusterName)
clusterFile := constants.Clusterfile(clusterName)
cluster, err = GetClusterFromFile(clusterFile)
return
}
@@ -75,7 +75,7 @@ func GetDefaultCluster() (cluster *v2.Cluster, err error) {
return nil, err
}
var filepath = contants.Clusterfile(name)
var filepath = constants.Clusterfile(name)
return GetClusterFromFile(filepath)
}
@@ -87,10 +87,10 @@ func GetClusterFromDataCompatV1(data []byte) (*v2.Cluster, error) {
if err != nil {
return nil, err
}
if metaType.Kind != contants.Cluster {
if metaType.Kind != constants.Cluster {
return nil, fmt.Errorf("not found type cluster from: \n%s", data)
}
c, err := runtime.DecodeCRDFromString(string(data), contants.Cluster)
c, err := runtime.DecodeCRDFromString(string(data), constants.Cluster)
if err != nil {
return nil, err
} else if c == nil {
+2 -2
View File
@@ -22,7 +22,7 @@ import (
"github.com/labring/sealos/pkg/utils/maps"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/file"
@@ -64,7 +64,7 @@ func NewConfiguration(rootPath string, configs []v1beta1.Config) Interface {
}
func NewDefaultConfiguration(clusterName string) Interface {
return &Dumper{
RootPath: contants.NewData(clusterName).RootFSPath(),
RootPath: constants.NewData(clusterName).RootFSPath(),
}
}
+9 -9
View File
@@ -31,7 +31,7 @@ import (
"github.com/labring/sealos/pkg/env"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/exec"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/ssh"
@@ -63,7 +63,7 @@ func (f *defaultRootfs) getSSH(cluster *v2.Cluster) ssh.Interface {
}
func (f *defaultRootfs) mountRootfs(cluster *v2.Cluster, ipList []string, initFlag, appFlag bool) error {
target := contants.NewData(f.getClusterName(cluster)).RootFSPath()
target := constants.NewData(f.getClusterName(cluster)).RootFSPath()
eg, _ := errgroup.WithContext(context.Background())
envProcessor := env.NewEnvProcessor(cluster, f.images)
@@ -83,7 +83,7 @@ func (f *defaultRootfs) mountRootfs(cluster *v2.Cluster, ipList []string, initFl
return errors.Wrap(err, "get rootfs files failed")
}
if len(dirs) != 0 {
_, err = exec.RunBashCmd(fmt.Sprintf(contants.DefaultChmodBash, src.MountPoint))
_, err = exec.RunBashCmd(fmt.Sprintf(constants.DefaultChmodBash, src.MountPoint))
if err != nil {
return errors.Wrap(err, "run chmod to rootfs failed")
}
@@ -94,7 +94,7 @@ func (f *defaultRootfs) mountRootfs(cluster *v2.Cluster, ipList []string, initFl
if err := eg.Wait(); err != nil {
return err
}
check := contants.NewBash(f.getClusterName(cluster), cluster.GetImageLabels())
check := constants.NewBash(f.getClusterName(cluster), cluster.GetImageLabels())
sshClient := f.getSSH(cluster)
for _, IP := range ipList {
ip := IP
@@ -163,7 +163,7 @@ func (f *defaultRootfs) mountRootfs(cluster *v2.Cluster, ipList []string, initFl
return endEg.Wait()
}
func (f *defaultRootfs) unmountRootfs(cluster *v2.Cluster, ipList []string) error {
clusterRootfsDir := contants.NewData(f.getClusterName(cluster)).Homedir()
clusterRootfsDir := constants.NewData(f.getClusterName(cluster)).Homedir()
rmRootfs := fmt.Sprintf("rm -rf %s", clusterRootfsDir)
eg, _ := errgroup.WithContext(context.Background())
@@ -179,9 +179,9 @@ func (f *defaultRootfs) unmountRootfs(cluster *v2.Cluster, ipList []string) erro
func renderENV(mountDir string, ipList []string, p env.Interface) error {
var (
renderEtc = path.Join(mountDir, contants.EtcDirName)
renderChart = path.Join(mountDir, contants.ChartsDirName)
renderManifests = path.Join(mountDir, contants.ManifestsDirName)
renderEtc = path.Join(mountDir, constants.EtcDirName)
renderChart = path.Join(mountDir, constants.ChartsDirName)
renderManifests = path.Join(mountDir, constants.ManifestsDirName)
)
for _, ip := range ipList {
@@ -211,7 +211,7 @@ func CopyFiles(sshEntry ssh.Interface, isRegistry, isApp bool, ip, src, target s
targetIP = "127.0.0.1"
}
for _, f := range files {
if f.Name() == contants.RegistryDirName {
if f.Name() == constants.RegistryDirName {
continue
}
err = sshEntry.Copy(targetIP, filepath.Join(src, f.Name()), filepath.Join(target, f.Name()))
+4 -4
View File
@@ -33,7 +33,7 @@ import (
"github.com/labring/sealos/pkg/image/types"
"github.com/labring/sealos/pkg/runtime"
v2 "github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/maps"
)
@@ -55,14 +55,14 @@ func NewGuestManager() (Interface, error) {
}
func (d *Default) Apply(cluster *v2.Cluster, mounts []v2.MountImage) error {
clusterRootfs := runtime.GetContantData(cluster.Name).RootFSPath()
clusterRootfs := runtime.GetConstantData(cluster.Name).RootFSPath()
envInterface := env.NewEnvProcessor(cluster, cluster.Status.Mounts)
envs := envInterface.WrapperEnv(cluster.GetMaster0IP()) //clusterfile
guestCMD := d.getGuestCmd(envs, cluster, mounts)
kubeConfig := filepath.Join(homedir.HomeDir(), ".kube", "config")
if !fileutil.IsExist(kubeConfig) {
adminFile := runtime.GetContantData(cluster.Name).AdminFile()
adminFile := runtime.GetConstantData(cluster.Name).AdminFile()
data, err := fileutil.ReadAll(adminFile)
if err != nil {
return errors.Wrap(err, "read admin.conf error in guest")
@@ -82,7 +82,7 @@ func (d *Default) Apply(cluster *v2.Cluster, mounts []v2.MountImage) error {
continue
}
logger.Info("guest cmd is %s", value)
if err := exec.Cmd("bash", "-c", fmt.Sprintf(contants.CdAndExecCmd, clusterRootfs, value)); err != nil {
if err := exec.Cmd("bash", "-c", fmt.Sprintf(constants.CdAndExecCmd, clusterRootfs, value)); err != nil {
return err
}
}
+5 -5
View File
@@ -26,7 +26,7 @@ import (
"github.com/labring/sealos/pkg/buildimage"
"github.com/labring/sealos/pkg/registry"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/logger"
fileutil "github.com/labring/sealos/pkg/utils/file"
@@ -109,14 +109,14 @@ func inspectImage(data string) (*v1.Image, error) {
}
func (d *ImageService) Build(options *types.BuildOptions, contextDir, imageName string) error {
//contants.ImageShimDirName
imageFetchDir := path.Join(contextDir, contants.ManifestsDirName)
//constants.ImageShimDirName
imageFetchDir := path.Join(contextDir, constants.ManifestsDirName)
yamlImages, err := buildimage.ParseYamlImages(imageFetchDir)
logger.Info("fetch manifests images: %v", yamlImages)
if err != nil {
return errors.Wrap(err, "get images list failed in this context")
}
imageListDir := path.Join(contextDir, contants.ImagesDirName, contants.ImageShimDirName)
imageListDir := path.Join(contextDir, constants.ImagesDirName, constants.ImageShimDirName)
images, err := buildimage.LoadImages(imageListDir)
if err != nil {
return errors.Wrap(err, "load images list failed in this context")
@@ -143,7 +143,7 @@ func (d *ImageService) Build(options *types.BuildOptions, contextDir, imageName
}
logger.Info("pull images %v for platform is %s", images, strings.Join([]string{platformVar.OS, platformVar.Architecture}, "/"))
images, err = is.SaveImages(images, path.Join(contextDir, contants.RegistryDirName), platformVar)
images, err = is.SaveImages(images, path.Join(contextDir, constants.RegistryDirName), platformVar)
if err != nil {
return errors.Wrap(err, "save images failed in this context")
}
+5 -5
View File
@@ -39,21 +39,21 @@ import (
"github.com/labring/sealos/pkg/buildimage"
"github.com/labring/sealos/pkg/image/types"
"github.com/labring/sealos/pkg/registry"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/logger"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
func (d *ImageService) Build(options *types.BuildOptions, contextDir, imageName string) error {
//contants.ImageShimDirName
imageFetchDir := path.Join(contextDir, contants.ManifestsDirName)
//constants.ImageShimDirName
imageFetchDir := path.Join(contextDir, constants.ManifestsDirName)
yamlImages, err := buildimage.ParseYamlImages(imageFetchDir)
logger.Info("fetch manifests images: %v", yamlImages)
if err != nil {
return errors.Wrap(err, "get images list failed in this context")
}
imageListDir := path.Join(contextDir, contants.ImagesDirName, contants.ImageShimDirName)
imageListDir := path.Join(contextDir, constants.ImagesDirName, constants.ImageShimDirName)
images, err := buildimage.LoadImages(imageListDir)
if err != nil {
return errors.Wrap(err, "load images list failed in this context")
@@ -80,7 +80,7 @@ func (d *ImageService) Build(options *types.BuildOptions, contextDir, imageName
}
logger.Info("pull images %v for platform is %s", images, strings.Join([]string{platformVar.OS, platformVar.Architecture}, "/"))
images, err = is.SaveImages(images, path.Join(contextDir, contants.RegistryDirName), platformVar)
images, err = is.SaveImages(images, path.Join(contextDir, constants.RegistryDirName), platformVar)
if err != nil {
return errors.Wrap(err, "save images failed in this context")
}
+2 -2
View File
@@ -17,7 +17,7 @@ package ipvs
import (
"fmt"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
@@ -35,7 +35,7 @@ func LvsStaticPodYaml(vip string, masters []string, image, name string) (string,
return "", fmt.Errorf("vip and mster not allow empty")
}
if image == "" {
image = contants.DefaultLvsCareImage
image = constants.DefaultLvsCareImage
}
args := []string{"care", "--vs", vip, "--health-path", "/healthz", "--health-schem", "https"}
for _, m := range masters {
+2 -2
View File
@@ -17,7 +17,7 @@ package ipvs
import (
"testing"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
)
var want = []string{
@@ -92,7 +92,7 @@ func TestLvsStaticPodYaml(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got, _ := LvsStaticPodYaml(tt.args.vip, tt.args.masters, tt.args.image, contants.LvsCareStaticPodName); got != tt.want {
if got, _ := LvsStaticPodYaml(tt.args.vip, tt.args.masters, tt.args.image, constants.LvsCareStaticPodName); got != tt.want {
t.Errorf("LvsStaticPodYaml() = %v, want %v", got, tt.want)
}
})
+3 -3
View File
@@ -21,7 +21,7 @@ import (
"fmt"
"text/template"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/ssh"
)
@@ -36,13 +36,13 @@ func renderTemplate(tmpl *template.Template, data map[string]interface{}) (strin
}
func bashToString(clusterName string, sshInterface ssh.Interface, host, cmd string) (string, error) {
data := contants.NewData(clusterName)
data := constants.NewData(clusterName)
cmd = fmt.Sprintf("%s %s", data.RootFSSealctlPath(), cmd)
logger.Debug("start to exec remote %s shell: %s", host, cmd)
return sshInterface.CmdToString(host, cmd, "")
}
func bashSync(clusterName string, sshInterface ssh.Interface, host, cmd string) error {
data := contants.NewData(clusterName)
data := constants.NewData(clusterName)
cmd = fmt.Sprintf("%s %s", data.RootFSSealctlPath(), cmd)
logger.Debug("start to exec remote %s shell: %s", host, cmd)
return sshInterface.CmdAsync(host, cmd)
+3 -3
View File
@@ -20,7 +20,7 @@ import (
"fmt"
"path"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/yaml"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -31,7 +31,7 @@ var defaultRootDirectory = "/var/lib/image-cri-shim"
//GetImageShim default dir is /var/lib/image-cri-shim
func GetImageShim(rootfs string) string {
const imageCustomConfig = "image-cri-shim.yaml"
etcPath := path.Join(rootfs, contants.EtcDirName, imageCustomConfig)
etcPath := path.Join(rootfs, constants.EtcDirName, imageCustomConfig)
registryConfig, err := yaml.Unmarshal(etcPath)
if err != nil {
logger.Debug("use default registry config")
@@ -44,7 +44,7 @@ func GetImageShim(rootfs string) string {
func ApplyImageShimCMD(rootfs string) string {
shimData := GetImageShim(rootfs)
return fmt.Sprintf(contants.DefaultCPFmt, shimData, path.Join(rootfs, contants.ImagesDirName, contants.ImageShimDirName), shimData)
return fmt.Sprintf(constants.DefaultCPFmt, shimData, path.Join(rootfs, constants.ImagesDirName, constants.ImageShimDirName), shimData)
}
func DeleteImageShimCMD(rootfs string) string {
+3 -3
View File
@@ -19,7 +19,7 @@ import (
"path"
"github.com/labring/sealos/pkg/cert"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/logger"
)
@@ -30,8 +30,8 @@ func (k *KubeadmRuntime) ConfigInitKubeadmToMaster0() error {
if err != nil {
return fmt.Errorf("generator config init kubeadm config error: %s", err.Error())
}
initConfigPath := path.Join(k.getContentData().TmpPath(), contants.DefaultInitKubeadmFileName)
outConfigPath := path.Join(k.getContentData().EtcPath(), contants.DefaultInitKubeadmFileName)
initConfigPath := path.Join(k.getContentData().TmpPath(), constants.DefaultInitKubeadmFileName)
outConfigPath := path.Join(k.getContentData().EtcPath(), constants.DefaultInitKubeadmFileName)
err = file.WriteFile(initConfigPath, data)
if err != nil {
return fmt.Errorf("write Config init kubeadm config error: %s", err.Error())
+4 -4
View File
@@ -29,7 +29,7 @@ import (
"github.com/labring/sealos/pkg/runtime/apis/kubeadm/v1beta3"
"github.com/pkg/errors"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/runtime/apis/kubeadm"
"github.com/labring/sealos/pkg/token"
@@ -140,7 +140,7 @@ func (k *KubeadmRuntime) validateVIP(ip string) error {
}
func (k *KubeadmRuntime) getDefaultKubeadmConfig() string {
return filepath.Join(k.getContentData().RootFSEtcPath(), contants.DefaultRootfsKubeadmFileName)
return filepath.Join(k.getContentData().RootFSEtcPath(), constants.DefaultRootfsKubeadmFileName)
}
func (k *KubeadmRuntime) getClusterName() string {
@@ -178,7 +178,7 @@ func (k *KubeadmRuntime) getDNSDomain() string {
}
func (k *KubeadmRuntime) writeTokenFile() error {
tokenFile := path.Join(k.getContentData().EtcPath(), contants.DefaultKubeadmTokenFileName)
tokenFile := path.Join(k.getContentData().EtcPath(), constants.DefaultKubeadmTokenFileName)
data, err := k.execToken(k.getMaster0IPAndPort())
if err != nil {
return err
@@ -198,7 +198,7 @@ func (k *KubeadmRuntime) writeTokenFile() error {
func (k *KubeadmRuntime) setKubernetesToken() error {
logger.Info("start to get kubernetes token...")
if k.Token == nil {
tokenFile := path.Join(k.getContentData().EtcPath(), contants.DefaultKubeadmTokenFileName)
tokenFile := path.Join(k.getContentData().EtcPath(), constants.DefaultKubeadmTokenFileName)
if !fileutil.IsExist(tokenFile) {
err := k.writeTokenFile()
if err != nil {
+3 -3
View File
@@ -20,7 +20,7 @@ import (
"path"
"sync"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/ssh"
@@ -77,8 +77,8 @@ func (k *KubeadmRuntime) ConfigJoinMasterKubeadmToMaster(master string) error {
if err != nil {
return fmt.Errorf("generator config join master kubeadm config error: %s", err.Error())
}
joinConfigPath := path.Join(k.getContentData().TmpPath(), contants.DefaultJoinMasterKubeadmFileName)
outConfigPath := path.Join(k.getContentData().EtcPath(), contants.DefaultJoinMasterKubeadmFileName)
joinConfigPath := path.Join(k.getContentData().TmpPath(), constants.DefaultJoinMasterKubeadmFileName)
outConfigPath := path.Join(k.getContentData().EtcPath(), constants.DefaultJoinMasterKubeadmFileName)
err = file.WriteFile(joinConfigPath, data)
if err != nil {
return fmt.Errorf("write config join master kubeadm config error: %s", err.Error())
+3 -3
View File
@@ -19,7 +19,7 @@ import (
"fmt"
"path"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/file"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/ssh"
@@ -85,8 +85,8 @@ func (k *KubeadmRuntime) ConfigJoinNodeKubeadmToNode(node string) error {
if err != nil {
return fmt.Errorf("generator config join kubeadm config error: %s", err.Error())
}
joinConfigPath := path.Join(k.getContentData().TmpPath(), contants.DefaultJoinNodeKubeadmFileName)
outConfigPath := path.Join(k.getContentData().EtcPath(), contants.DefaultJoinNodeKubeadmFileName)
joinConfigPath := path.Join(k.getContentData().TmpPath(), constants.DefaultJoinNodeKubeadmFileName)
outConfigPath := path.Join(k.getContentData().EtcPath(), constants.DefaultJoinNodeKubeadmFileName)
err = file.WriteFile(joinConfigPath, data)
if err != nil {
return fmt.Errorf("write config join kubeadm config error: %s", err.Error())
+4 -4
View File
@@ -22,7 +22,7 @@ import (
"github.com/labring/sealos/pkg/utils/iputils"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/yaml"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -36,10 +36,10 @@ func GetRegistry(rootfs, defaultRegistry string) *v1beta1.RegistryConfig {
const registryCustomConfig = "registry.yml"
var DefaultConfig = &v1beta1.RegistryConfig{
IP: defaultRegistry,
Domain: contants.DefaultRegistryDomain,
Domain: constants.DefaultRegistryDomain,
Port: "5000",
}
etcPath := path.Join(rootfs, contants.EtcDirName, registryCustomConfig)
etcPath := path.Join(rootfs, constants.EtcDirName, registryCustomConfig)
registryConfig, err := yaml.Unmarshal(etcPath)
if err != nil {
logger.Debug("use default registry config")
@@ -87,7 +87,7 @@ func (k *KubeadmRuntime) htpasswd() error {
func (k *KubeadmRuntime) ApplyRegistry() error {
logger.Info("start to apply registry")
registry := k.getRegistry()
err := k.sshCmdAsync(registry.IP, fmt.Sprintf(contants.DefaultLnFmt, k.getContentData().RootFSRegistryPath(), registry.Data))
err := k.sshCmdAsync(registry.IP, fmt.Sprintf(constants.DefaultLnFmt, k.getContentData().RootFSRegistryPath(), registry.Data))
if err != nil {
return fmt.Errorf("copy registry data failed %v", err)
}
+11 -11
View File
@@ -29,7 +29,7 @@ import (
"github.com/labring/sealos/pkg/env"
"github.com/labring/sealos/pkg/remote"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/ssh"
"golang.org/x/sync/errgroup"
)
@@ -44,7 +44,7 @@ func (k *KubeadmRuntime) getKubeVersion() string {
func (k *KubeadmRuntime) getKubeVersionFromImage() string {
labels := k.getImageLabels()
image := labels[contants.ImageKubeVersionKey]
image := labels[constants.ImageKubeVersionKey]
if image == "" {
return ""
}
@@ -89,9 +89,9 @@ func (k *KubeadmRuntime) getMaster0IPAPIServer() string {
func (k *KubeadmRuntime) getLvscareImage() (string, error) {
labels := k.getImageLabels()
image := labels[contants.ImageKubeLvscareImageKey]
image := labels[constants.ImageKubeLvscareImageKey]
if image == "" {
image = contants.DefaultLvsCareImage
image = constants.DefaultLvsCareImage
}
return image, nil
}
@@ -126,7 +126,7 @@ func (k *KubeadmRuntime) execIPVSPod(ip string, masters []string) error {
if err != nil {
return err
}
return k.getRemoteInterface().StaticPod(ip, k.getVipAndPort(), contants.LvsCareStaticPodName, image, masters)
return k.getRemoteInterface().StaticPod(ip, k.getVipAndPort(), constants.LvsCareStaticPodName, image, masters)
}
func (k *KubeadmRuntime) execToken(ip string) (string, error) {
@@ -190,15 +190,15 @@ func (k *KubeadmRuntime) getRemoteInterface() remote.Interface {
return remote.New(k.getClusterName(), k.getSSHInterface())
}
func (k *KubeadmRuntime) getScriptsBash() contants.Bash {
func (k *KubeadmRuntime) getScriptsBash() constants.Bash {
render := k.getImageLabels()
return contants.NewBash(k.getClusterName(), render)
return constants.NewBash(k.getClusterName(), render)
}
func (k *KubeadmRuntime) getContentData() contants.Data {
return contants.NewData(k.getClusterName())
func (k *KubeadmRuntime) getContentData() constants.Data {
return constants.NewData(k.getClusterName())
}
func GetContantData(clusterName string) contants.Data {
return contants.NewData(clusterName)
func GetConstantData(clusterName string) constants.Data {
return constants.NewData(clusterName)
}
+4 -4
View File
@@ -22,7 +22,7 @@ import (
"strconv"
"strings"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/logger"
"github.com/labring/sealos/pkg/utils/versionutil"
)
@@ -49,9 +49,9 @@ func (k *KubeadmRuntime) Command(version string, name CommandType) (cmd string)
JoinNode115Upper = "kubeadm join --config=%s"
)
initConfigPath := path.Join(k.getContentData().EtcPath(), contants.DefaultInitKubeadmFileName)
joinMasterConfigPath := path.Join(k.getContentData().EtcPath(), contants.DefaultJoinMasterKubeadmFileName)
joinNodeConfigPath := path.Join(k.getContentData().EtcPath(), contants.DefaultJoinNodeKubeadmFileName)
initConfigPath := path.Join(k.getContentData().EtcPath(), constants.DefaultInitKubeadmFileName)
joinMasterConfigPath := path.Join(k.getContentData().EtcPath(), constants.DefaultJoinMasterKubeadmFileName)
joinNodeConfigPath := path.Join(k.getContentData().EtcPath(), constants.DefaultJoinNodeKubeadmFileName)
var discoveryTokens []string
for _, data := range k.getTokenCaCertHash() {
+3 -3
View File
@@ -23,7 +23,7 @@ import (
"github.com/labring/sealos/pkg/utils/iputils"
"github.com/labring/sealos/pkg/client-go/kubernetes"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
"github.com/labring/sealos/pkg/utils/logger"
"golang.org/x/sync/errgroup"
v12 "k8s.io/api/core/v1"
@@ -78,14 +78,14 @@ func (k *KubeadmRuntime) ReplaceKubeConfigV1991V1992(masters []string) bool {
}
func (k *KubeadmRuntime) sendKubeConfigFile(hosts []string, kubeFile string) error {
absKubeFile := fmt.Sprintf("%s/%s", contants.KubernetesEtc, kubeFile)
absKubeFile := fmt.Sprintf("%s/%s", constants.KubernetesEtc, kubeFile)
sealosKubeFile := fmt.Sprintf("%s/%s", k.getContentData().EtcPath(), kubeFile)
return k.sendFileToHosts(hosts, sealosKubeFile, absKubeFile)
}
func (k *KubeadmRuntime) sendNewCertAndKey(hosts []string) error {
logger.Info("start to copy etc pki files to masters")
return k.sendFileToHosts(hosts, k.getContentData().PkiPath(), contants.KubernetesEtcPKI)
return k.sendFileToHosts(hosts, k.getContentData().PkiPath(), constants.KubernetesEtcPKI)
}
func (k *KubeadmRuntime) sendFileToHosts(Hosts []string, src, dst string) error {
+3 -3
View File
@@ -17,7 +17,7 @@ limitations under the License.
package v1beta1
import (
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
)
const (
@@ -46,6 +46,6 @@ const (
)
var (
DefaultConfigPath = contants.GetHomeDir() + "/.sealos"
DefaultPKFile = contants.GetHomeDir() + "/.ssh/id_rsa"
DefaultConfigPath = constants.GetHomeDir() + "/.sealos"
DefaultPKFile = constants.GetHomeDir() + "/.ssh/id_rsa"
)
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package contants
package constants
import "fmt"
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package contants
package constants
import (
"github.com/mitchellh/go-homedir"
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package contants
package constants
import "path/filepath"
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package contants
package constants
const (
KubernetesEtcStaticPod = "/etc/kubernetes/manifests"
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package contants
package constants
import "path/filepath"
+7 -7
View File
@@ -20,14 +20,14 @@ import (
"io"
"github.com/labring/sealos/pkg/types/v1beta1"
"github.com/labring/sealos/pkg/utils/contants"
"github.com/labring/sealos/pkg/utils/constants"
fileutil "github.com/labring/sealos/pkg/utils/file"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/yaml"
)
func Cluster(filepath string) (clusters []v1beta1.Cluster, err error) {
decodeClusters, err := decodeCRD(filepath, contants.Cluster)
decodeClusters, err := decodeCRD(filepath, constants.Cluster)
if err != nil {
return nil, fmt.Errorf("failed to decode cluster from %s, %v", filepath, err)
}
@@ -36,7 +36,7 @@ func Cluster(filepath string) (clusters []v1beta1.Cluster, err error) {
}
func Configs(filepath string) (configs []v1beta1.Config, err error) {
decodeConfigs, err := decodeCRD(filepath, contants.Config)
decodeConfigs, err := decodeCRD(filepath, constants.Config)
if err != nil {
return nil, fmt.Errorf("failed to decode config from %s, %v", filepath, err)
}
@@ -78,23 +78,23 @@ func CRDForBytes(data []byte, kind string) (out interface{}, err error) {
}
// ext.Raw
switch kind {
case contants.Cluster:
case constants.Cluster:
cluster := v1beta1.Cluster{}
err = yaml.Unmarshal(ext.Raw, &cluster)
if err != nil {
return nil, fmt.Errorf("decode cluster failed %v", err)
}
if cluster.Kind == contants.Cluster {
if cluster.Kind == constants.Cluster {
clusters = append(clusters, cluster)
}
i = clusters
case contants.Config:
case constants.Config:
config := v1beta1.Config{}
err = yaml.Unmarshal(ext.Raw, &config)
if err != nil {
return nil, fmt.Errorf("decode config failed %v", err)
}
if config.Kind == contants.Config {
if config.Kind == constants.Config {
configs = append(configs, config)
}
i = configs
+1 -1
View File
@@ -30,7 +30,7 @@ loop:
MOVD $NUM_ROUNDS, R21
VLD1 (R11), [V30.S4, V31.S4]
// load contants
// load constants
// VLD4R (R10), [V0.S4, V1.S4, V2.S4, V3.S4]
WORD $0x4D60E940