1
- package docker
1
+ package kubernetes
2
2
3
3
import (
4
4
"bufio"
@@ -21,9 +21,9 @@ import (
21
21
"k8s.io/client-go/kubernetes/scheme"
22
22
"k8s.io/client-go/tools/remotecommand"
23
23
24
- "github.com/pterodactyl/wings /config"
25
- "github.com/pterodactyl/wings /environment"
26
- "github.com/pterodactyl/wings /system"
24
+ "github.com/kubectyl/kuber /config"
25
+ "github.com/kubectyl/kuber /environment"
26
+ "github.com/kubectyl/kuber /system"
27
27
)
28
28
29
29
var ErrNotAttached = errors .Sentinel ("not attached to instance" )
@@ -145,33 +145,48 @@ func (e *Environment) Attach(ctx context.Context) error {
145
145
// fly for individual instances.
146
146
147
147
func (e * Environment ) InSituUpdate () error {
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
- // }
148
+ ctx , cancel := context .WithTimeout (context .Background (), time .Second * 10 )
149
+ defer cancel ()
150
+
151
+ if _ , err := e .client .CoreV1 ().Pods (config .Get ().System .Namespace ).Get (ctx , e .Id , metav1.GetOptions {}); err != nil {
152
+ // If the pod 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 pod if needed at this point.
158
+ if apierrors .IsNotFound (err ) {
159
+ return nil
160
+ }
161
+ return errors .Wrap (err , "environment/docker: could not get pod" )
162
+ } else {
163
+ // resources := e.Configuration.Limits()
164
+ // Resources:
165
+ // corev1.ResourceRequirements{
166
+ // Limits: corev1.ResourceList{
167
+ // "cpu": *resource.NewQuantity(resources.CpuLimit/100, resource.DecimalSI),
168
+ // "memory": *resource.NewQuantity(resources.BoundedMemoryLimit(), resource.BinarySI),
169
+ // },
170
+ // Requests: corev1.ResourceList{
171
+ // "cpu": *resource.NewQuantity(resources.CpuLimit/100, resource.DecimalSI),
172
+ // "memory": *resource.NewQuantity(resources.BoundedMemoryLimit(), resource.BinarySI),
173
+ // },
174
+ // },
175
+ // pod.Spec.Containers[0].Resources.Limits.Cpu() = append()
176
+ // pod.Spec.Containers[0].Resources.Requests[v1.ResourceCPU] = *resource.NewQuantity(resources.CpuLimit*10, resource.DecimalSI)
177
+ }
163
178
164
179
// CPU pinning cannot be removed once it is applied to a container. The same is true
165
180
// for removing memory limits, a container must be re-created.
166
- //
181
+
167
182
// @see https://github.com/moby/moby/issues/41946
168
183
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
- // }
184
+ // if _, err := e.client.ContainerUpdate(ctx, e.Id, container.UpdateConfig{
185
+ // Resources: e.Configuration.Limits().AsContainerResources(),
186
+ // }); err != nil {
187
+ // return errors.Wrap(err, "environment/docker: could not update container")
188
+ // }
189
+
175
190
return nil
176
191
}
177
192
0 commit comments