diff --git a/data/ignition/controlplane/systemd/install-cni-plugin.service.template b/data/ignition/controlplane/systemd/install-cni-plugin.service.template index aa2b45f68b333ce8eccd1011d63cde543425d2db..44cc40ac66a805cb838b634b60faaa443dd0e371 100644 --- a/data/ignition/controlplane/systemd/install-cni-plugin.service.template +++ b/data/ignition/controlplane/systemd/install-cni-plugin.service.template @@ -9,7 +9,7 @@ Type=oneshot RemainAfterExit=yes ExecStart=bash -c "sed -i 's#usr/libexec/#opt/libexec/#g' /etc/nkd/calico.yaml" ExecStart=bash -c "sed -i 's/# - name: CALICO_IPV4POOL_CIDR/- name: CALICO_IPV4POOL_CIDR/g' /etc/nkd/calico.yaml" -ExecStart=bash -c "sed -i 's?# value: "{{.IpSegment}}/16"? value: "10.100.0.0/16"?g' /etc/nkd/calico.yaml" +ExecStart=bash -c "sed -i 's?# value: "192.168.0.0/16"? value: "{{.IpSegment}}/16"?g' /etc/nkd/calico.yaml" ExecStart=kubectl apply -f /etc/nkd/calico.yaml --kubeconfig=/etc/kubernetes/admin.conf [Install] diff --git a/data/ignition/worker/systemd/join-worker.service b/data/ignition/worker/systemd/join-worker.service index 52a3dde2acb5b1da4d44e4f3c4d7687e759d3194..39045be948c2fcdc25070fca0e102a210e00005a 100644 --- a/data/ignition/worker/systemd/join-worker.service +++ b/data/ignition/worker/systemd/join-worker.service @@ -8,10 +8,9 @@ ConditionPathExists=/var/log/node-pivot.stamp ConditionPathExists=!/var/log/join-worker.stamp [Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=kubeadm join --config=/etc/nkd/join-config.yaml -ExecStart=/bin/touch /var/log/join-worker.stamp +ExecStart=/bin/bash -c "kubeadm join --config=/etc/nkd/join-config.yaml && touch /var/log/join-worker.stamp" +Restart=on-failure +RestartSec=5s [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/housekeeper/daemon/files/housekeeper-daemon.service b/housekeeper/daemon/files/housekeeper-daemon.service new file mode 100755 index 0000000000000000000000000000000000000000..e34b5636734f2450834ee78662c18cd5ae657617 --- /dev/null +++ b/housekeeper/daemon/files/housekeeper-daemon.service @@ -0,0 +1,26 @@ +# Copyright 2023 KylinSoft Co., Ltd. + +# 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. + + +[Unit] +Description=daemon of the housekeeper + +[Service] +ExecStart=/usr/bin/housekeeper-daemon +Restart=on-failure +KillMode=process + +[Install] +WantedBy=multi-user.target + diff --git a/housekeeper/daemon/server/server.go b/housekeeper/daemon/server/server.go index 4daafa496d2266b917ea66c87cb82617e40fa973..385ff9458452044c46e4fcde3f232855e84e78e5 100644 --- a/housekeeper/daemon/server/server.go +++ b/housekeeper/daemon/server/server.go @@ -27,7 +27,6 @@ import ( "github.com/sirupsen/logrus" "housekeeper.io/pkg/common" pb "housekeeper.io/pkg/connection/proto" - utilVersion "k8s.io/apimachinery/pkg/util/version" ) const ( @@ -76,18 +75,16 @@ func (s *Server) Upgrade(_ context.Context, req *pb.UpgradeRequest) (*pb.Upgrade } func checkOsVersion(req *pb.UpgradeRequest) error { - args := []string{"-c", "cat /etc/os-release | grep 'VERSION=' | head -n 1 | awk -F 'VERSION=' '{print $2}'"} + cmd := "awk -F= '/PRETTY_NAME/ {gsub(/\"/, \"\", $2); print $2}' /etc/os-release" + args := []string{"-c", cmd} osVersion, err := runCmd("/bin/sh", args...) if err != nil { logrus.Errorf("failed to get os version: %v", err) return err } - if cmp, err := utilVersion.MustParseSemantic(string(osVersion)).Compare(req.OsVersion); err != nil { - logrus.Errorf("failed to parse os version: %v", err) - return err - } else if cmp == 0 { - logrus.Infof("The current os version %s and the desired upgrade version %s are the same", - string(osVersion), req.OsVersion) + + if string(osVersion) == req.OsVersion { + logrus.Infof("The current OS version %s and the desired upgrade version %s are the same", string(osVersion), req.OsVersion) return nil } //Compare the current os version with the desired version. @@ -106,16 +103,10 @@ func checkKubeVersion(req *pb.UpgradeRequest) error { logrus.Errorf("kubeadm get version failed: %v", err) return err } - if cmp, err := utilVersion.MustParseSemantic(string(kubeadmVersion)).Compare(req.KubeVersion); err != nil { - logrus.Errorf("failed to parse kubeadm version: %v", err) - return err - } else if cmp == -1 { - logrus.Infof("the request upgraded version %s is larger than kubeadm's version %s", - req.KubeVersion, string(kubeadmVersion)) + if string(kubeadmVersion) == req.KubeVersion { + logrus.Infof("The current k8s version %s and the desired upgrade version %s are the same", string(kubeadmVersion), req.KubeVersion) return nil } - //If the version of kubeadm is not less than the version requested for upgrade, - //the upgrade command is executed if err := upgradeKubeVersion(req); err != nil { logrus.Errorf("upgrade kubernetes version error: %v", err) return err diff --git a/housekeeper/operator/config/manager/manager.yaml b/housekeeper/operator/config/manager/manager.yaml index 702b8ce491f2470f1cc6f282c4507a1a712f7539..545b1f42c8511269f813e9fbb998a8863d66e8d4 100644 --- a/housekeeper/operator/config/manager/manager.yaml +++ b/housekeeper/operator/config/manager/manager.yaml @@ -58,6 +58,13 @@ spec: labels: control-plane: housekeeper-controller-manager spec: + tolerations: + - key: "node-role.kubernetes.io/master" + operator: "Exists" + effect: "NoSchedule" + - key: "node-role.kubernetes.io/worker" + operator: "Exists" + effect: "NoSchedule" containers: - name: housekeeper-controller-manager command: diff --git a/housekeeper/operator/housekeeper-controller/controllers/update_controller.go b/housekeeper/operator/housekeeper-controller/controllers/update_controller.go index ea4e428aa8b33d163afe8e355f7265edd8c0c30a..0bd63740c68e10f0722e49b1c2e6542e1f1c9b50 100644 --- a/housekeeper/operator/housekeeper-controller/controllers/update_controller.go +++ b/housekeeper/operator/housekeeper-controller/controllers/update_controller.go @@ -91,7 +91,7 @@ func (r *UpdateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr return common.RequeueNow, err } } else { - r.refreshNodes(ctx, &upInstance, &nodeInstance) + r.refreshNodes(ctx, &nodeInstance) } return common.RequeueAfter, nil } @@ -127,7 +127,7 @@ func (r *UpdateReconciler) upgradeNodes(ctx context.Context, upInstance *houseke return nil } -func (r *UpdateReconciler) refreshNodes(ctx context.Context, upInstance *housekeeperiov1alpha1.Update, node *corev1.Node) error { +func (r *UpdateReconciler) refreshNodes(ctx context.Context, node *corev1.Node) error { deleteLabel(ctx, r, node) if node.Spec.Unschedulable { drainer := &drain.Helper{