Skip to content

Commit 3132f82

Browse files
committed
fix get docker host panic when dind replica is 0
Signed-off-by: Patrick Zhao <zhaoyu@koderover.com>
1 parent 700041f commit 3132f82

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

pkg/microservice/aslan/core/common/service/workflowcontroller/jobcontroller/job_freestyle.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ func (c *FreestyleJobCtl) run(ctx context.Context) error {
150150

151151
// decide which docker host to use.
152152
// TODO: do not use code in warpdrive moudule, should move to a public place
153-
dockerhosts := dockerhost.NewDockerHosts(hubServerAddr, c.logger)
154-
c.jobTaskSpec.Properties.DockerHost = dockerhosts.GetBestHost(dockerhost.ClusterID(c.jobTaskSpec.Properties.ClusterID), fmt.Sprintf("%v", c.workflowCtx.TaskID))
153+
if !c.jobTaskSpec.Properties.UseHostDockerDaemon {
154+
dockerhosts := dockerhost.NewDockerHosts(hubServerAddr, c.logger)
155+
c.jobTaskSpec.Properties.DockerHost = dockerhosts.GetBestHost(dockerhost.ClusterID(c.jobTaskSpec.Properties.ClusterID), fmt.Sprintf("%v", c.workflowCtx.TaskID))
156+
}
155157

156158
// not local cluster
157159
var (

pkg/tool/dockerhost/docker_host.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ func (d *dockerhosts) GetBestHost(clusterID ClusterID, key string) string {
100100
d.initClusterInfo(clusterID)
101101
}
102102

103-
// round-robin
104103
members := d.store[clusterID].GetMembers()
104+
if len(members) == 0 {
105+
return ""
106+
}
107+
108+
// round-robin
105109
index := d.GetBestHostIndex(clusterID)
106110
index = (index + 1) % len(members)
107111
member := members[index]

0 commit comments

Comments
 (0)