kubekey/pkg/container/containerd.go
24sama f4b7fd4605 dev-v2.0.0: add copyright
Signed-off-by: 24sama <leo@kubesphere.io>
2021-11-15 11:31:28 +08:00

74 lines
2.2 KiB
Go

/*
Copyright 2021 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.
*/
package container
import (
"fmt"
"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/connector"
"github.com/kubesphere/kubekey/pkg/files"
"github.com/kubesphere/kubekey/pkg/utils"
"github.com/pkg/errors"
"path/filepath"
)
type SyncCrictlBinaries struct {
common.KubeAction
}
func (s *SyncCrictlBinaries) Execute(runtime connector.Runtime) error {
if err := utils.ResetTmpDir(runtime); err != nil {
return err
}
binariesMapObj, ok := s.PipelineCache.Get(common.KubeBinaries)
if !ok {
return errors.New("get KubeBinary by pipeline cache failed")
}
binariesMap := binariesMapObj.(map[string]files.KubeBinary)
crictl, ok := binariesMap[common.Crictl]
if !ok {
return errors.New("get KubeBinary key crictl by pipeline cache failed")
}
dst := filepath.Join(common.TmpDir, crictl.Name)
if err := runtime.GetRunner().SudoScp(crictl.Path, dst); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("sync crictl binaries failed"))
}
if _, err := runtime.GetRunner().SudoCmd(
fmt.Sprintf("mkdir -p /usr/bin && tar -zxf %s -C /usr/bin ", dst),
false); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("install crictl binaries failed"))
}
return nil
}
type EnableContainerd struct {
common.KubeAction
}
func (e *EnableContainerd) Execute(runtime connector.Runtime) error {
if _, err := runtime.GetRunner().SudoCmd(
"systemctl daemon-reload && systemctl enable containerd && systemctl start containerd",
false); err != nil {
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("enable and start containerd failed"))
}
return nil
}