Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix: efs & elb upgrade e2e tests #5418

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions controllers/awscluster_controller.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ import (
"fmt"
"time"

"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
@@ -32,9 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

@@ -393,28 +390,6 @@ func (r *AWSClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
WithOptions(options).
For(&infrav1.AWSCluster{}).
WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), log.GetLogger(), r.WatchFilterValue)).
WithEventFilter(
predicate.Funcs{
// Avoid reconciling if the event triggering the reconciliation is related to incremental status updates
// for AWSCluster resources only
UpdateFunc: func(e event.UpdateEvent) bool {
if e.ObjectOld.GetObjectKind().GroupVersionKind().Kind != "AWSCluster" {
return true
}

oldCluster := e.ObjectOld.(*infrav1.AWSCluster).DeepCopy()
newCluster := e.ObjectNew.(*infrav1.AWSCluster).DeepCopy()

oldCluster.Status = infrav1.AWSClusterStatus{}
newCluster.Status = infrav1.AWSClusterStatus{}

oldCluster.ObjectMeta.ResourceVersion = ""
newCluster.ObjectMeta.ResourceVersion = ""

return !cmp.Equal(oldCluster, newCluster)
},
},
).
Comment on lines -396 to -417
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we reckon that removing this will have any unrelated side effects?
For example, downstream we do externally manage the AWSCluster, will this create many reconciliations for the CAPA infracluster controller then?

Copy link
Member Author

@richardcase richardcase Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there will be too may side affets. It will result in more Reconcile runs potentially, but:

  • Our original code is at odds with how other infrastructure providers work
  • Keeping this would cause issues with the Paused condition being added and would still cause that initial delay in reconciliation
  • If we kept this, our change for ELB wouldn't be called until there was a "Spec" change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, I think this is fine to remove for now.
If we notice any issues we can open a follow-up thread to discuss countermeasures.
Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could always create a custom predicate

WithEventFilter(predicates.ResourceIsNotExternallyManaged(mgr.GetScheme(), log.GetLogger())).
Build(r)
if err != nil {
97 changes: 2 additions & 95 deletions controllers/awscluster_controller_unit_test.go
Original file line number Diff line number Diff line change
@@ -28,19 +28,16 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/mock_services"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
)
@@ -60,7 +57,8 @@ func TestAWSClusterReconcilerReconcile(t *testing.T) {
Kind: "Cluster",
Name: "capi-fail-test",
UID: "1",
}}}},
},
}}},
expectError: true,
},
{
@@ -532,97 +530,6 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
})
}

func TestAWSClusterReconcilerRequeueAWSClusterForUnpausedCluster(t *testing.T) {
testCases := []struct {
name string
awsCluster *infrav1.AWSCluster
ownerCluster *clusterv1.Cluster
requeue bool
}{
{
name: "Should create reconcile request successfully",
awsCluster: &infrav1.AWSCluster{
ObjectMeta: metav1.ObjectMeta{GenerateName: "aws-test-"}, TypeMeta: metav1.TypeMeta{Kind: "AWSCluster", APIVersion: infrav1.GroupVersion.String()},
},
ownerCluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "capi-test"}},
requeue: true,
},
{
name: "Should not create reconcile request if AWSCluster is externally managed",
awsCluster: &infrav1.AWSCluster{
ObjectMeta: metav1.ObjectMeta{GenerateName: "aws-test-", Annotations: map[string]string{clusterv1.ManagedByAnnotation: "capi-test"}},
TypeMeta: metav1.TypeMeta{Kind: "AWSCluster", APIVersion: infrav1.GroupVersion.String()},
},
ownerCluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "capi-test"}},
requeue: false,
},
{
name: "Should not create reconcile request for deleted clusters",
ownerCluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "capi-test", DeletionTimestamp: &metav1.Time{Time: time.Now()}}},
requeue: false,
},
{
name: "Should not create reconcile request if infrastructure ref for AWSCluster on owner cluster is not set",
ownerCluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "capi-test"}},
requeue: false,
},
{
name: "Should not create reconcile request if infrastructure ref type on owner cluster is not AWSCluster",
ownerCluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "capi-test"}, Spec: clusterv1.ClusterSpec{InfrastructureRef: &corev1.ObjectReference{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Cluster",
Name: "aws-test"}}},
requeue: false,
},
{
name: "Should not create reconcile request if AWSCluster not found",
ownerCluster: &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: "capi-test"}, Spec: clusterv1.ClusterSpec{InfrastructureRef: &corev1.ObjectReference{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "AWSCluster",
Name: "aws-test"}}},
requeue: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
log := logger.FromContext(ctx)
reconciler := &AWSClusterReconciler{
Client: testEnv.Client,
}

ns, err := testEnv.CreateNamespace(ctx, fmt.Sprintf("namespace-%s", util.RandomString(5)))
g.Expect(err).To(BeNil())
createCluster(g, tc.awsCluster, ns.Name)
defer cleanupCluster(g, tc.awsCluster, ns)

if tc.ownerCluster != nil {
if tc.awsCluster != nil {
tc.ownerCluster.Spec = clusterv1.ClusterSpec{InfrastructureRef: &corev1.ObjectReference{
APIVersion: infrav1.GroupVersion.String(),
Kind: "AWSCluster",
Name: tc.awsCluster.Name,
Namespace: ns.Name,
}}
}
tc.ownerCluster.Namespace = ns.Name
}
handlerFunc := reconciler.requeueAWSClusterForUnpausedCluster(ctx, log)
result := handlerFunc(ctx, tc.ownerCluster)
if tc.requeue {
g.Expect(result).To(ContainElement(reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: ns.Name,
Name: tc.awsCluster.Name,
},
}))
} else {
g.Expect(result).To(BeNil())
}
})
}
}

func createCluster(g *WithT, awsCluster *infrav1.AWSCluster, namespace string) {
if awsCluster != nil {
awsCluster.Namespace = namespace
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -128,6 +128,7 @@ var (
// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create

func main() {
setupLog.Info("starting cluster-api-provider-aws", "version", version.Get().String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition, thanks!

initFlags(pflag.CommandLine)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
2 changes: 1 addition & 1 deletion test/e2e/data/e2e_conf.yaml
Original file line number Diff line number Diff line change
@@ -241,4 +241,4 @@ intervals:
default/wait-deployment-ready: ["5m", "10s"]
default/wait-loadbalancer-ready: ["5m", "30s"]
default/wait-classic-elb-health-check-short: ["1m", "10s"]
default/wait-classic-elb-health-check-long: ["10m", "10s"]
default/wait-classic-elb-health-check-long: ["15m", "30s"]
Original file line number Diff line number Diff line change
@@ -15,3 +15,13 @@ spec:
spec:
rootVolume:
size: 16
---
kind: AWSMachineTemplate
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
metadata:
name: "${CLUSTER_NAME}-control-plane"
spec:
template:
spec:
rootVolume:
size: 16
2 changes: 1 addition & 1 deletion test/e2e/shared/aws_helpers.go
Original file line number Diff line number Diff line change
@@ -196,7 +196,7 @@ func CheckClassicElbHealthCheck(input CheckClassicElbHealthCheckInput, intervals
}

if *lb.HealthCheck.Target != input.ExpectedTarget {
return fmt.Errorf("health check target does not match expected target")
return fmt.Errorf("health check target %q does not match expected target %q", *lb.HealthCheck.Target, input.ExpectedTarget)
}

return nil
2 changes: 1 addition & 1 deletion test/e2e/suites/unmanaged/helpers_test.go
Original file line number Diff line number Diff line change
@@ -539,7 +539,7 @@ func createPodWithEFSMount(clusterClient crclient.Client) {
Containers: []corev1.Container{
{
Name: "app",
Image: "centos",
Image: "ubuntu",
Command: []string{"/bin/sh"},
Args: []string{"-c", "while true; do echo $(date -u) >> /data/out; sleep 5; done"},
VolumeMounts: []corev1.VolumeMount{