Skip to content

Commit f9c52e2

Browse files
Fix TFE version parsing for newer version types (#641)
1 parent 64e19d4 commit f9c52e2

File tree

5 files changed

+68
-12
lines changed

5 files changed

+68
-12
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: Support TFE versions of type vX.Y.Z
3+
time: 2025-09-18T16:38:16.255351-07:00
4+
custom:
5+
PR: "641"

docs/faq.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,15 @@
235235

236236
- **Can I delete a project that has workspaces in it?**
237237

238-
This decision was made intentionally to follow the single-responsibility principle and to simplify deployment in a multi-cluster environment.
238+
No, you can only delete a project if it is empty and you have the proper permissions.
239+
239240

240241
## Runs Collector Controller
241242

242243
- **Why can't I configure multiple Agent Pools for scraping within a single CR?**
243244

244-
No, you can only delete a project if it is empty and you have the proper permissions.
245+
This decision was made intentionally to follow the single-responsibility principle and to simplify deployment in a multi-cluster environment.
246+
245247

246248
## Workspace Controller
247249

internal/controller/agentpool_controller_autoscaling.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (r *AgentPoolReconciler) reconcileAgentAutoscaling(ctx context.Context, ap
245245
return pendingWorkspaceRuns(ctx, ap)
246246
}
247247
tfeVersion := ap.tfClient.Client.RemoteTFEVersion()
248-
version, err := parseTFEVersion(tfeVersion)
248+
useRunsEndpoint, err := validateTFEVersion(tfeVersion)
249249
if err != nil {
250250
// If the TFE version parsing fails, do not return the error here and proceed further.
251251
// In this case, a legacy algorithm will be taken.
@@ -254,7 +254,7 @@ func (r *AgentPoolReconciler) reconcileAgentAutoscaling(ctx context.Context, ap
254254
}
255255
// In TFE version v202409-1, a new API endpoint was introduced.
256256
// It now allows retrieving a list of runs for the organization.
257-
if version >= 2024091 {
257+
if useRunsEndpoint {
258258
ap.log.Info("Reconcile Agent Autoscaling", "msg", fmt.Sprintf("Proceeding with the new algorithm based on the detected TFE version %s", tfeVersion))
259259
return pendingWorkspaceRuns(ctx, ap)
260260
}

internal/controller/helpers.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,34 @@ func secretKeyRef(ctx context.Context, c client.Client, nn types.NamespacedName,
100100
return "", fmt.Errorf("unable to find key=%q in secret=%q namespace=%q", key, nn.Name, nn.Namespace)
101101
}
102102

103-
func parseTFEVersion(version string) (int, error) {
103+
func validateTFEVersion(version string) (bool, error) {
104+
// For versions 1.0.0 and 1.0.1 version string will be empty
105+
if version == "" {
106+
return true, nil
107+
}
108+
109+
// Check for the version format vYYYYMM-N (e.g., v202310-1)
104110
versionRegexp := regexp.MustCompile(`^v([0-9]{6})-([0-9]{1})$`)
105111
matches := versionRegexp.FindStringSubmatch(version)
106112
if len(matches) == 3 {
107-
return strconv.Atoi(matches[1] + matches[2])
113+
dateVersion, err := strconv.Atoi(matches[1] + matches[2])
114+
if err != nil {
115+
return false, err
116+
}
117+
if dateVersion >= 2024091 {
118+
return true, nil
119+
}
120+
}
121+
122+
// Check for the version format vX.Y.Z (e.g., v1.2.3) or X.Y.Z (e.g., 1.2.3)
123+
isASemVer, err := regexp.MatchString(`v?([0-9]+)\.([0-9]+)\.([0-9]+)`, version)
124+
if err != nil {
125+
return false, err
126+
}
127+
if isASemVer {
128+
return true, nil
108129
}
109130

110-
return 0, fmt.Errorf("malformed TFE version %s", version)
131+
// If the version does not match any of the expected formats, return an error
132+
return false, fmt.Errorf("malformed TFE version %s", version)
111133
}

internal/controller/helpers_test.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,49 @@ var _ = Describe("Helpers", Label("Unit"), func() {
200200
})
201201
})
202202

203-
Context("ParseTFEVersion", func() {
203+
Context("ValidateTFEVersion", func() {
204204
It("Valid TFE version", func() {
205205
version := "v202502-1"
206-
v, err := parseTFEVersion(version)
206+
answer, err := validateTFEVersion(version)
207207
Expect(err).To(Succeed())
208-
Expect(v).To(Equal(2025021))
208+
Expect(answer).To(Equal(true))
209209
})
210210
It("Invalid TFE version", func() {
211211
version := "202502-1"
212-
_, err := parseTFEVersion(version)
212+
answer, err := validateTFEVersion(version)
213213
Expect(err).ToNot(Succeed())
214+
Expect(answer).To(Equal(false))
215+
214216
})
215217
It("Empty TFE version", func() {
216218
version := ""
217-
_, err := parseTFEVersion(version)
219+
answer, err := validateTFEVersion(version)
220+
Expect(err).To(Succeed())
221+
Expect(answer).To(Equal(true))
222+
})
223+
It("New valid TFE version", func() {
224+
version := "1.0.0"
225+
answer, err := validateTFEVersion(version)
226+
Expect(err).To(Succeed())
227+
Expect(answer).To(Equal(true))
228+
})
229+
It("New valid TFE version 2", func() {
230+
version := "v1.0.1"
231+
answer, err := validateTFEVersion(version)
232+
Expect(err).To(Succeed())
233+
Expect(answer).To(Equal(true))
234+
})
235+
It("New invalid TFE version", func() {
236+
version := "1.0"
237+
answer, err := validateTFEVersion(version)
238+
Expect(err).ToNot(Succeed())
239+
Expect(answer).To(Equal(false))
240+
})
241+
It("New invalid TFE version 2", func() {
242+
version := "v1.0"
243+
answer, err := validateTFEVersion(version)
218244
Expect(err).ToNot(Succeed())
245+
Expect(answer).To(Equal(false))
219246
})
220247
})
221248
})

0 commit comments

Comments
 (0)