Skip to content

Commit

Permalink
[Dapr] Disable applying CRDs during a downgrade (Azure#193)
Browse files Browse the repository at this point in the history
* Add logging

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

* Lint

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

* Update log

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

* Revert applyCrds when not downgrading

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

* Update logic for removing hooks.applyCrds

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

* Revert logic

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

* Handle explicit hooks configuration

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

* Update comment

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

* re-trigger pipeline

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>
  • Loading branch information
shubham1172 authored Nov 28, 2022
1 parent 464cca7 commit 0487616
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/k8s-extension/azext_k8s_extension/partner_extensions/Dapr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
from typing import Tuple

from azure.cli.core.azclierror import InvalidArgumentValueError
from copy import deepcopy
from knack.log import get_logger
from knack.prompting import prompt, prompt_y_n

from ..vendored_sdks.models import Extension, Scope, ScopeCluster
from ..vendored_sdks.models import Extension, PatchExtension, Scope, ScopeCluster
from .DefaultExtension import DefaultExtension

logger = get_logger(__name__)
Expand All @@ -31,6 +32,7 @@ def __init__(self):
# constants for configuration settings.
self.CLUSTER_TYPE_KEY = 'global.clusterType'
self.HA_KEY_ENABLED_KEY = 'global.ha.enabled'
self.APPLY_CRDS_HOOK_ENABLED_KEY = 'hooks.applyCrds'
self.SKIP_EXISTING_DAPR_CHECK_KEY = 'skipExistingDaprCheck'
self.EXISTING_DAPR_RELEASE_NAME_KEY = 'existingDaprReleaseName'
self.EXISTING_DAPR_RELEASE_NAMESPACE_KEY = 'existingDaprReleaseNamespace'
Expand Down Expand Up @@ -144,3 +146,43 @@ def Create(self, cmd, client, resource_group_name: str, cluster_name: str, name:
location=""
)
return extension_instance, release_name, create_identity

def Update(self, cmd, resource_group_name: str, cluster_name: str, auto_upgrade_minor_version: bool,
release_train: str, version: str, configuration_settings: dict,
configuration_protected_settings: dict, original_extension: Extension, yes: bool = False) \
-> PatchExtension:
"""ExtensionType 'Microsoft.Dapr' specific validations & defaults for Update.
Must create and return a valid 'PatchExtension' object.
"""
input_configuration_settings = deepcopy(configuration_settings)

# configuration_settings can be None, so we need to set it to an empty dict.
if configuration_settings is None:
configuration_settings = {}

# If we are downgrading the extension, then we need to disable the apply-CRDs hook.
# This is because CRD updates while downgrading can cause issues.
# As CRDs are additive, skipping their removal while downgrading is safe.
original_version = original_extension.version
if self.APPLY_CRDS_HOOK_ENABLED_KEY in configuration_settings:
logger.debug("'%s' is set to '%s' in --configuration-settings, not overriding it.",
self.APPLY_CRDS_HOOK_ENABLED_KEY, configuration_settings[self.APPLY_CRDS_HOOK_ENABLED_KEY])
elif original_version and version and version < original_version:
logger.debug("Downgrade detected from %s to %s. Setting %s to false.",
original_version, version, self.APPLY_CRDS_HOOK_ENABLED_KEY)
configuration_settings[self.APPLY_CRDS_HOOK_ENABLED_KEY] = 'false'
else:
# If we are not downgrading, enable the apply-CRDs hook explicitly.
# This is because the value may have been set to false during a previous downgrade.
logger.debug("No downgrade detected. Setting %s to true.", self.APPLY_CRDS_HOOK_ENABLED_KEY)
configuration_settings[self.APPLY_CRDS_HOOK_ENABLED_KEY] = 'true'

# If no changes were made, return the original dict (empty or None).
if len(configuration_settings) == 0:
configuration_settings = input_configuration_settings

return PatchExtension(auto_upgrade_minor_version=auto_upgrade_minor_version,
release_train=release_train,
version=version,
configuration_settings=configuration_settings,
configuration_protected_settings=configuration_protected_settings)

0 comments on commit 0487616

Please sign in to comment.