Skip to content

Commit

Permalink
Merge pull request #279 from xiaods/dev
Browse files Browse the repository at this point in the history
feat: add init os config
  • Loading branch information
xiaods authored Nov 11, 2022
2 parents 2ba8950 + 36c4fa5 commit c7e7898
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 71 deletions.
1 change: 1 addition & 0 deletions cmd/k8e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func main() {
cmds.NewCRICTL(externalCLIAction("crictl", dataDir)),
cmds.NewCtrCommand(externalCLIAction("ctr", dataDir)),
cmds.NewCheckConfigCommand(externalCLIAction("check-config", dataDir)),
cmds.NewInitOSConfigCommand(externalCLIAction("init-os-config", dataDir)),
cmds.NewEtcdSnapshotCommand(etcdsnapshotCommand,
cmds.NewEtcdSnapshotSubcommands(
etcdsnapshotCommand,
Expand Down
3 changes: 2 additions & 1 deletion contrib/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ download_and_verify() {

# --- check-config ---
check_config() {
info "Checking k8e configuration"
info "init OS config && Checking k8e config"
$SUDO $BIN_DIR/k8e init-os
$SUDO $BIN_DIR/k8e check-config
}

Expand Down
47 changes: 0 additions & 47 deletions contrib/util/cilium-sysctlfix.sh

This file was deleted.

28 changes: 5 additions & 23 deletions contrib/initOS.sh → contrib/util/init-os-config.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#!/usr/bin/env bash
# Copyright 2020 The KubeSphere Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# bits of this were adapted from initOS.sh for kubekey
# see also https://github.com/kubesphere/kubekey/blob/b5bb4acbebaa5ef04d9de743274171be1ebad3fd/cmd/kk/pkg/bootstrap/os/templates/init_script.go

swapoff -a
sed -i /^[^#]*swap*/s/^/\#/g /etc/fstab
# See https://github.com/kubernetes/website/issues/14457
if [ -f /etc/selinux/config ]; then
if [ -f /etc/selinux/config ]; then
sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
fi
# for ubuntu: sudo apt install selinux-utils
Expand Down Expand Up @@ -81,15 +72,6 @@ if [ $? -eq 0 ]; then
echo 'nf_conntrack' > /etc/modules-load.d/kube_proxy-ipvs.conf
fi
sysctl -p
sed -i ':a;$!{N;ba};s@# kubekey hosts BEGIN.*# kubekey hosts END@@' /etc/hosts
sed -i '/^$/N;/\n$/N;//D' /etc/hosts
cat >>/etc/hosts<<EOF
# kubekey hosts BEGIN
{{- range .Hosts }}
{{ . }}
{{- end }}
# kubekey hosts END
EOF
echo 3 > /proc/sys/vm/drop_caches
# Make sure the iptables utility doesn't use the nftables backend.
update-alternatives --set iptables /usr/sbin/iptables-legacy >/dev/null 2>&1 || true
Expand Down
1 change: 1 addition & 0 deletions hack/package-cli
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ for i in crictl kubectl k8e-agent k8e-server k8e-etcd-snapshot k8e-secrets-encry
done

cp contrib/util/check-config.sh bin/check-config
cp contrib/util/init-os-config.sh bin/init-os-config

rm -rf build/data
mkdir -p build/data build/out
Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/cmds/check-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ func NewCheckConfigCommand(action func(*cli.Context) error) cli.Command {
Action: action,
}
}

func NewInitOSConfigCommand(action func(*cli.Context) error) cli.Command {
return cli.Command{
Name: "init-os-config",
Usage: "Initialize OS configuration",
SkipFlagParsing: true,
SkipArgReorder: true,
Action: action,
}
}

0 comments on commit c7e7898

Please sign in to comment.