Skip to content

Commit ec8ed8e

Browse files
authored
Allow to set ImagePullSecrets in pods (#444)
1 parent 363e06c commit ec8ed8e

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.gobuild
44
bin
55
logs
6+
vendor/
7+
.idea/

docs/Manual/Deployment/Kubernetes/DeploymentResource.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ Possible values are:
9696
- `IfNotPresent` (default) to pull only when the image is not found on the node.
9797
- `Always` to always pull the image before using it.
9898

99+
### `spec.imagePullSecrets: []string`
100+
101+
This setting specifies the list of image pull secrets for the docker image to use for all ArangoDB servers.
102+
99103
### `spec.storageEngine: string`
100104

101105
This setting specifies the type of storage engine used for all servers

pkg/apis/deployment/v1alpha/deployment_spec.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ func validatePullPolicy(v v1.PullPolicy) error {
4747

4848
// DeploymentSpec contains the spec part of a ArangoDeployment resource.
4949
type DeploymentSpec struct {
50-
Mode *DeploymentMode `json:"mode,omitempty"`
51-
Environment *Environment `json:"environment,omitempty"`
52-
StorageEngine *StorageEngine `json:"storageEngine,omitempty"`
53-
Image *string `json:"image,omitempty"`
54-
ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"`
55-
DowntimeAllowed *bool `json:"downtimeAllowed,omitempty"`
56-
DisableIPv6 *bool `json:"disableIPv6,omitempty"`
50+
Mode *DeploymentMode `json:"mode,omitempty"`
51+
Environment *Environment `json:"environment,omitempty"`
52+
StorageEngine *StorageEngine `json:"storageEngine,omitempty"`
53+
Image *string `json:"image,omitempty"`
54+
ImagePullPolicy *v1.PullPolicy `json:"imagePullPolicy,omitempty"`
55+
ImagePullSecrets []string `json:"imagePullSecrets,omitempty"`
56+
DowntimeAllowed *bool `json:"downtimeAllowed,omitempty"`
57+
DisableIPv6 *bool `json:"disableIPv6,omitempty"`
58+
5759
LocallyAttachedVolumes *bool `json:"locallyAttachedVolumes,omitempty"`
5860

5961
ExternalAccess ExternalAccessSpec `json:"externalAccess"`

pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
197197
SecretKey: constants.SecretKeyToken,
198198
}
199199
}
200-
if err := k8sutil.CreateArangodPod(ib.KubeCli, true, ib.APIObject, role, id, podName, "", image, "", "", ib.Spec.GetImagePullPolicy(), "", false, terminationGracePeriod, args, env, nil, nil, nil,
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,
201201
tolerations, serviceAccountName, "", "", "", nil, "", v1.ResourceRequirements{}, nil, nil, nil); err != nil {
202202
log.Debug().Err(err).Msg("Failed to create image ID pod")
203203
return true, maskAny(err)

pkg/deployment/resources/pod_creator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
662662
engine := spec.GetStorageEngine().AsArangoArgument()
663663
requireUUID := group == api.ServerGroupDBServers && m.IsInitialized
664664
finalizers := r.createPodFinalizers(group)
665-
if err := k8sutil.CreateArangodPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, m.PersistentVolumeClaimName, imageInfo.ImageID, lifecycleImage, alpineImage, spec.GetImagePullPolicy(),
665+
if err := k8sutil.CreateArangodPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, m.PersistentVolumeClaimName, imageInfo.ImageID, lifecycleImage, alpineImage, spec.GetImagePullPolicy(), spec.ImagePullSecrets,
666666
engine, requireUUID, terminationGracePeriod, args, env, finalizers, livenessProbe, readinessProbe, tolerations, serviceAccountName, tlsKeyfileSecretName, rocksdbEncryptionSecretName,
667667
clusterJWTSecretName, groupSpec.GetNodeSelector(), groupSpec.PriorityClassName, groupSpec.Resources, exporter, groupSpec.GetSidecars(), groupSpec.VolumeClaimTemplate); err != nil {
668668
return maskAny(err)
@@ -755,7 +755,7 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
755755
if group == api.ServerGroupSyncWorkers {
756756
affinityWithRole = api.ServerGroupDBServers.AsRole()
757757
}
758-
if err := k8sutil.CreateArangoSyncPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, imageID, lifecycleImage, spec.GetImagePullPolicy(), terminationGracePeriod, args, env,
758+
if err := k8sutil.CreateArangoSyncPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, imageID, lifecycleImage, spec.GetImagePullPolicy(), spec.ImagePullSecrets, terminationGracePeriod, args, env,
759759
livenessProbe, tolerations, serviceAccountName, tlsKeyfileSecretName, clientAuthCASecretName, masterJWTSecretName, clusterJWTSecretName, affinityWithRole, groupSpec.GetNodeSelector(),
760760
groupSpec.PriorityClassName, groupSpec.Resources, groupSpec.GetSidecars()); err != nil {
761761
return maskAny(err)

pkg/util/k8sutil/pods.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func initLifecycleContainer(image string) (v1.Container, error) {
497497
}
498498

499499
// newPod creates a basic Pod for given settings.
500-
func newPod(deploymentName, ns, role, id, podName string, finalizers []string, tolerations []v1.Toleration, serviceAccountName string, nodeSelector map[string]string) v1.Pod {
500+
func newPod(deploymentName, ns, role, id, podName string, imagePullSecrets []string, finalizers []string, tolerations []v1.Toleration, serviceAccountName string, nodeSelector map[string]string) v1.Pod {
501501
hostname := CreatePodHostName(deploymentName, role, id)
502502
p := v1.Pod{
503503
ObjectMeta: metav1.ObjectMeta{
@@ -514,6 +514,18 @@ func newPod(deploymentName, ns, role, id, podName string, finalizers []string, t
514514
NodeSelector: nodeSelector,
515515
},
516516
}
517+
518+
// Add ImagePullSecrets
519+
if imagePullSecrets != nil {
520+
imagePullSecretsReference := make([]v1.LocalObjectReference, len(imagePullSecrets))
521+
for id := range imagePullSecrets {
522+
imagePullSecretsReference[id] = v1.LocalObjectReference{
523+
Name: imagePullSecrets[id],
524+
}
525+
}
526+
p.Spec.ImagePullSecrets = imagePullSecretsReference
527+
}
528+
517529
return p
518530
}
519531

@@ -530,15 +542,16 @@ type ArangodbExporterContainerConf struct {
530542
// If the pod already exists, nil is returned.
531543
// If another error occurs, that error is returned.
532544
func CreateArangodPod(kubecli kubernetes.Interface, developmentMode bool, deployment APIObject,
533-
role, id, podName, pvcName, image, lifecycleImage, alpineImage string, imagePullPolicy v1.PullPolicy,
545+
role, id, podName, pvcName, image, lifecycleImage, alpineImage string,
546+
imagePullPolicy v1.PullPolicy, imagePullSecrets []string,
534547
engine string, requireUUID bool, terminationGracePeriod time.Duration,
535548
args []string, env map[string]EnvValue, finalizers []string,
536549
livenessProbe *HTTPProbeConfig, readinessProbe *HTTPProbeConfig, tolerations []v1.Toleration, serviceAccountName string,
537550
tlsKeyfileSecretName, rocksdbEncryptionSecretName string, clusterJWTSecretName string, nodeSelector map[string]string,
538551
podPriorityClassName string, resources v1.ResourceRequirements, exporter *ArangodbExporterContainerConf, sidecars []v1.Container, vct *v1.PersistentVolumeClaim) error {
539552

540553
// Prepare basic pod
541-
p := newPod(deployment.GetName(), deployment.GetNamespace(), role, id, podName, finalizers, tolerations, serviceAccountName, nodeSelector)
554+
p := newPod(deployment.GetName(), deployment.GetNamespace(), role, id, podName, imagePullSecrets, finalizers, tolerations, serviceAccountName, nodeSelector)
542555
terminationGracePeriodSeconds := int64(math.Ceil(terminationGracePeriod.Seconds()))
543556
p.Spec.TerminationGracePeriodSeconds = &terminationGracePeriodSeconds
544557

@@ -688,12 +701,13 @@ func CreateArangodPod(kubecli kubernetes.Interface, developmentMode bool, deploy
688701
// CreateArangoSyncPod creates a Pod that runs `arangosync`.
689702
// If the pod already exists, nil is returned.
690703
// If another error occurs, that error is returned.
691-
func CreateArangoSyncPod(kubecli kubernetes.Interface, developmentMode bool, deployment APIObject, role, id, podName, image, lifecycleImage string, imagePullPolicy v1.PullPolicy,
704+
func CreateArangoSyncPod(kubecli kubernetes.Interface, developmentMode bool, deployment APIObject, role, id, podName, image, lifecycleImage string,
705+
imagePullPolicy v1.PullPolicy, imagePullSecrets []string,
692706
terminationGracePeriod time.Duration, args []string, env map[string]EnvValue, livenessProbe *HTTPProbeConfig, tolerations []v1.Toleration, serviceAccountName string,
693707
tlsKeyfileSecretName, clientAuthCASecretName, masterJWTSecretName, clusterJWTSecretName, affinityWithRole string, nodeSelector map[string]string,
694708
podPriorityClassName string, resources v1.ResourceRequirements, sidecars []v1.Container) error {
695709
// Prepare basic pod
696-
p := newPod(deployment.GetName(), deployment.GetNamespace(), role, id, podName, nil, tolerations, serviceAccountName, nodeSelector)
710+
p := newPod(deployment.GetName(), deployment.GetNamespace(), role, id, podName, imagePullSecrets, nil, tolerations, serviceAccountName, nodeSelector)
697711
terminationGracePeriodSeconds := int64(math.Ceil(terminationGracePeriod.Seconds()))
698712
p.Spec.TerminationGracePeriodSeconds = &terminationGracePeriodSeconds
699713

0 commit comments

Comments
 (0)