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

[PLT-1654] Fix AWS ClusterRole patch during cloud-provisioner upgrade #680

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.17.0-0.5.8 (upcoming)

* [PLT-1654] Fix AWS ClusterRole patch during cloud-provisioner upgrade
* [PLT-1656] Fix cluster-operator upgrade cloud-provisioner upgrade when using an OCI helm repository

## 0.17.0-0.5.7 (2024-12-09)
Expand Down
63 changes: 19 additions & 44 deletions scripts/upgrade-provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,52 +217,27 @@ def install_lb_controller(cluster_name, account_id, dry_run):
print("DRY-RUN")

def patch_clusterrole_aws_node(dry_run):
aws_node_clusterrole = """
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: aws-node
rules:
- apiGroups:
- crd.k8s.amazonaws.com
resources:
- eniconfigs
verbs: ["list", "watch", "get"]
- apiGroups: [""]
resources:
- namespaces
verbs: ["list", "watch", "get"]
- apiGroups: [""]
resources:
- pods
verbs: ["list", "watch", "get", "patch"]
- apiGroups: [""]
resources:
- nodes
verbs: ["list", "watch", "get"]
- apiGroups: ["", "events.k8s.io"]
resources:
- events
verbs: ["create", "patch", "list"]
- apiGroups: ["networking.k8s.aws"]
resources:
- policyendpoints
verbs: ["get", "list", "watch"]
- apiGroups: ["networking.k8s.aws"]
resources:
- policyendpoints/status
verbs: ["get"]
- apiGroups:
- vpcresources.k8s.aws
resources:
- cninodes
verbs: ["get", "list", "watch", "patch"]
"""
aws_node_clusterrole_name = "aws-node"
print("[INFO] Modifying aws-node ClusterRole:", end =" ", flush=True)
if not dry_run:
command = "cat <<EOF | " + kubectl + " apply -f -" + aws_node_clusterrole + "EOF"
execute_command(command, False)
get_clusterrole_command = kubectl + " get clusterrole -o json " + aws_node_clusterrole_name + " | jq -r '.rules'"
cluster_role_rule = json.loads(execute_command(get_clusterrole_command, False))
rule_pods_index = next((i for i, rule in enumerate(cluster_role_rule) if 'pods' in rule.get('resources', [])), None)
if rule_pods_index is not None:
verbs = cluster_role_rule[rule_pods_index].get('verbs', [])
if 'patch' not in verbs:
patch = [
{
"op": "add",
"path": f"/rules/{rule_pods_index}/verbs/-",
"value": "patch"
}
]
patch_clusterrole_command = kubectl + " patch clusterrole " + aws_node_clusterrole_name + " --type=json -p='" + json.dumps(patch) + "'"
execute_command(patch_clusterrole_command, False, False)
else:
print("[ERROR] Pods resource not found in the ClusterRole " + aws_node_clusterrole_name)
sys.exit(1)
else:
print("DRY-RUN")

Expand Down