Skip to content

Commit

Permalink
Use healthEndpoint if defined when transforming a server port
Browse files Browse the repository at this point in the history
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 spinnaker/spinnaker#2533
  • Loading branch information
dmichel1 committed Apr 17, 2021
1 parent edd804d commit 7da7b80
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/deploy/spindeploy/transformer/serverport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/deploy/spindeploy/transformer/serverport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7da7b80

Please sign in to comment.