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

Add fixes for make-mi-fic.py consistency #4493

Merged
merged 1 commit into from
Dec 10, 2024
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
2 changes: 1 addition & 1 deletion scripts/v2/create-kind-wi-storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ cat <<EOF > "${DIR}/openid-configuration.json"
}
EOF

CREATION_TIME="$(date --utc +"%Y-%m-%dT%H:%M:%SZ")"
CREATION_TIME="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"

az group create -l westus -n "${RESOURCE_GROUP}" --tags "CreatedAt=${CREATION_TIME}"

Expand Down
32 changes: 17 additions & 15 deletions scripts/v2/make-mi-fic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import argparse
import time
import datetime
import ast


def create_role_assignment(subscription_id: str, object_id: str) -> str:
Expand Down Expand Up @@ -83,26 +84,27 @@ def main():
parser.print_help()
exit(1)

subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID")

# TODO: Might almost be easier to use the Azure SDK here...
identities = subprocess.check_output(
["az", "identity", "list", "--resource-group", resource_group, "--output", "table"])
identities = identities.rstrip()
if identities:
print("An identity already exists, not creating another one")
exit(0)
existing_identity = False

subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID")
identity_name = os.getenv("AZURE_IDENTITY_NAME")
existing_identity = False
if identity_name:
existing_identity = True
resource_group = os.getenv("AZURE_IDENTITY_RG")
else:
identity_name = f"mi{generate_random_string()}"
print(f"Generated new identity name: {identity_name}")
# TODO: Might almost be easier to use the Azure SDK here...
identities = subprocess.check_output(
["az", "identity", "list", "--resource-group", resource_group, "--query", "[].name"])
identities = identities.decode('utf-8')
identities = ast.literal_eval(identities)
if len(identities) > 0:
identity_name = identities[0]
print(f"An identity '{identity_name}' already exists, not creating another one")
existing_identity = True

if not existing_identity:
identity_name = f"mi{generate_random_string()}"
print(f"Generated new identity name: {identity_name}")
subprocess.run(
["az", "identity", "create", "--name", identity_name, "--resource-group", resource_group],
check=True)
Expand Down Expand Up @@ -147,13 +149,13 @@ def main():
role_assignment_id = retry_create_role_assignment(subscription_id, user_assigned_object_id)
with open(os.path.join(directory, "azure/roleassignmentid.txt"), "w") as f:
f.write(role_assignment_id)
else:
with open(os.path.join(directory, "azure/fic.txt"), "w") as f:
f.write("fic")

with open(os.path.join(directory, "azure/miclientid.txt"), "w") as f:
f.write(user_assigned_client_id)

if existing_identity:
with open(os.path.join(directory, "azure/fic.txt"), "w") as f:
f.write("fic")


if __name__ == "__main__":
Expand Down
Loading