Skip to content

Commit

Permalink
Merge pull request #691 from caohe/kubelet-configz
Browse files Browse the repository at this point in the history
fix(*): adapt to kubelet configz endpoint changes to support K8s 1.28
  • Loading branch information
xu282934741 authored Sep 3, 2024
2 parents 2333cae + 69fafb1 commit 41dedc0
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
podresv1 "k8s.io/kubelet/pkg/apis/podresources/v1"
apisconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
Expand All @@ -49,6 +48,7 @@ import (
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
"github.com/kubewharf/katalyst-core/pkg/metrics"
"github.com/kubewharf/katalyst-core/pkg/util/machine"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

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

func generateTestMetaServer(podList ...*v1.Pod) *metaserver.MetaServer {
fakeKubeletConfig := kubeletconfigv1beta1.KubeletConfiguration{
fakeKubeletConfig := native.KubeletConfiguration{
TopologyManagerPolicy: apisconfig.SingleNumaNodeTopologyManagerPolicy,
TopologyManagerScope: apisconfig.ContainerTopologyManagerScope,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
podresv1 "k8s.io/kubelet/pkg/apis/podresources/v1"
"k8s.io/kubernetes/pkg/kubelet/apis/config"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
Expand All @@ -51,6 +50,7 @@ import (
"github.com/kubewharf/katalyst-core/pkg/util"
"github.com/kubewharf/katalyst-core/pkg/util/kubelet/podresources"
"github.com/kubewharf/katalyst-core/pkg/util/machine"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

type fakePodResourcesServer struct {
Expand Down Expand Up @@ -2913,7 +2913,7 @@ func Test_podResourcesServerTopologyAdapterImpl_GetTopologyZones(t *testing.T) {
func Test_podResourcesServerTopologyAdapterImpl_GetTopologyPolicy(t *testing.T) {
t.Parallel()

fakeKubeletConfig := kubeletconfigv1beta1.KubeletConfiguration{
fakeKubeletConfig := native.KubeletConfiguration{
TopologyManagerPolicy: config.SingleNumaNodeTopologyManagerPolicy,
TopologyManagerScope: config.ContainerTopologyManagerScope,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"testing"
"time"

consts2 "github.com/kubewharf/katalyst-api/pkg/consts"

info "github.com/google/cadvisor/info/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -34,9 +32,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"
dynamicfake "k8s.io/client-go/dynamic/fake"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/kubelet/config/v1beta1"

internalfake "github.com/kubewharf/katalyst-api/pkg/client/clientset/versioned/fake"
consts2 "github.com/kubewharf/katalyst-api/pkg/consts"
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options"
"github.com/kubewharf/katalyst-core/pkg/client"
"github.com/kubewharf/katalyst-core/pkg/config"
Expand All @@ -47,6 +45,7 @@ import (
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
"github.com/kubewharf/katalyst-core/pkg/metrics"
metric2 "github.com/kubewharf/katalyst-core/pkg/util/metric"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

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

meta.MetricsFetcher = fakeMetricsFetcher

meta.KubeletConfigFetcher = kubeletconfig.NewFakeKubeletConfigFetcher(v1beta1.KubeletConfiguration{})
meta.KubeletConfigFetcher = kubeletconfig.NewFakeKubeletConfigFetcher(native.KubeletConfiguration{})

meta.MachineInfo = &info.MachineInfo{
NumCores: 16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"

Expand All @@ -35,12 +34,13 @@ import (
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent"
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/kubeletconfig"
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

func TestGetReportContent(t *testing.T) {
t.Parallel()

fakeKubeletConfig := kubeletconfigv1beta1.KubeletConfiguration{
fakeKubeletConfig := native.KubeletConfiguration{
FeatureGates: map[string]bool{
string(features.CPUManager): true,
string(features.MemoryManager): false,
Expand Down
4 changes: 2 additions & 2 deletions pkg/metaserver/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/fake"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/kubernetes/pkg/kubelet/apis/config"

"github.com/kubewharf/katalyst-api/pkg/apis/node/v1alpha1"
Expand All @@ -45,6 +44,7 @@ import (
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/node"
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
"github.com/kubewharf/katalyst-core/pkg/metrics"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

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

fakeKubeletConfig := kubeletconfigv1beta1.KubeletConfiguration{
fakeKubeletConfig := native.KubeletConfiguration{
TopologyManagerPolicy: config.SingleNumaNodeTopologyManagerPolicy,
TopologyManagerScope: config.ContainerTopologyManagerScope,
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/metaserver/agent/kubeletconfig/fake_kubeletconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ package kubeletconfig
import (
"context"

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

// NewFakeKubeletConfigFetcher returns a fakeKubeletConfigFetcherImpl.
func NewFakeKubeletConfigFetcher(kubeletConfig kubeletconfigv1beta1.KubeletConfiguration) KubeletConfigFetcher {
func NewFakeKubeletConfigFetcher(kubeletConfig native.KubeletConfiguration) KubeletConfigFetcher {
return &fakeKubeletConfigFetcherImpl{
kubeletConfig: kubeletConfig,
}
}

// fakeKubeletConfigFetcherImpl returns a fake kubelet config.
type fakeKubeletConfigFetcherImpl struct {
kubeletConfig kubeletconfigv1beta1.KubeletConfiguration
kubeletConfig native.KubeletConfiguration
}

// GetKubeletConfig returns a fake kubelet config.
func (f *fakeKubeletConfigFetcherImpl) GetKubeletConfig(_ context.Context) (*kubeletconfigv1beta1.KubeletConfiguration, error) {
func (f *fakeKubeletConfigFetcherImpl) GetKubeletConfig(_ context.Context) (*native.KubeletConfiguration, error) {
return &f.kubeletConfig, nil
}
8 changes: 3 additions & 5 deletions pkg/metaserver/agent/kubeletconfig/kubeletconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"context"
"fmt"

kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"

"github.com/kubewharf/katalyst-core/pkg/config/agent/global"
"github.com/kubewharf/katalyst-core/pkg/metrics"
"github.com/kubewharf/katalyst-core/pkg/util/native"
Expand All @@ -30,7 +28,7 @@ import (
// KubeletConfigFetcher is used to get the configuration of kubelet.
type KubeletConfigFetcher interface {
// GetKubeletConfig returns the configuration of kubelet.
GetKubeletConfig(ctx context.Context) (*kubeletconfigv1beta1.KubeletConfiguration, error)
GetKubeletConfig(ctx context.Context) (*native.KubeletConfiguration, error)
}

// NewKubeletConfigFetcher returns a KubeletConfigFetcher
Expand All @@ -48,13 +46,13 @@ type kubeletConfigFetcherImpl struct {
}

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

type configzWrapper struct {
ComponentConfig kubeletconfigv1beta1.KubeletConfiguration `json:"kubeletconfig"`
ComponentConfig native.KubeletConfiguration `json:"kubeletconfig"`
}
configz := configzWrapper{}

Expand Down
8 changes: 4 additions & 4 deletions pkg/util/kubelet/config/kubeletconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (

"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/klog/v2"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/kubernetes/pkg/features"

"github.com/kubewharf/katalyst-api/pkg/consts"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

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

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

// GetInTreeProviderPolicies returns a map containing the policy for in-tree
// topology-hint-provider, i.e. cpu-manager && memory-manager
func GetInTreeProviderPolicies(kubeletConfig *kubeletconfigv1beta1.KubeletConfiguration) (map[string]string, error) {
func GetInTreeProviderPolicies(kubeletConfig *native.KubeletConfiguration) (map[string]string, error) {
if kubeletConfig == nil {
return map[string]string{}, fmt.Errorf("nil KubeletConfiguration")
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/util/kubelet/config/kubeletconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import (

"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/resource"
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
"k8s.io/kubernetes/pkg/features"

"github.com/kubewharf/katalyst-api/pkg/consts"
"github.com/kubewharf/katalyst-core/pkg/util/native"
)

func TestCheckFeatureGateEnable(t *testing.T) {
t.Parallel()

tests := []struct {
name string
conf *kubeletconfigv1beta1.KubeletConfiguration
conf *native.KubeletConfiguration
features []string
enabled bool
err error
Expand All @@ -44,7 +44,7 @@ func TestCheckFeatureGateEnable(t *testing.T) {
},
{
name: "partial enabled",
conf: &kubeletconfigv1beta1.KubeletConfiguration{
conf: &native.KubeletConfiguration{
FeatureGates: map[string]bool{
"a": true,
},
Expand All @@ -55,7 +55,7 @@ func TestCheckFeatureGateEnable(t *testing.T) {
},
{
name: "total enabled",
conf: &kubeletconfigv1beta1.KubeletConfiguration{
conf: &native.KubeletConfiguration{
FeatureGates: map[string]bool{
"a": true,
"b": true,
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestGetReservedQuantity(t *testing.T) {

tests := []struct {
name string
conf *kubeletconfigv1beta1.KubeletConfiguration
conf *native.KubeletConfiguration
resourceName string
resourceQuantity resource.Quantity
valid bool
Expand All @@ -100,7 +100,7 @@ func TestGetReservedQuantity(t *testing.T) {
},
{
name: "resource both exists",
conf: &kubeletconfigv1beta1.KubeletConfiguration{
conf: &native.KubeletConfiguration{
KubeReserved: map[string]string{
"cpu": "1024m",
},
Expand All @@ -115,7 +115,7 @@ func TestGetReservedQuantity(t *testing.T) {
},
{
name: "resource only-one exists",
conf: &kubeletconfigv1beta1.KubeletConfiguration{
conf: &native.KubeletConfiguration{
KubeReserved: map[string]string{
"cpu": "1024m",
},
Expand All @@ -127,7 +127,7 @@ func TestGetReservedQuantity(t *testing.T) {
},
{
name: "resource not exists",
conf: &kubeletconfigv1beta1.KubeletConfiguration{
conf: &native.KubeletConfiguration{
KubeReserved: map[string]string{
"cpu": "1024m",
},
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestGetInTreeProviderPolicies(t *testing.T) {

tests := []struct {
name string
conf *kubeletconfigv1beta1.KubeletConfiguration
conf *native.KubeletConfiguration
res map[string]string
err error
}{
Expand All @@ -172,7 +172,7 @@ func TestGetInTreeProviderPolicies(t *testing.T) {
},
{
name: "cpu only",
conf: &kubeletconfigv1beta1.KubeletConfiguration{
conf: &native.KubeletConfiguration{
FeatureGates: map[string]bool{
string(features.CPUManager): true,
},
Expand All @@ -186,7 +186,7 @@ func TestGetInTreeProviderPolicies(t *testing.T) {
},
{
name: "all policies",
conf: &kubeletconfigv1beta1.KubeletConfiguration{
conf: &native.KubeletConfiguration{
FeatureGates: map[string]bool{
string(features.CPUManager): true,
string(features.MemoryManager): true,
Expand Down
Loading

0 comments on commit 41dedc0

Please sign in to comment.