Skip to content
63 changes: 44 additions & 19 deletions pkg/deployment/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ type ContainerIdentity struct {
// ArangoDIdentity helps to resolve the ArangoD identity, e.g.: image ID, version of the entrypoint.
type ArangoDIdentity struct {
interfaces.ContainerCreator
License api.LicenseSpec
License api.LicenseSpec
ipAddress string
}

// ArangoSyncIdentity helps to resolve the ArangoSync identity, e.g.: image ID, version of the entrypoint.
Expand Down Expand Up @@ -209,13 +210,6 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac
Msg("Found image ID and ArangoDB version")
return false, nil
}
// Pod cannot be fetched, ensure it is created
args := []string{
"--server.authentication=false",
fmt.Sprintf("--server.endpoint=tcp://%s:%d", ib.Spec.GetListenAddr(), k8sutil.ArangoPort),
"--database.directory=" + k8sutil.ArangodVolumeMountDir,
"--log.output=+",
}

imagePod := ImageUpdatePod{
spec: ib.Spec,
Expand All @@ -226,11 +220,12 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac
image: image,
imagePullPolicy: ib.Spec.GetImagePullPolicy(),
},
License: ib.Spec.License,
License: ib.Spec.License,
ipAddress: ib.Spec.GetListenAddr(),
},
}

pod, err = resources.RenderArangoPod(cachedStatus, ib.APIObject, role, id, podName, args, &imagePod)
pod, err = resources.RenderArangoPod(cachedStatus, ib.APIObject, role, id, podName, &imagePod)
if err != nil {
log.Debug().Err(err).Msg("Failed to render image ID pod")
return true, errors.WithStack(err)
Expand Down Expand Up @@ -282,14 +277,8 @@ func (i *ImageUpdatePod) GetAffinityRole() string {
return ""
}

func (i *ImageUpdatePod) GetVolumes() ([]core.Volume, []core.VolumeMount) {
var volumes []core.Volume
var volumeMounts []core.VolumeMount

volumes = append(volumes, k8sutil.CreateVolumeEmptyDir(k8sutil.ArangodVolumeName))
volumeMounts = append(volumeMounts, k8sutil.ArangodVolumeMount())

return volumes, volumeMounts
func (i *ImageUpdatePod) GetVolumes() []core.Volume {
return getVolumes().Volumes()
}

func (i *ImageUpdatePod) GetSidecars(*core.Pod) error {
Expand Down Expand Up @@ -376,6 +365,10 @@ func (i *ImageUpdatePod) ApplyPodSpec(_ *core.PodSpec) error {
return nil
}

func (a *ContainerIdentity) GetArgs() ([]string, error) {
return nil, nil
}

func (a *ContainerIdentity) GetEnvs() []core.EnvVar {
return nil
}
Expand All @@ -396,10 +389,14 @@ func (a *ContainerIdentity) GetLifecycle() (*core.Lifecycle, error) {
return nil, nil
}

func (a *ContainerIdentity) GetName() string {
return k8sutil.ServerContainerName
}

func (a *ContainerIdentity) GetPorts() []core.ContainerPort {
return []core.ContainerPort{
{
Name: "server",
Name: k8sutil.ServerContainerName,
ContainerPort: int32(k8sutil.ArangoPort),
Protocol: core.ProtocolTCP,
},
Expand All @@ -418,6 +415,21 @@ func (a *ContainerIdentity) GetSecurityContext() *core.SecurityContext {
return a.ID.Get().SecurityContext.NewSecurityContext()
}

// GetVolumeMounts returns nil for the basic container identity.
func (a *ContainerIdentity) GetVolumeMounts() []core.VolumeMount {
return nil
}

// GetArgs returns the list of arguments for the ArangoD container identification.
func (a *ArangoDIdentity) GetArgs() ([]string, error) {
return []string{
"--server.authentication=false",
fmt.Sprintf("--server.endpoint=tcp://%s:%d", a.ipAddress, k8sutil.ArangoPort),
"--database.directory=" + k8sutil.ArangodVolumeMountDir,
"--log.output=+",
}, nil
}

func (a *ArangoDIdentity) GetEnvs() []core.EnvVar {
env := make([]core.EnvVar, 0)

Expand All @@ -433,7 +445,20 @@ func (a *ArangoDIdentity) GetEnvs() []core.EnvVar {
return nil
}

// GetVolumeMounts returns volume mount for the ArangoD data.
func (a *ArangoDIdentity) GetVolumeMounts() []core.VolumeMount {
return getVolumes().VolumeMounts()
}

// GetExecutor returns the fixed path to the ArangoSync binary in the container.
func (a *ArangoSyncIdentity) GetExecutor() string {
return resources.ArangoSyncExecutor
}

func getVolumes() pod.Volumes {
volumes := pod.NewVolumes()
volumes.AddVolume(k8sutil.CreateVolumeEmptyDir(k8sutil.ArangodVolumeName))
volumes.AddVolumeMount(k8sutil.ArangodVolumeMount())

return volumes
}
17 changes: 2 additions & 15 deletions pkg/deployment/pod/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ func NewVolumes() Volumes {

type Volumes interface {
Append(b Builder, i Input)

AddVolume(volumes ...core.Volume)
AddVolumes(volumes []core.Volume)

AddVolumeMount(mounts ...core.VolumeMount)
AddVolumeMounts(mounts []core.VolumeMount)

Volumes() []core.Volume
VolumeMounts() []core.VolumeMount
}
Expand All @@ -52,15 +47,11 @@ type volumes struct {

func (v *volumes) Append(b Builder, i Input) {
vols, mounts := b.Volumes(i)
v.AddVolumes(vols)
v.AddVolumeMounts(mounts)
v.AddVolume(vols...)
v.AddVolumeMount(mounts...)
}

func (v *volumes) AddVolume(volumes ...core.Volume) {
v.AddVolumes(volumes)
}

func (v *volumes) AddVolumes(volumes []core.Volume) {
if len(volumes) == 0 {
return
}
Expand All @@ -69,10 +60,6 @@ func (v *volumes) AddVolumes(volumes []core.Volume) {
}

func (v *volumes) AddVolumeMount(mounts ...core.VolumeMount) {
v.AddVolumeMounts(mounts)
}

func (v *volumes) AddVolumeMounts(mounts []core.VolumeMount) {
if len(mounts) == 0 {
return
}
Expand Down
31 changes: 10 additions & 21 deletions pkg/deployment/resources/pod_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ func createArangodArgs(cachedStatus interfaces.Inspector, input pod.Input, addit
}

// createArangoSyncArgs creates command line arguments for an arangosync server in the given group.
func createArangoSyncArgs(apiObject meta.Object, spec api.DeploymentSpec, group api.ServerGroup, groupSpec api.ServerGroupSpec, member api.MemberStatus) []string {
func createArangoSyncArgs(apiObject meta.Object, spec api.DeploymentSpec, group api.ServerGroup,
groupSpec api.ServerGroupSpec, member api.MemberStatus) []string {
options := k8sutil.CreateOptionPairs(64)
var runCmd string
var port int
Expand Down Expand Up @@ -343,7 +344,6 @@ func (r *Resources) RenderPodForMember(ctx context.Context, cachedStatus inspect
newMember.PodName = k8sutil.CreatePodName(apiObject.GetName(), roleAbbr, newMember.ID, CreatePodSuffix(spec))

var podCreator interfaces.PodCreator
var args []string
if group.IsArangod() {
// Prepare arguments
autoUpgrade := newMember.Conditions.IsTrue(api.ConditionTypeAutoUpgrade) || spec.Upgrade.Get().AutoUpgrade
Expand All @@ -358,16 +358,8 @@ func (r *Resources) RenderPodForMember(ctx context.Context, cachedStatus inspect
context: r.context,
autoUpgrade: autoUpgrade,
deploymentStatus: status,
id: memberID,
arangoMember: *member,
}

input := memberPod.AsInput()

var err error
args, err = createArangodArgs(cachedStatus, input)
if err != nil {
return nil, errors.WithStack(err)
cachedStatus: cachedStatus,
}

if err := memberPod.Validate(cachedStatus); err != nil {
Expand Down Expand Up @@ -428,10 +420,7 @@ func (r *Resources) RenderPodForMember(ctx context.Context, cachedStatus inspect
}
}

// Prepare arguments
args = createArangoSyncArgs(apiObject, spec, group, groupSpec, *newMember)

memberSyncPod := MemberSyncPod{
podCreator = &MemberSyncPod{
tlsKeyfileSecretName: tlsKeyfileSecretName,
clientAuthCASecretName: clientAuthCASecretName,
masterJWTSecretName: masterJWTSecretName,
Expand All @@ -442,14 +431,14 @@ func (r *Resources) RenderPodForMember(ctx context.Context, cachedStatus inspect
resources: r,
imageInfo: imageInfo,
arangoMember: *member,
apiObject: apiObject,
memberStatus: *newMember,
}

podCreator = &memberSyncPod
} else {
return nil, errors.Newf("unable to render Pod")
}

pod, err := RenderArangoPod(cachedStatus, apiObject, role, newMember.ID, newMember.PodName, args, podCreator)
pod, err := RenderArangoPod(cachedStatus, apiObject, role, newMember.ID, newMember.PodName, podCreator)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -637,7 +626,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect

// RenderArangoPod renders new ArangoD Pod
func RenderArangoPod(cachedStatus inspectorInterface.Inspector, deployment k8sutil.APIObject, role, id, podName string,
args []string, podCreator interfaces.PodCreator) (*core.Pod, error) {
podCreator interfaces.PodCreator) (*core.Pod, error) {

// Prepare basic pod
p := k8sutil.NewPod(deployment.GetName(), role, id, podName, podCreator)
Expand Down Expand Up @@ -666,12 +655,12 @@ func RenderArangoPod(cachedStatus inspectorInterface.Inspector, deployment k8sut
p.Spec.InitContainers = append(p.Spec.InitContainers, initContainers...)
}

c, err := k8sutil.NewContainer(args, podCreator.GetContainerCreator())
p.Spec.Volumes = podCreator.GetVolumes()
c, err := k8sutil.NewContainer(podCreator.GetContainerCreator())
if err != nil {
return nil, errors.WithStack(err)
}

p.Spec.Volumes, c.VolumeMounts = podCreator.GetVolumes()
p.Spec.Containers = append(p.Spec.Containers, c)
if err := podCreator.GetSidecars(&p); err != nil {
return nil, err
Expand Down
Loading