Skip to content

Commit 7ded84f

Browse files
committed
pod will requeue for reconcile if nodes are not managed and requested eni
1 parent 712887d commit 7ded84f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

controllers/core/pod_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/node"
2828
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/node/manager"
2929
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/resource"
30+
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/utils"
3031
"github.com/google/uuid"
3132

3233
"github.com/go-logr/logr"
@@ -112,6 +113,10 @@ func (r *PodReconciler) Reconcile(request custom.Request) (ctrl.Result, error) {
112113
logger.V(1).Info("pod's node is not yet initialized by the manager, will retry", "Requested", request.NamespacedName.String(), "Cached pod name", pod.ObjectMeta.Name, "Cached pod namespace", pod.ObjectMeta.Namespace)
113114
return PodRequeueRequest, nil
114115
} else if !node.IsManaged() {
116+
if utils.PodHasENIRequest(pod) {
117+
logger.V(1).Info("pod's node is not managed, but has eni request, will retry", "Requested", request.NamespacedName.String(), "Cached pod name", pod.ObjectMeta.Name, "Cached pod namespace", pod.ObjectMeta.Namespace)
118+
return PodRequeueRequest, nil
119+
}
115120
logger.V(1).Info("pod's node is not managed, skipping pod event", "Requested", request.NamespacedName.String(), "Cached pod name", pod.ObjectMeta.Name, "Cached pod namespace", pod.ObjectMeta.Namespace)
116121
return ctrl.Result{}, nil
117122
} else if !node.IsReady() {

controllers/core/pod_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package controllers
1616
import (
1717
"errors"
1818
"testing"
19+
"time"
1920

2021
"github.com/aws/amazon-vpc-resource-controller-k8s/controllers/custom"
2122
mock_condition "github.com/aws/amazon-vpc-resource-controller-k8s/mocks/amazon-vcp-resource-controller-k8s/pkg/condition"
@@ -188,7 +189,7 @@ func TestPodReconciler_Reconcile_NonManaged(t *testing.T) {
188189

189190
result, err := mock.PodReconciler.Reconcile(mockReq)
190191
assert.NoError(t, err)
191-
assert.Equal(t, result, controllerruntime.Result{})
192+
assert.Equal(t, controllerruntime.Result{Requeue: true, RequeueAfter: time.Second}, result)
192193
}
193194

194195
// TestPodReconciler_Reconcile_NoNodeAssigned tests that the request for a Pod with no Node assigned

pkg/utils/helper.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import (
2121

2222
vpcresourcesv1beta1 "github.com/aws/amazon-vpc-resource-controller-k8s/apis/vpcresources/v1beta1"
2323
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/aws/vpc"
24+
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/config"
2425

2526
"github.com/aws/aws-sdk-go/aws/arn"
2627

2728
"github.com/go-logr/logr"
2829
corev1 "k8s.io/api/core/v1"
30+
v1 "k8s.io/api/core/v1"
2931
"k8s.io/apimachinery/pkg/api/meta"
3032
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3133
"k8s.io/apimachinery/pkg/labels"
@@ -232,3 +234,13 @@ func GetSourceAcctAndArn(roleARN, region, clusterName string) (string, string, e
232234
sourceArn := fmt.Sprintf("arn:%s:eks:%s:%s:cluster/%s", parsedArn.Partition, region, parsedArn.AccountID, clusterName)
233235
return parsedArn.AccountID, sourceArn, nil
234236
}
237+
238+
// PodHasENIRequest will return true if first container of pod spec has request for eni indicating
239+
// it needs trunk interface from vpc-rc
240+
func PodHasENIRequest(pod *v1.Pod) bool {
241+
if len(pod.Spec.Containers) > 0 {
242+
_, hasEniRequest := pod.Spec.Containers[0].Resources.Requests[config.ResourceNamePodENI]
243+
return hasEniRequest
244+
}
245+
return false
246+
}

0 commit comments

Comments
 (0)