Skip to content

Commit

Permalink
+ [feat]: Implement embedded registry feature for K3s
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed Jun 18, 2024
1 parent 5a5f63c commit 26f4c81
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ issues:
- linters:
- goheader
text: "rights reserved"
- linters:
- staticcheck
text: "SA1019: common.ZenTaoOldOSSType is deprecated"
exclude-dirs:
- hack/bin
- testdata$
Expand Down Expand Up @@ -181,3 +184,4 @@ linters-settings:

gosmopolitan:
allow-time-local: true

6 changes: 6 additions & 0 deletions common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down Expand Up @@ -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:
`
4 changes: 4 additions & 0 deletions hack/manifests/hub/embedded-registries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mirrors:
hub.qucheng.com:
hub.zentao.net:

1 change: 1 addition & 0 deletions hack/manifests/scripts/node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/cli/k3stpl/k3stpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 26f4c81

Please sign in to comment.