mirror of https://github.com/k3s-io/k3s
Merge pull request #59970 from anubhakushwaha/Update_deployment_example
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Updated the "create-update-delete-deployment" example to use apps/v1 and removed rollback example **What this PR does / why we need it**: *Waiting for migration to apps/v1* > The current example at [create-update-delete-deployment/main.go](https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/examples/create-update-delete-deployment/main.go) was using `RollbackTo` of `v1beta1.DeploymentSpec` which is deprecated. The current implementation upgrades `create-update-delete-deployment` main.go to use **apps/v1** instead of **extensions/v1beta1** and removed rollback example for now. **Which issue(s) this PR fixes** Helps kubernetes/client-go#346 **Special notes for your reviewer**: Since it's my first PR dealing with codebase and not a typo fix :xD please let me know my mistakes. I would love to resolve them. @nikhita @sttts @jekohk Please review. The other PR #59663 got closed accidentally while changing branch.pull/8/head
commit
6dfcaabe84
|
@ -16,7 +16,7 @@ go_library(
|
|||
srcs = ["main.go"],
|
||||
importpath = "k8s.io/client-go/examples/create-update-delete-deployment",
|
||||
deps = [
|
||||
"//vendor/k8s.io/api/apps/v1beta1:go_default_library",
|
||||
"//vendor/k8s.io/api/apps/v1:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
|
||||
|
|
|
@ -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