mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Clean up deprecated references
This commit is contained in:
parent
6510d26b6a
commit
e06912ca3e
@ -75,7 +75,7 @@ func getDockerClient(dockerEndpoint string) (*dockerapi.Client, error) {
|
|||||||
klog.Infof("Connecting to docker on %s", dockerEndpoint)
|
klog.Infof("Connecting to docker on %s", dockerEndpoint)
|
||||||
return dockerapi.NewClient(dockerEndpoint, "", nil, nil)
|
return dockerapi.NewClient(dockerEndpoint, "", nil, nil)
|
||||||
}
|
}
|
||||||
return dockerapi.NewEnvClient()
|
return dockerapi.NewClientWithOpts(dockerapi.FromEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectToDockerOrDie creates docker client connecting to docker daemon.
|
// ConnectToDockerOrDie creates docker client connecting to docker daemon.
|
||||||
|
@ -68,7 +68,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
|
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
|
||||||
"//vendor/github.com/armon/circbuf:go_default_library",
|
"//vendor/github.com/armon/circbuf:go_default_library",
|
||||||
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
|
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
|
||||||
"//vendor/google.golang.org/grpc:go_default_library",
|
"//vendor/google.golang.org/grpc/status:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
] + select({
|
] + select({
|
||||||
"@io_bazel_rules_go//go/platform:linux": [
|
"@io_bazel_rules_go//go/platform:linux": [
|
||||||
@ -122,6 +122,7 @@ go_test(
|
|||||||
"//vendor/github.com/golang/mock/gomock:go_default_library",
|
"//vendor/github.com/golang/mock/gomock:go_default_library",
|
||||||
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
|
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
|
||||||
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
|
||||||
|
"//vendor/github.com/prometheus/client_golang/prometheus/promhttp:go_default_library",
|
||||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||||
"//vendor/github.com/stretchr/testify/require:go_default_library",
|
"//vendor/github.com/stretchr/testify/require:go_default_library",
|
||||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/metrics"
|
"k8s.io/kubernetes/pkg/kubelet/metrics"
|
||||||
@ -40,7 +41,7 @@ func TestRecordOperation(t *testing.T) {
|
|||||||
|
|
||||||
prometheusURL := "http://" + temporalServer + "/metrics"
|
prometheusURL := "http://" + temporalServer + "/metrics"
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/metrics", prometheus.Handler())
|
mux.Handle("/metrics", promhttp.Handler())
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: temporalServer,
|
Addr: temporalServer,
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
grpcstatus "google.golang.org/grpc/status"
|
||||||
|
|
||||||
"github.com/armon/circbuf"
|
"github.com/armon/circbuf"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
@ -94,7 +94,8 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
|
|||||||
// Step 1: pull the image.
|
// Step 1: pull the image.
|
||||||
imageRef, msg, err := m.imagePuller.EnsureImageExists(pod, container, pullSecrets, podSandboxConfig)
|
imageRef, msg, err := m.imagePuller.EnsureImageExists(pod, container, pullSecrets, podSandboxConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.recordContainerEvent(pod, container, "", v1.EventTypeWarning, events.FailedToCreateContainer, "Error: %v", grpc.ErrorDesc(err))
|
s, _ := grpcstatus.FromError(err)
|
||||||
|
m.recordContainerEvent(pod, container, "", v1.EventTypeWarning, events.FailedToCreateContainer, "Error: %v", s.Message())
|
||||||
return msg, err
|
return msg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,19 +118,22 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
|
|||||||
defer cleanupAction()
|
defer cleanupAction()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.recordContainerEvent(pod, container, "", v1.EventTypeWarning, events.FailedToCreateContainer, "Error: %v", grpc.ErrorDesc(err))
|
s, _ := grpcstatus.FromError(err)
|
||||||
return grpc.ErrorDesc(err), ErrCreateContainerConfig
|
m.recordContainerEvent(pod, container, "", v1.EventTypeWarning, events.FailedToCreateContainer, "Error: %v", s.Message())
|
||||||
|
return s.Message(), ErrCreateContainerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
containerID, err := m.runtimeService.CreateContainer(podSandboxID, containerConfig, podSandboxConfig)
|
containerID, err := m.runtimeService.CreateContainer(podSandboxID, containerConfig, podSandboxConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.recordContainerEvent(pod, container, containerID, v1.EventTypeWarning, events.FailedToCreateContainer, "Error: %v", grpc.ErrorDesc(err))
|
s, _ := grpcstatus.FromError(err)
|
||||||
return grpc.ErrorDesc(err), ErrCreateContainer
|
m.recordContainerEvent(pod, container, containerID, v1.EventTypeWarning, events.FailedToCreateContainer, "Error: %v", s.Message())
|
||||||
|
return s.Message(), ErrCreateContainer
|
||||||
}
|
}
|
||||||
err = m.internalLifecycle.PreStartContainer(pod, container, containerID)
|
err = m.internalLifecycle.PreStartContainer(pod, container, containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.recordContainerEvent(pod, container, containerID, v1.EventTypeWarning, events.FailedToStartContainer, "Internal PreStartContainer hook failed: %v", grpc.ErrorDesc(err))
|
s, _ := grpcstatus.FromError(err)
|
||||||
return grpc.ErrorDesc(err), ErrPreStartHook
|
m.recordContainerEvent(pod, container, containerID, v1.EventTypeWarning, events.FailedToStartContainer, "Internal PreStartContainer hook failed: %v", s.Message())
|
||||||
|
return s.Message(), ErrPreStartHook
|
||||||
}
|
}
|
||||||
m.recordContainerEvent(pod, container, containerID, v1.EventTypeNormal, events.CreatedContainer, fmt.Sprintf("Created container %s", container.Name))
|
m.recordContainerEvent(pod, container, containerID, v1.EventTypeNormal, events.CreatedContainer, fmt.Sprintf("Created container %s", container.Name))
|
||||||
|
|
||||||
@ -143,8 +147,9 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb
|
|||||||
// Step 3: start the container.
|
// Step 3: start the container.
|
||||||
err = m.runtimeService.StartContainer(containerID)
|
err = m.runtimeService.StartContainer(containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.recordContainerEvent(pod, container, containerID, v1.EventTypeWarning, events.FailedToStartContainer, "Error: %v", grpc.ErrorDesc(err))
|
s, _ := grpcstatus.FromError(err)
|
||||||
return grpc.ErrorDesc(err), kubecontainer.ErrRunContainer
|
m.recordContainerEvent(pod, container, containerID, v1.EventTypeWarning, events.FailedToStartContainer, "Error: %v", s.Message())
|
||||||
|
return s.Message(), kubecontainer.ErrRunContainer
|
||||||
}
|
}
|
||||||
m.recordContainerEvent(pod, container, containerID, v1.EventTypeNormal, events.StartedContainer, fmt.Sprintf("Started container %s", container.Name))
|
m.recordContainerEvent(pod, container, containerID, v1.EventTypeNormal, events.StartedContainer, fmt.Sprintf("Started container %s", container.Name))
|
||||||
|
|
||||||
|
@ -296,6 +296,7 @@ func (s *Server) InstallDefaultHandlers(enableCAdvisorJSONEndpoints bool) {
|
|||||||
s.restfulCont.Add(ws)
|
s.restfulCont.Add(ws)
|
||||||
|
|
||||||
s.restfulCont.Add(stats.CreateHandlers(statsPath, s.host, s.resourceAnalyzer, enableCAdvisorJSONEndpoints))
|
s.restfulCont.Add(stats.CreateHandlers(statsPath, s.host, s.resourceAnalyzer, enableCAdvisorJSONEndpoints))
|
||||||
|
//lint:ignore SA1019 https://github.com/kubernetes/enhancements/issues/1206
|
||||||
s.restfulCont.Handle(metricsPath, prometheus.Handler())
|
s.restfulCont.Handle(metricsPath, prometheus.Handler())
|
||||||
|
|
||||||
// cAdvisor metrics are exposed under the secured handler as well
|
// cAdvisor metrics are exposed under the secured handler as well
|
||||||
|
@ -23,7 +23,6 @@ go_library(
|
|||||||
"//staging/src/k8s.io/client-go/tools/remotecommand:go_default_library",
|
"//staging/src/k8s.io/client-go/tools/remotecommand:go_default_library",
|
||||||
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
|
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
|
||||||
"//vendor/github.com/emicklei/go-restful:go_default_library",
|
"//vendor/github.com/emicklei/go-restful:go_default_library",
|
||||||
"//vendor/google.golang.org/grpc:go_default_library",
|
|
||||||
"//vendor/google.golang.org/grpc/codes:go_default_library",
|
"//vendor/google.golang.org/grpc/codes:go_default_library",
|
||||||
"//vendor/google.golang.org/grpc/status:go_default_library",
|
"//vendor/google.golang.org/grpc/status:go_default_library",
|
||||||
],
|
],
|
||||||
|
@ -20,25 +20,25 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
grpcstatus "google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewErrorStreamingDisabled creates an error for disabled streaming method.
|
// NewErrorStreamingDisabled creates an error for disabled streaming method.
|
||||||
func NewErrorStreamingDisabled(method string) error {
|
func NewErrorStreamingDisabled(method string) error {
|
||||||
return status.Errorf(codes.NotFound, "streaming method %s disabled", method)
|
return grpcstatus.Errorf(codes.NotFound, "streaming method %s disabled", method)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewErrorTooManyInFlight creates an error for exceeding the maximum number of in-flight requests.
|
// NewErrorTooManyInFlight creates an error for exceeding the maximum number of in-flight requests.
|
||||||
func NewErrorTooManyInFlight() error {
|
func NewErrorTooManyInFlight() error {
|
||||||
return status.Error(codes.ResourceExhausted, "maximum number of in-flight requests exceeded")
|
return grpcstatus.Error(codes.ResourceExhausted, "maximum number of in-flight requests exceeded")
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteError translates a CRI streaming error into an appropriate HTTP response.
|
// WriteError translates a CRI streaming error into an appropriate HTTP response.
|
||||||
func WriteError(err error, w http.ResponseWriter) error {
|
func WriteError(err error, w http.ResponseWriter) error {
|
||||||
|
s, _ := grpcstatus.FromError(err)
|
||||||
var status int
|
var status int
|
||||||
switch grpc.Code(err) {
|
switch s.Code() {
|
||||||
case codes.NotFound:
|
case codes.NotFound:
|
||||||
status = http.StatusNotFound
|
status = http.StatusNotFound
|
||||||
case codes.ResourceExhausted:
|
case codes.ResourceExhausted:
|
||||||
|
@ -68,10 +68,11 @@ func TestInsert(t *testing.T) {
|
|||||||
// Insert again (should evict)
|
// Insert again (should evict)
|
||||||
_, err = c.Insert(nextRequest())
|
_, err = c.Insert(nextRequest())
|
||||||
assert.Error(t, err, "should reject further requests")
|
assert.Error(t, err, "should reject further requests")
|
||||||
errResponse := httptest.NewRecorder()
|
recorder := httptest.NewRecorder()
|
||||||
require.NoError(t, WriteError(err, errResponse))
|
require.NoError(t, WriteError(err, recorder))
|
||||||
assert.Equal(t, errResponse.Code, http.StatusTooManyRequests)
|
errResponse := recorder.Result()
|
||||||
assert.Equal(t, strconv.Itoa(int(cacheTTL.Seconds())), errResponse.HeaderMap.Get("Retry-After"))
|
assert.Equal(t, errResponse.StatusCode, http.StatusTooManyRequests)
|
||||||
|
assert.Equal(t, strconv.Itoa(int(cacheTTL.Seconds())), errResponse.Header.Get("Retry-After"))
|
||||||
|
|
||||||
assertCacheSize(t, c, maxInFlight)
|
assertCacheSize(t, c, maxInFlight)
|
||||||
_, ok = c.Consume(oldestTok)
|
_, ok = c.Consume(oldestTok)
|
||||||
|
Loading…
Reference in New Issue
Block a user