Skip to content

Commit dea16fb

Browse files
committed
* Adds volumes and volumeMounts to argocd types * Adds volumes ans volumeMounts to appset deployment and pod * Updates generated files * Updates docs * Adds unit tests Signed-off-by: appiepollo14 <[email protected]>
1 parent 3334487 commit dea16fb

File tree

8 files changed

+3471
-34
lines changed

8 files changed

+3471
-34
lines changed

api/v1beta1/argocd_types.go

+6
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ type ArgoCDApplicationSet struct {
207207

208208
// Custom labels to pods deployed by the operator
209209
Labels map[string]string `json:"labels,omitempty"`
210+
211+
// Volumes adds volumes to the Argo CD ApplicationSet Controller container.
212+
Volumes []corev1.Volume `json:"volumes,omitempty"`
213+
214+
// VolumeMounts adds volumeMounts to the Argo CD ApplicationSet Controller container.
215+
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
210216
}
211217

212218
func (a *ArgoCDApplicationSet) IsEnabled() bool {

api/v1beta1/zz_generated.deepcopy.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/argocd-operator.clusterserviceversion.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ metadata:
247247
capabilities: Deep Insights
248248
categories: Integration & Delivery
249249
certified: "false"
250-
createdAt: "2024-09-16T21:29:22Z"
250+
createdAt: "2024-10-13T21:19:01Z"
251251
description: Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.
252252
operators.operatorframework.io/builder: operator-sdk-v1.35.0
253253
operators.operatorframework.io/project_layout: go.kubebuilder.io/v4

bundle/manifests/argoproj.io_argocds.yaml

+1,655
Large diffs are not rendered by default.

config/crd/bases/argoproj.io_argocds.yaml

+1,655
Large diffs are not rendered by default.

controllers/argocd/applicationset.go

+43-29
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ func (r *ReconcileArgoCD) reconcileApplicationSetDeployment(cr *argoproj.ArgoCD,
184184
if sa != nil {
185185
podSpec.ServiceAccountName = sa.ObjectMeta.Name
186186
}
187-
podSpec.Volumes = []corev1.Volume{
187+
188+
serverVolumes := []corev1.Volume{
188189
{
189190
Name: "ssh-known-hosts",
190191
VolumeSource: corev1.VolumeSource{
@@ -228,6 +229,10 @@ func (r *ReconcileArgoCD) reconcileApplicationSetDeployment(cr *argoproj.ArgoCD,
228229
},
229230
},
230231
}
232+
if cr.Spec.ApplicationSet.Volumes != nil {
233+
serverVolumes = append(serverVolumes, cr.Spec.ApplicationSet.Volumes...)
234+
}
235+
podSpec.Volumes = serverVolumes
231236
addSCMGitlabVolumeMount := false
232237
if scmRootCAConfigMapName := getSCMRootCAConfigMapName(cr); scmRootCAConfigMapName != "" {
233238
cm := newConfigMapWithName(scmRootCAConfigMapName, cr)
@@ -322,35 +327,50 @@ func (r *ReconcileArgoCD) applicationSetContainer(cr *argoproj.ArgoCD, addSCMGit
322327
// Environment specified in the CR take precedence over everything else
323328
appSetEnv = argoutil.EnvMerge(appSetEnv, proxyEnvVars(), false)
324329

330+
// Default VolumeMounts for ApplicationSetController
331+
serverVolumeMounts := []corev1.VolumeMount{
332+
{
333+
Name: "ssh-known-hosts",
334+
MountPath: "/app/config/ssh",
335+
},
336+
{
337+
Name: "tls-certs",
338+
MountPath: "/app/config/tls",
339+
},
340+
{
341+
Name: "gpg-keys",
342+
MountPath: "/app/config/gpg/source",
343+
},
344+
{
345+
Name: "gpg-keyring",
346+
MountPath: "/app/config/gpg/keys",
347+
},
348+
{
349+
Name: "tmp",
350+
MountPath: "/tmp",
351+
},
352+
}
353+
354+
// Optional extra VolumeMounts for ApplicationSetController
355+
if cr.Spec.ApplicationSet.VolumeMounts != nil {
356+
serverVolumeMounts = append(serverVolumeMounts, cr.Spec.ApplicationSet.VolumeMounts...)
357+
}
358+
359+
if addSCMGitlabVolumeMount {
360+
serverVolumeMounts = append(serverVolumeMounts, corev1.VolumeMount{
361+
Name: "appset-gitlab-scm-tls-cert",
362+
MountPath: ApplicationSetGitlabSCMTlsMountPath,
363+
})
364+
}
365+
325366
container := corev1.Container{
326367
Command: r.getArgoApplicationSetCommand(cr),
327368
Env: appSetEnv,
328369
Image: getApplicationSetContainerImage(cr),
329370
ImagePullPolicy: corev1.PullAlways,
330371
Name: "argocd-applicationset-controller",
331372
Resources: getApplicationSetResources(cr),
332-
VolumeMounts: []corev1.VolumeMount{
333-
{
334-
Name: "ssh-known-hosts",
335-
MountPath: "/app/config/ssh",
336-
},
337-
{
338-
Name: "tls-certs",
339-
MountPath: "/app/config/tls",
340-
},
341-
{
342-
Name: "gpg-keys",
343-
MountPath: "/app/config/gpg/source",
344-
},
345-
{
346-
Name: "gpg-keyring",
347-
MountPath: "/app/config/gpg/keys",
348-
},
349-
{
350-
Name: "tmp",
351-
MountPath: "/tmp",
352-
},
353-
},
373+
VolumeMounts: serverVolumeMounts,
354374
Ports: []corev1.ContainerPort{
355375
{
356376
ContainerPort: 7000,
@@ -375,12 +395,6 @@ func (r *ReconcileArgoCD) applicationSetContainer(cr *argoproj.ArgoCD, addSCMGit
375395
},
376396
},
377397
}
378-
if addSCMGitlabVolumeMount {
379-
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
380-
Name: "appset-gitlab-scm-tls-cert",
381-
MountPath: ApplicationSetGitlabSCMTlsMountPath,
382-
})
383-
}
384398
return container
385399
}
386400

controllers/argocd/applicationset_test.go

+95-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ func TestReconcileApplicationSet_CreateDeployments(t *testing.T) {
103103
deployment))
104104

105105
// Ensure the created Deployment has the expected properties
106-
checkExpectedDeploymentValues(t, r, deployment, &sa, a)
106+
checkExpectedDeploymentValues(t, r, deployment, &sa, nil, nil, a)
107107
}
108108

109-
func checkExpectedDeploymentValues(t *testing.T, r *ReconcileArgoCD, deployment *appsv1.Deployment, sa *corev1.ServiceAccount, a *argoproj.ArgoCD) {
109+
func checkExpectedDeploymentValues(t *testing.T, r *ReconcileArgoCD, deployment *appsv1.Deployment, sa *corev1.ServiceAccount, extraVolumes *[]corev1.Volume, extraVolumeMounts *[]corev1.VolumeMount, a *argoproj.ArgoCD) {
110110
assert.Equal(t, deployment.Spec.Template.Spec.ServiceAccountName, sa.ObjectMeta.Name)
111111
appsetAssertExpectedLabels(t, &deployment.ObjectMeta)
112112

@@ -174,10 +174,46 @@ func checkExpectedDeploymentValues(t *testing.T, r *ReconcileArgoCD, deployment
174174
})
175175
}
176176

177+
if extraVolumes != nil {
178+
volumes = append(volumes, *extraVolumes...)
179+
}
180+
177181
if diff := cmp.Diff(volumes, deployment.Spec.Template.Spec.Volumes); diff != "" {
178182
t.Fatalf("failed to reconcile applicationset-controller deployment volumes:\n%s", diff)
179183
}
180184

185+
volumeMounts := []corev1.VolumeMount{
186+
{
187+
Name: "ssh-known-hosts",
188+
MountPath: "/app/config/ssh",
189+
},
190+
{
191+
Name: "tls-certs",
192+
MountPath: "/app/config/tls",
193+
},
194+
{
195+
Name: "gpg-keys",
196+
MountPath: "/app/config/gpg/source",
197+
},
198+
{
199+
Name: "gpg-keyring",
200+
MountPath: "/app/config/gpg/keys",
201+
},
202+
{
203+
Name: "tmp",
204+
MountPath: "/tmp",
205+
},
206+
}
207+
208+
if extraVolumeMounts != nil {
209+
volumeMounts = append(volumeMounts, *extraVolumeMounts...)
210+
}
211+
212+
// Verify VolumeMounts
213+
if diff := cmp.Diff(volumeMounts, deployment.Spec.Template.Spec.Containers[0].VolumeMounts); diff != "" {
214+
t.Fatalf("failed to reconcile applicationset-controller deployment volume mounts:\n%s", diff)
215+
}
216+
181217
expectedSelector := &metav1.LabelSelector{
182218
MatchLabels: map[string]string{
183219
common.ArgoCDKeyName: deployment.Name,
@@ -249,6 +285,61 @@ func TestReconcileApplicationSetProxyConfiguration(t *testing.T) {
249285

250286
}
251287

288+
func TestReconcileApplicationSetVolumes(t *testing.T) {
289+
logf.SetLogger(ZapLogger(true))
290+
291+
extraVolumes := []corev1.Volume{
292+
{
293+
Name: "example-volume",
294+
VolumeSource: corev1.VolumeSource{
295+
EmptyDir: &corev1.EmptyDirVolumeSource{},
296+
},
297+
},
298+
}
299+
300+
extraVolumeMounts := []corev1.VolumeMount{
301+
{
302+
Name: "example-volume",
303+
MountPath: "/mnt/data",
304+
},
305+
}
306+
307+
a := makeTestArgoCD()
308+
a.Spec.ApplicationSet = &argoproj.ArgoCDApplicationSet{
309+
Volumes: extraVolumes,
310+
VolumeMounts: extraVolumeMounts,
311+
}
312+
313+
resObjs := []client.Object{a}
314+
subresObjs := []client.Object{a}
315+
runtimeObjs := []runtime.Object{}
316+
sch := makeTestReconcilerScheme(argoproj.AddToScheme)
317+
cl := makeTestReconcilerClient(sch, resObjs, subresObjs, runtimeObjs)
318+
r := makeTestReconciler(cl, sch)
319+
320+
sa := corev1.ServiceAccount{}
321+
322+
// Reconcile the ApplicationSet deployment
323+
assert.NoError(t, r.reconcileApplicationSetDeployment(a, &sa))
324+
325+
// Get the deployment after reconciliation
326+
deployment := &appsv1.Deployment{}
327+
err := r.Client.Get(
328+
context.TODO(),
329+
types.NamespacedName{
330+
Name: "argocd-applicationset-controller",
331+
Namespace: a.Namespace,
332+
},
333+
deployment,
334+
)
335+
if err != nil {
336+
t.Fatalf("failed to get deployment: %v", err)
337+
}
338+
339+
// Ensure the created Deployment has the expected properties
340+
checkExpectedDeploymentValues(t, r, deployment, &sa, &extraVolumes, &extraVolumeMounts, a)
341+
}
342+
252343
func TestReconcileApplicationSet_UpdateExistingDeployments(t *testing.T) {
253344
logf.SetLogger(ZapLogger(true))
254345
a := makeTestArgoCD()
@@ -294,7 +385,7 @@ func TestReconcileApplicationSet_UpdateExistingDeployments(t *testing.T) {
294385
deployment))
295386

296387
// Ensure the updated Deployment has the expected properties
297-
checkExpectedDeploymentValues(t, r, deployment, &sa, a)
388+
checkExpectedDeploymentValues(t, r, deployment, &sa, nil, nil, a)
298389

299390
}
300391

@@ -454,7 +545,7 @@ func TestReconcileApplicationSet_Deployments_SpecOverride(t *testing.T) {
454545

455546
specImage := deployment.Spec.Template.Spec.Containers[0].Image
456547
assert.Equal(t, test.expectedContainerImage, specImage)
457-
checkExpectedDeploymentValues(t, r, deployment, &sa, a)
548+
checkExpectedDeploymentValues(t, r, deployment, &sa, nil, nil, a)
458549
})
459550
}
460551

docs/reference/argocd.md

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ SCMRootCAConfigMap (#add-tls-certificate-for-gitlab-scm-provider-to-applications
8989
Enabled|true|Flag to enable/disable the ApplicationSet Controller during ArgoCD installation.
9090
SourceNamespaces|[Empty]|List of namespaces other than control-plane namespace where appsets can be created.
9191
SCMProviders|[Empty]|List of allowed Source Code Manager (SCM) providers URL.
92+
Volumes | [Empty] | Configure addition volumes for the ArgoCD Application Controller component. This field is optional.
93+
VolumeMounts | [Empty] | Configure addition volume mounts for the ArgoCD Application Controller component. This field is optional.
9294

9395
### ApplicationSet Controller Example
9496

0 commit comments

Comments
 (0)