MCPcopy Index your code
hub / github.com/devspace-sh/devspace / scaleUpTarget

Function scaleUpTarget

pkg/devspace/services/podreplace/revert.go:83–139  ·  view source on GitHub ↗
(ctx devspacecontext.Context, parent runtime.Object)

Source from the content-addressed store, hash-verified

81}
82
83func scaleUpTarget(ctx devspacecontext.Context, parent runtime.Object) error {
84 clonedParent := parent.DeepCopyObject()
85 metaParent, err := meta.Accessor(parent)
86 if err != nil {
87 return errors.Wrap(err, "parent accessor")
88 }
89
90 // check if required annotation is there
91 annotations := metaParent.GetAnnotations()
92 if annotations == nil || annotations[ReplicasAnnotation] == "" {
93 return nil
94 }
95
96 // scale up parent
97 oldReplica, err := strconv.Atoi(annotations[ReplicasAnnotation])
98 if err != nil {
99 return errors.Wrap(err, "parse old replicas")
100 } else if oldReplica == 0 {
101 return nil
102 }
103
104 oldReplica32 := int32(oldReplica)
105 switch t := parent.(type) {
106 case *appsv1.ReplicaSet:
107 t.Spec.Replicas = &oldReplica32
108 case *appsv1.Deployment:
109 t.Spec.Replicas = &oldReplica32
110 case *appsv1.StatefulSet:
111 t.Spec.Replicas = &oldReplica32
112 }
113
114 // delete replicas annotation
115 delete(annotations, ReplicasAnnotation)
116 metaParent.SetAnnotations(annotations)
117
118 // create patch
119 patch := patch2.MergeFrom(clonedParent)
120 bytes, err := patch.Data(parent)
121 if err != nil {
122 return errors.Wrap(err, "create parent patch")
123 }
124
125 // patch parent
126 switch t := parent.(type) {
127 case *appsv1.ReplicaSet:
128 _, err = ctx.KubeClient().KubeClient().AppsV1().ReplicaSets(t.Namespace).Patch(ctx.Context(), t.Name, patch.Type(), bytes, metav1.PatchOptions{})
129 case *appsv1.Deployment:
130 _, err = ctx.KubeClient().KubeClient().AppsV1().Deployments(t.Namespace).Patch(ctx.Context(), t.Name, patch.Type(), bytes, metav1.PatchOptions{})
131 case *appsv1.StatefulSet:
132 _, err = ctx.KubeClient().KubeClient().AppsV1().StatefulSets(t.Namespace).Patch(ctx.Context(), t.Name, patch.Type(), bytes, metav1.PatchOptions{})
133 }
134 if err != nil {
135 return errors.Wrap(err, "patch parent")
136 }
137
138 return nil
139}

Callers 1

RevertReplacePodMethod · 0.85

Calls 4

DataMethod · 0.65
KubeClientMethod · 0.65
ContextMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected