Skip to content

Commit

Permalink
Merge branch 'k8s-configuration' into joinnis/bucket-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Dec 2, 2021
2 parents 88e3567 + 235065f commit 7fc4e02
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 45 deletions.
48 changes: 24 additions & 24 deletions src/k8s-configuration/azext_k8s_configuration/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
"k8s-configuration flux create"
] = """
type: command
short-summary: Create a Kubernetes Flux v2 Configuration.
short-summary: Create a Flux v2 Kubernetes configuration.
examples:
- name: Create a Kubernetes v2 Flux Configuration
- name: Create a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux create --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters \\
Expand All @@ -100,9 +100,9 @@
"k8s-configuration flux update"
] = """
type: command
short-summary: Update a Kubernetes Flux v2 Configuration.
short-summary: Update a Flux v2 Kubernetes configuration.
examples:
- name: Update a Kubernetes v2 Flux Configuration
- name: Update a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux update --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
Expand All @@ -114,9 +114,9 @@
"k8s-configuration flux list"
] = """
type: command
short-summary: List Kubernetes Flux v2 Configurations.
short-summary: List all Flux v2 Kubernetes configurations.
examples:
- name: List all Kubernetes Flux v2 Configurations on a cluster
- name: List Flux v2 Kubernetes configurations on a cluster
text: |-
az k8s-configuration flux list --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters
Expand All @@ -126,9 +126,9 @@
"k8s-configuration flux show"
] = """
type: command
short-summary: Show a Kubernetes Flux v2 Configuration.
short-summary: Show a Flux v2 Kubernetes configuration.
examples:
- name: Show details of a Kubernetes Flux v2 Configuration
- name: Show details of a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux show --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig
Expand All @@ -138,9 +138,9 @@
"k8s-configuration flux delete"
] = """
type: command
short-summary: Delete a Kubernetes Flux v2 Configuration.
short-summary: Delete a Flux v2 Kubernetes configuration.
examples:
- name: Delete an existing Kubernetes Flux v2 Configuration
- name: Delete an existing Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux delete --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig
Expand All @@ -157,9 +157,9 @@
"k8s-configuration flux kustomization create"
] = """
type: command
short-summary: Create a Kustomization associated with a Kubernetes Flux v2 Configuration.
short-summary: Create a Kustomization associated with a Flux v2 Kubernetes configuration.
examples:
- name: Create a Kustomization associated with a Kubernetes v2 Flux Configuration
- name: Create a Kustomization associated with a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux kustomization create --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
Expand All @@ -170,9 +170,9 @@
"k8s-configuration flux kustomization update"
] = """
type: command
short-summary: Update a Kustomization associated with a Kubernetes Flux v2 Configuration.
short-summary: Update a Kustomization associated with a Flux v2 Kubernetes configuration.
examples:
- name: Update a Kustomization associated with a Kubernetes v2 Flux Configuration
- name: Update a Kustomization associated with a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux kustomization update --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
Expand All @@ -183,9 +183,9 @@
"k8s-configuration flux kustomization list"
] = """
type: command
short-summary: List Kustomizations associated with a Kubernetes Flux v2 Configuration.
short-summary: List Kustomizations associated with a Flux v2 Kubernetes configuration.
examples:
- name: List all Kustomizations associated with a Kubernetes Flux v2 Configuration on a cluster
- name: List all Kustomizations associated with a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux kustomization list --resource-group my-resource-group \\
--cluster-name mycluster --name myconfig --cluster-type connectedClusters
Expand All @@ -195,9 +195,9 @@
"k8s-configuration flux kustomization show"
] = """
type: command
short-summary: Show a Kustomization associated with a Flux v2 Configuration.
short-summary: Show a Kustomization associated with a Flux v2 Kubernetes configuration.
examples:
- name: Show details of a Kustomization associated with a Kubernetes Flux v2 Configuration
- name: Show details of a Kustomization associated with a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux kustomization show --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
Expand All @@ -208,9 +208,9 @@
"k8s-configuration flux kustomization delete"
] = """
type: command
short-summary: Delete a Kustomization associated with a Kubernetes Flux v2 Configuration.
short-summary: Delete a Kustomization associated with a Flux v2 Kubernetes configuration.
examples:
- name: Delete an existing Kustomization associated with a Kubernetes Flux v2 Configuration
- name: Delete an existing Kustomization associated with a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux kustomization delete --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
Expand All @@ -228,9 +228,9 @@
"k8s-configuration flux deployed-object list"
] = """
type: command
short-summary: List deployed objects associated with a Kubernetes Flux v2 Configuration.
short-summary: List deployed objects associated with a Flux v2 Kubernetes configuration.
examples:
- name: List all deployed objects associated with a Kubernetes Flux v2 Configuration on a cluster
- name: List all deployed objects associated with a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux deployed-object list --resource-group my-resource-group \\
--cluster-name mycluster --name myconfig --cluster-type connectedClusters
Expand All @@ -240,9 +240,9 @@
"k8s-configuration flux deployed-object show"
] = """
type: command
short-summary: Show a deployed object associated with a Flux v2 Configuration.
short-summary: Show a deployed object associated with a Flux v2 Kubernetes configuration.
examples:
- name: Show details of a deployed object associated with a Kubernetes Flux v2 Configuration
- name: Show details of a deployed object associated with a Flux v2 Kubernetes configuration
text: |-
az k8s-configuration flux deployed-object show --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
Expand Down
15 changes: 13 additions & 2 deletions src/k8s-configuration/azext_k8s_configuration/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# API VERSIONS -----------------------------------------

SOURCE_CONTROL_API_VERSION = "2021-03-01"
FLUXCONFIG_API_VERSION = "2021-11-01-preview"
FLUXCONFIG_API_VERSION = "2022-01-01-preview"
EXTENSION_API_VERSION = "2021-09-01"

# ERROR/HELP TEXT DEFINITIONS -----------------------------------------
Expand All @@ -35,6 +35,13 @@
)
REQUIRED_VALUES_MISSING_HELP = "Add the missing required properties and try again"

REQUIRED_BUCKET_VALUES_MISSING_ERROR = (
"Error! Auth properties must be specified for kind 'bucket'"
)
REQUIRED_BUCKET_VALUES_MISSING_HELP = (
"Provide either both of '--secret-key' and '--access-key' or '--local-auth-ref'"
)

EXTRA_VALUES_PROVIDED_ERROR = (
"Error! Invalid properties [{}] were specified for kind '{}'"
)
Expand Down Expand Up @@ -183,6 +190,8 @@
"tag",
"semver",
"commit",
"sync_interval",
"timeout",
"ssh_private_key",
"ssh_private_key_file",
"https_user",
Expand All @@ -194,10 +203,12 @@
"local_auth_ref",
}

BUCKET_REQUIRED_PARAMS = {"url", "bucket_name", "access_key", "secret_key"}
BUCKET_REQUIRED_PARAMS = {"url", "bucket_name"}
BUCKET_VALID_PARAMS = {
"url",
"bucket_name",
"sync_interval",
"timeout",
"access_key",
"secret_key",
"insecure",
Expand Down
2 changes: 1 addition & 1 deletion src/k8s-configuration/azext_k8s_configuration/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __get_fluxconfig_table_row(result):
("scope", result["scope"]),
("provisioningState", result["provisioningState"]),
("complianceState", result["complianceState"]),
("lastSourceSyncedAt", result["lastSourceSyncedAt"]),
("lastSourceUpdatedAt", result["lastSourceUpdatedAt"]),
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
KustomizationDefinition,
KustomizationPatchDefinition,
DependsOnDefinition,
SourceKindType,
)
from ..vendored_sdks.v2021_09_01.models import Extension, Identity

Expand Down Expand Up @@ -200,7 +201,6 @@ def create_config(
flux_configuration = FluxConfiguration(
scope=scope,
namespace=namespace,
source_kind=factory.get_rp_source_kind(),
suspend=suspend,
kustomizations=kustomization,
configuration_protected_settings=protected_settings,
Expand Down Expand Up @@ -311,8 +311,9 @@ def update_config(
user_confirmation_factory(
cmd,
yes,
f"You are choosing to migrate from source kind {convert_to_cli_source_kind(config.source_kind).lower()} "
+ f" to source kind {kind.lower()}. Are you sure you want to change kinds?",
f"You are choosing to migrate from source kind '{convert_to_cli_source_kind(config.source_kind).lower()}' "
+ f"to source kind '{kind.lower()}'. Changing your source repository may also require you to change your "
+ "kustomizations. Are you sure you want to change kinds?",
)

if kustomization:
Expand Down Expand Up @@ -815,11 +816,6 @@ def validate_params(self, **kwargs):
),
)

def get_rp_source_kind(self):
if self.kind == consts.GIT:
return consts.GIT_REPOSITORY
return consts.BUCKET


def pretty_parameter(parameter):
parameter = parameter.replace("_", "-")
Expand Down Expand Up @@ -881,11 +877,7 @@ def __init__(self, **kwargs):
commit=kwargs.get("commit"),
)

def generate_update_func(self):
"""
generate_update_func(self) generates a function to add a GitRepository
object to the flux configuration for the PUT case
"""
def validate(self):
super().validate_required_params(**self.kwargs)
validate_git_url(self.url)
validate_url_with_params(
Expand All @@ -899,6 +891,13 @@ def generate_update_func(self):
)
validate_repository_ref(self.repository_ref)

def generate_update_func(self):
"""
generate_update_func(self) generates a function to add a GitRepository
object to the flux configuration for the PUT case
"""
self.validate()

def updater(config):
config.git_repository = GitRepositoryDefinition(
url=self.url,
Expand All @@ -910,6 +909,7 @@ def updater(config):
local_auth_ref=self.local_auth_ref,
https_ca_file=self.https_ca_data,
)
config.source_kind = SourceKindType.GIT_REPOSITORY
return config

return updater
Expand All @@ -922,7 +922,7 @@ def generate_patch_update_func(self, swapped_kind):
"""

def git_repository_updater(config):
if any(self.kwargs.values()):
if any(kwarg is not None for kwarg in self.kwargs.values()):
config.git_repository = GitRepositoryPatchDefinition(
url=self.url,
timeout_in_seconds=parse_duration(self.timeout),
Expand All @@ -933,8 +933,17 @@ def git_repository_updater(config):
local_auth_ref=self.local_auth_ref,
https_ca_file=self.https_ca_data,
)
if swapped_kind:
config.bucket = BucketDefinition()
if swapped_kind:
self.validate()
config.source_kind = SourceKindType.GIT_REPOSITORY

# Have to set these things to none otherwise the patch will fail
# due to default values
config.bucket = BucketDefinition(
insecure=None,
timeout_in_seconds=None,
sync_interval_in_seconds=None,
)
return config

return git_repository_updater
Expand All @@ -958,15 +967,24 @@ def __init__(self, **kwargs):
self.timeout = kwargs.get("timeout")
self.sync_interval = kwargs.get("sync_interval")
self.access_key = kwargs.get("access_key")
self.secret_key = kwargs.get("secret_key")
self.local_auth_ref = kwargs.get("local_auth_ref")
self.insecure = kwargs.get("insecure")

def validate(self):
super().validate_required_params(**self.kwargs)
if not ((self.access_key and self.secret_key) or self.local_auth_ref):
raise RequiredArgumentMissingError(
consts.REQUIRED_BUCKET_VALUES_MISSING_ERROR,
consts.REQUIRED_BUCKET_VALUES_MISSING_HELP,
)

def generate_update_func(self):
"""
generate_update_func(self) generates a function to add a Bucket
object to the flux configuration for the PUT case
"""
super().validate_required_params(**self.kwargs)
self.validate()

def bucket_updater(config):
config.bucket = BucketDefinition(
Expand All @@ -978,6 +996,8 @@ def bucket_updater(config):
local_auth_ref=self.local_auth_ref,
insecure=self.insecure,
)
config.source_kind = SourceKindType.BUCKET
return config

return bucket_updater

Expand All @@ -989,7 +1009,7 @@ def generate_patch_update_func(self, swapped_kind):
"""

def bucket_patch_updater(config):
if any(self.kwargs.values()):
if any(kwarg is not None for kwarg in self.kwargs.values()):
config.bucket = BucketDefinition(
url=self.url,
bucket_name=self.bucket_name,
Expand All @@ -1000,6 +1020,8 @@ def bucket_patch_updater(config):
insecure=self.insecure,
)
if swapped_kind:
self.validate()
config.source_kind = SourceKindType.BUCKET
config.git_repository = GitRepositoryPatchDefinition()
return config

Expand Down

0 comments on commit 7fc4e02

Please sign in to comment.