summaryrefslogtreecommitdiff
path: root/keadm
diff options
context:
space:
mode:
authorShelley-BaoYue <baoyue2@huawei.com>2023-08-30 11:20:49 +0800
committerShelley-BaoYue <baoyue2@huawei.com>2023-09-11 10:19:49 +0800
commitd8660e2cd6973212480a771b8523442b51a56ee7 (patch)
tree05af4f31786f5444571327e20bb813f8f86fd4f1 /keadm
parentupdate vendor and licenses (diff)
downloadkubeedge-d8660e2cd6973212480a771b8523442b51a56ee7.tar.gz
compatibility modification
Signed-off-by: Shelley-BaoYue <baoyue2@huawei.com>
Diffstat (limited to 'keadm')
-rw-r--r--keadm/cmd/keadm/app/cmd/helm/installer.go16
-rw-r--r--keadm/cmd/keadm/app/cmd/util/image.go33
2 files changed, 26 insertions, 23 deletions
diff --git a/keadm/cmd/keadm/app/cmd/helm/installer.go b/keadm/cmd/keadm/app/cmd/helm/installer.go
index 639bd33b9..5ffb7d566 100644
--- a/keadm/cmd/keadm/app/cmd/helm/installer.go
+++ b/keadm/cmd/keadm/app/cmd/helm/installer.go
@@ -74,8 +74,8 @@ type KubeCloudHelmInstTool struct {
// InstallTools downloads KubeEdge for the specified version
// and makes the required configuration changes and initiates cloudcore.
func (cu *KubeCloudHelmInstTool) InstallTools() error {
- cu.SetOSInterface(util.GetOSInterface())
- cu.SetKubeEdgeVersion(cu.ToolVersion)
+ cu.Common.SetOSInterface(util.GetOSInterface())
+ cu.Common.OSTypeInstaller.SetKubeEdgeVersion(cu.ToolVersion)
baseHelmRoot := DefaultBaseHelmDir
if cu.ExternalHelmRoot != "" {
@@ -103,7 +103,7 @@ func (cu *KubeCloudHelmInstTool) RunHelmInstall(baseHelmRoot string) error {
// --force would not care about whether the cloud components exist or not
// Also, if gives a external helm root, no need to check and verify. Because it is always not a cloudcore.
if !cu.Force && cu.ExternalHelmRoot == "" {
- cloudCoreRunning, err := cu.IsKubeEdgeProcessRunning(util.KubeCloudBinaryName)
+ cloudCoreRunning, err := cu.Common.OSTypeInstaller.IsKubeEdgeProcessRunning(util.KubeCloudBinaryName)
if err != nil {
return err
}
@@ -112,7 +112,7 @@ func (cu *KubeCloudHelmInstTool) RunHelmInstall(baseHelmRoot string) error {
}
}
- err := cu.IsK8SComponentInstalled(cu.KubeConfig, cu.Master)
+ err := cu.Common.OSTypeInstaller.IsK8SComponentInstalled(cu.KubeConfig, cu.Master)
if err != nil {
return err
}
@@ -171,7 +171,7 @@ func (cu *KubeCloudHelmInstTool) RunHelmManifest(baseHelmRoot string) error {
// beforeRenderer handles the value of the profile.
func (cu *KubeCloudHelmInstTool) beforeRenderer(baseHelmRoot string) error {
if cu.Profile == "" {
- cu.Profile = fmt.Sprintf("%s=v%s", VersionProfileKey, cu.ToolVersion.String())
+ cu.Profile = fmt.Sprintf("%s=v%s", VersionProfileKey, cu.Common.ToolVersion.String())
}
// profile must be invalid
p := strings.Split(cu.Profile, "=")
@@ -275,7 +275,7 @@ func (cu *KubeCloudHelmInstTool) runHelmManifest(r *Renderer, stdout io.Writer)
// runHelmInstall starts cloudcore deployment with the given flags
func (cu *KubeCloudHelmInstTool) runHelmInstall(r *Renderer) (*release.Release, error) {
cf := genericclioptions.NewConfigFlags(true)
- cf.KubeConfig = &cu.KubeConfig
+ cf.KubeConfig = &cu.Common.KubeConfig
cf.Namespace = &cu.Namespace
cfg := &action.Configuration{}
@@ -331,7 +331,7 @@ func (cu *KubeCloudHelmInstTool) runHelmInstall(r *Renderer) (*release.Release,
// TearDown method will remove the edge node from api-server and stop cloudcore process
func (cu *KubeCloudHelmInstTool) TearDown() error {
// clean kubeedge namespace
- err := cu.CleanNameSpace(constants.SystemNamespace, cu.KubeConfig)
+ err := cu.Common.CleanNameSpace(constants.SystemNamespace, cu.KubeConfig)
if err != nil {
return fmt.Errorf("fail to clean kubeedge namespace, err:%v", err)
}
@@ -362,7 +362,7 @@ func (cu *KubeCloudHelmInstTool) checkProfile(baseHelmRoot string) error {
// handleProfile only handles inner profile
func (cu *KubeCloudHelmInstTool) handleProfile(profileValue string) error {
// the current version
- currentVersion := cu.ToolVersion.String()
+ currentVersion := cu.Common.ToolVersion.String()
switch cu.ProfileKey {
case VersionProfileKey:
if profileValue == "" {
diff --git a/keadm/cmd/keadm/app/cmd/util/image.go b/keadm/cmd/keadm/app/cmd/util/image.go
index e769c76ff..9f2bd7a39 100644
--- a/keadm/cmd/keadm/app/cmd/util/image.go
+++ b/keadm/cmd/keadm/app/cmd/util/image.go
@@ -29,6 +29,7 @@ import (
"github.com/docker/docker/api/types/filters"
dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
+ oteltrace "go.opentelemetry.io/otel/trace"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
"k8s.io/klog/v2"
@@ -65,11 +66,11 @@ func NewContainerRuntime(runtimeType string, endpoint string) (ContainerRuntime,
ctx: ctx,
}
case constants.RemoteContainerRuntime:
- imageService, err := remote.NewRemoteImageService(endpoint, time.Second*10)
+ imageService, err := remote.NewRemoteImageService(endpoint, time.Second*10, oteltrace.NewNoopTracerProvider())
if err != nil {
return runtime, err
}
- runtimeService, err := remote.NewRemoteRuntimeService(endpoint, time.Second*10)
+ runtimeService, err := remote.NewRemoteRuntimeService(endpoint, time.Second*10, oteltrace.NewNoopTracerProvider())
if err != nil {
return runtime, err
}
@@ -77,6 +78,7 @@ func NewContainerRuntime(runtimeType string, endpoint string) (ContainerRuntime,
endpoint: endpoint,
ImageManagerService: imageService,
RuntimeService: runtimeService,
+ ctx: context.Background(),
}
default:
return runtime, fmt.Errorf("unsupport CRI runtime: %s", runtimeType)
@@ -230,6 +232,7 @@ type CRIRuntime struct {
endpoint string
ImageManagerService internalapi.ImageManagerService
RuntimeService internalapi.RuntimeService
+ ctx context.Context
}
func convertCRIImage(image string) string {
@@ -247,12 +250,12 @@ func (runtime *CRIRuntime) PullImages(images []string) error {
image = convertCRIImage(image)
fmt.Printf("Pulling %s ...\n", image)
imageSpec := &runtimeapi.ImageSpec{Image: image}
- status, err := runtime.ImageManagerService.ImageStatus(imageSpec, true)
+ status, err := runtime.ImageManagerService.ImageStatus(runtime.ctx, imageSpec, true)
if err != nil {
return err
}
if status == nil || status.Image == nil {
- if _, err := runtime.ImageManagerService.PullImage(imageSpec, nil, nil); err != nil {
+ if _, err := runtime.ImageManagerService.PullImage(runtime.ctx, imageSpec, nil, nil); err != nil {
return err
}
}
@@ -280,12 +283,12 @@ func (runtime *CRIRuntime) CopyResources(edgeImage string, files map[string]stri
},
},
}
- sandbox, err := runtime.RuntimeService.RunPodSandbox(psc, "")
+ sandbox, err := runtime.RuntimeService.RunPodSandbox(runtime.ctx, psc, "")
if err != nil {
return err
}
defer func() {
- if err := runtime.RuntimeService.RemovePodSandbox(sandbox); err != nil {
+ if err := runtime.RuntimeService.RemovePodSandbox(runtime.ctx, sandbox); err != nil {
klog.V(3).ErrorS(err, "Remove pod sandbox failed", "containerID", sandbox)
}
}()
@@ -314,17 +317,17 @@ func (runtime *CRIRuntime) CopyResources(edgeImage string, files map[string]stri
},
Mounts: mounts,
}
- containerID, err := runtime.RuntimeService.CreateContainer(sandbox, containerConfig, psc)
+ containerID, err := runtime.RuntimeService.CreateContainer(runtime.ctx, sandbox, containerConfig, psc)
if err != nil {
return fmt.Errorf("create container failed: %v", err)
}
defer func() {
- if err := runtime.RuntimeService.RemoveContainer(containerID); err != nil {
+ if err := runtime.RuntimeService.RemoveContainer(runtime.ctx, containerID); err != nil {
klog.V(3).ErrorS(err, "Remove container failed", "containerID", containerID)
}
}()
- err = runtime.RuntimeService.StartContainer(containerID)
+ err = runtime.RuntimeService.StartContainer(runtime.ctx, containerID)
if err != nil {
return fmt.Errorf("start container failed: %v", err)
}
@@ -335,7 +338,7 @@ func (runtime *CRIRuntime) CopyResources(edgeImage string, files map[string]stri
"-c",
copyCmd,
}
- stdout, stderr, err := runtime.RuntimeService.ExecSync(containerID, cmd, 30*time.Second)
+ stdout, stderr, err := runtime.RuntimeService.ExecSync(runtime.ctx, containerID, cmd, 30*time.Second)
if err != nil {
return fmt.Errorf("failed to exec copy cmd, err: %v, stderr: %s, stdout: %s", err, string(stderr), string(stdout))
}
@@ -368,7 +371,7 @@ func (runtime *CRIRuntime) RunMQTT(mqttImage string) error {
},
},
}
- sandbox, err := runtime.RuntimeService.RunPodSandbox(psc, "")
+ sandbox, err := runtime.RuntimeService.RunPodSandbox(runtime.ctx, psc, "")
if err != nil {
return err
}
@@ -385,11 +388,11 @@ func (runtime *CRIRuntime) RunMQTT(mqttImage string) error {
},
},
}
- containerID, err := runtime.RuntimeService.CreateContainer(sandbox, containerConfig, psc)
+ containerID, err := runtime.RuntimeService.CreateContainer(runtime.ctx, sandbox, containerConfig, psc)
if err != nil {
return err
}
- return runtime.RuntimeService.StartContainer(containerID)
+ return runtime.RuntimeService.StartContainer(runtime.ctx, containerID)
}
func (runtime *CRIRuntime) RemoveMQTT() error {
@@ -397,7 +400,7 @@ func (runtime *CRIRuntime) RemoveMQTT() error {
LabelSelector: mqttLabel,
}
- sandbox, err := runtime.RuntimeService.ListPodSandbox(sandboxFilter)
+ sandbox, err := runtime.RuntimeService.ListPodSandbox(runtime.ctx, sandboxFilter)
if err != nil {
fmt.Printf("List MQTT containers failed: %v\n", err)
return err
@@ -408,7 +411,7 @@ func (runtime *CRIRuntime) RemoveMQTT() error {
// RemovePodSandbox removes the sandbox. If there are running containers in the
// sandbox, they should be forcibly removed.
// so we can remove mqtt containers totally.
- err = runtime.RuntimeService.RemovePodSandbox(c.Id)
+ err = runtime.RuntimeService.RemovePodSandbox(runtime.ctx, c.Id)
if err != nil {
fmt.Printf("failed to remove MQTT container: %v\n", err)
}