From 6cdb1c225dca5f88a84cdbc7e01fd8ec73712d2c Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Sat, 18 Dec 2021 12:18:25 +0200 Subject: [PATCH 1/2] Clean up dockerless build tag Signed-off-by: Ciprian Hacman --- hack/make-rules/verify.sh | 1 - hack/verify-typecheck-dockerless.sh | 34 -------------------- pkg/kubelet/kubelet_dockerless_test.go | 34 -------------------- pkg/kubelet/kubelet_dockershim_nodocker.go | 37 ---------------------- pkg/kubelet/legacy/logs.go | 11 ------- 5 files changed, 117 deletions(-) delete mode 100755 hack/verify-typecheck-dockerless.sh delete mode 100644 pkg/kubelet/kubelet_dockerless_test.go delete mode 100644 pkg/kubelet/kubelet_dockershim_nodocker.go diff --git a/hack/make-rules/verify.sh b/hack/make-rules/verify.sh index f4da3be4e3c..d3cec85c8c6 100755 --- a/hack/make-rules/verify.sh +++ b/hack/make-rules/verify.sh @@ -49,7 +49,6 @@ if [[ ${EXCLUDE_TYPECHECK:-} =~ ^[yY]$ ]]; then EXCLUDED_PATTERNS+=( "verify-typecheck.sh" # runs in separate typecheck job "verify-typecheck-providerless.sh" # runs in separate typecheck job - "verify-typecheck-dockerless.sh" # runs in separate typecheck job ) fi diff --git a/hack/verify-typecheck-dockerless.sh b/hack/verify-typecheck-dockerless.sh deleted file mode 100755 index d8f95e6b2ec..00000000000 --- a/hack/verify-typecheck-dockerless.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 The Kubernetes 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. - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. - -cd "${KUBE_ROOT}" -# verify the dockerless build -# https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/1547-building-kubelet-without-docker/README.md -hack/verify-typecheck.sh --skip-test --tags=dockerless --ignore-dirs=test - -# verify using go list -if _out="$(go list -mod=readonly -tags "dockerless" -e -json k8s.io/kubernetes/cmd/kubelet/... \ - | grep -e dockershim)"; then - echo "${_out}" >&2 - echo "Verify typecheck for dockerless tag failed. Found restricted packages." >&2 - exit 1 -fi diff --git a/pkg/kubelet/kubelet_dockerless_test.go b/pkg/kubelet/kubelet_dockerless_test.go deleted file mode 100644 index 3a494fd9a31..00000000000 --- a/pkg/kubelet/kubelet_dockerless_test.go +++ /dev/null @@ -1,34 +0,0 @@ -//go:build dockerless -// +build dockerless - -/* -Copyright 2020 The Kubernetes 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 kubelet_test - -import ( - "testing" - - "k8s.io/kubernetes/pkg/kubelet" - kubetypes "k8s.io/kubernetes/pkg/kubelet/types" -) - -func TestPreInitRuntimeService(t *testing.T) { - err := kubelet.PreInitRuntimeService(nil, nil, nil, kubetypes.DockerContainerRuntime, "", "", "", "") - if err == nil { - t.Fatal("PreInitRuntimeService should fail when configured to use docker and compiled dockerless") - } -} diff --git a/pkg/kubelet/kubelet_dockershim_nodocker.go b/pkg/kubelet/kubelet_dockershim_nodocker.go deleted file mode 100644 index 85dbc449791..00000000000 --- a/pkg/kubelet/kubelet_dockershim_nodocker.go +++ /dev/null @@ -1,37 +0,0 @@ -//go:build dockerless -// +build dockerless - -/* -Copyright 2020 The Kubernetes 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 kubelet - -import ( - "fmt" - kubeletconfiginternal "k8s.io/kubernetes/pkg/kubelet/apis/config" - "k8s.io/kubernetes/pkg/kubelet/config" -) - -func runDockershim(kubeCfg *kubeletconfiginternal.KubeletConfiguration, - kubeDeps *Dependencies, - crOptions *config.ContainerRuntimeOptions, - runtimeCgroups string, - remoteRuntimeEndpoint string, - remoteImageEndpoint string, - nonMasqueradeCIDR string) error { - - return fmt.Errorf("trying to use docker runtime when Kubelet was compiled without docker support") -} diff --git a/pkg/kubelet/legacy/logs.go b/pkg/kubelet/legacy/logs.go index d4b938a05c7..d0b6b8c2e10 100644 --- a/pkg/kubelet/legacy/logs.go +++ b/pkg/kubelet/legacy/logs.go @@ -29,17 +29,6 @@ import ( // It used to live in the `pkg/kubelet/dockershim` package. While we // would eventually like to remove it entirely, we need to give users some form // of warning. -// -// By including the interface in -// `pkg/kubelet/legacy/logs.go`, we ensure the interface is -// available to `pkg/kubelet`, even when we are building with the `dockerless` -// tag (i.e. not compiling the dockershim). -// While the interface always exists, there will be no implementations of the -// interface when building with the `dockerless` tag. The lack of -// implementations should not be an issue, as we only expect `pkg/kubelet` code -// to need an implementation of the `DockerLegacyService` when we are using -// docker. If we are using docker, but building with the `dockerless` tag, than -// this will be just one of many things that breaks. type DockerLegacyService interface { // GetContainerLogs gets logs for a specific container. GetContainerLogs(context.Context, *v1.Pod, kubecontainer.ContainerID, *v1.PodLogOptions, io.Writer, io.Writer) error From 5bae9b92884163ee96683502a3ca5f7abeea20a3 Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Sat, 18 Dec 2021 12:24:54 +0200 Subject: [PATCH 2/2] Clean up DockerLegacyService interface Signed-off-by: Ciprian Hacman --- pkg/kubelet/kubelet.go | 8 ---- pkg/kubelet/kubelet_pods.go | 6 --- .../kuberuntime/kuberuntime_container.go | 10 +---- .../kuberuntime/kuberuntime_manager.go | 11 ----- pkg/kubelet/legacy/logs.go | 42 ------------------- 5 files changed, 1 insertion(+), 76 deletions(-) delete mode 100644 pkg/kubelet/legacy/logs.go diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 0e6f5f946de..975c984c36c 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -78,7 +78,6 @@ import ( "k8s.io/kubernetes/pkg/kubelet/images" "k8s.io/kubernetes/pkg/kubelet/kubeletconfig" "k8s.io/kubernetes/pkg/kubelet/kuberuntime" - "k8s.io/kubernetes/pkg/kubelet/legacy" "k8s.io/kubernetes/pkg/kubelet/lifecycle" "k8s.io/kubernetes/pkg/kubelet/logs" "k8s.io/kubernetes/pkg/kubelet/metrics" @@ -243,7 +242,6 @@ type Dependencies struct { KubeletConfigController *kubeletconfig.Controller RemoteRuntimeService internalapi.RuntimeService RemoteImageService internalapi.ImageManagerService - dockerLegacyService legacy.DockerLegacyService // remove it after cadvisor.UsingLegacyCadvisorStats dropped. useLegacyCadvisorStats bool } @@ -608,7 +606,6 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration, klet.resourceAnalyzer = serverstats.NewResourceAnalyzer(klet, kubeCfg.VolumeStatsAggPeriod.Duration, kubeDeps.Recorder) - klet.dockerLegacyService = kubeDeps.dockerLegacyService klet.runtimeService = kubeDeps.RemoteRuntimeService if kubeDeps.KubeClient != nil { @@ -667,7 +664,6 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration, kubeDeps.RemoteRuntimeService, kubeDeps.RemoteImageService, kubeDeps.ContainerManager.InternalContainerLifecycle(), - kubeDeps.dockerLegacyService, klet.containerLogManager, klet.runtimeClassManager, seccompDefault, @@ -1188,10 +1184,6 @@ type Kubelet struct { // experimental behavior is desired. experimentalHostUserNamespaceDefaulting bool - // dockerLegacyService contains some legacy methods for backward compatibility. - // It should be set only when docker is using non json-file logging driver. - dockerLegacyService legacy.DockerLegacyService - // StatsProvider provides the node and the container stats. StatsProvider *stats.Provider diff --git a/pkg/kubelet/kubelet_pods.go b/pkg/kubelet/kubelet_pods.go index ba0ab34b5c7..a6ec21bcc05 100644 --- a/pkg/kubelet/kubelet_pods.go +++ b/pkg/kubelet/kubelet_pods.go @@ -1321,12 +1321,6 @@ func (kl *Kubelet) GetKubeletContainerLogs(ctx context.Context, podFullName, con return err } - if kl.dockerLegacyService != nil { - // dockerLegacyService should only be non-nil when we actually need it, so - // inject it into the runtimeService. - // TODO(random-liu): Remove this hack after deprecating unsupported log driver. - return kl.dockerLegacyService.GetContainerLogs(ctx, pod, containerID, logOptions, stdout, stderr) - } return kl.containerRuntime.GetContainerLogs(ctx, pod, containerID, logOptions, stdout, stderr) } diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index 34337e04b11..3de4fcadd17 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -520,15 +520,7 @@ func (m *kubeGenericRuntimeManager) getPodContainerStatuses(uid kubetypes.UID, n cStatus.ExitCode != 0 && cStatus.Reason != "ContainerCannotRun" tMessage, checkLogs := getTerminationMessage(status, annotatedInfo.TerminationMessagePath, fallbackToLogs) if checkLogs { - // if dockerLegacyService is populated, we're supposed to use it to fetch logs - if m.legacyLogProvider != nil { - tMessage, err = m.legacyLogProvider.GetContainerLogTail(uid, name, namespace, kubecontainer.ContainerID{Type: m.runtimeName, ID: c.Id}) - if err != nil { - tMessage = fmt.Sprintf("Error reading termination message from logs: %v", err) - } - } else { - tMessage = m.readLastStringFromContainerLogs(status.GetLogPath()) - } + tMessage = m.readLastStringFromContainerLogs(status.GetLogPath()) } // Enrich the termination message written by the application is not empty if len(tMessage) != 0 { diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index 7f4f82aacb6..b9cc4bca4cc 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -133,9 +133,6 @@ type kubeGenericRuntimeManager struct { // Internal lifecycle event handlers for container resource management. internalLifecycle cm.InternalContainerLifecycle - // A shim to legacy functions for backward compatibility. - legacyLogProvider LegacyLogProvider - // Manage container logs. logManager logs.ContainerLogManager @@ -168,12 +165,6 @@ type KubeGenericRuntime interface { kubecontainer.CommandRunner } -// LegacyLogProvider gives the ability to use unsupported docker log drivers (e.g. journald) -type LegacyLogProvider interface { - // GetContainerLogTail gets the last few lines of the logs for a specific container. - GetContainerLogTail(uid kubetypes.UID, name, namespace string, containerID kubecontainer.ContainerID) (string, error) -} - // NewKubeGenericRuntimeManager creates a new kubeGenericRuntimeManager func NewKubeGenericRuntimeManager( recorder record.EventRecorder, @@ -197,7 +188,6 @@ func NewKubeGenericRuntimeManager( runtimeService internalapi.RuntimeService, imageService internalapi.ImageManagerService, internalLifecycle cm.InternalContainerLifecycle, - legacyLogProvider LegacyLogProvider, logManager logs.ContainerLogManager, runtimeClassManager *runtimeclass.Manager, seccompDefault bool, @@ -219,7 +209,6 @@ func NewKubeGenericRuntimeManager( runtimeService: newInstrumentedRuntimeService(runtimeService), imageService: newInstrumentedImageManagerService(imageService), internalLifecycle: internalLifecycle, - legacyLogProvider: legacyLogProvider, logManager: logManager, runtimeClassManager: runtimeClassManager, logReduction: logreduction.NewLogReduction(identicalErrorDelay), diff --git a/pkg/kubelet/legacy/logs.go b/pkg/kubelet/legacy/logs.go deleted file mode 100644 index d0b6b8c2e10..00000000000 --- a/pkg/kubelet/legacy/logs.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2020 The Kubernetes 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 legacy - -import ( - "context" - "io" - - "k8s.io/api/core/v1" - kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" - "k8s.io/kubernetes/pkg/kubelet/kuberuntime" -) - -// DockerLegacyService interface is used throughout `pkg/kubelet`. -// It used to live in the `pkg/kubelet/dockershim` package. While we -// would eventually like to remove it entirely, we need to give users some form -// of warning. -type DockerLegacyService interface { - // GetContainerLogs gets logs for a specific container. - GetContainerLogs(context.Context, *v1.Pod, kubecontainer.ContainerID, *v1.PodLogOptions, io.Writer, io.Writer) error - - // IsCRISupportedLogDriver checks whether the logging driver used by docker is - // supported by native CRI integration. - // TODO(resouer): remove this when deprecating unsupported log driver - IsCRISupportedLogDriver() (bool, error) - - kuberuntime.LegacyLogProvider -}