Repository: Azure/azure-cli-extensions

Issue:
AKS Private-Cluster fails with Nonetype stackTrace via Jumpbox
### Extension name (the extension in question)

* `aks-preview`


### Description of issue (in as much detail as possible)

_Before I detail_: This is placeholder issue for transparency, plus to log and correctly identify the `aks private-cluster` behavior to rectify the code. If this is Network \ Storage issue then its worth to identify that as well and involve right folks to identify correct fix for it.

**Steps to Reproduce**:

* Create az-aks Private cluster: https://docs.microsoft.com/en-us/azure/aks/private-clusters
	* Obviously from the local dev box the `privatelink` will not be visible so pursue the `jumpbox` vm approach. i.e. create vm in same subnet as aks private cluster.
* After creating jumpbox vm > install and run `az cli` and add > `aks=preview` extension.
* Run `AKS Kollect` command for the private cluster from the jumpbox, the [`aks_kollect` call ](https://github.com/Azure/azure-cli-extensions/blob/master/src/aks-preview/azext_aks_preview/custom.py#L1321) **fails to get any result for line** `1332` -- `client.get` call in `custom.py`  gives empty result for the `private cluster` hence the error like below where it tries toaccess `fqdn` (fullyqualified domain name) but it is `None` or refer to screenshot. This might very well be connected to a portal issue where for the `private ak cluster` the **Properties** tab shows empty API Server address.

* This issue needs deeper investigation and then right solution needs to be implemented. If you know much about how `Private-Cluster` behave please feel free to reachout.
    * Further: if its the case where >> `kollect` command do not support `private-cluster` we should update docs to represent that.

Please feel free to assign back to me, but this is added for mere transparency and to get right folks eyes for comments.

Just as fyi: @Jen7714 and @yunjchoi 


```
  File "/root/.azure/cliextensions/aks-preview/azext_aks_preview/custom.py", line 1485, in aks_kollect
    normalized_fqdn = mc.fqdn.replace('.', '-')
AttributeError: 'NoneType' object has no attribute 'replace'
```

![image](https://user-images.githubusercontent.com/6233295/81518926-a66f2980-9393-11ea-8223-5070acc0ee39.png)


Sample command: 

```
az aks kollect 
-g MyResourceGroup
-n **Private_ManagedCluster**
--storage-account MyStorageAccount
--sas-token "MySasToken"
```


Discussion:
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Azure/aks-pm.
AKS 
routing to appropriate team
@yunjchoi looks like you might be aware of this, but could your team take a look?
Filed PR https://github.com/Azure/azure-cli-extensions/pull/1685.

Resolving patch:
diff --git a/src/aks-preview/azext_aks_preview/_consts.py b/src/aks-preview/azext_aks_preview/_consts.py
--- a/src/aks-preview/azext_aks_preview/_consts.py
+++ b/src/aks-preview/azext_aks_preview/_consts.py
@@ -23,3 +23,7 @@
 
 CONST_NODEPOOL_MODE_SYSTEM = "System"
 CONST_NODEPOOL_MODE_USER = "User"
+
+# refer https://docs.microsoft.com/en-us/rest/api/storageservices/
+# naming-and-referencing-containers--blobs--and-metadata#container-names
+CONST_CONTAINER_NAME_MAX_LENGTH = 63
diff --git a/src/aks-preview/azext_aks_preview/_helpers.py b/src/aks-preview/azext_aks_preview/_helpers.py
--- a/src/aks-preview/azext_aks_preview/_helpers.py
+++ b/src/aks-preview/azext_aks_preview/_helpers.py
@@ -9,6 +9,7 @@
 
 # pylint: disable=no-name-in-module,import-error
 from .vendored_sdks.azure_mgmt_preview_aks.v2020_03_01.models import ManagedClusterAPIServerAccessProfile
+from ._consts import CONST_CONTAINER_NAME_MAX_LENGTH
 from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING
 
 
@@ -88,4 +89,6 @@ def _trim_fqdn_name_containing_hcp(normalized_fqdn: str) -> str:
     attached
     """
     storage_name_without_hcp, _, _ = normalized_fqdn.partition('-hcp-')
+    if len(storage_name_without_hcp) > CONST_CONTAINER_NAME_MAX_LENGTH:
+        return storage_name_without_hcp[:CONST_CONTAINER_NAME_MAX_LENGTH]
     return storage_name_without_hcp
diff --git a/src/aks-preview/azext_aks_preview/custom.py b/src/aks-preview/azext_aks_preview/custom.py
--- a/src/aks-preview/azext_aks_preview/custom.py
+++ b/src/aks-preview/azext_aks_preview/custom.py
@@ -1472,7 +1472,8 @@ def aks_kollect(cmd,    # pylint: disable=too-many-statements,too-many-locals
         os.remove(temp_yaml_path)
 
     print()
-    normalized_fqdn = mc.fqdn.replace('.', '-')
+    fqdn = mc.fqdn if mc.fqdn is not None else mc.private_fqdn
+    normalized_fqdn = fqdn.replace('.', '-')
     token_in_storage_account_url = readonly_sas_token if readonly_sas_token is not None else sas_token
     log_storage_account_url = f"https://{storage_account_name}.blob.core.windows.net/" \
                               f"{_trim_fqdn_name_containing_hcp(normalized_fqdn)}?{token_in_storage_account_url}"


Test patch:
diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_helpers.py b/src/aks-preview/azext_aks_preview/tests/latest/test_helpers.py
--- a/src/aks-preview/azext_aks_preview/tests/latest/test_helpers.py
+++ b/src/aks-preview/azext_aks_preview/tests/latest/test_helpers.py
@@ -52,3 +52,9 @@ def test_trim_fqdn_name_containing_hcp(self):
         expected_container_name = 'abcdef-dns-ed55ba6d'
         trim_container_name = helpers._trim_fqdn_name_containing_hcp(container_name)
         self.assertEqual(expected_container_name, trim_container_name)
+
+    def test_trim_fqdn_name_not_containing_hcp(self):
+        container_name = 'abcdef-dns-ed55ba6d-e48fe2bd-b4bc-4aac-bc23-29bc44154fe1-privatelink-centralus-azmk8s-io'
+        expected_container_name = 'abcdef-dns-ed55ba6d-e48fe2bd-b4bc-4aac-bc23-29bc44154fe1-privat'
+        trim_container_name = helpers._trim_fqdn_name_containing_hcp(container_name)
+        self.assertEqual(expected_container_name, trim_container_name)