-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow smooth upgrades to new kube-proxy with nft
The new eks-d version includes the new kube-proxy with support for iptables nft. The old kube-proxy always uses iptables legacy. During an upgrade, when the new machine for the new CP node is started, if the machine has iptables nft as the default, the kubelet will use it. Then, before capi updates the kube-proxy image version in the DS (this doesn't happen until the CP upgrade is finished), the old kube-proxy is scheduled in the node. This old kube-proxy doesn't support nft and always uses iptables legacy. When it starts, it adds legacy iptables rules. However, at this point the kubelet has already added iptables-nft rules. After the CP has been updated, capi updates the kube-proxy DS to the new version. This new version has the new wrapper, which detects the rules introduced by the kubelet, so it starts using nft. The hypothesis is that these leftover legacy rules break the k8s service IP "redirection". This allows a smooth transition by scheduling a DS with the old kube proxy only in the old nodes and schedule a DS with the new kube-proxy only in the new nodes.
- Loading branch information
Showing
27 changed files
with
1,584 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package resource | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-logr/logr" | ||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
||
"github.com/aws/eks-anywhere/internal/test/envtest" | ||
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1" | ||
"github.com/aws/eks-anywhere/pkg/clusterapi" | ||
"github.com/aws/eks-anywhere/pkg/constants" | ||
) | ||
|
||
func TestClusterReconcilerApplyTemplatesAnnotationsArePreserved(t *testing.T) { | ||
g := NewWithT(t) | ||
ctx := context.Background() | ||
|
||
cluster := &anywherev1.Cluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "my-cluster-test", | ||
}, | ||
} | ||
kcp := &controlplanev1.KubeadmControlPlane{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "KubeadmControlPlane", | ||
APIVersion: "controlplane.cluster.x-k8s.io/v1beta1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: clusterapi.KubeadmControlPlaneName(cluster), | ||
Namespace: constants.EksaSystemNamespace, | ||
Annotations: map[string]string{ | ||
"my-custom-annotation": "true", | ||
}, | ||
}, | ||
} | ||
newKCP := kcp.DeepCopy() | ||
newKCP.Annotations = map[string]string{ | ||
"eksa-annotation": "false", | ||
} | ||
newKCPUnstructured, err := runtime.DefaultUnstructuredConverter.ToUnstructured(newKCP) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
|
||
resources := []*unstructured.Unstructured{{Object: newKCPUnstructured}} | ||
|
||
client := fake.NewClientBuilder().WithObjects(cluster, kcp).Build() | ||
log := logr.Discard() | ||
|
||
r := NewClusterReconciler( | ||
NewCAPIResourceFetcher(client, log), | ||
NewCAPIResourceUpdater(client, log), | ||
time.Now, | ||
log, | ||
) | ||
|
||
g.Expect(r.applyTemplates(ctx, cluster, resources, false)).To(Succeed()) | ||
|
||
api := envtest.NewAPIExpecter(t, client) | ||
api.ShouldEventuallyMatch(ctx, kcp, func(g Gomega) { | ||
g.Expect(kcp.Annotations).To(HaveKeyWithValue("my-custom-annotation", "true")) | ||
g.Expect(kcp.Annotations).To(HaveKeyWithValue("eksa-annotation", "false")) | ||
}) | ||
} | ||
|
||
func TestClusterReconcilerApplyTemplatesNoExistingAnnotations(t *testing.T) { | ||
g := NewWithT(t) | ||
ctx := context.Background() | ||
|
||
cluster := &anywherev1.Cluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "my-cluster-test", | ||
}, | ||
} | ||
kcp := &controlplanev1.KubeadmControlPlane{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "KubeadmControlPlane", | ||
APIVersion: "controlplane.cluster.x-k8s.io/v1beta1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: clusterapi.KubeadmControlPlaneName(cluster), | ||
Namespace: constants.EksaSystemNamespace, | ||
}, | ||
} | ||
newKCP := kcp.DeepCopy() | ||
newKCP.Annotations = map[string]string{ | ||
"eksa-annotation": "false", | ||
} | ||
newKCPUnstructured, err := runtime.DefaultUnstructuredConverter.ToUnstructured(newKCP) | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
|
||
resources := []*unstructured.Unstructured{{Object: newKCPUnstructured}} | ||
|
||
client := fake.NewClientBuilder().WithObjects(cluster, kcp).Build() | ||
log := logr.Discard() | ||
|
||
r := NewClusterReconciler( | ||
NewCAPIResourceFetcher(client, log), | ||
NewCAPIResourceUpdater(client, log), | ||
time.Now, | ||
log, | ||
) | ||
|
||
g.Expect(r.applyTemplates(ctx, cluster, resources, false)).To(Succeed()) | ||
|
||
api := envtest.NewAPIExpecter(t, client) | ||
api.ShouldEventuallyMatch(ctx, kcp, func(g Gomega) { | ||
g.Expect(kcp.Annotations).To(HaveKeyWithValue("eksa-annotation", "false")) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.