@@ -12,8 +12,6 @@ import (
12
12
13
13
"emperror.dev/errors"
14
14
"github.com/apex/log"
15
- "github.com/docker/docker/api/types/container"
16
- "github.com/docker/docker/client"
17
15
corev1 "k8s.io/api/core/v1"
18
16
v1 "k8s.io/api/core/v1"
19
17
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -48,7 +46,7 @@ func (e *Environment) isPodRunning(podName, namespace string) wait.ConditionFunc
48
46
return func () (bool , error ) {
49
47
// fmt.Printf(".") // progress bar!
50
48
51
- pod , err := e .client2 .CoreV1 ().Pods (config .Get ().System .Namespace ).Get (context .TODO (), podName , metav1.GetOptions {})
49
+ pod , err := e .client .CoreV1 ().Pods (config .Get ().System .Namespace ).Get (context .TODO (), podName , metav1.GetOptions {})
52
50
if err != nil {
53
51
return false , err
54
52
}
@@ -119,7 +117,7 @@ func (e *Environment) Attach(ctx context.Context) error {
119
117
}
120
118
}()
121
119
122
- reader := e .client2 .CoreV1 ().Pods (config .Get ().System .Namespace ).GetLogs (e .Id , & corev1.PodLogOptions {
120
+ reader := e .client .CoreV1 ().Pods (config .Get ().System .Namespace ).GetLogs (e .Id , & corev1.PodLogOptions {
123
121
Follow : true ,
124
122
})
125
123
podLogs , err := reader .Stream (context .TODO ())
@@ -145,32 +143,35 @@ func (e *Environment) Attach(ctx context.Context) error {
145
143
// limits without actually making any changes to the operational state of the
146
144
// container. This allows memory, cpu, and IO limitations to be adjusted on the
147
145
// fly for individual instances.
146
+
148
147
func (e * Environment ) InSituUpdate () error {
149
- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
150
- defer cancel ()
151
-
152
- if _ , err := e .ContainerInspect (ctx ); err != nil {
153
- // If the container doesn't exist for some reason there really isn't anything
154
- // we can do to fix that in this process (it doesn't make sense at least). In those
155
- // cases just return without doing anything since we still want to save the configuration
156
- // to the disk.
157
- //
158
- // We'll let a boot process make modifications to the container if needed at this point.
159
- if client .IsErrNotFound (err ) {
160
- return nil
161
- }
162
- return errors .Wrap (err , "environment/docker: could not inspect container" )
163
- }
148
+ // ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
149
+ // defer cancel()
150
+
151
+ // if _, err := e.ContainerInspect(ctx); err != nil {
152
+ // // If the container doesn't exist for some reason there really isn't anything
153
+ // // we can do to fix that in this process (it doesn't make sense at least). In those
154
+ // // cases just return without doing anything since we still want to save the configuration
155
+ // // to the disk.
156
+ // //
157
+ // // We'll let a boot process make modifications to the container if needed at this point.
158
+ // if client.IsErrNotFound(err) {
159
+ // return nil
160
+ // }
161
+ // return errors.Wrap(err, "environment/docker: could not inspect container")
162
+ // }
164
163
165
164
// CPU pinning cannot be removed once it is applied to a container. The same is true
166
165
// for removing memory limits, a container must be re-created.
167
166
//
168
167
// @see https://github.com/moby/moby/issues/41946
169
- if _ , err := e .client .ContainerUpdate (ctx , e .Id , container.UpdateConfig {
170
- Resources : e .Configuration .Limits ().AsContainerResources (),
171
- }); err != nil {
172
- return errors .Wrap (err , "environment/docker: could not update container" )
173
- }
168
+
169
+ // if _, err := e.client.ContainerUpdate(ctx, e.Id, container.UpdateConfig{
170
+ // Resources: e.Configuration.Limits().AsContainerResources(),
171
+ // }); err != nil {
172
+ //
173
+ // return errors.Wrap(err, "environment/docker: could not update container")
174
+ // }
174
175
return nil
175
176
}
176
177
@@ -183,7 +184,7 @@ func (e *Environment) Create() error {
183
184
// If the pod already exists don't hit the user with an error, just return
184
185
// the current information about it which is what we would do when creating the
185
186
// pod anyways.
186
- if _ , err := e .client2 .CoreV1 ().Pods (config .Get ().System .Namespace ).Get (ctx , e .Id , metav1.GetOptions {}); err == nil {
187
+ if _ , err := e .client .CoreV1 ().Pods (config .Get ().System .Namespace ).Get (ctx , e .Id , metav1.GetOptions {}); err == nil {
187
188
return nil
188
189
} else if ! apierrors .IsNotFound (err ) {
189
190
return errors .Wrap (err , "environment/kubernetes: failed to inspect pod" )
@@ -296,7 +297,7 @@ func (e *Environment) Create() error {
296
297
// conf.User = strconv.Itoa(cfg.System.User.Uid) + ":" + strconv.Itoa(cfg.System.User.Gid)
297
298
// }
298
299
299
- if _ , err := e .client2 .CoreV1 ().Pods (config .Get ().System .Namespace ).Create (ctx , pod , metav1.CreateOptions {}); err != nil {
300
+ if _ , err := e .client .CoreV1 ().Pods (config .Get ().System .Namespace ).Create (ctx , pod , metav1.CreateOptions {}); err != nil {
300
301
return errors .Wrap (err , "environment/kubernetes: failed to create pod" )
301
302
}
302
303
@@ -327,7 +328,7 @@ func (e *Environment) Create() error {
327
328
service .Spec .Ports = append (service .Spec .Ports , corev1.ServicePort {Name : b .Proto () + b .Port (), Protocol : corev1 .Protocol (protocol ), Port : int32 (port )})
328
329
}
329
330
330
- if _ , err := e .client2 .CoreV1 ().Services (config .Get ().System .Namespace ).Create (ctx , service , metav1.CreateOptions {}); err != nil {
331
+ if _ , err := e .client .CoreV1 ().Services (config .Get ().System .Namespace ).Create (ctx , service , metav1.CreateOptions {}); err != nil {
331
332
if ! apierrors .IsAlreadyExists (err ) {
332
333
return errors .Wrap (err , "environment/kubernetes: failed to create service" )
333
334
}
@@ -346,19 +347,19 @@ func (e *Environment) Destroy() error {
346
347
policy := metav1 .DeletePropagationForeground
347
348
348
349
// Delete Pod
349
- err := e .client2 .CoreV1 ().Pods (config .Get ().System .Namespace ).Delete (context .Background (), e .Id , metav1.DeleteOptions {GracePeriodSeconds : & zero , PropagationPolicy : & policy })
350
+ err := e .client .CoreV1 ().Pods (config .Get ().System .Namespace ).Delete (context .Background (), e .Id , metav1.DeleteOptions {GracePeriodSeconds : & zero , PropagationPolicy : & policy })
350
351
if err != nil && ! apierrors .IsNotFound (err ) {
351
352
return err
352
353
}
353
354
354
355
// Delete Service
355
- err = e .client2 .CoreV1 ().Services (config .Get ().System .Namespace ).Delete (context .Background (), "svc-" + e .Id , metav1.DeleteOptions {GracePeriodSeconds : & zero , PropagationPolicy : & policy })
356
+ err = e .client .CoreV1 ().Services (config .Get ().System .Namespace ).Delete (context .Background (), "svc-" + e .Id , metav1.DeleteOptions {GracePeriodSeconds : & zero , PropagationPolicy : & policy })
356
357
if err != nil && ! apierrors .IsNotFound (err ) {
357
358
return err
358
359
}
359
360
360
361
// Delete PVC
361
- err = e .client2 .CoreV1 ().PersistentVolumeClaims (config .Get ().System .Namespace ).Delete (context .Background (), e .Id + "-pvc" , metav1.DeleteOptions {GracePeriodSeconds : & zero , PropagationPolicy : & policy })
362
+ err = e .client .CoreV1 ().PersistentVolumeClaims (config .Get ().System .Namespace ).Delete (context .Background (), e .Id + "-pvc" , metav1.DeleteOptions {GracePeriodSeconds : & zero , PropagationPolicy : & policy })
362
363
if err != nil && ! apierrors .IsNotFound (err ) {
363
364
return err
364
365
}
@@ -386,7 +387,7 @@ func (e *Environment) SendCommand(c string) error {
386
387
e .SetState (environment .ProcessStoppingState )
387
388
}
388
389
389
- req := e .client2 .CoreV1 ().RESTClient ().
390
+ req := e .client .CoreV1 ().RESTClient ().
390
391
Post ().
391
392
Namespace (config .Get ().System .Namespace ).
392
393
Resource ("pods" ).
@@ -428,7 +429,7 @@ func (e *Environment) SendCommand(c string) error {
428
429
// is running or not, it will simply try to read the last X bytes of the file
429
430
// and return them.
430
431
func (e * Environment ) Readlog (lines int ) ([]string , error ) {
431
- r := e .client2 .CoreV1 ().Pods (config .Get ().System .Namespace ).GetLogs (e .Id , & corev1.PodLogOptions {
432
+ r := e .client .CoreV1 ().Pods (config .Get ().System .Namespace ).GetLogs (e .Id , & corev1.PodLogOptions {
432
433
TailLines : & []int64 {int64 (lines )}[0 ],
433
434
})
434
435
podLogs , err := r .Stream (context .Background ())
0 commit comments