From 7da7b8094139361d20f5fd282ea5de774786c49e Mon Sep 17 00:00:00 2001 From: Drew Michel Date: Sat, 17 Apr 2021 16:44:45 -0400 Subject: [PATCH] Use healthEndpoint if defined when transforming a server port If a custom healthEndpoint is defined it should be used otherwise k8s will never mark the node as ready. I encountered this bug with the below config. ```yaml profiles: gate: servlet: context-path: /api/v1 service-settings: gate: healthEndpoint: /api/v1/health server: port: 9002 default: apiPort: 8085 legacyServerPort: 8084 ``` Related to https://github.com/spinnaker/spinnaker/issues/2533 --- .../spindeploy/transformer/serverport.go | 7 +++++- .../spindeploy/transformer/serverport_test.go | 15 ++++++++++++ .../spinsvc_profile_health_endpoint.yml | 23 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 pkg/deploy/spindeploy/transformer/testdata/spinsvc_profile_health_endpoint.yml diff --git a/pkg/deploy/spindeploy/transformer/serverport.go b/pkg/deploy/spindeploy/transformer/serverport.go index fa188c63..a7fe85ce 100644 --- a/pkg/deploy/spindeploy/transformer/serverport.go +++ b/pkg/deploy/spindeploy/transformer/serverport.go @@ -34,6 +34,11 @@ func (g *ServerPortTransformerGenerator) GetName() string { } func (t *serverPortTransformer) transformDeploymentManifest(ctx context.Context, deploymentName string, deployment *v1.Deployment) error { + healthEndpoint, err := t.svc.GetSpinnakerConfig().GetServiceConfigPropString(ctx, deploymentName, "healthEndpoint") + if err != nil { + healthEndpoint = "/health" + } + if targetPort, _ := t.svc.GetSpinnakerConfig().GetServiceConfigPropString(ctx, deploymentName, "server.port"); targetPort != "" { intTargetPort, err := strconv.ParseInt(targetPort, 10, 32) if err != nil { @@ -50,7 +55,7 @@ func (t *serverPortTransformer) transformDeploymentManifest(ctx context.Context, if !strings.Contains(cmd, "http://localhost") { continue } - c.ReadinessProbe.Exec.Command[i] = fmt.Sprintf("http://localhost:%d/health", intTargetPort) + c.ReadinessProbe.Exec.Command[i] = fmt.Sprintf("http://localhost:%d%s", intTargetPort, healthEndpoint) } } } diff --git a/pkg/deploy/spindeploy/transformer/serverport_test.go b/pkg/deploy/spindeploy/transformer/serverport_test.go index 98f424e9..f8a3c63a 100644 --- a/pkg/deploy/spindeploy/transformer/serverport_test.go +++ b/pkg/deploy/spindeploy/transformer/serverport_test.go @@ -23,3 +23,18 @@ func TestTransformManifests_CustomServerPort(t *testing.T) { expected.Spec.Template.Spec.Containers[0].ReadinessProbe.Exec.Command[4] = "http://localhost:1111/health" assert.Equal(t, expected, gen.Config["gate"].Deployment) } + +func TestTransformManifests_CustomServerPortAndHealthEndpoint(t *testing.T) { + tr, _ := th.SetupTransformerFromSpinFile(&ServerPortTransformerGenerator{}, "testdata/spinsvc_profile_health_endpoint.yml", t) + gen := &generated.SpinnakerGeneratedConfig{} + test.AddDeploymentToGenConfig(gen, "gate", "testdata/input_deployment.yml", t) + + err := tr.TransformManifests(context.TODO(), gen) + assert.Nil(t, err) + + expected := &v1.Deployment{} + test.ReadYamlFile("testdata/input_deployment.yml", expected, t) + expected.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort = int32(1111) + expected.Spec.Template.Spec.Containers[0].ReadinessProbe.Exec.Command[4] = "http://localhost:1111/api/v1/health" + assert.Equal(t, expected, gen.Config["gate"].Deployment) +} \ No newline at end of file diff --git a/pkg/deploy/spindeploy/transformer/testdata/spinsvc_profile_health_endpoint.yml b/pkg/deploy/spindeploy/transformer/testdata/spinsvc_profile_health_endpoint.yml new file mode 100644 index 00000000..5f3699d1 --- /dev/null +++ b/pkg/deploy/spindeploy/transformer/testdata/spinsvc_profile_health_endpoint.yml @@ -0,0 +1,23 @@ +apiVersion: spinnaker.io/v1alpha2 +kind: SpinnakerService +metadata: + name: spinnaker + namespace: ns1 +spec: + spinnakerConfig: + config: + version: 1.15.1 + persistentStorage: + persistentStoreType: s3 + s3: + bucket: my-bucket + region: us-west-2 + rootFolder: front50 + profiles: + gate: + healthEndpoint: /api/v1/health + server: + port: 1111 +status: + apiUrl: http://acme.com + uiUrl: http://acme.com