Skip to content

Commit 41dedc0

Browse files
authored
Merge pull request #691 from caohe/kubelet-configz
fix(*): adapt to kubelet configz endpoint changes to support K8s 1.28
2 parents 2333cae + 69fafb1 commit 41dedc0

File tree

11 files changed

+111
-38
lines changed

11 files changed

+111
-38
lines changed

pkg/agent/resourcemanager/fetcher/kubelet/kubeletplugin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
v1 "k8s.io/api/core/v1"
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
"k8s.io/klog/v2"
34-
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
3534
podresv1 "k8s.io/kubelet/pkg/apis/podresources/v1"
3635
apisconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
3736
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
@@ -49,6 +48,7 @@ import (
4948
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
5049
"github.com/kubewharf/katalyst-core/pkg/metrics"
5150
"github.com/kubewharf/katalyst-core/pkg/util/machine"
51+
"github.com/kubewharf/katalyst-core/pkg/util/native"
5252
)
5353

5454
type fakePodResourcesServer struct {
@@ -89,7 +89,7 @@ func generateTestConfiguration(t *testing.T, dir string) *config.Configuration {
8989
}
9090

9191
func generateTestMetaServer(podList ...*v1.Pod) *metaserver.MetaServer {
92-
fakeKubeletConfig := kubeletconfigv1beta1.KubeletConfiguration{
92+
fakeKubeletConfig := native.KubeletConfiguration{
9393
TopologyManagerPolicy: apisconfig.SingleNumaNodeTopologyManagerPolicy,
9494
TopologyManagerScope: apisconfig.ContainerTopologyManagerScope,
9595
}

pkg/agent/resourcemanager/fetcher/kubelet/topology/topology_adapter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/types"
3535
"k8s.io/apimachinery/pkg/util/sets"
36-
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
3736
podresv1 "k8s.io/kubelet/pkg/apis/podresources/v1"
3837
"k8s.io/kubernetes/pkg/kubelet/apis/config"
3938
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
@@ -51,6 +50,7 @@ import (
5150
"github.com/kubewharf/katalyst-core/pkg/util"
5251
"github.com/kubewharf/katalyst-core/pkg/util/kubelet/podresources"
5352
"github.com/kubewharf/katalyst-core/pkg/util/machine"
53+
"github.com/kubewharf/katalyst-core/pkg/util/native"
5454
)
5555

5656
type fakePodResourcesServer struct {
@@ -2913,7 +2913,7 @@ func Test_podResourcesServerTopologyAdapterImpl_GetTopologyZones(t *testing.T) {
29132913
func Test_podResourcesServerTopologyAdapterImpl_GetTopologyPolicy(t *testing.T) {
29142914
t.Parallel()
29152915

2916-
fakeKubeletConfig := kubeletconfigv1beta1.KubeletConfiguration{
2916+
fakeKubeletConfig := native.KubeletConfiguration{
29172917
TopologyManagerPolicy: config.SingleNumaNodeTopologyManagerPolicy,
29182918
TopologyManagerScope: config.ContainerTopologyManagerScope,
29192919
}

pkg/agent/sysadvisor/plugin/overcommitmentaware/realtime/realtime_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"testing"
2424
"time"
2525

26-
consts2 "github.com/kubewharf/katalyst-api/pkg/consts"
27-
2826
info "github.com/google/cadvisor/info/v1"
2927
"github.com/stretchr/testify/assert"
3028
"github.com/stretchr/testify/require"
@@ -34,9 +32,9 @@ import (
3432
"k8s.io/apimachinery/pkg/runtime"
3533
dynamicfake "k8s.io/client-go/dynamic/fake"
3634
"k8s.io/client-go/kubernetes/fake"
37-
"k8s.io/kubelet/config/v1beta1"
3835

3936
internalfake "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned/fake"
37+
consts2 "github.com/kubewharf/katalyst-api/pkg/consts"
4038
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options"
4139
"github.com/kubewharf/katalyst-core/pkg/client"
4240
"github.com/kubewharf/katalyst-core/pkg/config"
@@ -47,6 +45,7 @@ import (
4745
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
4846
"github.com/kubewharf/katalyst-core/pkg/metrics"
4947
metric2 "github.com/kubewharf/katalyst-core/pkg/util/metric"
48+
"github.com/kubewharf/katalyst-core/pkg/util/native"
5049
)
5150

5251
func TestUpdate(t *testing.T) {
@@ -437,7 +436,7 @@ func generateTestMetaServer(t *testing.T, conf *config.Configuration, podList []
437436

438437
meta.MetricsFetcher = fakeMetricsFetcher
439438

440-
meta.KubeletConfigFetcher = kubeletconfig.NewFakeKubeletConfigFetcher(v1beta1.KubeletConfiguration{})
439+
meta.KubeletConfigFetcher = kubeletconfig.NewFakeKubeletConfigFetcher(native.KubeletConfiguration{})
441440

442441
meta.MachineInfo = &info.MachineInfo{
443442
NumCores: 16,

pkg/agent/sysadvisor/plugin/overcommitmentaware/reporter/reporter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
v1 "k8s.io/api/core/v1"
2727
"k8s.io/apimachinery/pkg/api/resource"
2828
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
29-
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
3029
"k8s.io/kubernetes/pkg/features"
3130
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
3231

@@ -35,12 +34,13 @@ import (
3534
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent"
3635
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/kubeletconfig"
3736
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
37+
"github.com/kubewharf/katalyst-core/pkg/util/native"
3838
)
3939

4040
func TestGetReportContent(t *testing.T) {
4141
t.Parallel()
4242

43-
fakeKubeletConfig := kubeletconfigv1beta1.KubeletConfiguration{
43+
fakeKubeletConfig := native.KubeletConfiguration{
4444
FeatureGates: map[string]bool{
4545
string(features.CPUManager): true,
4646
string(features.MemoryManager): false,

pkg/metaserver/agent/agent_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"k8s.io/apimachinery/pkg/types"
3030
"k8s.io/client-go/kubernetes/fake"
3131
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
32-
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
3332
"k8s.io/kubernetes/pkg/kubelet/apis/config"
3433

3534
"github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1"
@@ -45,6 +44,7 @@ import (
4544
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/node"
4645
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
4746
"github.com/kubewharf/katalyst-core/pkg/metrics"
47+
"github.com/kubewharf/katalyst-core/pkg/util/native"
4848
)
4949

5050
func constructNodeInterface(name string) corev1.NodeInterface {
@@ -169,7 +169,7 @@ func TestFetcher(t *testing.T) {
169169
}
170170
s := &ObjectFetcherTest{obj: obj}
171171

172-
fakeKubeletConfig := kubeletconfigv1beta1.KubeletConfiguration{
172+
fakeKubeletConfig := native.KubeletConfiguration{
173173
TopologyManagerPolicy: config.SingleNumaNodeTopologyManagerPolicy,
174174
TopologyManagerScope: config.ContainerTopologyManagerScope,
175175
}

pkg/metaserver/agent/kubeletconfig/fake_kubeletconfig.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ package kubeletconfig
1919
import (
2020
"context"
2121

22-
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
22+
"github.com/kubewharf/katalyst-core/pkg/util/native"
2323
)
2424

2525
// NewFakeKubeletConfigFetcher returns a fakeKubeletConfigFetcherImpl.
26-
func NewFakeKubeletConfigFetcher(kubeletConfig kubeletconfigv1beta1.KubeletConfiguration) KubeletConfigFetcher {
26+
func NewFakeKubeletConfigFetcher(kubeletConfig native.KubeletConfiguration) KubeletConfigFetcher {
2727
return &fakeKubeletConfigFetcherImpl{
2828
kubeletConfig: kubeletConfig,
2929
}
3030
}
3131

3232
// fakeKubeletConfigFetcherImpl returns a fake kubelet config.
3333
type fakeKubeletConfigFetcherImpl struct {
34-
kubeletConfig kubeletconfigv1beta1.KubeletConfiguration
34+
kubeletConfig native.KubeletConfiguration
3535
}
3636

3737
// GetKubeletConfig returns a fake kubelet config.
38-
func (f *fakeKubeletConfigFetcherImpl) GetKubeletConfig(_ context.Context) (*kubeletconfigv1beta1.KubeletConfiguration, error) {
38+
func (f *fakeKubeletConfigFetcherImpl) GetKubeletConfig(_ context.Context) (*native.KubeletConfiguration, error) {
3939
return &f.kubeletConfig, nil
4040
}

pkg/metaserver/agent/kubeletconfig/kubeletconfig.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222

23-
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
24-
2523
"github.com/kubewharf/katalyst-core/pkg/config/agent/global"
2624
"github.com/kubewharf/katalyst-core/pkg/metrics"
2725
"github.com/kubewharf/katalyst-core/pkg/util/native"
@@ -30,7 +28,7 @@ import (
3028
// KubeletConfigFetcher is used to get the configuration of kubelet.
3129
type KubeletConfigFetcher interface {
3230
// GetKubeletConfig returns the configuration of kubelet.
33-
GetKubeletConfig(ctx context.Context) (*kubeletconfigv1beta1.KubeletConfiguration, error)
31+
GetKubeletConfig(ctx context.Context) (*native.KubeletConfiguration, error)
3432
}
3533

3634
// NewKubeletConfigFetcher returns a KubeletConfigFetcher
@@ -48,13 +46,13 @@ type kubeletConfigFetcherImpl struct {
4846
}
4947

5048
// GetKubeletConfig gets kubelet config from kubelet 10250/configz api
51-
func (k *kubeletConfigFetcherImpl) GetKubeletConfig(ctx context.Context) (*kubeletconfigv1beta1.KubeletConfiguration, error) {
49+
func (k *kubeletConfigFetcherImpl) GetKubeletConfig(ctx context.Context) (*native.KubeletConfiguration, error) {
5250
if !k.baseConf.KubeletSecurePortEnabled {
5351
return nil, fmt.Errorf("it is not enabled to get contents from kubelet secure port")
5452
}
5553

5654
type configzWrapper struct {
57-
ComponentConfig kubeletconfigv1beta1.KubeletConfiguration `json:"kubeletconfig"`
55+
ComponentConfig native.KubeletConfiguration `json:"kubeletconfig"`
5856
}
5957
configz := configzWrapper{}
6058

pkg/util/kubelet/config/kubeletconfig.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121

2222
"k8s.io/apimachinery/pkg/api/resource"
2323
"k8s.io/klog/v2"
24-
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
2524
"k8s.io/kubernetes/pkg/features"
2625

2726
"github.com/kubewharf/katalyst-api/pkg/consts"
27+
"github.com/kubewharf/katalyst-core/pkg/util/native"
2828
)
2929

3030
// CheckFeatureGateEnable returns true if all the given features are enabled
31-
func CheckFeatureGateEnable(kubeletConfig *kubeletconfigv1beta1.KubeletConfiguration, features ...string) (bool, error) {
31+
func CheckFeatureGateEnable(kubeletConfig *native.KubeletConfiguration, features ...string) (bool, error) {
3232
if kubeletConfig == nil {
3333
return false, fmt.Errorf("nil KubeletConfiguration")
3434
}
@@ -41,7 +41,7 @@ func CheckFeatureGateEnable(kubeletConfig *kubeletconfigv1beta1.KubeletConfigura
4141
}
4242

4343
// GetReservedQuantity the quantity for reserved resources defined in KubeletConfiguration
44-
func GetReservedQuantity(kubeletConfig *kubeletconfigv1beta1.KubeletConfiguration, resourceName string) (resource.Quantity, bool, error) {
44+
func GetReservedQuantity(kubeletConfig *native.KubeletConfiguration, resourceName string) (resource.Quantity, bool, error) {
4545
if kubeletConfig == nil {
4646
return resource.MustParse("0"), false, fmt.Errorf("nil KubeletConfiguration")
4747
}
@@ -73,7 +73,7 @@ func GetReservedQuantity(kubeletConfig *kubeletconfigv1beta1.KubeletConfiguratio
7373

7474
// GetInTreeProviderPolicies returns a map containing the policy for in-tree
7575
// topology-hint-provider, i.e. cpu-manager && memory-manager
76-
func GetInTreeProviderPolicies(kubeletConfig *kubeletconfigv1beta1.KubeletConfiguration) (map[string]string, error) {
76+
func GetInTreeProviderPolicies(kubeletConfig *native.KubeletConfiguration) (map[string]string, error) {
7777
if kubeletConfig == nil {
7878
return map[string]string{}, fmt.Errorf("nil KubeletConfiguration")
7979
}

pkg/util/kubelet/config/kubeletconfig_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ import (
2222

2323
"github.com/stretchr/testify/assert"
2424
"k8s.io/apimachinery/pkg/api/resource"
25-
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
2625
"k8s.io/kubernetes/pkg/features"
2726

2827
"github.com/kubewharf/katalyst-api/pkg/consts"
28+
"github.com/kubewharf/katalyst-core/pkg/util/native"
2929
)
3030

3131
func TestCheckFeatureGateEnable(t *testing.T) {
3232
t.Parallel()
3333

3434
tests := []struct {
3535
name string
36-
conf *kubeletconfigv1beta1.KubeletConfiguration
36+
conf *native.KubeletConfiguration
3737
features []string
3838
enabled bool
3939
err error
@@ -44,7 +44,7 @@ func TestCheckFeatureGateEnable(t *testing.T) {
4444
},
4545
{
4646
name: "partial enabled",
47-
conf: &kubeletconfigv1beta1.KubeletConfiguration{
47+
conf: &native.KubeletConfiguration{
4848
FeatureGates: map[string]bool{
4949
"a": true,
5050
},
@@ -55,7 +55,7 @@ func TestCheckFeatureGateEnable(t *testing.T) {
5555
},
5656
{
5757
name: "total enabled",
58-
conf: &kubeletconfigv1beta1.KubeletConfiguration{
58+
conf: &native.KubeletConfiguration{
5959
FeatureGates: map[string]bool{
6060
"a": true,
6161
"b": true,
@@ -88,7 +88,7 @@ func TestGetReservedQuantity(t *testing.T) {
8888

8989
tests := []struct {
9090
name string
91-
conf *kubeletconfigv1beta1.KubeletConfiguration
91+
conf *native.KubeletConfiguration
9292
resourceName string
9393
resourceQuantity resource.Quantity
9494
valid bool
@@ -100,7 +100,7 @@ func TestGetReservedQuantity(t *testing.T) {
100100
},
101101
{
102102
name: "resource both exists",
103-
conf: &kubeletconfigv1beta1.KubeletConfiguration{
103+
conf: &native.KubeletConfiguration{
104104
KubeReserved: map[string]string{
105105
"cpu": "1024m",
106106
},
@@ -115,7 +115,7 @@ func TestGetReservedQuantity(t *testing.T) {
115115
},
116116
{
117117
name: "resource only-one exists",
118-
conf: &kubeletconfigv1beta1.KubeletConfiguration{
118+
conf: &native.KubeletConfiguration{
119119
KubeReserved: map[string]string{
120120
"cpu": "1024m",
121121
},
@@ -127,7 +127,7 @@ func TestGetReservedQuantity(t *testing.T) {
127127
},
128128
{
129129
name: "resource not exists",
130-
conf: &kubeletconfigv1beta1.KubeletConfiguration{
130+
conf: &native.KubeletConfiguration{
131131
KubeReserved: map[string]string{
132132
"cpu": "1024m",
133133
},
@@ -162,7 +162,7 @@ func TestGetInTreeProviderPolicies(t *testing.T) {
162162

163163
tests := []struct {
164164
name string
165-
conf *kubeletconfigv1beta1.KubeletConfiguration
165+
conf *native.KubeletConfiguration
166166
res map[string]string
167167
err error
168168
}{
@@ -172,7 +172,7 @@ func TestGetInTreeProviderPolicies(t *testing.T) {
172172
},
173173
{
174174
name: "cpu only",
175-
conf: &kubeletconfigv1beta1.KubeletConfiguration{
175+
conf: &native.KubeletConfiguration{
176176
FeatureGates: map[string]bool{
177177
string(features.CPUManager): true,
178178
},
@@ -186,7 +186,7 @@ func TestGetInTreeProviderPolicies(t *testing.T) {
186186
},
187187
{
188188
name: "all policies",
189-
conf: &kubeletconfigv1beta1.KubeletConfiguration{
189+
conf: &native.KubeletConfiguration{
190190
FeatureGates: map[string]bool{
191191
string(features.CPUManager): true,
192192
string(features.MemoryManager): true,

0 commit comments

Comments
 (0)