From 26f4c81746d394cfdbb6b0b90950877c639cb738 Mon Sep 17 00:00:00 2001 From: ysicing Date: Tue, 18 Jun 2024 16:29:04 +0800 Subject: [PATCH] + [feat]: Implement embedded registry feature for K3s --- .golangci.yml | 4 ++++ common/const.go | 6 ++++++ hack/manifests/hub/embedded-registries.yaml | 4 ++++ hack/manifests/scripts/node.sh | 1 + internal/pkg/cli/k3stpl/k3stpl.go | 5 ++++- 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 hack/manifests/hub/embedded-registries.yaml diff --git a/.golangci.yml b/.golangci.yml index 306e9b51..7c7a907f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -68,6 +68,9 @@ issues: - linters: - goheader text: "rights reserved" + - linters: + - staticcheck + text: "SA1019: common.ZenTaoOldOSSType is deprecated" exclude-dirs: - hack/bin - testdata$ @@ -181,3 +184,4 @@ linters-settings: gosmopolitan: allow-time-local: true + diff --git a/common/const.go b/common/const.go index cb3c7074..41b2d48c 100644 --- a/common/const.go +++ b/common/const.go @@ -160,6 +160,7 @@ ExecStart=/usr/local/bin/k3s \ --tls-san kubeapi.corp.cc \ --tls-san apiserver.cluster.local \ --tls-san {{ .KubeAPI }} \ + --embedded-registry \ {{if .PodCIDR -}} --cluster-cidr {{ .PodCIDR }} \ {{end -}} @@ -200,3 +201,8 @@ ExecStart=/usr/local/bin/k3s \ --kube-proxy-arg "proxy-mode=ipvs" "masquerade-all=true" \ --kube-proxy-arg "metrics-bind-address=0.0.0.0" ` + +const K3SEmbeddedMirrorsTpl = `mirrors: + hub.qucheng.com: + hub.zentao.net: +` diff --git a/hack/manifests/hub/embedded-registries.yaml b/hack/manifests/hub/embedded-registries.yaml new file mode 100644 index 00000000..7d9b1f43 --- /dev/null +++ b/hack/manifests/hub/embedded-registries.yaml @@ -0,0 +1,4 @@ +mirrors: + hub.qucheng.com: + hub.zentao.net: + diff --git a/hack/manifests/scripts/node.sh b/hack/manifests/scripts/node.sh index 17dcb897..7f644fe9 100755 --- a/hack/manifests/scripts/node.sh +++ b/hack/manifests/scripts/node.sh @@ -44,6 +44,7 @@ check_docker() { which_cmd=$(command -v docker 2>/dev/null || true) if [ -z "${which_cmd}" ]; then sed -i "s#--docker \\\##g" /root/.k3s.service + sed -i "s#--embedded-registry \\\##g" /root/.k3s.service fi } diff --git a/internal/pkg/cli/k3stpl/k3stpl.go b/internal/pkg/cli/k3stpl/k3stpl.go index b1b94947..e0447e6d 100644 --- a/internal/pkg/cli/k3stpl/k3stpl.go +++ b/internal/pkg/cli/k3stpl/k3stpl.go @@ -79,8 +79,11 @@ func EmbedCommand(f factory.Factory) *cobra.Command { Run: func(cmd *cobra.Command, args []string) { log := f.GetLog() tplfile, _ := os.CreateTemp("/tmp", "") - log.Infof("file: %s", tplfile.Name()) + log.Infof("file k3s service: %s", tplfile.Name()) file.WriteFile(tplfile.Name(), k3sargs.Manifests(""), true) + registriesfile, _ := os.CreateTemp("/tmp", "") + log.Infof("file embedded registries: %s", registriesfile.Name()) + file.WriteFile(registriesfile.Name(), k3sargs.Manifests(common.K3SEmbeddedMirrorsTpl), true) }, } rootCmd.Flags().StringVar(&k3sargs.PodCIDR, "pod-cidr", "10.42.0.0/16", "cluster cidr")