@@ -35,14 +35,21 @@ import (
3535 "k8s.io/client-go/kubernetes"
3636
3737 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
38+ "github.com/arangodb/kube-arangodb/pkg/deployment/resources"
3839 "github.com/arangodb/kube-arangodb/pkg/util/arangod"
3940 "github.com/arangodb/kube-arangodb/pkg/util/constants"
4041 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
4142)
4243
43- const (
44- dockerPullableImageIDPrefix_ = "docker-pullable://"
45- )
44+ type ImageUpdatePod struct {
45+ spec api.DeploymentSpec
46+ image string
47+ }
48+
49+ type ArangoDImageUpdateContainer struct {
50+ spec api.DeploymentSpec
51+ image string
52+ }
4653
4754type imagesBuilder struct {
4855 APIObject k8sutil.APIObject
@@ -182,26 +189,130 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
182189 "--database.directory=" + k8sutil .ArangodVolumeMountDir ,
183190 "--log.output=+" ,
184191 }
185- terminationGracePeriod := time .Second * 30
186- tolerations := make ([]v1.Toleration , 0 , 2 )
187- shortDur := k8sutil.TolerationDuration {Forever : false , TimeSpan : time .Second * 5 }
188- tolerations = k8sutil .AddTolerationIfNotFound (tolerations , k8sutil .NewNoExecuteToleration (k8sutil .TolerationKeyNodeNotReady , shortDur ))
189- tolerations = k8sutil .AddTolerationIfNotFound (tolerations , k8sutil .NewNoExecuteToleration (k8sutil .TolerationKeyNodeUnreachable , shortDur ))
190- tolerations = k8sutil .AddTolerationIfNotFound (tolerations , k8sutil .NewNoExecuteToleration (k8sutil .TolerationKeyNodeAlphaUnreachable , shortDur ))
191- serviceAccountName := ""
192-
193- env := make (map [string ]k8sutil.EnvValue )
194- if ib .Spec .License .HasSecretName () {
195- env [constants .EnvArangoLicenseKey ] = k8sutil.EnvValue {
196- SecretName : ib .Spec .License .GetSecretName (),
197- SecretKey : constants .SecretKeyToken ,
198- }
192+
193+ imagePod := ImageUpdatePod {
194+ spec : ib .Spec ,
195+ image : image ,
199196 }
200- if err := k8sutil . CreateArangodPod ( ib . KubeCli , true , ib . APIObject , role , id , podName , "" , image , "" , "" , ib . Spec . GetImagePullPolicy (), ib . Spec . ImagePullSecrets , "" , false , terminationGracePeriod , args , env , nil , nil , nil ,
201- tolerations , serviceAccountName , "" , "" , "" , nil , "" , v1. ResourceRequirements {}, nil , nil , nil ); err != nil {
197+
198+ if err := resources . CreateArangoPod ( ib . KubeCli , ib . APIObject , role , id , podName , args , & imagePod ); err != nil {
202199 log .Debug ().Err (err ).Msg ("Failed to create image ID pod" )
203200 return true , maskAny (err )
204201 }
205202 // Come back soon to inspect the pod
206203 return true , nil
207204}
205+
206+ func (a * ArangoDImageUpdateContainer ) GetExecutor () string {
207+ return resources .ArangoDExecutor
208+ }
209+
210+ func (a * ArangoDImageUpdateContainer ) GetProbes () (* v1.Probe , * v1.Probe , error ) {
211+ return nil , nil , nil
212+ }
213+
214+ func (a * ArangoDImageUpdateContainer ) GetResourceRequirements () v1.ResourceRequirements {
215+ return v1.ResourceRequirements {
216+ Limits : make (v1.ResourceList ),
217+ Requests : make (v1.ResourceList ),
218+ }
219+ }
220+
221+ func (a * ArangoDImageUpdateContainer ) GetImage () string {
222+ return a .image
223+ }
224+
225+ func (a * ArangoDImageUpdateContainer ) GetEnvs () []v1.EnvVar {
226+ env := make ([]v1.EnvVar , 0 )
227+
228+ if a .spec .License .HasSecretName () {
229+ env = append (env , k8sutil .CreateEnvSecretKeySelector (constants .EnvArangoLicenseKey ,
230+ a .spec .License .GetSecretName (), constants .SecretKeyToken ))
231+ }
232+
233+ if len (env ) > 0 {
234+ return env
235+ }
236+
237+ return nil
238+ }
239+
240+ func (a * ArangoDImageUpdateContainer ) GetLifecycle () (* v1.Lifecycle , error ) {
241+ return nil , nil
242+ }
243+
244+ func (a * ArangoDImageUpdateContainer ) GetImagePullPolicy () v1.PullPolicy {
245+ return a .spec .GetImagePullPolicy ()
246+ }
247+
248+ func (i * ImageUpdatePod ) Init (pod * v1.Pod ) {
249+ terminationGracePeriodSeconds := int64 ((time .Second * 30 ).Seconds ())
250+ pod .Spec .TerminationGracePeriodSeconds = & terminationGracePeriodSeconds
251+ }
252+
253+ func (i * ImageUpdatePod ) GetImagePullSecrets () []string {
254+ return i .spec .ImagePullSecrets
255+ }
256+
257+ func (i * ImageUpdatePod ) GetContainerCreator () k8sutil.ContainerCreator {
258+ return & ArangoDImageUpdateContainer {
259+ spec : i .spec ,
260+ image : i .image ,
261+ }
262+ }
263+
264+ func (i * ImageUpdatePod ) GetAffinityRole () string {
265+ return ""
266+ }
267+
268+ func (i * ImageUpdatePod ) GetVolumes () ([]v1.Volume , []v1.VolumeMount ) {
269+ var volumes []v1.Volume
270+ var volumeMounts []v1.VolumeMount
271+
272+ volumes = append (volumes , k8sutil .CreateVolumeEmptyDir (k8sutil .ArangodVolumeName ))
273+ volumeMounts = append (volumeMounts , k8sutil .ArangodVolumeMount ())
274+
275+ return volumes , volumeMounts
276+ }
277+
278+ func (i * ImageUpdatePod ) GetSidecars (* v1.Pod ) {
279+ return
280+ }
281+
282+ func (i * ImageUpdatePod ) GetInitContainers () ([]v1.Container , error ) {
283+ return nil , nil
284+ }
285+
286+ func (i * ImageUpdatePod ) GetFinalizers () []string {
287+ return nil
288+ }
289+
290+ func (i * ImageUpdatePod ) GetTolerations () []v1.Toleration {
291+
292+ shortDur := k8sutil.TolerationDuration {
293+ Forever : false ,
294+ TimeSpan : time .Second * 5 ,
295+ }
296+
297+ tolerations := make ([]v1.Toleration , 0 , 2 )
298+ tolerations = k8sutil .AddTolerationIfNotFound (tolerations ,
299+ k8sutil .NewNoExecuteToleration (k8sutil .TolerationKeyNodeNotReady , shortDur ))
300+ tolerations = k8sutil .AddTolerationIfNotFound (tolerations ,
301+ k8sutil .NewNoExecuteToleration (k8sutil .TolerationKeyNodeUnreachable , shortDur ))
302+ tolerations = k8sutil .AddTolerationIfNotFound (tolerations ,
303+ k8sutil .NewNoExecuteToleration (k8sutil .TolerationKeyNodeAlphaUnreachable , shortDur ))
304+
305+ return tolerations
306+ }
307+
308+ func (i * ImageUpdatePod ) IsDeploymentMode () bool {
309+ return true
310+ }
311+
312+ func (i * ImageUpdatePod ) GetNodeSelector () map [string ]string {
313+ return nil
314+ }
315+
316+ func (i * ImageUpdatePod ) GetServiceAccountName () string {
317+ return ""
318+ }
0 commit comments