-
Notifications
You must be signed in to change notification settings - Fork 241
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
Fixing script bug #3651
Fixing script bug #3651
Changes from 1 commit
9881911
dd4fa8b
4596d2a
6bf359c
8356392
e88f9e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1203,7 +1203,7 @@ def paasta_spark_run(args): | |
document = POD_TEMPLATE.format( | ||
spark_pod_label=limit_size_with_hash(f"exec-{app_base_name}"), | ||
) | ||
parsed_pod_template = yaml.load(document) | ||
parsed_pod_template = yaml.full_load(document) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should probably be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
with open(pod_template_path, "w") as f: | ||
yaml.dump(parsed_pod_template, f) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
from kubernetes.client import V1Affinity | ||
from kubernetes.client import V1AWSElasticBlockStoreVolumeSource | ||
from kubernetes.client import V1beta1CustomResourceDefinition | ||
from kubernetes.client import V1beta1CustomResourceDefinitionList | ||
from kubernetes.client import V1beta1PodDisruptionBudget | ||
from kubernetes.client import V1beta1PodDisruptionBudgetSpec | ||
from kubernetes.client import V1Capabilities | ||
|
@@ -3859,27 +3860,32 @@ def mode_to_int(mode: Optional[Union[str, int]]) -> Optional[int]: | |
|
||
|
||
def update_crds( | ||
apiextensions: Union[ | ||
kube_client.ApiextensionsV1Api, kube_client.ApiextensionsV1beta1Api | ||
], | ||
kube_client: KubeClient, | ||
desired_crds: Collection[ | ||
Union[V1CustomResourceDefinition, V1beta1CustomResourceDefinition] | ||
], | ||
existing_crds: V1CustomResourceDefinitionList, | ||
existing_crds: Union[ | ||
V1CustomResourceDefinitionList, V1beta1CustomResourceDefinitionList | ||
], | ||
) -> bool: | ||
success = True | ||
for desired_crd in desired_crds: | ||
existing_crd = None | ||
for crd in existing_crds.items: | ||
if crd.metadata.name == desired_crd.metadata["name"]: | ||
existing_crd = crd | ||
break | ||
|
||
try: | ||
|
||
if "beta" in desired_crd.api_version: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we check for equality rather than substring? e.g., if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is not the version, the version is a longer string if I'm not mistaken, that's why I left it like "in" instead of matching the whole thing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ack - my understanding is that this should be something like |
||
apiextensions = kube_client.apiextensions_v1_beta1 | ||
else: | ||
apiextensions = kube_client.apiextensions | ||
|
||
if existing_crd: | ||
desired_crd.metadata[ | ||
"resourceVersion" | ||
] = existing_crd.metadata.resource_version | ||
|
||
apiextensions.replace_custom_resource_definition( | ||
name=desired_crd.metadata["name"], body=desired_crd | ||
) | ||
|
@@ -3901,9 +3907,9 @@ def update_crds( | |
f"status: {exc.status}, reason: {exc.reason}" | ||
) | ||
log.debug(exc.body) | ||
success = False | ||
return False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a slight behavior change (previously, we'd attempt to apply all CRDs regardless of whether any of them failed) - do we potentially rely on the previous behavior anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right, the reason is: we need to succeed in ever CRD now, since now to the list of desired_crd we send all of those CRDs that need to be updated and not that "may get updated" since we know now which is the apiversion of each |
||
|
||
return success | ||
return True | ||
|
||
|
||
def sanitise_label_value(value: str) -> str: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import service_configuration_lib | ||
from kubernetes.client import V1beta1CustomResourceDefinition | ||
from kubernetes.client import V1CustomResourceDefinition | ||
from kubernetes.client.exceptions import ApiException | ||
|
||
from paasta_tools.kubernetes_tools import KubeClient | ||
from paasta_tools.kubernetes_tools import paasta_prefixed | ||
|
@@ -101,43 +102,64 @@ def setup_kube_crd( | |
services: Sequence[str], | ||
soa_dir: str = DEFAULT_SOA_DIR, | ||
) -> bool: | ||
for apiextension, crd_class in [ | ||
(kube_client.apiextensions, V1CustomResourceDefinition), | ||
(kube_client.apiextensions_v1_beta1, V1beta1CustomResourceDefinition), | ||
]: | ||
existing_crds = apiextension.list_custom_resource_definition( | ||
label_selector=paasta_prefixed("service") | ||
) | ||
existing_crds = kube_client.apiextensions.list_custom_resource_definition( | ||
label_selector=paasta_prefixed("service") | ||
) | ||
|
||
desired_crds = [] | ||
for service in services: | ||
crd_config = service_configuration_lib.read_extra_service_information( | ||
service, f"crd-{cluster}", soa_dir=soa_dir | ||
# This step can fail in k8s 1.22 since this version is not existing anymore | ||
# we need to support this for the transition | ||
try: | ||
existing_crds_v1_beta1 = ( | ||
nemacysts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kube_client.apiextensions_v1_beta1.list_custom_resource_definition( | ||
label_selector=paasta_prefixed("service") | ||
) | ||
) | ||
except ApiException as e: | ||
existing_crds_v1_beta1 = [] | ||
log.debug(e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this debug statment be deleted or do we want to reword this message to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that log message, will change it now |
||
|
||
desired_crds = [] | ||
desired_crds_v1_beta_1 = [] | ||
for service in services: | ||
crd_config = service_configuration_lib.read_extra_service_information( | ||
service, f"crd-{cluster}", soa_dir=soa_dir | ||
) | ||
if not crd_config: | ||
log.info("nothing to deploy") | ||
continue | ||
|
||
metadata = crd_config.get("metadata", {}) | ||
if "labels" not in metadata: | ||
metadata["labels"] = {} | ||
metadata["labels"]["yelp.com/paasta_service"] = service | ||
metadata["labels"][paasta_prefixed("service")] = service | ||
|
||
if "beta" in crd_config["apiVersion"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, should we maybe be checking for version equality? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added now |
||
desired_crd = V1beta1CustomResourceDefinition( | ||
api_version=crd_config.get("apiVersion"), | ||
kind=crd_config.get("kind"), | ||
metadata=metadata, | ||
spec=crd_config.get("spec"), | ||
) | ||
if not crd_config: | ||
log.info("nothing to deploy") | ||
continue | ||
|
||
metadata = crd_config.get("metadata", {}) | ||
if "labels" not in metadata: | ||
metadata["labels"] = {} | ||
metadata["labels"]["yelp.com/paasta_service"] = service | ||
metadata["labels"][paasta_prefixed("service")] = service | ||
desired_crd = crd_class( | ||
desired_crds_v1_beta_1.append(desired_crd) | ||
else: | ||
desired_crd = V1CustomResourceDefinition( | ||
api_version=crd_config.get("apiVersion"), | ||
kind=crd_config.get("kind"), | ||
metadata=metadata, | ||
spec=crd_config.get("spec"), | ||
) | ||
desired_crds.append(desired_crd) | ||
|
||
if update_crds( | ||
apiextensions=apiextension, | ||
desired_crds=desired_crds, | ||
existing_crds=existing_crds, | ||
): | ||
return True | ||
return False | ||
return update_crds( | ||
kube_client=kube_client, | ||
desired_crds=desired_crds, | ||
existing_crds=existing_crds, | ||
) and update_crds( | ||
kube_client=kube_client, | ||
desired_crds=desired_crds_v1_beta_1, | ||
existing_crds=existing_crds_v1_beta1, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,6 @@ basepython = python3.7 | |
whitelist_externals = bash | ||
deps = | ||
urllib3<2.0 | ||
docker-compose=={[tox]docker_compose_version} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'll need to figure out what to do internally as well: we'll need the docker-compose deb installed on jenkins + devboxes before we merge this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alternatively, we can continue using docker-compose internally since our internal setup is guaranteed to only hit our pypi + we have things setup internally to grab wheels ...or maybe do the potentially painful thing and start removing the usage of pip-custom-platform in this repo so that we hopefully grab the pypi.org wheels and skip these shenanigans? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how can I achieve the first option? I need to deploy these changes AFAP since is blocking me from upgrading to k8s 1.22 |
||
setenv = | ||
passenv = | ||
KIND_CLUSTER | ||
|
@@ -118,8 +117,6 @@ commands = | |
[testenv:example_cluster] | ||
changedir=example_cluster/ | ||
passenv = DOCKER_TLS_VERIFY DOCKER_HOST DOCKER_CERT_PATH | ||
deps = | ||
docker-compose=={[tox]docker_compose_version} | ||
commands = | ||
docker-compose down | ||
docker-compose --verbose build --build-arg DOCKER_REGISTRY={env:DOCKER_REGISTRY:docker-dev.yelpcorp.com/} --build-arg PIP_INDEX_URL={env:PIP_INDEX_URL:https://pypi.yelpcorp.com/simple} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed, thnx for the catch