From d0d1a6c3e870d06c928eaa124b3c58ed99afbc4b Mon Sep 17 00:00:00 2001 From: Jason Parraga Date: Fri, 22 Nov 2024 18:39:29 -0800 Subject: [PATCH] Address comments, fix issues, more tests Signed-off-by: Jason Parraga --- .../install/armadaserver_controller.go | 25 +- .../install/armadaserver_controller_test.go | 215 +++++++++++++++++- .../install/binoculars_controller.go | 27 +-- .../install/binoculars_controller_test.go | 214 ++++++++++++++++- internal/controller/install/common_helpers.go | 10 +- .../controller/install/executor_controller.go | 7 +- .../install/executor_controller_test.go | 169 ++++++++++++++ .../controller/install/lookout_controller.go | 9 +- .../install/scheduler_controller.go | 8 +- 9 files changed, 602 insertions(+), 82 deletions(-) diff --git a/internal/controller/install/armadaserver_controller.go b/internal/controller/install/armadaserver_controller.go index abd2e05..3dd642b 100644 --- a/internal/controller/install/armadaserver_controller.go +++ b/internal/controller/install/armadaserver_controller.go @@ -449,12 +449,7 @@ func createArmadaServerDeployment( volumeMounts := createVolumeMounts(GetConfigFilename(as.Name), as.Spec.AdditionalVolumeMounts) volumeMounts = append(volumeMounts, createPulsarVolumeMounts(pulsarConfig)...) - asConfig, err := extractArmadaServerConfig(as.Spec.ApplicationConfig) - if err != nil { - return nil, err - } - - readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(asConfig.Grpc.Tls)) + readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(commonConfig.GRPC.TLS)) deployment := appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -687,21 +682,3 @@ func createServerPrometheusRule(server *installv1alpha1.ArmadaServer) *monitorin }, } } - -type ArmadaServerConfig struct { - Grpc GrpcConfig -} - -// extractArmadaServerConfig will unmarshal the appconfig and return the AramadaServerConfig portion -func extractArmadaServerConfig(config runtime.RawExtension) (ArmadaServerConfig, error) { - appConfig, err := builders.ConvertRawExtensionToYaml(config) - if err != nil { - return ArmadaServerConfig{}, err - } - var asConfig ArmadaServerConfig - err = yaml.Unmarshal([]byte(appConfig), &asConfig) - if err != nil { - return ArmadaServerConfig{}, err - } - return asConfig, err -} diff --git a/internal/controller/install/armadaserver_controller_test.go b/internal/controller/install/armadaserver_controller_test.go index e94f12e..e0c0956 100644 --- a/internal/controller/install/armadaserver_controller_test.go +++ b/internal/controller/install/armadaserver_controller_test.go @@ -5,6 +5,10 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" + "google.golang.org/protobuf/testing/protocmp" + "k8s.io/apimachinery/pkg/util/intstr" + "github.com/armadaproject/armada-operator/internal/controller/builders" "k8s.io/utils/ptr" @@ -429,12 +433,12 @@ func TestSchedulerReconciler_createIngress(t *testing.T) { input := v1alpha1.ArmadaServer{ TypeMeta: metav1.TypeMeta{ - Kind: "Lookout", + Kind: "armadaserver", APIVersion: "install.armadaproject.io/v1alpha1", }, ObjectMeta: metav1.ObjectMeta{ Namespace: "default", - Name: "lookout", + Name: "armadaserver", }, Spec: v1alpha1.ArmadaServerSpec{ Replicas: ptr.To[int32](2), @@ -459,3 +463,210 @@ func TestSchedulerReconciler_createIngress(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, ingress) } + +func TestArmadaServerReconciler_CreateDeployment(t *testing.T) { + t.Parallel() + + commonConfig := &builders.CommonApplicationConfig{ + HTTPPort: 8080, + GRPCPort: 5051, + MetricsPort: 9000, + Profiling: builders.ProfilingConfig{ + Port: 1337, + }, + } + + armadaServer := &installv1alpha1.ArmadaServer{ + TypeMeta: metav1.TypeMeta{ + Kind: "ArmadaServer", + APIVersion: "install.armadaproject.io/v1alpha1", + }, + ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "armadaserver"}, + Spec: installv1alpha1.ArmadaServerSpec{ + PulsarInit: true, + CommonSpecBase: installv1alpha1.CommonSpecBase{ + Labels: map[string]string{"test": "hello"}, + Image: installv1alpha1.Image{ + Repository: "testrepo", + Tag: "1.0.0", + }, + ApplicationConfig: runtime.RawExtension{}, + Resources: &corev1.ResourceRequirements{}, + Prometheus: &installv1alpha1.PrometheusConfig{Enabled: true}, + }, + ClusterIssuer: "test", + HostNames: []string{"localhost"}, + Ingress: &installv1alpha1.IngressConfig{ + IngressClass: "nginx", + Labels: map[string]string{"test": "hello"}, + Annotations: map[string]string{"test": "hello"}, + }, + }, + } + + deployment, err := createArmadaServerDeployment(armadaServer, "armadaserver", commonConfig) + assert.NoError(t, err) + + expectedDeployment := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "armadaserver", + Namespace: "default", + Labels: map[string]string{ + "app": "armadaserver", + "release": "armadaserver", + }, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: ptr.To[int32](1), + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app": "armadaserver", + }, + }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RollingUpdateDeploymentStrategyType, + RollingUpdate: &appsv1.RollingUpdateDeployment{ + MaxUnavailable: &intstr.IntOrString{ + IntVal: 1, + }, + }, + }, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Name: "armadaserver", + Namespace: "default", + Labels: map[string]string{ + "app": "armadaserver", + "release": "armadaserver", + }, + Annotations: map[string]string{ + "checksum/config": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + }, + }, + Spec: corev1.PodSpec{ + Affinity: &corev1.Affinity{ + PodAffinity: &corev1.PodAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ + { + Weight: 100, + PodAffinityTerm: corev1.PodAffinityTerm{ + LabelSelector: &metav1.LabelSelector{ + MatchExpressions: []metav1.LabelSelectorRequirement{ + { + Key: "app", + Operator: metav1.LabelSelectorOpIn, + Values: []string{ + "armadaserver", + }, + }, + }, + }, + TopologyKey: "kubernetes.io/hostname", + }, + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "user-config", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "armadaserver", + }, + }, + }, + }, + Containers: []corev1.Container{ + { + Args: []string{ + "--config", + "/config/application_config.yaml", + }, + Env: []corev1.EnvVar{ + { + Name: "SERVICE_ACCOUNT", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + FieldPath: "spec.serviceAccountName", + }, + }, + }, + { + Name: "POD_NAMESPACE", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + FieldPath: "metadata.namespace", + }, + }, + }, + }, + Image: "testrepo:1.0.0", + ImagePullPolicy: corev1.PullIfNotPresent, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health", + Port: intstr.FromString("http"), + Scheme: corev1.URISchemeHTTP, + }, + }, + InitialDelaySeconds: 10, + TimeoutSeconds: 10, + FailureThreshold: 3, + }, + Name: "armadaserver", + Ports: []corev1.ContainerPort{ + { + Name: "grpc", + ContainerPort: 5051, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "http", + ContainerPort: 8080, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "metrics", + ContainerPort: 9000, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "profiling", + ContainerPort: 1337, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health", + Port: intstr.FromString("http"), + Scheme: corev1.URISchemeHTTP, + }, + }, + InitialDelaySeconds: 5, + TimeoutSeconds: 5, + FailureThreshold: 2, + }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "user-config", + ReadOnly: true, + MountPath: appConfigFilepath, + SubPath: "armadaserver-config.yaml", + }, + }, + }, + }, + ServiceAccountName: "armadaserver", + }, + }, + }, + } + + if !cmp.Equal(expectedDeployment, deployment, protocmp.Transform()) { + t.Fatalf("deployment is not the same %s", cmp.Diff(expectedDeployment, deployment, protocmp.Transform())) + } +} diff --git a/internal/controller/install/binoculars_controller.go b/internal/controller/install/binoculars_controller.go index 5917347..95b328c 100644 --- a/internal/controller/install/binoculars_controller.go +++ b/internal/controller/install/binoculars_controller.go @@ -20,8 +20,6 @@ import ( "context" "time" - "sigs.k8s.io/yaml" - "github.com/pkg/errors" installv1alpha1 "github.com/armadaproject/armada-operator/api/install/v1alpha1" @@ -229,12 +227,7 @@ func createBinocularsDeployment( env := createEnv(binoculars.Spec.Environment) volumes := createVolumes(binoculars.Name, binoculars.Spec.AdditionalVolumes) volumeMounts := createVolumeMounts(GetConfigFilename(secret.Name), binoculars.Spec.AdditionalVolumeMounts) - - binocularsConfig, err := extractBinocularsConfig(binoculars.Spec.ApplicationConfig) - if err != nil { - return nil, err - } - readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(binocularsConfig.Grpc.Tls)) + readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(commonConfig.GRPC.TLS)) containers := []corev1.Container{{ Name: "binoculars", @@ -378,21 +371,3 @@ func (r *BinocularsReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&installv1alpha1.Binoculars{}). Complete(r) } - -type BinocularsConfig struct { - Grpc GrpcConfig -} - -// extractBinocularsConfig will unmarshal the appconfig and return the BinocularsConfig portion -func extractBinocularsConfig(config runtime.RawExtension) (BinocularsConfig, error) { - appConfig, err := builders.ConvertRawExtensionToYaml(config) - if err != nil { - return BinocularsConfig{}, err - } - var binocularsConfig BinocularsConfig - err = yaml.Unmarshal([]byte(appConfig), &binocularsConfig) - if err != nil { - return BinocularsConfig{}, err - } - return binocularsConfig, err -} diff --git a/internal/controller/install/binoculars_controller_test.go b/internal/controller/install/binoculars_controller_test.go index 1049608..2e6f5d3 100644 --- a/internal/controller/install/binoculars_controller_test.go +++ b/internal/controller/install/binoculars_controller_test.go @@ -5,6 +5,10 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" + "google.golang.org/protobuf/testing/protocmp" + "k8s.io/apimachinery/pkg/util/intstr" + "github.com/armadaproject/armada-operator/internal/controller/builders" "k8s.io/utils/ptr" @@ -14,6 +18,7 @@ import ( "github.com/armadaproject/armada-operator/test/k8sclient" "github.com/golang/mock/gomock" + appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" @@ -476,12 +481,12 @@ func TestSchedulerReconciler_createBinocularsIngress(t *testing.T) { input := v1alpha1.Binoculars{ TypeMeta: metav1.TypeMeta{ - Kind: "Lookout", + Kind: "binoculars", APIVersion: "install.armadaproject.io/v1alpha1", }, ObjectMeta: metav1.ObjectMeta{ Namespace: "default", - Name: "lookout", + Name: "binoculars", }, Spec: v1alpha1.BinocularsSpec{ Replicas: ptr.To[int32](2), @@ -506,3 +511,208 @@ func TestSchedulerReconciler_createBinocularsIngress(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, ingress) } + +func TestBinocularsReconciler_CreateDeployment(t *testing.T) { + t.Parallel() + + commonConfig := &builders.CommonApplicationConfig{ + HTTPPort: 8080, + GRPCPort: 5051, + MetricsPort: 9000, + Profiling: builders.ProfilingConfig{ + Port: 1337, + }, + } + + secret := &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "binoculars", + }, + } + + binoculars := &v1alpha1.Binoculars{ + TypeMeta: metav1.TypeMeta{ + Kind: "Binoculars", + APIVersion: "install.armadaproject.io/v1alpha1", + }, + ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "binoculars"}, + Spec: v1alpha1.BinocularsSpec{ + CommonSpecBase: installv1alpha1.CommonSpecBase{ + Labels: map[string]string{"test": "hello"}, + Image: installv1alpha1.Image{ + Repository: "testrepo", + Tag: "1.0.0", + }, + ApplicationConfig: runtime.RawExtension{}, + Resources: &corev1.ResourceRequirements{}, + }, + + Replicas: ptr.To[int32](2), + HostNames: []string{"localhost"}, + ClusterIssuer: "test", + Ingress: &installv1alpha1.IngressConfig{ + IngressClass: "nginx", + Labels: map[string]string{"test": "hello"}, + Annotations: map[string]string{"test": "hello"}, + }, + }, + } + + deployment, err := createBinocularsDeployment(binoculars, secret, "binoculars", commonConfig) + assert.NoError(t, err) + + expectedDeployment := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "binoculars", + Namespace: "default", + Labels: map[string]string{ + "app": "binoculars", + "release": "binoculars", + }, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: ptr.To[int32](2), + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app": "binoculars", + }, + }, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Name: "binoculars", + Namespace: "default", + Labels: map[string]string{ + "app": "binoculars", + "release": "binoculars", + }, + Annotations: map[string]string{ + "checksum/config": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + }, + }, + Spec: corev1.PodSpec{ + Affinity: &corev1.Affinity{ + PodAffinity: &corev1.PodAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ + { + Weight: 100, + PodAffinityTerm: corev1.PodAffinityTerm{ + LabelSelector: &metav1.LabelSelector{ + MatchExpressions: []metav1.LabelSelectorRequirement{ + { + Key: "app", + Operator: metav1.LabelSelectorOpIn, + Values: []string{ + "binoculars", + }, + }, + }, + }, + TopologyKey: "kubernetes.io/hostname", + }, + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "user-config", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "binoculars", + }, + }, + }, + }, + Containers: []corev1.Container{ + { + Args: []string{ + "--config", + "/config/application_config.yaml", + }, + Env: []corev1.EnvVar{ + { + Name: "SERVICE_ACCOUNT", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + FieldPath: "spec.serviceAccountName", + }, + }, + }, + { + Name: "POD_NAMESPACE", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + FieldPath: "metadata.namespace", + }, + }, + }, + }, + Image: "testrepo:1.0.0", + ImagePullPolicy: corev1.PullIfNotPresent, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health", + Port: intstr.FromString("http"), + Scheme: corev1.URISchemeHTTP, + }, + }, + InitialDelaySeconds: 10, + TimeoutSeconds: 10, + FailureThreshold: 3, + }, + Name: "binoculars", + Ports: []corev1.ContainerPort{ + { + Name: "grpc", + ContainerPort: 5051, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "http", + ContainerPort: 8080, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "metrics", + ContainerPort: 9000, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "profiling", + ContainerPort: 1337, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health", + Port: intstr.FromString("http"), + Scheme: corev1.URISchemeHTTP, + }, + }, + InitialDelaySeconds: 5, + TimeoutSeconds: 5, + FailureThreshold: 2, + }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "user-config", + ReadOnly: true, + MountPath: appConfigFilepath, + SubPath: "binoculars-config.yaml", + }, + }, + }, + }, + ServiceAccountName: "binoculars", + }, + }, + }, + } + + if !cmp.Equal(expectedDeployment, deployment, protocmp.Transform()) { + t.Fatalf("deployment is not the same %s", cmp.Diff(expectedDeployment, deployment, protocmp.Transform())) + } +} diff --git a/internal/controller/install/common_helpers.go b/internal/controller/install/common_helpers.go index 0b61f70..5d9e0ff 100644 --- a/internal/controller/install/common_helpers.go +++ b/internal/controller/install/common_helpers.go @@ -229,14 +229,6 @@ type PulsarConfig struct { Cacert string } -type GrpcConfig struct { - Tls TlsConfig -} - -type TlsConfig struct { - Enabled bool -} - // ArmadaInit used to initialize pulsar type ArmadaInit struct { Enabled bool @@ -329,7 +321,7 @@ func ExtractPulsarConfig(config runtime.RawExtension) (PulsarConfig, error) { } // GetServerScheme returns the URI scheme for the grpc server -func GetServerScheme(tlsConfig TlsConfig) corev1.URIScheme { +func GetServerScheme(tlsConfig builders.TLSConfig) corev1.URIScheme { if tlsConfig.Enabled { return corev1.URISchemeHTTPS } diff --git a/internal/controller/install/executor_controller.go b/internal/controller/install/executor_controller.go index 9fac5c0..3e79c0e 100644 --- a/internal/controller/install/executor_controller.go +++ b/internal/controller/install/executor_controller.go @@ -180,7 +180,7 @@ func (r *ExecutorReconciler) generateExecutorInstallComponents( } serviceAccountName = serviceAccount.Name } - deployment := r.createDeployment(executor, serviceAccountName, config) + deployment := createExecutorDeployment(executor, serviceAccountName, config) if err = controllerutil.SetOwnerReference(executor, deployment, scheme); err != nil { return nil, errors.WithStack(err) } @@ -241,7 +241,7 @@ func (r *ExecutorReconciler) generateExecutorInstallComponents( return components, nil } -func (r *ExecutorReconciler) createDeployment( +func createExecutorDeployment( executor *installv1alpha1.Executor, serviceAccountName string, config *builders.CommonApplicationConfig, @@ -249,7 +249,6 @@ func (r *ExecutorReconciler) createDeployment( var replicas int32 = 1 volumes := createVolumes(executor.Name, executor.Spec.AdditionalVolumes) volumeMounts := createVolumeMounts(GetConfigFilename(executor.Name), executor.Spec.AdditionalVolumeMounts) - readinessProbe, livenessProbe := CreateProbesWithScheme(corev1.URISchemeHTTP) env := []corev1.EnvVar{ @@ -276,7 +275,7 @@ func (r *ExecutorReconciler) createDeployment( ImagePullPolicy: corev1.PullIfNotPresent, Image: ImageString(executor.Spec.Image), Args: []string{appConfigFlag, appConfigFilepath}, - Ports: newContainerPortsMetrics(config), + Ports: newContainerPortsHTTPWithMetrics(config), Env: env, VolumeMounts: volumeMounts, SecurityContext: executor.Spec.SecurityContext, diff --git a/internal/controller/install/executor_controller_test.go b/internal/controller/install/executor_controller_test.go index 0d9a480..830d4ca 100644 --- a/internal/controller/install/executor_controller_test.go +++ b/internal/controller/install/executor_controller_test.go @@ -5,6 +5,13 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" + "google.golang.org/protobuf/testing/protocmp" + "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/utils/ptr" + + "github.com/armadaproject/armada-operator/internal/controller/builders" + monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "github.com/armadaproject/armada-operator/test/k8sclient" @@ -394,3 +401,165 @@ func TestExecutorReconciler_generateAdditionalClusterRoles(t *testing.T) { } assert.Equal(t, expectedClusterRoleBinding2, *bindings[1]) } + +func TestExecutorReconciler_CreateDeployment(t *testing.T) { + t.Parallel() + + commonConfig := &builders.CommonApplicationConfig{ + HTTPPort: 8080, + GRPCPort: 5051, + MetricsPort: 9000, + Profiling: builders.ProfilingConfig{ + Port: 1337, + }, + } + + executor := &installv1alpha1.Executor{ + TypeMeta: metav1.TypeMeta{ + Kind: "Executor", + APIVersion: "install.armadaproject.io/v1alpha1", + }, + ObjectMeta: metav1.ObjectMeta{Namespace: "default", Name: "executor"}, + Spec: installv1alpha1.ExecutorSpec{ + CommonSpecBase: installv1alpha1.CommonSpecBase{ + Labels: nil, + Image: installv1alpha1.Image{ + Repository: "testrepo", + Tag: "1.0.0", + }, + ApplicationConfig: runtime.RawExtension{}, + Resources: &corev1.ResourceRequirements{}, + Prometheus: &installv1alpha1.PrometheusConfig{Enabled: true, ScrapeInterval: &metav1.Duration{Duration: 1 * time.Second}}, + }, + }, + } + + deployment := createExecutorDeployment(executor, "executor", commonConfig) + + expectedDeployment := &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Name: "executor", + Namespace: "default", + Labels: map[string]string{ + "app": "executor", + "release": "executor", + }, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: ptr.To[int32](1), + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app": "executor", + }, + }, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Name: "executor", + Namespace: "default", + Labels: map[string]string{ + "app": "executor", + "release": "executor", + }, + Annotations: map[string]string{ + "checksum/config": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + }, + }, + Spec: corev1.PodSpec{ + Volumes: []corev1.Volume{ + { + Name: "user-config", + VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "executor", + }, + }, + }, + }, + Containers: []corev1.Container{ + { + Args: []string{ + "--config", + "/config/application_config.yaml", + }, + Env: []corev1.EnvVar{ + { + Name: "SERVICE_ACCOUNT", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + FieldPath: "spec.serviceAccountName", + }, + }, + }, + { + Name: "POD_NAMESPACE", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + FieldPath: "metadata.namespace", + }, + }, + }, + }, + Image: "testrepo:1.0.0", + ImagePullPolicy: corev1.PullIfNotPresent, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health", + Port: intstr.FromString("http"), + Scheme: corev1.URISchemeHTTP, + }, + }, + InitialDelaySeconds: 10, + TimeoutSeconds: 10, + FailureThreshold: 3, + }, + Name: "executor", + Ports: []corev1.ContainerPort{ + { + Name: "http", + ContainerPort: 8080, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "metrics", + ContainerPort: 9000, + Protocol: corev1.ProtocolTCP, + }, + { + Name: "profiling", + ContainerPort: 1337, + Protocol: corev1.ProtocolTCP, + }, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health", + Port: intstr.FromString("http"), + Scheme: corev1.URISchemeHTTP, + }, + }, + InitialDelaySeconds: 5, + TimeoutSeconds: 5, + FailureThreshold: 2, + }, + VolumeMounts: []corev1.VolumeMount{ + { + Name: "user-config", + ReadOnly: true, + MountPath: appConfigFilepath, + SubPath: "executor-config.yaml", + }, + }, + }, + }, + ServiceAccountName: "executor", + }, + }, + }, + } + + if !cmp.Equal(expectedDeployment, deployment, protocmp.Transform()) { + t.Fatalf("deployment is not the same %s", cmp.Diff(expectedDeployment, deployment, protocmp.Transform())) + } +} diff --git a/internal/controller/install/lookout_controller.go b/internal/controller/install/lookout_controller.go index 82f7f3b..79a6c0f 100644 --- a/internal/controller/install/lookout_controller.go +++ b/internal/controller/install/lookout_controller.go @@ -139,7 +139,6 @@ func (r *LookoutReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct type LookoutConfig struct { Postgres PostgresConfig - Tls TlsConfig } func generateLookoutInstallComponents( @@ -271,13 +270,7 @@ func createLookoutDeployment(lookout *installv1alpha1.Lookout, serviceAccountNam env := createEnv(lookout.Spec.Environment) volumes := createVolumes(lookout.Name, lookout.Spec.AdditionalVolumes) volumeMounts := createVolumeMounts(GetConfigFilename(lookout.Name), lookout.Spec.AdditionalVolumeMounts) - - lookoutConfig, err := extractLookoutConfig(lookout.Spec.ApplicationConfig) - if err != nil { - return nil, err - } - - readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(lookoutConfig.Tls)) + readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(config.GRPC.TLS)) deployment := appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{Name: lookout.Name, Namespace: lookout.Namespace, Labels: AllLabels(lookout.Name, lookout.Labels)}, diff --git a/internal/controller/install/scheduler_controller.go b/internal/controller/install/scheduler_controller.go index cae19a9..a221926 100644 --- a/internal/controller/install/scheduler_controller.go +++ b/internal/controller/install/scheduler_controller.go @@ -141,7 +141,6 @@ func (r *SchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } type SchedulerConfig struct { - Grpc GrpcConfig Postgres PostgresConfig } @@ -290,12 +289,7 @@ func newSchedulerDeployment( volumes = append(volumes, createPulsarVolumes(pulsarConfig)...) volumeMounts := createVolumeMounts(GetConfigFilename(scheduler.Name), scheduler.Spec.AdditionalVolumeMounts) volumeMounts = append(volumeMounts, createPulsarVolumeMounts(pulsarConfig)...) - - schedulerConfig, err := extractSchedulerConfig(scheduler.Spec.ApplicationConfig) - if err != nil { - return nil, err - } - readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(schedulerConfig.Grpc.Tls)) + readinessProbe, livenessProbe := CreateProbesWithScheme(GetServerScheme(config.GRPC.TLS)) deployment := appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{Name: scheduler.Name, Namespace: scheduler.Namespace, Labels: AllLabels(scheduler.Name, scheduler.Labels)},