Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transformer): Use healthEndpoint if defined when transforming a server port #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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