mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
update kube-apiserver
This commit is contained in:
parent
bea17e1497
commit
33ba585534
@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
apiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
@ -182,6 +183,9 @@ func TestClusterServiceIPRange(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if !tc.ipAllocatorGate {
|
||||
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, utilfeature.DefaultFeatureGate, version.MustParse("1.32"))
|
||||
}
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.MultiCIDRServiceAllocator, tc.ipAllocatorGate)
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DisableAllocatorDualWrite, tc.disableDualWriteGate)
|
||||
|
||||
|
@ -23,19 +23,19 @@ import (
|
||||
"time"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
networkingapiv1beta1 "k8s.io/api/networking/v1beta1"
|
||||
networkingapiv1 "k8s.io/api/networking/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
metav1apply "k8s.io/client-go/applyconfigurations/meta/v1"
|
||||
networkingapiv1beta1apply "k8s.io/client-go/applyconfigurations/networking/v1beta1"
|
||||
networkingv1beta1informers "k8s.io/client-go/informers/networking/v1beta1"
|
||||
networkingapiv1apply "k8s.io/client-go/applyconfigurations/networking/v1"
|
||||
networkingv1informers "k8s.io/client-go/informers/networking/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
networkingv1beta1listers "k8s.io/client-go/listers/networking/v1beta1"
|
||||
networkingv1listers "k8s.io/client-go/listers/networking/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/klog/v2"
|
||||
@ -67,13 +67,13 @@ func NewController(
|
||||
}
|
||||
// instead of using the shared informers from the controlplane instance, we construct our own informer
|
||||
// because we need such a small subset of the information available, only the kubernetes.default ServiceCIDR
|
||||
c.serviceCIDRInformer = networkingv1beta1informers.NewFilteredServiceCIDRInformer(client, 12*time.Hour,
|
||||
c.serviceCIDRInformer = networkingv1informers.NewFilteredServiceCIDRInformer(client, 12*time.Hour,
|
||||
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
|
||||
func(options *metav1.ListOptions) {
|
||||
options.FieldSelector = fields.OneTermEqualSelector("metadata.name", DefaultServiceCIDRName).String()
|
||||
})
|
||||
|
||||
c.serviceCIDRLister = networkingv1beta1listers.NewServiceCIDRLister(c.serviceCIDRInformer.GetIndexer())
|
||||
c.serviceCIDRLister = networkingv1listers.NewServiceCIDRLister(c.serviceCIDRInformer.GetIndexer())
|
||||
c.serviceCIDRsSynced = c.serviceCIDRInformer.HasSynced
|
||||
|
||||
return c
|
||||
@ -88,7 +88,7 @@ type Controller struct {
|
||||
eventRecorder record.EventRecorder
|
||||
|
||||
serviceCIDRInformer cache.SharedIndexInformer
|
||||
serviceCIDRLister networkingv1beta1listers.ServiceCIDRLister
|
||||
serviceCIDRLister networkingv1listers.ServiceCIDRLister
|
||||
serviceCIDRsSynced cache.InformerSynced
|
||||
|
||||
interval time.Duration
|
||||
@ -149,15 +149,15 @@ func (c *Controller) sync() error {
|
||||
|
||||
// default ServiceCIDR does not exist
|
||||
klog.Infof("Creating default ServiceCIDR with CIDRs: %v", c.cidrs)
|
||||
serviceCIDR = &networkingapiv1beta1.ServiceCIDR{
|
||||
serviceCIDR = &networkingapiv1.ServiceCIDR{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: DefaultServiceCIDRName,
|
||||
},
|
||||
Spec: networkingapiv1beta1.ServiceCIDRSpec{
|
||||
Spec: networkingapiv1.ServiceCIDRSpec{
|
||||
CIDRs: c.cidrs,
|
||||
},
|
||||
}
|
||||
serviceCIDR, err = c.client.NetworkingV1beta1().ServiceCIDRs().Create(context.Background(), serviceCIDR, metav1.CreateOptions{})
|
||||
serviceCIDR, err = c.client.NetworkingV1().ServiceCIDRs().Create(context.Background(), serviceCIDR, metav1.CreateOptions{})
|
||||
if err != nil && !apierrors.IsAlreadyExists(err) {
|
||||
c.eventRecorder.Eventf(serviceCIDR, v1.EventTypeWarning, "KubernetesDefaultServiceCIDRError", "The default ServiceCIDR can not be created")
|
||||
return err
|
||||
@ -166,7 +166,7 @@ func (c *Controller) sync() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Controller) syncStatus(serviceCIDR *networkingapiv1beta1.ServiceCIDR) {
|
||||
func (c *Controller) syncStatus(serviceCIDR *networkingapiv1.ServiceCIDR) {
|
||||
// don't sync the status of the ServiceCIDR if is being deleted,
|
||||
// deletion must be handled by the controller-manager
|
||||
if !serviceCIDR.GetDeletionTimestamp().IsZero() {
|
||||
@ -176,7 +176,7 @@ func (c *Controller) syncStatus(serviceCIDR *networkingapiv1beta1.ServiceCIDR) {
|
||||
// This controller will set the Ready condition to true if the Ready condition
|
||||
// does not exist and the CIDR values match this controller CIDR values.
|
||||
for _, condition := range serviceCIDR.Status.Conditions {
|
||||
if condition.Type == networkingapiv1beta1.ServiceCIDRConditionReady {
|
||||
if condition.Type == networkingapiv1.ServiceCIDRConditionReady {
|
||||
if condition.Status == metav1.ConditionTrue {
|
||||
return
|
||||
}
|
||||
@ -188,14 +188,14 @@ func (c *Controller) syncStatus(serviceCIDR *networkingapiv1beta1.ServiceCIDR) {
|
||||
// set status to ready if the ServiceCIDR matches this configuration
|
||||
if reflect.DeepEqual(c.cidrs, serviceCIDR.Spec.CIDRs) {
|
||||
klog.Infof("Setting default ServiceCIDR condition Ready to True")
|
||||
svcApplyStatus := networkingapiv1beta1apply.ServiceCIDRStatus().WithConditions(
|
||||
svcApplyStatus := networkingapiv1apply.ServiceCIDRStatus().WithConditions(
|
||||
metav1apply.Condition().
|
||||
WithType(networkingapiv1beta1.ServiceCIDRConditionReady).
|
||||
WithType(networkingapiv1.ServiceCIDRConditionReady).
|
||||
WithStatus(metav1.ConditionTrue).
|
||||
WithMessage("Kubernetes default Service CIDR is ready").
|
||||
WithLastTransitionTime(metav1.Now()))
|
||||
svcApply := networkingapiv1beta1apply.ServiceCIDR(DefaultServiceCIDRName).WithStatus(svcApplyStatus)
|
||||
if _, errApply := c.client.NetworkingV1beta1().ServiceCIDRs().ApplyStatus(context.Background(), svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); errApply != nil {
|
||||
svcApply := networkingapiv1apply.ServiceCIDR(DefaultServiceCIDRName).WithStatus(svcApplyStatus)
|
||||
if _, errApply := c.client.NetworkingV1().ServiceCIDRs().ApplyStatus(context.Background(), svcApply, metav1.ApplyOptions{FieldManager: controllerName, Force: true}); errApply != nil {
|
||||
klog.Infof("error updating default ServiceCIDR status: %v", errApply)
|
||||
c.eventRecorder.Eventf(serviceCIDR, v1.EventTypeWarning, "KubernetesDefaultServiceCIDRError", "The default ServiceCIDR Status can not be set to Ready=True")
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
networkingapiv1beta1 "k8s.io/api/networking/v1beta1"
|
||||
networkingapiv1 "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
@ -35,11 +35,11 @@ const (
|
||||
defaultIPv6CIDR = "2001:db8::/64"
|
||||
)
|
||||
|
||||
func newController(t *testing.T, objects []*networkingapiv1beta1.ServiceCIDR) (*fake.Clientset, *Controller) {
|
||||
func newController(t *testing.T, objects []*networkingapiv1.ServiceCIDR) (*fake.Clientset, *Controller) {
|
||||
client := fake.NewSimpleClientset()
|
||||
|
||||
informerFactory := informers.NewSharedInformerFactory(client, 0)
|
||||
serviceCIDRInformer := informerFactory.Networking().V1beta1().ServiceCIDRs()
|
||||
serviceCIDRInformer := informerFactory.Networking().V1().ServiceCIDRs()
|
||||
|
||||
store := serviceCIDRInformer.Informer().GetStore()
|
||||
for _, obj := range objects {
|
||||
@ -64,7 +64,7 @@ func newController(t *testing.T, objects []*networkingapiv1beta1.ServiceCIDR) (*
|
||||
func TestControllerSync(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
cidrs []*networkingapiv1beta1.ServiceCIDR
|
||||
cidrs []*networkingapiv1.ServiceCIDR
|
||||
actions [][]string // verb and resource
|
||||
}{
|
||||
{
|
||||
@ -73,12 +73,12 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "existing default service CIDR update Ready condition",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: DefaultServiceCIDRName,
|
||||
},
|
||||
Spec: networkingapiv1beta1.ServiceCIDRSpec{
|
||||
Spec: networkingapiv1.ServiceCIDRSpec{
|
||||
CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR},
|
||||
},
|
||||
},
|
||||
@ -87,12 +87,12 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "existing default service CIDR not matching cidrs",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: DefaultServiceCIDRName,
|
||||
},
|
||||
Spec: networkingapiv1beta1.ServiceCIDRSpec{
|
||||
Spec: networkingapiv1.ServiceCIDRSpec{
|
||||
CIDRs: []string{"fd00::/112"},
|
||||
},
|
||||
},
|
||||
@ -100,18 +100,18 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "existing default service CIDR not ready",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: DefaultServiceCIDRName,
|
||||
},
|
||||
Spec: networkingapiv1beta1.ServiceCIDRSpec{
|
||||
Spec: networkingapiv1.ServiceCIDRSpec{
|
||||
CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR},
|
||||
},
|
||||
Status: networkingapiv1beta1.ServiceCIDRStatus{
|
||||
Status: networkingapiv1.ServiceCIDRStatus{
|
||||
Conditions: []metav1.Condition{
|
||||
{
|
||||
Type: string(networkingapiv1beta1.ServiceCIDRConditionReady),
|
||||
Type: string(networkingapiv1.ServiceCIDRConditionReady),
|
||||
Status: metav1.ConditionFalse,
|
||||
},
|
||||
},
|
||||
@ -121,13 +121,13 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "existing default service CIDR being deleted",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: DefaultServiceCIDRName,
|
||||
DeletionTimestamp: ptr.To(metav1.Now()),
|
||||
},
|
||||
Spec: networkingapiv1beta1.ServiceCIDRSpec{
|
||||
Spec: networkingapiv1.ServiceCIDRSpec{
|
||||
CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR},
|
||||
},
|
||||
},
|
||||
@ -135,12 +135,12 @@ func TestControllerSync(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "existing service CIDRs but not default",
|
||||
cidrs: []*networkingapiv1beta1.ServiceCIDR{
|
||||
cidrs: []*networkingapiv1.ServiceCIDR{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "non-default-cidr",
|
||||
},
|
||||
Spec: networkingapiv1beta1.ServiceCIDRSpec{
|
||||
Spec: networkingapiv1.ServiceCIDRSpec{
|
||||
CIDRs: []string{defaultIPv4CIDR, defaultIPv6CIDR},
|
||||
},
|
||||
},
|
||||
|
@ -62,6 +62,8 @@ var GVRToStorageVersionHash = map[string]string{
|
||||
"networking.k8s.io/v1/networkpolicies": "YpfwF18m1G8=",
|
||||
"networking.k8s.io/v1/ingresses": "39NQlfNR+bo=",
|
||||
"networking.k8s.io/v1/ingressclasses": "l/iqIbDgFyQ=",
|
||||
"networking.k8s.io/v1/ipaddresses": "O4H8VxQhW5Y=",
|
||||
"networking.k8s.io/v1/servicecidrs": "8ufAXOnr3Yg=",
|
||||
"node.k8s.io/v1/runtimeclasses": "WQTu1GL3T2Q=",
|
||||
"policy/v1/poddisruptionbudgets": "EVWiDmWqyJw=",
|
||||
"rbac.authorization.k8s.io/v1/clusterrolebindings": "48tpQ8gZHFc=",
|
||||
|
Loading…
Reference in New Issue
Block a user