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

Release train #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
56 changes: 46 additions & 10 deletions src/connectedk8s/azext_connectedk8s/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import uuid
import datetime
import time
import requests
from azure.cli.core._profile import Profile


logger = get_logger(__name__)
Expand All @@ -43,6 +45,9 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name,
# Setting subscription id
subscription_id = get_subscription_id(cmd.cli_ctx)

# Setting user profile
profile = Profile(cli_ctx=cmd.cli_ctx)

resourceClient = _resource_client_factory(cmd.cli_ctx, subscription_id=subscription_id)

# Resource group Creation
Expand Down Expand Up @@ -251,21 +256,52 @@ def create_connectedk8s(cmd, client, resource_group_name, cluster_name,
if config_present is False:
raise CLIError("Helm release named 'azure-arc' is already present but the azure-arc agent pods are either missing or deployed unsuccessfully.")

# Adding helm repo
if kube_context is None:
cmd1 = ["helm", "repo", "add", "azurearcfork8s", "https://azurearcfork8s.azurecr.io/helm/v1/repo", "--kubeconfig", kube_config]
# Retrieving Helm chart OCI Artifact location
repository_path = None
cred, _, _ = profile.get_login_credentials(
resource='https://management.core.windows.net/')
token = cred._token_retriever()[2].get('accessToken')

get_chart_location_url = "https://{}.dp.kubernetesconfiguration.azure.com/{}/GetLatestHelmPackagePath?api-version=2019-11-01-preview".format(location, 'azure-arc-k8sagents')
query_parameters = {}
query_parameters['releaseTrain'] = 'stable'
header_parameters = {}
header_parameters['Authorization'] = "Bearer {}".format(str(token))
try:
response = requests.post(get_chart_location_url, params=query_parameters, headers=header_parameters)
except Exception as e:
raise CLIError("Error while fetching helm chart repository path: " + str(e))
if response.status_code == 200:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Do you want to retry the config dp call in case of 429 (throttling scenario)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not expecting throttling for private preview. Hence will not add for this PR.

repository_path = response.json().get('repositoryPath')
else:
cmd1 = ["helm", "repo", "add", "azurearcfork8s", "https://azurearcfork8s.azurecr.io/helm/v1/repo", "--kubeconfig", kube_config, "--kube-context", kube_context]
response1 = subprocess.Popen(cmd1, stdout=PIPE, stderr=PIPE)
output1, error1 = response1.communicate()
if response1.returncode != 0:
raise CLIError("Helm unable to add repository: " + error1.decode("ascii"))
raise CLIError("Error while fetching helm chart repository path: {}".format(str(response.json())))

# Pulling helm chart from repository
os.environ['HELM_EXPERIMENTAL_OCI'] = '1'
cmd_helm_chart_pull = ["helm", "chart", "pull", repository_path, "--kubeconfig", kube_config]
if kube_context:
cmd_helm_chart_pull.extend(["--kube-context", kube_context])
response_helm_chart_pull = subprocess.Popen(cmd_helm_chart_pull, stdout=PIPE, stderr=PIPE)
_, error_helm_chart_pull = response_helm_chart_pull.communicate()
if response_helm_chart_pull.returncode != 0:
raise CLIError("Unable to pull helm chart from the repository '{}': ".format(repository_path) + error_helm_chart_pull.decode("ascii"))

# Exporting helm chart
chart_export_path = os.path.join(os.path.expanduser('~'), '.azure', 'AzureArcCharts')
cmd_helm_chart_export = ["helm", "chart", "export", repository_path, "--destination", chart_export_path, "--kubeconfig", kube_config]
if kube_context:
cmd_helm_chart_export.extend(["--kube-context", kube_context])
response_helm_chart_export = subprocess.Popen(cmd_helm_chart_export, stdout=PIPE, stderr=PIPE)
_, error_helm_chart_export= response_helm_chart_export.communicate()
if response_helm_chart_export.returncode != 0:
raise CLIError("Unable to export helm chart from the repository '{}': ".format(repository_path) + error_helm_chart_export.decode("ascii"))

# Install agents
helm_chart_path = os.path.join(chart_export_path, 'azure-arc-k8sagents')
if kube_context is None:
cmd4 = ["helm", "install", "azure-arc", "azurearcfork8s/azure-arc-k8sagents", "--set", "global.subscriptionId={}".format(subscription_id), "--set", "global.resourceGroupName={}".format(resource_group_name), "--set", "global.resourceName={}".format(cluster_name), "--set", "global.location={}".format(location), "--set", "global.tenantId={}".format(onboarding_tenant_id), "--set", "global.clientId={}".format(onboarding_spn_id), "--set", "global.clientSecret={}".format(onboarding_spn_secret), "--kubeconfig", kube_config, "--output", "json"]
cmd4 = ["helm", "install", "azure-arc", helm_chart_path, "--set", "global.subscriptionId={}".format(subscription_id), "--set", "global.resourceGroupName={}".format(resource_group_name), "--set", "global.resourceName={}".format(cluster_name), "--set", "global.location={}".format(location), "--set", "global.tenantId={}".format(onboarding_tenant_id), "--set", "global.clientId={}".format(onboarding_spn_id), "--set", "global.clientSecret={}".format(onboarding_spn_secret), "--kubeconfig", kube_config, "--output", "json"]
else:
cmd4 = ["helm", "install", "azure-arc", "azurearcfork8s/azure-arc-k8sagents", "--set", "global.subscriptionId={}".format(subscription_id), "--set", "global.resourceGroupName={}".format(resource_group_name), "--set", "global.resourceName={}".format(cluster_name), "--set", "global.location={}".format(location), "--set", "global.tenantId={}".format(onboarding_tenant_id), "--set", "global.clientId={}".format(onboarding_spn_id), "--set", "global.clientSecret={}".format(onboarding_spn_secret), "--kubeconfig", kube_config, "--kube-context", kube_context, "--output", "json"]
cmd4 = ["helm", "install", "azure-arc", helm_chart_path, "--set", "global.subscriptionId={}".format(subscription_id), "--set", "global.resourceGroupName={}".format(resource_group_name), "--set", "global.resourceName={}".format(cluster_name), "--set", "global.location={}".format(location), "--set", "global.tenantId={}".format(onboarding_tenant_id), "--set", "global.clientId={}".format(onboarding_spn_id), "--set", "global.clientSecret={}".format(onboarding_spn_secret), "--kubeconfig", kube_config, "--kube-context", kube_context, "--output", "json"]
response4 = subprocess.Popen(cmd4, stdout=PIPE, stderr=PIPE)
output4, error4 = response4.communicate()
if response4.returncode != 0:
Expand Down
2 changes: 1 addition & 1 deletion src/connectedk8s/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.
VERSION = '0.1.3'
VERSION = '0.1.4'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down