-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Unable to use create_namespaced_deployment_rollback in Kubernetes 1.16+ #1232
Comments
There is no deployment rollback endpoint in apps/v1 API: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#deployment-v1-apps. |
@roycaihw should we drop support for ExtensionsV1beta1Api and AppsV1beta1Api in 12.0 release? I'd like to contribute to this. |
@pigletfly 12.0 release corresponds to Kubernetes 1.16, which still has those API groups. |
Any update on this? Rollback is indeed an important feature. Release 12 is still in beta. These updates can be incorporated I believe |
An interim solution that may help others who stumble upon this issue: from kubernetes import client as k8s, config as k8s_config
k8s_config.load_kube_config()
def rollback_deployment(deployment: k8s.V1Deployment) -> None:
"""Rollback a deployment to its previous version.
:param deployment: A configured deployment object.
"""
name = deployment.metadata.name
namespace = deployment.metadata.namespace
associated_replica_sets = k8s.AppsV1Api().list_namespaced_replica_set(
namespace=namespace,
label_selector=f'app={deployment.spec.template.metadata.labels["app"]}'
)
revision_ordered_replica_sets = sorted(
associated_replica_sets.items,
key=lambda e: e.metadata.annotations['deployment.kubernetes.io/revision'],
reverse=True
)
rollback_replica_set = (
revision_ordered_replica_sets[0]
if len(revision_ordered_replica_sets) == 1
else revision_ordered_replica_sets[1]
)
rollback_revision_number = (
rollback_replica_set
.metadata
.annotations['deployment.kubernetes.io/revision']
)
patch = [
{
'op': 'replace',
'path': '/spec/template',
'value': rollback_replica_set.spec.template
},
{
'op': 'replace',
'path': '/metadata/annotations',
'value': {
'deployment.kubernetes.io/revision': rollback_revision_number,
**deployment.metadata.annotations
}
}
]
k8s.AppsV1Api().patch_namespaced_deployment(
body=patch,
name=name,
namespace=namespace
) Basically, I've reverse-engineered what |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Hello, I am currently running into this issue. Does anyone know if it was resolved, or will I be using the interim solution? |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
It is still an issue. |
/remove-lifecycle rotten |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
@AlexIoannides I would recommend casting the metadata.annotations['deployment.kubernetes.io/revision'] to integer in the sorted method, because as soon as you have more than 9 replicasets you will get an inaccurate results because you will be comparing string '10' vs '7' |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Any update on this Issue? |
What happened (please include outputs or screenshots):
Got a 404 error from the Kubernetes API due to the fact that both
ExtensionsV1beta1Api
andAppsV1beta1Api
are deprecated in Kubernetes 1.16The recently released 12.0.0a1 is supposed to have Kubernetes 1.16 support, but also doesn't have rollback with the proper API
AppsV1Api
https://github.com/kubernetes-client/python/blob/v12.0.0a1/kubernetes/README.md
What you expected to happen:
There should be a
create_namespaced_deployment_rollback
in theAppsV1Api
Class so that it uses the non-deprecated APIHow to reproduce it (as minimally and precisely as possible):
Attempt to rollback a deployment with either API against a cluster running 1.16:
OR
Environment:
kubectl version
): 1.16.11python --version
) 3.8.5pip list | grep kubernetes
) 12.0.0a1The text was updated successfully, but these errors were encountered: