Skip to content

Commit

Permalink
fix: use more precise way to determine grpc port
Browse files Browse the repository at this point in the history
  • Loading branch information
derecknowayback committed Oct 23, 2023
1 parent 766e8c0 commit 300b14f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pkg/controller/rsm/transformer_object_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,30 @@ func injectRoleProbeBaseContainer(rsm workloads.ReplicatedStateMachine, template
return nil
}

tryToGetLorryGrpcPort := func(container *corev1.Container) int {
for i, port := range container.Ports {
if port.Name == constant.LorryGRPCPortName {
return int(container.Ports[i].ContainerPort)
}
}
return 0
}

// if role probe container exists, update the readiness probe, env and serving container port
if container := tryToGetRoleProbeContainer(); container != nil {
// presume the second port is the grpc port.
// this is an easily broken contract between rsm controller and cluster controller.
// TODO(free6om): design a better way to do this
portNum := tryToGetLorryGrpcPort(container)
if portNum == 0 {
portNum = probeGRPCPort
grpcPort := corev1.ContainerPort{
Name: roleProbeGRPCPortName,
ContainerPort: int32(portNum),
Protocol: "TCP",
}
container.Ports = append(container.Ports, grpcPort)
}
readinessProbe.Exec.Command = []string{
grpcHealthProbeBinaryPath,
fmt.Sprintf(grpcHealthProbeArgsFormat, int(container.Ports[1].ContainerPort)),
fmt.Sprintf(grpcHealthProbeArgsFormat, portNum),
}
readinessProbe.HTTPGet = nil
container.ReadinessProbe = readinessProbe
Expand Down

0 comments on commit 300b14f

Please sign in to comment.