@@ -5,6 +5,10 @@ import (
5
5
"testing"
6
6
"time"
7
7
8
+ "github.com/google/go-cmp/cmp"
9
+ "google.golang.org/protobuf/testing/protocmp"
10
+ "k8s.io/apimachinery/pkg/util/intstr"
11
+
8
12
"github.com/armadaproject/armada-operator/internal/controller/builders"
9
13
10
14
"k8s.io/utils/ptr"
@@ -429,12 +433,12 @@ func TestSchedulerReconciler_createIngress(t *testing.T) {
429
433
430
434
input := v1alpha1.ArmadaServer {
431
435
TypeMeta : metav1.TypeMeta {
432
- Kind : "Lookout " ,
436
+ Kind : "armadaserver " ,
433
437
APIVersion : "install.armadaproject.io/v1alpha1" ,
434
438
},
435
439
ObjectMeta : metav1.ObjectMeta {
436
440
Namespace : "default" ,
437
- Name : "lookout " ,
441
+ Name : "armadaserver " ,
438
442
},
439
443
Spec : v1alpha1.ArmadaServerSpec {
440
444
Replicas : ptr.To [int32 ](2 ),
@@ -459,3 +463,210 @@ func TestSchedulerReconciler_createIngress(t *testing.T) {
459
463
assert .NoError (t , err )
460
464
assert .NotNil (t , ingress )
461
465
}
466
+
467
+ func TestArmadaServerReconciler_CreateDeployment (t * testing.T ) {
468
+ t .Parallel ()
469
+
470
+ commonConfig := & builders.CommonApplicationConfig {
471
+ HTTPPort : 8080 ,
472
+ GRPCPort : 5051 ,
473
+ MetricsPort : 9000 ,
474
+ Profiling : builders.ProfilingConfig {
475
+ Port : 1337 ,
476
+ },
477
+ }
478
+
479
+ armadaServer := & installv1alpha1.ArmadaServer {
480
+ TypeMeta : metav1.TypeMeta {
481
+ Kind : "ArmadaServer" ,
482
+ APIVersion : "install.armadaproject.io/v1alpha1" ,
483
+ },
484
+ ObjectMeta : metav1.ObjectMeta {Namespace : "default" , Name : "armadaserver" },
485
+ Spec : installv1alpha1.ArmadaServerSpec {
486
+ PulsarInit : true ,
487
+ CommonSpecBase : installv1alpha1.CommonSpecBase {
488
+ Labels : map [string ]string {"test" : "hello" },
489
+ Image : installv1alpha1.Image {
490
+ Repository : "testrepo" ,
491
+ Tag : "1.0.0" ,
492
+ },
493
+ ApplicationConfig : runtime.RawExtension {},
494
+ Resources : & corev1.ResourceRequirements {},
495
+ Prometheus : & installv1alpha1.PrometheusConfig {Enabled : true },
496
+ },
497
+ ClusterIssuer : "test" ,
498
+ HostNames : []string {"localhost" },
499
+ Ingress : & installv1alpha1.IngressConfig {
500
+ IngressClass : "nginx" ,
501
+ Labels : map [string ]string {"test" : "hello" },
502
+ Annotations : map [string ]string {"test" : "hello" },
503
+ },
504
+ },
505
+ }
506
+
507
+ deployment , err := createArmadaServerDeployment (armadaServer , "armadaserver" , commonConfig )
508
+ assert .NoError (t , err )
509
+
510
+ expectedDeployment := & appsv1.Deployment {
511
+ ObjectMeta : metav1.ObjectMeta {
512
+ Name : "armadaserver" ,
513
+ Namespace : "default" ,
514
+ Labels : map [string ]string {
515
+ "app" : "armadaserver" ,
516
+ "release" : "armadaserver" ,
517
+ },
518
+ },
519
+ Spec : appsv1.DeploymentSpec {
520
+ Replicas : ptr.To [int32 ](1 ),
521
+ Selector : & metav1.LabelSelector {
522
+ MatchLabels : map [string ]string {
523
+ "app" : "armadaserver" ,
524
+ },
525
+ },
526
+ Strategy : appsv1.DeploymentStrategy {
527
+ Type : appsv1 .RollingUpdateDeploymentStrategyType ,
528
+ RollingUpdate : & appsv1.RollingUpdateDeployment {
529
+ MaxUnavailable : & intstr.IntOrString {
530
+ IntVal : 1 ,
531
+ },
532
+ },
533
+ },
534
+ Template : corev1.PodTemplateSpec {
535
+ ObjectMeta : metav1.ObjectMeta {
536
+ Name : "armadaserver" ,
537
+ Namespace : "default" ,
538
+ Labels : map [string ]string {
539
+ "app" : "armadaserver" ,
540
+ "release" : "armadaserver" ,
541
+ },
542
+ Annotations : map [string ]string {
543
+ "checksum/config" : "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
544
+ },
545
+ },
546
+ Spec : corev1.PodSpec {
547
+ Affinity : & corev1.Affinity {
548
+ PodAffinity : & corev1.PodAffinity {
549
+ PreferredDuringSchedulingIgnoredDuringExecution : []corev1.WeightedPodAffinityTerm {
550
+ {
551
+ Weight : 100 ,
552
+ PodAffinityTerm : corev1.PodAffinityTerm {
553
+ LabelSelector : & metav1.LabelSelector {
554
+ MatchExpressions : []metav1.LabelSelectorRequirement {
555
+ {
556
+ Key : "app" ,
557
+ Operator : metav1 .LabelSelectorOpIn ,
558
+ Values : []string {
559
+ "armadaserver" ,
560
+ },
561
+ },
562
+ },
563
+ },
564
+ TopologyKey : "kubernetes.io/hostname" ,
565
+ },
566
+ },
567
+ },
568
+ },
569
+ },
570
+ Volumes : []corev1.Volume {
571
+ {
572
+ Name : "user-config" ,
573
+ VolumeSource : corev1.VolumeSource {
574
+ Secret : & corev1.SecretVolumeSource {
575
+ SecretName : "armadaserver" ,
576
+ },
577
+ },
578
+ },
579
+ },
580
+ Containers : []corev1.Container {
581
+ {
582
+ Args : []string {
583
+ "--config" ,
584
+ "/config/application_config.yaml" ,
585
+ },
586
+ Env : []corev1.EnvVar {
587
+ {
588
+ Name : "SERVICE_ACCOUNT" ,
589
+ ValueFrom : & corev1.EnvVarSource {
590
+ FieldRef : & corev1.ObjectFieldSelector {
591
+ FieldPath : "spec.serviceAccountName" ,
592
+ },
593
+ },
594
+ },
595
+ {
596
+ Name : "POD_NAMESPACE" ,
597
+ ValueFrom : & corev1.EnvVarSource {
598
+ FieldRef : & corev1.ObjectFieldSelector {
599
+ FieldPath : "metadata.namespace" ,
600
+ },
601
+ },
602
+ },
603
+ },
604
+ Image : "testrepo:1.0.0" ,
605
+ ImagePullPolicy : corev1 .PullIfNotPresent ,
606
+ LivenessProbe : & corev1.Probe {
607
+ ProbeHandler : corev1.ProbeHandler {
608
+ HTTPGet : & corev1.HTTPGetAction {
609
+ Path : "/health" ,
610
+ Port : intstr .FromString ("http" ),
611
+ Scheme : corev1 .URISchemeHTTP ,
612
+ },
613
+ },
614
+ InitialDelaySeconds : 10 ,
615
+ TimeoutSeconds : 10 ,
616
+ FailureThreshold : 3 ,
617
+ },
618
+ Name : "armadaserver" ,
619
+ Ports : []corev1.ContainerPort {
620
+ {
621
+ Name : "grpc" ,
622
+ ContainerPort : 5051 ,
623
+ Protocol : corev1 .ProtocolTCP ,
624
+ },
625
+ {
626
+ Name : "http" ,
627
+ ContainerPort : 8080 ,
628
+ Protocol : corev1 .ProtocolTCP ,
629
+ },
630
+ {
631
+ Name : "metrics" ,
632
+ ContainerPort : 9000 ,
633
+ Protocol : corev1 .ProtocolTCP ,
634
+ },
635
+ {
636
+ Name : "profiling" ,
637
+ ContainerPort : 1337 ,
638
+ Protocol : corev1 .ProtocolTCP ,
639
+ },
640
+ },
641
+ ReadinessProbe : & corev1.Probe {
642
+ ProbeHandler : corev1.ProbeHandler {
643
+ HTTPGet : & corev1.HTTPGetAction {
644
+ Path : "/health" ,
645
+ Port : intstr .FromString ("http" ),
646
+ Scheme : corev1 .URISchemeHTTP ,
647
+ },
648
+ },
649
+ InitialDelaySeconds : 5 ,
650
+ TimeoutSeconds : 5 ,
651
+ FailureThreshold : 2 ,
652
+ },
653
+ VolumeMounts : []corev1.VolumeMount {
654
+ {
655
+ Name : "user-config" ,
656
+ ReadOnly : true ,
657
+ MountPath : appConfigFilepath ,
658
+ SubPath : "armadaserver-config.yaml" ,
659
+ },
660
+ },
661
+ },
662
+ },
663
+ ServiceAccountName : "armadaserver" ,
664
+ },
665
+ },
666
+ },
667
+ }
668
+
669
+ if ! cmp .Equal (expectedDeployment , deployment , protocmp .Transform ()) {
670
+ t .Fatalf ("deployment is not the same %s" , cmp .Diff (expectedDeployment , deployment , protocmp .Transform ()))
671
+ }
672
+ }
0 commit comments