Skip to content

Commit

Permalink
refactor: refactor configuration for improved consistency and clarity
Browse files Browse the repository at this point in the history
- Add common package import to `market.go` and `precheck.go`
- Update error messages in `market.go` to include the default hub URL
- Replace hardcoded values with constants for service and pod CIDRs in multiple files
- Change default storage type from `nfs` to `local` in several files
- Adjust registry references from a hardcoded URL to a constant
- Update script metadata comments in `devops.sh` and `install.sh`
- Modify flags in `k3stpl.go` to use common default values for pod and service CIDRs
- Update logging messages to reflect changes in default storage handling

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed Jan 14, 2025
1 parent ab26c8b commit 5577fd2
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 36 deletions.
5 changes: 3 additions & 2 deletions cmd/app/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/easysoft/qcadmin/common"
"github.com/easysoft/qcadmin/internal/pkg/util/factory"
"github.com/easysoft/qcadmin/internal/pkg/util/helm"

Expand All @@ -41,7 +42,7 @@ func NewCmdAppMarket(f factory.Factory) *cobra.Command {
return err
}
if len(repos) == 0 {
return errors.Errorf("not found qucheng market, you should: %s exp helm repo-add --name qucheng --url https://hub.zentao.net/chartrepo/stable", os.Args[0])
return errors.Errorf("not found qucheng market, you should: %s exp helm repo-add --name qucheng --url https://%s/chartrepo/stable", os.Args[0], common.DefaultHub)
}
quchengRepoName := ""
for _, repo := range repos {
Expand All @@ -51,7 +52,7 @@ func NewCmdAppMarket(f factory.Factory) *cobra.Command {
}
}
if len(quchengRepoName) == 0 {
return errors.Errorf("not found qucheng market, you should: %s exp helm repo-add --name qucheng --url https://hub.zentao.net/chartrepo/stable", os.Args[0])
return errors.Errorf("not found qucheng market, you should: %s exp helm repo-add --name qucheng --url https://%s/chartrepo/stable", os.Args[0], common.DefaultHub)
}
charts, err := hc.ListCharts(quchengRepoName, "", false)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/precheck/precheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package precheck

import (
"github.com/easysoft/qcadmin/common"
"github.com/easysoft/qcadmin/internal/pkg/types"
"github.com/easysoft/qcadmin/internal/pkg/util/log"
"github.com/easysoft/qcadmin/internal/pkg/util/preflight"
Expand All @@ -24,8 +25,8 @@ func (pc PreCheck) Run() error {
log := log.GetInstance()
log.Info("start pre-flight checks")
if err := preflight.RunInitNodeChecks(utilsexec.New(), &types.Metadata{
ServiceCidr: "10.42.0.0/16",
ClusterCidr: "10.43.0.0/16",
ClusterCidr: common.DefaultClusterPodCidr,
ServiceCidr: common.DefaultClusterServiceCidr,
}, pc.IgnorePreflightErrors, pc.OffLine, pc.Devops); err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ const (
DefaultCneOperatorName = "cne-operator"
DefaultIngressName = "nginx-ingress-controller"
DefaultKubeAPIDomain = "kubeapi.quickon.local"
DefaultStorageType = "nfs"
DefaultStorageType = "local"
DefaultHub = "hub.zentao.net" // chart repo & image registry
DefaultClusterPodCidr = "10.42.0.0/16"
DefaultClusterServiceCidr = "10.43.0.0/16"
InitFileName = ".initdone"
InitLockFileName = ".qlock"
InitModeCluster = ".incluster"
Expand Down
2 changes: 1 addition & 1 deletion common/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetChartRepo(p string) string {
} else {
p = "stable"
}
return fmt.Sprintf("https://hub.zentao.net/chartrepo/%s", p)
return fmt.Sprintf("https://%s/chartrepo/%s", DefaultHub, p)
}

// GetChannel 获取chartrepo channel地址
Expand Down
12 changes: 6 additions & 6 deletions hack/scripts/devops/devops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

# Source code is available at https://github.com/easysoft/quickon_cli

# SCRIPT_COMMIT_SHA="b617b5260d947c69caeafcfb89408e2b54d3d2a9"
# SCRIPT_DATA="Wed Jan 8 16:02:39 CST 2025"
# SCRIPT_COMMIT_SHA="46bbc9273f52a922c6071d43dd1f7a7e538d8a81"
# SCRIPT_DATA="Tue Jan 14 13:12:29 CST 2025"

# Usage:
# curl ... | ENV_VAR=... sh -
Expand All @@ -32,8 +32,8 @@
# - DEBUG
# If set, print debug information
# - STORAGE_TYPE
# Storage Type when install Zentao DevOPS default use nfs as storage provider.
# Defaults to '', support 'local'
# Storage Type when install Zentao DevOPS default use local as storage provider.
# Defaults to '', support 'local', 'nfs'

set -e
set -o noglob
Expand Down Expand Up @@ -212,8 +212,8 @@ install_zentao_devops() {
# if [ "${SKIP_DEVOPS_INIT}" = "false" ]; then
# INSTALL_COMMAND="${INSTALL_COMMAND} --skip-devops-init false"
# fi
if [ "${STORAGE_TYPE}" = "local" ]; then
INSTALL_COMMAND="${INSTALL_COMMAND} --storage local"
if [ "${STORAGE_TYPE}" = "nfs" ]; then
INSTALL_COMMAND="${INSTALL_COMMAND} --storage nfs"
fi
if [ -n "${DEBUG}" ]; then
INSTALL_COMMAND="${INSTALL_COMMAND} --debug"
Expand Down
12 changes: 6 additions & 6 deletions hack/scripts/devops/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

# Source code is available at https://github.com/easysoft/quickon_cli

# SCRIPT_COMMIT_SHA="b617b5260d947c69caeafcfb89408e2b54d3d2a9"
# SCRIPT_DATA="Wed Jan 8 16:02:39 CST 2025"
# SCRIPT_COMMIT_SHA="46bbc9273f52a922c6071d43dd1f7a7e538d8a81"
# SCRIPT_DATA="Tue Jan 14 13:12:29 CST 2025"

# Usage:
# curl ... | ENV_VAR=... sh -
Expand All @@ -32,8 +32,8 @@
# - DEBUG
# If set, print debug information
# - STORAGE_TYPE
# Storage Type when install Zentao DevOPS default use nfs as storage provider.
# Defaults to '', support 'local'
# Storage Type when install Zentao DevOPS default use local as storage provider.
# Defaults to '', support 'local', 'nfs'

set -e
set -o noglob
Expand Down Expand Up @@ -212,8 +212,8 @@ install_zentao_devops() {
# if [ "${SKIP_DEVOPS_INIT}" = "false" ]; then
# INSTALL_COMMAND="${INSTALL_COMMAND} --skip-devops-init false"
# fi
if [ "${STORAGE_TYPE}" = "local" ]; then
INSTALL_COMMAND="${INSTALL_COMMAND} --storage local"
if [ "${STORAGE_TYPE}" = "nfs" ]; then
INSTALL_COMMAND="${INSTALL_COMMAND} --storage nfs"
fi
if [ -n "${DEBUG}" ]; then
INSTALL_COMMAND="${INSTALL_COMMAND} --debug"
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/cli/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package helm

import (
"context"
"fmt"

"github.com/cockroachdb/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -77,7 +78,7 @@ func repoInit(f factory.Factory) *cobra.Command {
},
}
helm.Flags().StringVarP(&name, "name", "n", "install", "repo name")
helm.Flags().StringVarP(&url, "url", "u", "https://hub.zentao.net/chartrepo/stable", "repo url")
helm.Flags().StringVarP(&url, "url", "u", fmt.Sprintf("https://%s/chartrepo/stable", common.DefaultHub), "repo url")
return helm
}

Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/cli/k3stpl/k3stpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (k3s K3sArgs) Manifests(template string) string {
k3s.Master0IP = exnet.LocalIPs()[0]
}
if k3s.Registry == "" {
k3s.Registry = "hub.zentao.net"
k3s.Registry = common.DefaultHub
}
return render(k3s, template)
}
Expand All @@ -85,8 +85,8 @@ func EmbedCommand(f factory.Factory) *cobra.Command {
file.WriteFile(tplfile.Name(), k3sargs.Manifests(""), true)
},
}
rootCmd.Flags().StringVar(&k3sargs.PodCIDR, "pod-cidr", "10.42.0.0/16", "cluster cidr")
rootCmd.Flags().StringVar(&k3sargs.ServiceCIDR, "service-cidr", "10.43.0.0/16", "service cidr")
rootCmd.Flags().StringVar(&k3sargs.PodCIDR, "pod-cidr", common.DefaultClusterPodCidr, "cluster cidr")
rootCmd.Flags().StringVar(&k3sargs.ServiceCIDR, "service-cidr", common.DefaultClusterServiceCidr, "service cidr")
rootCmd.Flags().StringVar(&k3sargs.DataDir, "data-dir", "", "data dir")
rootCmd.Flags().StringVar(&k3sargs.DataStore, "data", "", "data type")
rootCmd.Flags().StringVar(&k3sargs.KubeAPI, "kubeapi", "", "kubeapi")
Expand All @@ -95,7 +95,7 @@ func EmbedCommand(f factory.Factory) *cobra.Command {
rootCmd.Flags().BoolVar(&k3sargs.OffLine, "offline", false, "offline")
rootCmd.Flags().BoolVar(&k3sargs.LocalStorage, "local-storage", true, "local-storage")
rootCmd.Flags().StringVar(&k3sargs.Master0IP, "master0ip", "", "master0ip, only work offline mode")
rootCmd.Flags().StringVar(&k3sargs.Registry, "registry", "hub.zentao.net", "registry")
rootCmd.Flags().StringVar(&k3sargs.Registry, "registry", common.DefaultHub, "registry")
rootCmd.Flags().StringVar(&k3sargs.CNI, "cni", "", "cni")
return rootCmd
}
14 changes: 7 additions & 7 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ func NewCluster(f factory.Factory) *Cluster {
return &Cluster{
log: f.GetLog(),
CNI: "flannel",
PodCIDR: "10.42.0.0/16",
ServiceCIDR: "10.43.0.0/16",
DataDir: "/opt/quickon",
PodCIDR: common.DefaultClusterPodCidr,
ServiceCIDR: common.DefaultClusterServiceCidr,
DataDir: common.DefaultQuickonDataDir,
SSH: types.SSH{
User: "root",
},
DataStore: "",
Storage: "nfs",
Registry: "hub.zentao.net",
Storage: common.DefaultStorageType,
Registry: common.DefaultHub,
OffLine: false,
IgnorePreflightErrors: false,
}
Expand All @@ -87,8 +87,8 @@ func (c *Cluster) getInitFlags() []types.Flag {
Name: "hub",
P: &c.Registry,
V: c.Registry,
EnvVar: "hub.zentao.net",
Usage: `custom image hub, e.g: hub.zentao.net`,
EnvVar: common.DefaultHub,
Usage: `custom image hub`,
},
{
Name: "storage",
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/devops/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (q *Devops) GetFlags() []types.Flag {
V: q.MetaData.Version,
}, types.Flag{
Name: "type",
Usage: "devops type, support oss, max, biz, ipd",
Usage: "devops type, support open(oss), max, biz, ipd",
P: &q.MetaData.Type,
V: common.ZenTaoOSSType.String(),
ShortHand: "t",
Expand Down
14 changes: 9 additions & 5 deletions pkg/quickon/quickon.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,19 @@ func (m *Meta) checkStorage() {
if defaultClass == nil {
// default storage
cfg, _ := config.LoadConfig()
m.Log.Infof("not found default storage class, will install %s as default storage", cfg.Storage.Type)
m.Log.Debugf("start install default storage: nfs")
storage := common.DefaultStorageType
cfg.Storage.Type = storage
defer cfg.SaveConfig()
m.Log.Warnf("not found default storage class, will install %s as default storage", storage)
m.Log.Debugf("start install default storage: %s", storage)
if len(cfg.Cluster.InitNode) == 0 {
cfg.Cluster.InitNode = exnet.LocalIPs()[0]
}
if err := qcexec.CommandRun(os.Args[0], "cluster", "storage", "nfs", "--ip", cfg.Cluster.InitNode, "--path", common.GetDefaultNFSStoragePath(cfg.DataDir)); err != nil {
m.Log.Errorf("install storage %s failed, reason: %v", cfg.Storage.Type, err)
// old use nfs as default storage os.Args[0], "cluster", "storage", "nfs", "--ip", cfg.Cluster.InitNode, "--path", common.GetDefaultNFSStoragePath(cfg.DataDir)
if err := qcexec.CommandRun(os.Args[0], "cluster", "storage", "local"); err != nil {
m.Log.Errorf("install storage %s failed, reason: %v", storage, err)
} else {
m.Log.Donef("install storage %s success", cfg.Storage.Type)
m.Log.Donef("install storage %s success", storage)
}
// if err := qcexec.CommandRun(os.Args[0], "cluster", "storage", "set-default"); err != nil {
// m.Log.Errorf("set default storageclass failed, reason: %v", err)
Expand Down

0 comments on commit 5577fd2

Please sign in to comment.