Skip to content

Commit d0d1a6c

Browse files
committed
Address comments, fix issues, more tests
Signed-off-by: Jason Parraga <[email protected]>
1 parent 6ec02d6 commit d0d1a6c

9 files changed

+602
-82
lines changed

internal/controller/install/armadaserver_controller.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,7 @@ func createArmadaServerDeployment(
449449
volumeMounts := createVolumeMounts(GetConfigFilename(as.Name), as.Spec.AdditionalVolumeMounts)
450450
volumeMounts = append(volumeMounts, createPulsarVolumeMounts(pulsarConfig)...)
451451

452-
asConfig, err := extractArmadaServerConfig(as.Spec.ApplicationConfig)
453-
if err != nil {
454-
return nil, err
455-
}
456-
457-
readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(asConfig.Grpc.Tls))
452+
readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(commonConfig.GRPC.TLS))
458453

459454
deployment := appsv1.Deployment{
460455
ObjectMeta: metav1.ObjectMeta{
@@ -687,21 +682,3 @@ func createServerPrometheusRule(server *installv1alpha1.ArmadaServer) *monitorin
687682
},
688683
}
689684
}
690-
691-
type ArmadaServerConfig struct {
692-
Grpc GrpcConfig
693-
}
694-
695-
// extractArmadaServerConfig will unmarshal the appconfig and return the AramadaServerConfig portion
696-
func extractArmadaServerConfig(config runtime.RawExtension) (ArmadaServerConfig, error) {
697-
appConfig, err := builders.ConvertRawExtensionToYaml(config)
698-
if err != nil {
699-
return ArmadaServerConfig{}, err
700-
}
701-
var asConfig ArmadaServerConfig
702-
err = yaml.Unmarshal([]byte(appConfig), &asConfig)
703-
if err != nil {
704-
return ArmadaServerConfig{}, err
705-
}
706-
return asConfig, err
707-
}

internal/controller/install/armadaserver_controller_test.go

Lines changed: 213 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/google/go-cmp/cmp"
9+
"google.golang.org/protobuf/testing/protocmp"
10+
"k8s.io/apimachinery/pkg/util/intstr"
11+
812
"github.com/armadaproject/armada-operator/internal/controller/builders"
913

1014
"k8s.io/utils/ptr"
@@ -429,12 +433,12 @@ func TestSchedulerReconciler_createIngress(t *testing.T) {
429433

430434
input := v1alpha1.ArmadaServer{
431435
TypeMeta: metav1.TypeMeta{
432-
Kind: "Lookout",
436+
Kind: "armadaserver",
433437
APIVersion: "install.armadaproject.io/v1alpha1",
434438
},
435439
ObjectMeta: metav1.ObjectMeta{
436440
Namespace: "default",
437-
Name: "lookout",
441+
Name: "armadaserver",
438442
},
439443
Spec: v1alpha1.ArmadaServerSpec{
440444
Replicas: ptr.To[int32](2),
@@ -459,3 +463,210 @@ func TestSchedulerReconciler_createIngress(t *testing.T) {
459463
assert.NoError(t, err)
460464
assert.NotNil(t, ingress)
461465
}
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+
}

internal/controller/install/binoculars_controller.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"context"
2121
"time"
2222

23-
"sigs.k8s.io/yaml"
24-
2523
"github.com/pkg/errors"
2624

2725
installv1alpha1 "github.com/armadaproject/armada-operator/api/install/v1alpha1"
@@ -229,12 +227,7 @@ func createBinocularsDeployment(
229227
env := createEnv(binoculars.Spec.Environment)
230228
volumes := createVolumes(binoculars.Name, binoculars.Spec.AdditionalVolumes)
231229
volumeMounts := createVolumeMounts(GetConfigFilename(secret.Name), binoculars.Spec.AdditionalVolumeMounts)
232-
233-
binocularsConfig, err := extractBinocularsConfig(binoculars.Spec.ApplicationConfig)
234-
if err != nil {
235-
return nil, err
236-
}
237-
readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(binocularsConfig.Grpc.Tls))
230+
readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(commonConfig.GRPC.TLS))
238231

239232
containers := []corev1.Container{{
240233
Name: "binoculars",
@@ -378,21 +371,3 @@ func (r *BinocularsReconciler) SetupWithManager(mgr ctrl.Manager) error {
378371
For(&installv1alpha1.Binoculars{}).
379372
Complete(r)
380373
}
381-
382-
type BinocularsConfig struct {
383-
Grpc GrpcConfig
384-
}
385-
386-
// extractBinocularsConfig will unmarshal the appconfig and return the BinocularsConfig portion
387-
func extractBinocularsConfig(config runtime.RawExtension) (BinocularsConfig, error) {
388-
appConfig, err := builders.ConvertRawExtensionToYaml(config)
389-
if err != nil {
390-
return BinocularsConfig{}, err
391-
}
392-
var binocularsConfig BinocularsConfig
393-
err = yaml.Unmarshal([]byte(appConfig), &binocularsConfig)
394-
if err != nil {
395-
return BinocularsConfig{}, err
396-
}
397-
return binocularsConfig, err
398-
}

0 commit comments

Comments
 (0)