mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-04 18:56:21 +00:00
Upgraded to apps/v1 and removed rollback example
Kubernetes-commit: 08c697283125dfa138746df4b286ce7574a9bed1
This commit is contained in:
parent
f2e4bfdd42
commit
c9a11b02aa
@ -24,7 +24,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
appsv1beta1 "k8s.io/api/apps/v1beta1"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@ -53,14 +53,19 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
deploymentsClient := clientset.AppsV1beta1().Deployments(apiv1.NamespaceDefault)
|
||||
deploymentsClient := clientset.AppsV1().Deployments(apiv1.NamespaceDefault)
|
||||
|
||||
deployment := &appsv1beta1.Deployment{
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "demo-deployment",
|
||||
},
|
||||
Spec: appsv1beta1.DeploymentSpec{
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Replicas: int32Ptr(2),
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"app": "demo",
|
||||
},
|
||||
},
|
||||
Template: apiv1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
@ -128,27 +133,6 @@ func main() {
|
||||
}
|
||||
fmt.Println("Updated deployment...")
|
||||
|
||||
// Rollback Deployment
|
||||
prompt()
|
||||
fmt.Println("Rolling back deployment...")
|
||||
// Once again use RetryOnConflict to avoid update conflicts
|
||||
retryErr = retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
||||
result, getErr := deploymentsClient.Get("demo-deployment", metav1.GetOptions{})
|
||||
if getErr != nil {
|
||||
panic(fmt.Errorf("Failed to get latest version of Deployment: %v", getErr))
|
||||
}
|
||||
|
||||
result.Spec.RollbackTo = &appsv1beta1.RollbackConfig{
|
||||
Revision: 0, // can be specific revision number, or 0 for last revision
|
||||
}
|
||||
_, updateErr := deploymentsClient.Update(result)
|
||||
return updateErr
|
||||
})
|
||||
if retryErr != nil {
|
||||
panic(fmt.Errorf("Rollback failed: %v", retryErr))
|
||||
}
|
||||
fmt.Println("Rolled back deployment...")
|
||||
|
||||
// List Deployments
|
||||
prompt()
|
||||
fmt.Printf("Listing deployments in namespace %q:\n", apiv1.NamespaceDefault)
|
||||
|
Loading…
Reference in New Issue
Block a user