Skip to content

Commit 849e5e0

Browse files
committed
1. support delete by rolearn or userarn
2. support update by rolearn or userarn (delete and then create instead of only create)
1 parent d47a1bc commit 849e5e0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

kubernetes/auth-operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
- --verbose
2626
- --liveness=http://0.0.0.0:8080/healthz
2727
- --standalone
28-
image: dcodetech/aws_auth_eks_crd:1.1.0
28+
image: dcodetech/aws_auth_eks_crd:1.1.8
2929
imagePullPolicy: IfNotPresent
3030
name: operator
3131
ports:

src/kubernetes_operator/iam_mapping.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@
3535
# in a IamIdentityMapping object.
3636
IGNORED_CM_IDENTITIES = [
3737
# EKS worker nodes
38-
"system:node:{{EC2PrivateDNSName}}",
38+
# "system:node:{{EC2PrivateDNSName}}",
3939
]
4040

4141

4242
@kopf.on.update(GROUP, VERSION, PLURAL)
43+
# async def update_mapping(spec: dict, diff: list, **_) -> None:
44+
async def update_mapping(old, new, diff, **_) -> None:
45+
# Do nothing when we have no diff
46+
if not diff:
47+
return
48+
49+
await delete_mapping(old["spec"])
50+
await create_mapping(new["spec"], diff)
51+
52+
# @kopf.on.update(GROUP, VERSION, PLURAL)
4353
@kopf.on.create(GROUP, VERSION, PLURAL)
4454
async def create_mapping(spec: dict, diff: list, **_) -> None:
4555
"""Create/update an identity mapping in the aws-auth configmap with the corresponding IamIdentityMapping.
@@ -235,7 +245,11 @@ def delete_identity(identity: dict, identity_list: list) -> list:
235245
"""
236246

237247
for i, existing_user in enumerate(identity_list):
238-
if existing_user["username"] == identity["username"]:
248+
if "rolearn" in existing_user and existing_user["rolearn"] == identity["rolearn"]:
249+
del identity_list[i]
250+
return identity_list
251+
252+
if "userarn" in existing_user and existing_user["userarn"] == identity["userarn"]:
239253
del identity_list[i]
240254
return identity_list
241255

0 commit comments

Comments
 (0)