Skip to content

Commit fdb0799

Browse files
committed
resolving merge conflic
2 parents 88a4fa4 + 01b330b commit fdb0799

8 files changed

+248
-157
lines changed

.go-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.21.12
1+
1.22.5

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
255255
ENVTEST ?= $(LOCALBIN)/setup-envtest
256256

257257
## Tool Versions
258-
KUSTOMIZE_VERSION ?= v3.8.7
259-
CONTROLLER_TOOLS_VERSION ?= v0.11.1
258+
KUSTOMIZE_VERSION ?= v5.4.3
259+
CONTROLLER_TOOLS_VERSION ?= v0.16.3
260260

261261
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
262262
.PHONY: kustomize

api/v1alpha1/zz_generated.deepcopy.go

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/policyendpoints_controller.go

+39-6
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,33 @@ func (r *PolicyEndpointsReconciler) cleanUpPolicyEndpoint(ctx context.Context, r
197197
return nil
198198
}
199199

200+
func (r *PolicyEndpointsReconciler) isProgFdShared(ctx context.Context, targetPodName string,
201+
targetPodNamespace string) bool {
202+
targetpodNamespacedName := utils.GetPodNamespacedName(targetPodName, targetPodNamespace)
203+
var foundSharedIngress bool
204+
var foundSharedEgress bool
205+
if targetProgFD, ok := r.ebpfClient.GetIngressPodToProgMap().Load(targetpodNamespacedName); ok {
206+
if currentList, ok := r.ebpfClient.GetIngressProgToPodsMap().Load(targetProgFD); ok {
207+
podsList, ok := currentList.(map[string]struct{})
208+
if ok && len(podsList) > 1 {
209+
foundSharedIngress = true
210+
r.log.Info("isProgFdShared", "Found shared ingress progFD for target: ", targetPodName, "progFD: ", targetProgFD)
211+
}
212+
}
213+
}
214+
215+
if targetProgFD, ok := r.ebpfClient.GetEgressPodToProgMap().Load(targetpodNamespacedName); ok {
216+
if currentList, ok := r.ebpfClient.GetEgressProgToPodsMap().Load(targetProgFD); ok {
217+
podsList, ok := currentList.(map[string]struct{})
218+
if ok && len(podsList) > 1 {
219+
foundSharedEgress = true
220+
r.log.Info("isProgFdShared", "Found shared egress progFD for target: ", targetPodName, "progFD: ", targetProgFD)
221+
}
222+
}
223+
}
224+
return foundSharedIngress || foundSharedEgress
225+
}
226+
200227
func (r *PolicyEndpointsReconciler) updatePolicyEnforcementStatusForPods(ctx context.Context, policyEndpointName string,
201228
targetPods []types.NamespacedName, podIdentifiers map[string]bool, isDeleteFlow bool) error {
202229
var err error
@@ -211,11 +238,10 @@ func (r *PolicyEndpointsReconciler) updatePolicyEnforcementStatusForPods(ctx con
211238
deletePinPath := true
212239
podIdentifier := utils.GetPodIdentifier(targetPod.Name, targetPod.Namespace, r.log)
213240
r.log.Info("Derived ", "Pod identifier to check if update is needed : ", podIdentifier)
214-
//Derive the podIdentifier and check if there is another pod in the same replicaset using the pinpath
215-
if found, ok := podIdentifiers[podIdentifier]; ok {
216-
//podIdentifiers will always have true in the value if found..
217-
r.log.Info("PodIdentifier pinpath ", "shared: ", found)
218-
deletePinPath = !found
241+
// check if ebpf progs are being shared by any other pods
242+
if progFdShared := r.isProgFdShared(ctx, targetPod.Name, targetPod.Namespace); progFdShared {
243+
r.log.Info("ProgFD pinpath ", "shared: ", progFdShared)
244+
deletePinPath = !progFdShared
219245
}
220246

221247
cleanupErr := r.cleanupeBPFProbes(ctx, targetPod, policyEndpointName, deletePinPath, isDeleteFlow)
@@ -584,9 +610,17 @@ func (r *PolicyEndpointsReconciler) getPodListToBeCleanedUp(oldPodSet []types.Na
584610
break
585611
}
586612
}
613+
// We want to clean up the pod and detach ebpf probes in two cases
614+
// 1. When pod is still running but pod is not an active pod against policy endpoint which implies policy endpoint is no longer applied to the podIdentifier
615+
// 2. When pod is deleted and is the last pod in the PodIdentifier
587616
if !activePod && !podIdentifiers[oldPodIdentifier] {
588617
r.log.Info("Pod to cleanup: ", "name: ", oldPod.Name, "namespace: ", oldPod.Namespace)
589618
podsToBeCleanedUp = append(podsToBeCleanedUp, oldPod)
619+
// When pod is deleted and this is not the last pod in podIdentifier, we are just updating the podName and progFD local caches
620+
} else if !activePod {
621+
r.log.Info("Pod not active. Deleting from progPod caches", "podName: ", oldPod.Name, "podNamespace: ", oldPod.Namespace)
622+
r.ebpfClient.DeletePodFromIngressProgPodCaches(oldPod.Name, oldPod.Namespace)
623+
r.ebpfClient.DeletePodFromEgressProgPodCaches(oldPod.Name, oldPod.Namespace)
590624
}
591625
}
592626

@@ -651,7 +685,6 @@ func (r *PolicyEndpointsReconciler) deletePolicyEndpointFromPodIdentifierMap(ctx
651685
policyEndpoint string) {
652686
r.podIdentifierToPolicyEndpointMapMutex.Lock()
653687
defer r.podIdentifierToPolicyEndpointMapMutex.Unlock()
654-
655688
var currentPEList []string
656689
if policyEndpointList, ok := r.podIdentifierToPolicyEndpointMap.Load(podIdentifier); ok {
657690
for _, policyEndpointName := range policyEndpointList.([]string) {

go.mod

+35-33
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
11
module github.com/aws/aws-network-policy-agent
22

3-
go 1.21.12
3+
go 1.22.3
4+
5+
toolchain go1.22.5
46

57
require (
6-
github.com/aws/amazon-vpc-cni-k8s v1.18.1
8+
github.com/aws/amazon-vpc-cni-k8s v1.18.3
79
github.com/aws/aws-ebpf-sdk-go v1.0.10
810
github.com/aws/aws-sdk-go v1.55.3
9-
github.com/go-logr/logr v1.4.1
11+
github.com/go-logr/logr v1.4.2
1012
github.com/go-logr/zapr v1.3.0
1113
github.com/golang/mock v1.6.0
1214
github.com/google/go-cmp v0.6.0
1315
github.com/google/uuid v1.6.0
1416
github.com/onsi/ginkgo/v2 v2.19.0
1517
github.com/onsi/gomega v1.33.1
1618
github.com/pkg/errors v0.9.1
17-
github.com/prometheus/client_golang v1.19.0
18-
github.com/spf13/cobra v1.8.0
19+
github.com/prometheus/client_golang v1.19.1
20+
github.com/spf13/cobra v1.8.1
1921
github.com/spf13/pflag v1.0.5
2022
github.com/stretchr/testify v1.9.0
2123
github.com/vishvananda/netlink v1.2.1-beta.2
2224
go.uber.org/zap v1.27.0
2325
golang.org/x/sys v0.24.0
24-
google.golang.org/grpc v1.63.2
26+
google.golang.org/grpc v1.65.0
2527
gopkg.in/natefinch/lumberjack.v2 v2.2.1
26-
k8s.io/api v0.29.1
27-
k8s.io/apimachinery v0.29.3
28-
k8s.io/client-go v0.29.1
29-
sigs.k8s.io/controller-runtime v0.17.2
28+
k8s.io/api v0.31.1
29+
k8s.io/apimachinery v0.31.1
30+
k8s.io/client-go v0.31.1
31+
sigs.k8s.io/controller-runtime v0.19.0
3032
)
3133

3234
require (
3335
github.com/beorn7/perks v1.0.1 // indirect
34-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
35-
github.com/davecgh/go-spew v1.1.1 // indirect
36+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
37+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3638
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
37-
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
39+
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
3840
github.com/fsnotify/fsnotify v1.7.0 // indirect
41+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
3942
github.com/go-openapi/jsonpointer v0.19.6 // indirect
4043
github.com/go-openapi/jsonreference v0.20.2 // indirect
41-
github.com/go-openapi/swag v0.22.3 // indirect
44+
github.com/go-openapi/swag v0.22.4 // indirect
4245
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
4346
github.com/gogo/protobuf v1.3.2 // indirect
4447
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4548
github.com/golang/protobuf v1.5.4 // indirect
4649
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
4750
github.com/google/gofuzz v1.2.0 // indirect
48-
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
51+
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af // indirect
4952
github.com/imdario/mergo v0.3.13 // indirect
5053
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5154
github.com/jmespath/go-jmespath v0.4.0 // indirect
@@ -55,31 +58,30 @@ require (
5558
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5659
github.com/modern-go/reflect2 v1.0.2 // indirect
5760
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
58-
github.com/pmezard/go-difflib v1.0.0 // indirect
59-
github.com/prometheus/client_model v0.6.0 // indirect
60-
github.com/prometheus/common v0.52.2 // indirect
61-
github.com/prometheus/procfs v0.12.0 // indirect
61+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
62+
github.com/prometheus/client_model v0.6.1 // indirect
63+
github.com/prometheus/common v0.55.0 // indirect
64+
github.com/prometheus/procfs v0.15.1 // indirect
6265
github.com/vishvananda/netns v0.0.4 // indirect
66+
github.com/x448/float16 v0.8.4 // indirect
6367
go.uber.org/multierr v1.11.0 // indirect
6468
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
65-
golang.org/x/net v0.25.0 // indirect
66-
golang.org/x/oauth2 v0.18.0 // indirect
67-
golang.org/x/term v0.18.0 // indirect
68-
golang.org/x/text v0.15.0 // indirect
69-
golang.org/x/time v0.3.0 // indirect
70-
golang.org/x/tools v0.21.0 // indirect
69+
golang.org/x/net v0.26.0 // indirect
70+
golang.org/x/oauth2 v0.21.0 // indirect
71+
golang.org/x/term v0.21.0 // indirect
72+
golang.org/x/text v0.16.0 // indirect
73+
golang.org/x/time v0.5.0 // indirect
74+
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
7175
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
72-
google.golang.org/appengine v1.6.8 // indirect
73-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
74-
google.golang.org/protobuf v1.33.0 // indirect
76+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
77+
google.golang.org/protobuf v1.34.2 // indirect
7578
gopkg.in/inf.v0 v0.9.1 // indirect
7679
gopkg.in/yaml.v2 v2.4.0 // indirect
7780
gopkg.in/yaml.v3 v3.0.1 // indirect
78-
k8s.io/apiextensions-apiserver v0.29.0 // indirect
79-
k8s.io/component-base v0.29.0 // indirect
80-
k8s.io/klog/v2 v2.110.1 // indirect
81-
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
82-
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
81+
k8s.io/apiextensions-apiserver v0.31.0 // indirect
82+
k8s.io/klog/v2 v2.130.1 // indirect
83+
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
84+
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
8385
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
8486
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
8587
sigs.k8s.io/yaml v1.4.0 // indirect

0 commit comments

Comments
 (0)