Skip to content

Commit 157d3b7

Browse files
chrisguidryclaude
andauthored
Fix work pool naming inconsistency that prevented worker connections (#207)
## Summary Fixes a naming inconsistency between what the controller creates in the Prefect API and what workers try to connect to for work pools starting with "prefect". Previously, the `EntrypointArguments()` method would prepend "pool-" to work pool names starting with "prefect", causing workers to attempt connections to work pools that didn't exist in the API. For example: - Controller would create work pool: `prefect-work-pool` - Worker would try to connect to: `pool-prefect-work-pool` - Result: Worker connection failures Now both use the exact work pool name from the Kubernetes resource, ensuring proper connectivity. ## Breaking Change This is a breaking change for users with work pools starting with "prefect". They'll need to: 1. Delete existing PrefectWorkPool resources 2. Recreate them with the same names 3. Update any PrefectDeployment references However, the previous behavior was fundamentally broken anyway, so this fixes existing deployments rather than introducing new issues. ## Testing - All existing unit and controller tests pass - Added comprehensive tests for naming consistency - Verified fix with end-to-end testing of various naming patterns Closes #206 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 98ee2d7 commit 157d3b7

2 files changed

Lines changed: 98 additions & 7 deletions

File tree

api/v1/prefectworkpool_types.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package v1
1818

1919
import (
20-
"strings"
21-
2220
corev1 "k8s.io/api/core/v1"
2321
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2422
"k8s.io/apimachinery/pkg/util/intstr"
@@ -136,13 +134,9 @@ func (s *PrefectWorkPool) Image() string {
136134
}
137135

138136
func (s *PrefectWorkPool) EntrypointArguments() []string {
139-
workPoolName := s.Name
140-
if strings.HasPrefix(workPoolName, "prefect") {
141-
workPoolName = "pool-" + workPoolName
142-
}
143137
return []string{
144138
"prefect", "worker", "start",
145-
"--pool", workPoolName, "--type", s.Spec.Type,
139+
"--pool", s.Name, "--type", s.Spec.Type,
146140
"--with-healthcheck",
147141
}
148142
}

api/v1/prefectworkpool_types_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,101 @@ var _ = Describe("PrefectWorkPool type", func() {
4646
Expect(copied).To(Equal(original))
4747
Expect(copied).NotTo(BeIdenticalTo(original))
4848
})
49+
50+
Describe("EntrypointArguments", func() {
51+
It("should use exact work pool name for names starting with 'prefect'", func() {
52+
workPool := &PrefectWorkPool{
53+
ObjectMeta: metav1.ObjectMeta{
54+
Name: "prefect-work-pool",
55+
},
56+
Spec: PrefectWorkPoolSpec{
57+
Type: "kubernetes",
58+
},
59+
}
60+
61+
args := workPool.EntrypointArguments()
62+
Expect(args).To(ContainElement("prefect-work-pool"))
63+
Expect(args).To(Equal([]string{
64+
"prefect", "worker", "start",
65+
"--pool", "prefect-work-pool", "--type", "kubernetes",
66+
"--with-healthcheck",
67+
}))
68+
})
69+
70+
It("should use exact work pool name for names not starting with 'prefect'", func() {
71+
workPool := &PrefectWorkPool{
72+
ObjectMeta: metav1.ObjectMeta{
73+
Name: "my-work-pool",
74+
},
75+
Spec: PrefectWorkPoolSpec{
76+
Type: "process",
77+
},
78+
}
79+
80+
args := workPool.EntrypointArguments()
81+
Expect(args).To(ContainElement("my-work-pool"))
82+
Expect(args).To(Equal([]string{
83+
"prefect", "worker", "start",
84+
"--pool", "my-work-pool", "--type", "process",
85+
"--with-healthcheck",
86+
}))
87+
})
88+
89+
It("ensures naming consistency between controller and worker", func() {
90+
workPool := &PrefectWorkPool{
91+
ObjectMeta: metav1.ObjectMeta{
92+
Name: "prefect-production",
93+
},
94+
Spec: PrefectWorkPoolSpec{
95+
Type: "kubernetes",
96+
},
97+
}
98+
99+
controllerName := workPool.Name
100+
101+
workerArgs := workPool.EntrypointArguments()
102+
var workerPoolName string
103+
for i, arg := range workerArgs {
104+
if arg == "--pool" && i+1 < len(workerArgs) {
105+
workerPoolName = workerArgs[i+1]
106+
break
107+
}
108+
}
109+
110+
Expect(controllerName).To(Equal("prefect-production"))
111+
Expect(workerPoolName).To(Equal("prefect-production"))
112+
Expect(controllerName).To(Equal(workerPoolName))
113+
})
114+
115+
It("should work consistently for all naming patterns", func() {
116+
testCases := []struct {
117+
name string
118+
expectedPool string
119+
}{
120+
{"prefect", "prefect"},
121+
{"prefect-k8s", "prefect-k8s"},
122+
{"prefect123", "prefect123"},
123+
{"k8s-pool", "k8s-pool"},
124+
{"my-prefect-pool", "my-prefect-pool"},
125+
{"PREFECT-POOL", "PREFECT-POOL"},
126+
{"production-pool", "production-pool"},
127+
{"dev", "dev"},
128+
}
129+
130+
for _, tc := range testCases {
131+
workPool := &PrefectWorkPool{
132+
ObjectMeta: metav1.ObjectMeta{
133+
Name: tc.name,
134+
},
135+
Spec: PrefectWorkPoolSpec{
136+
Type: "process",
137+
},
138+
}
139+
140+
args := workPool.EntrypointArguments()
141+
Expect(args).To(ContainElement(tc.expectedPool),
142+
"Work pool %s should use pool name %s", tc.name, tc.expectedPool)
143+
}
144+
})
145+
})
49146
})

0 commit comments

Comments
 (0)