Skip to content

Commit cc57baf

Browse files
authored
[Feature] Create container identity for arangosync-v2 (#827)
1 parent 071c837 commit cc57baf

File tree

1 file changed

+97
-77
lines changed

1 file changed

+97
-77
lines changed

pkg/deployment/images.go

Lines changed: 97 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
//
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
20-
// Author Ewout Prangsma
21-
// Author Tomasz Mielech
22-
//
2320

2421
package deployment
2522

@@ -30,45 +27,47 @@ import (
3027
"strings"
3128
"time"
3229

33-
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
34-
35-
"github.com/arangodb/kube-arangodb/pkg/util/errors"
36-
37-
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
38-
39-
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
40-
4130
"github.com/rs/zerolog"
4231
core "k8s.io/api/core/v1"
4332
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4433

4534
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
35+
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
4636
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
4737
"github.com/arangodb/kube-arangodb/pkg/util/arangod"
4838
"github.com/arangodb/kube-arangodb/pkg/util/constants"
39+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
4940
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
41+
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
42+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
5043
)
5144

5245
var _ interfaces.PodCreator = &ImageUpdatePod{}
53-
var _ interfaces.ContainerCreator = &ArangoDImageUpdateContainer{}
46+
var _ interfaces.ContainerCreator = &ContainerIdentity{}
5447

48+
// ImageUpdatePod describes how to launch the ID ArangoD POD.
5549
type ImageUpdatePod struct {
56-
spec api.DeploymentSpec
57-
apiObject k8sutil.APIObject
58-
image string
50+
spec api.DeploymentSpec
51+
apiObject k8sutil.APIObject
52+
containerCreator interfaces.ContainerCreator
5953
}
6054

61-
func (i *ImageUpdatePod) Annotations() map[string]string {
62-
return nil
55+
// ContainerIdentity helps to resolve the container identity, e.g.: image ID, version of the entrypoint.
56+
type ContainerIdentity struct {
57+
ID *api.ServerIDGroupSpec
58+
image string
59+
imagePullPolicy core.PullPolicy
6360
}
6461

65-
func (i *ImageUpdatePod) Labels() map[string]string {
66-
return nil
62+
// ArangoDIdentity helps to resolve the ArangoD identity, e.g.: image ID, version of the entrypoint.
63+
type ArangoDIdentity struct {
64+
interfaces.ContainerCreator
65+
License api.LicenseSpec
6766
}
6867

69-
type ArangoDImageUpdateContainer struct {
70-
spec api.DeploymentSpec
71-
image string
68+
// ArangoSyncIdentity helps to resolve the ArangoSync identity, e.g.: image ID, version of the entrypoint.
69+
type ArangoSyncIdentity struct {
70+
interfaces.ContainerCreator
7271
}
7372

7473
type imagesBuilder struct {
@@ -220,8 +219,15 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac
220219

221220
imagePod := ImageUpdatePod{
222221
spec: ib.Spec,
223-
image: image,
224222
apiObject: ib.APIObject,
223+
containerCreator: &ArangoDIdentity{
224+
ContainerCreator: &ContainerIdentity{
225+
ID: ib.Spec.ID,
226+
image: image,
227+
imagePullPolicy: ib.Spec.GetImagePullPolicy(),
228+
},
229+
License: ib.Spec.License,
230+
},
225231
}
226232

227233
pod, err = resources.RenderArangoPod(cachedStatus, ib.APIObject, role, id, podName, args, &imagePod)
@@ -242,43 +248,12 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac
242248
return true, nil
243249
}
244250

245-
func (a *ArangoDImageUpdateContainer) GetExecutor() string {
246-
return a.spec.ID.GetEntrypoint(resources.ArangoDExecutor)
247-
}
248-
249-
func (a *ArangoDImageUpdateContainer) GetProbes() (*core.Probe, *core.Probe, error) {
250-
return nil, nil, nil
251-
}
252-
253-
func (a *ArangoDImageUpdateContainer) GetResourceRequirements() core.ResourceRequirements {
254-
return a.spec.ID.GetResources()
255-
}
256-
257-
func (a *ArangoDImageUpdateContainer) GetImage() string {
258-
return a.image
259-
}
260-
261-
func (a *ArangoDImageUpdateContainer) GetEnvs() []core.EnvVar {
262-
env := make([]core.EnvVar, 0)
263-
264-
if a.spec.License.HasSecretName() {
265-
env = append(env, k8sutil.CreateEnvSecretKeySelector(constants.EnvArangoLicenseKey,
266-
a.spec.License.GetSecretName(), constants.SecretKeyToken))
267-
}
268-
269-
if len(env) > 0 {
270-
return env
271-
}
272-
251+
func (i *ImageUpdatePod) Annotations() map[string]string {
273252
return nil
274253
}
275254

276-
func (a *ArangoDImageUpdateContainer) GetLifecycle() (*core.Lifecycle, error) {
277-
return nil, nil
278-
}
279-
280-
func (a *ArangoDImageUpdateContainer) GetImagePullPolicy() core.PullPolicy {
281-
return a.spec.GetImagePullPolicy()
255+
func (i *ImageUpdatePod) Labels() map[string]string {
256+
return nil
282257
}
283258

284259
func (i *ImageUpdatePod) GetName() string {
@@ -300,10 +275,7 @@ func (i *ImageUpdatePod) GetImagePullSecrets() []string {
300275
}
301276

302277
func (i *ImageUpdatePod) GetContainerCreator() interfaces.ContainerCreator {
303-
return &ArangoDImageUpdateContainer{
304-
spec: i.spec,
305-
image: i.image,
306-
}
278+
return i.containerCreator
307279
}
308280

309281
func (i *ImageUpdatePod) GetAffinityRole() string {
@@ -368,20 +340,6 @@ func (i *ImageUpdatePod) GetServiceAccountName() string {
368340
return i.spec.ID.GetServiceAccountName()
369341
}
370342

371-
func (a *ArangoDImageUpdateContainer) GetPorts() []core.ContainerPort {
372-
return []core.ContainerPort{
373-
{
374-
Name: "server",
375-
ContainerPort: int32(k8sutil.ArangoPort),
376-
Protocol: core.ProtocolTCP,
377-
},
378-
}
379-
}
380-
381-
func (a *ArangoDImageUpdateContainer) GetSecurityContext() *core.SecurityContext {
382-
return a.spec.ID.Get().SecurityContext.NewSecurityContext()
383-
}
384-
385343
func (i *ImageUpdatePod) GetPodAntiAffinity() *core.PodAntiAffinity {
386344
a := core.PodAntiAffinity{}
387345

@@ -410,10 +368,72 @@ func (i *ImageUpdatePod) GetNodeAffinity() *core.NodeAffinity {
410368
return pod.ReturnNodeAffinityOrNil(a)
411369
}
412370

413-
func (i *ImageUpdatePod) Validate(cachedStatus interfaces.Inspector) error {
371+
func (i *ImageUpdatePod) Validate(_ interfaces.Inspector) error {
414372
return nil
415373
}
416374

417-
func (i *ImageUpdatePod) ApplyPodSpec(spec *core.PodSpec) error {
375+
func (i *ImageUpdatePod) ApplyPodSpec(_ *core.PodSpec) error {
418376
return nil
419377
}
378+
379+
func (a *ContainerIdentity) GetEnvs() []core.EnvVar {
380+
return nil
381+
}
382+
383+
func (a *ContainerIdentity) GetExecutor() string {
384+
return a.ID.GetEntrypoint(resources.ArangoDExecutor)
385+
}
386+
387+
func (a *ContainerIdentity) GetImage() string {
388+
return a.image
389+
}
390+
391+
func (a *ContainerIdentity) GetImagePullPolicy() core.PullPolicy {
392+
return a.imagePullPolicy
393+
}
394+
395+
func (a *ContainerIdentity) GetLifecycle() (*core.Lifecycle, error) {
396+
return nil, nil
397+
}
398+
399+
func (a *ContainerIdentity) GetPorts() []core.ContainerPort {
400+
return []core.ContainerPort{
401+
{
402+
Name: "server",
403+
ContainerPort: int32(k8sutil.ArangoPort),
404+
Protocol: core.ProtocolTCP,
405+
},
406+
}
407+
}
408+
409+
func (a *ContainerIdentity) GetProbes() (*core.Probe, *core.Probe, error) {
410+
return nil, nil, nil
411+
}
412+
413+
func (a *ContainerIdentity) GetResourceRequirements() core.ResourceRequirements {
414+
return a.ID.GetResources()
415+
}
416+
417+
func (a *ContainerIdentity) GetSecurityContext() *core.SecurityContext {
418+
return a.ID.Get().SecurityContext.NewSecurityContext()
419+
}
420+
421+
func (a *ArangoDIdentity) GetEnvs() []core.EnvVar {
422+
env := make([]core.EnvVar, 0)
423+
424+
if a.License.HasSecretName() {
425+
env = append(env, k8sutil.CreateEnvSecretKeySelector(constants.EnvArangoLicenseKey,
426+
a.License.GetSecretName(), constants.SecretKeyToken))
427+
}
428+
429+
if len(env) > 0 {
430+
return env
431+
}
432+
433+
return nil
434+
}
435+
436+
// GetExecutor returns the fixed path to the ArangoSync binary in the container.
437+
func (a *ArangoSyncIdentity) GetExecutor() string {
438+
return resources.ArangoSyncExecutor
439+
}

0 commit comments

Comments
 (0)