Skip to content

Commit 520fa7e

Browse files
authored
Add service information in status (#101)
1 parent 60974d8 commit 520fa7e

6 files changed

Lines changed: 73 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ The status will include:
147147
- Git information (branch, commit, last checked time)
148148
- Deployment details (image, runtime, build time, deployer)
149149
- Middleware status (current and available versions, auto-update settings, pending rebuild status)
150+
- Service status (URL and readiness)
150151

151152
## Advanced Use Cases
152153

@@ -325,6 +326,8 @@ make lint
325326
| `middleware.autoUpdate.source` | string | Source of the autoUpdate setting ("function" or "operator") |
326327
| `middleware.pendingRebuild` | boolean | Whether a rebuild is pending due to outdated middleware |
327328
| `middleware.lastRebuild` | timestamp | Last time the function was rebuilt for middleware updates |
329+
| `service.url` | string | URL of the function's service |
330+
| `service.ready` | string | Whether the function's service is ready (e.g., "true", "false", "UNKNOWN") |
328331

329332
#### Status Conditions
330333

api/v1alpha1/function_types.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ type FunctionSpecRegistry struct {
7777
type FunctionStatus struct {
7878
Name string `json:"name"`
7979

80-
Conditions []metav1.Condition `json:"conditions,omitempty"`
80+
Git FunctionStatusGit `json:"git,omitempty"`
81+
Deployment FunctionStatusDeployment `json:"deployment,omitempty"`
82+
Middleware FunctionStatusMiddleware `json:"middleware,omitempty"`
83+
Service FunctionServiceStatus `json:"service,omitempty"`
84+
85+
History []FunctionStatusHistoryEntry `json:"history,omitempty"`
8186

82-
Git FunctionStatusGit `json:"git,omitempty"`
83-
Deployment FunctionStatusDeployment `json:"deployment,omitempty"`
84-
Middleware FunctionStatusMiddleware `json:"middleware,omitempty"`
85-
History []FunctionStatusHistoryEntry `json:"history,omitempty"`
87+
Conditions []metav1.Condition `json:"conditions,omitempty"`
8688
}
8789

8890
type FunctionStatusHistoryEntry struct {
@@ -112,6 +114,11 @@ type FunctionStatusMiddleware struct {
112114
LastRebuild metav1.Time `json:"lastRebuild,omitempty"`
113115
}
114116

117+
type FunctionServiceStatus struct {
118+
URL string `json:"url,omitempty"`
119+
Ready string `json:"ready,omitempty"` // string, as it can be UNKNOWN too
120+
}
121+
115122
type FunctionStatusMiddlewareAutoUpdate struct {
116123
Enabled bool `json:"enabled"` // no omitempty to have it always shown
117124
Source string `json:"source,omitempty"`

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/functions.dev_functions.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ spec:
238238
type: object
239239
name:
240240
type: string
241+
service:
242+
properties:
243+
ready:
244+
type: string
245+
url:
246+
type: string
247+
type: object
241248
required:
242249
- name
243250
type: object

internal/controller/function_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ type middlewareUpToDate struct {
256256
currentRevision string
257257
serviceReady string
258258
currentVersion string
259+
serviceUrl string
259260
autoUpdate autoUpdateStatus
260261
}
261262

@@ -267,6 +268,7 @@ type middlewareOutdated struct {
267268
serviceReady string
268269
currentVersion string
269270
availableVersion string
271+
serviceUrl string
270272
autoUpdate autoUpdateStatus
271273
}
272274

@@ -298,6 +300,7 @@ func (r *FunctionReconciler) checkMiddlewareState(ctx context.Context, function
298300
currentImage: desc.Image,
299301
currentRevision: desc.Revision,
300302
serviceReady: desc.Ready,
303+
serviceUrl: desc.Route,
301304
currentVersion: desc.Middleware.Version,
302305
autoUpdate: autoUpdate,
303306
}, nil
@@ -307,6 +310,7 @@ func (r *FunctionReconciler) checkMiddlewareState(ctx context.Context, function
307310
currentImage: desc.Image,
308311
currentRevision: desc.Revision,
309312
serviceReady: desc.Ready,
313+
serviceUrl: desc.Route,
310314
currentVersion: desc.Middleware.Version,
311315
availableVersion: latestVersion,
312316
autoUpdate: autoUpdate,
@@ -340,6 +344,8 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
340344
function.Status.Middleware.AutoUpdate.Enabled = check.autoUpdate.enabled
341345
function.Status.Middleware.AutoUpdate.Source = check.autoUpdate.source
342346
function.Status.Middleware.PendingRebuild = false
347+
function.Status.Service.URL = check.serviceUrl
348+
function.Status.Service.Ready = check.serviceReady
343349
markServiceStatus(check.serviceReady, function)
344350
function.MarkMiddlewareUpToDate()
345351

@@ -351,6 +357,8 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
351357
function.Status.Middleware.AutoUpdate.Source = check.autoUpdate.source
352358
function.Status.Middleware.Available = ptr.To(check.availableVersion)
353359
function.Status.Middleware.PendingRebuild = false
360+
function.Status.Service.URL = check.serviceUrl
361+
function.Status.Service.Ready = check.serviceReady
354362
markServiceStatus(check.serviceReady, function)
355363

356364
if !check.autoUpdate.enabled {
@@ -380,6 +388,8 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
380388
function.Status.Middleware.LastRebuild = metav1.Now()
381389
function.Status.Deployment.ImageBuilt = metav1.Now()
382390
function.Status.Middleware.Available = nil
391+
function.Status.Service.URL = desc.Route
392+
function.Status.Service.Ready = desc.Ready
383393
markServiceStatus(desc.Ready, function)
384394

385395
function.RecordHistoryEvent(fmt.Sprintf("Middleware updated from %q to %q", check.currentVersion, check.availableVersion))

internal/controller/function_controller_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,25 @@ var _ = Describe("Function Controller", func() {
321321
Expect(status.Middleware.Available).Should(BeNil())
322322
},
323323
}),
324+
Entry("should populate Service information in the status", reconcileTestCase{
325+
spec: defaultSpec,
326+
configureMocks: func(funcMock *funccli.MockManager, gitMock *git.MockManager) {
327+
funcMock.EXPECT().Describe(mock.Anything, functionName, resourceNamespace).Return(functions.Instance{
328+
Middleware: functions.Middleware{
329+
Version: "v1.0.0",
330+
},
331+
Ready: "true",
332+
Route: "http://example.com",
333+
}, nil)
334+
funcMock.EXPECT().GetLatestMiddlewareVersion(mock.Anything, mock.Anything, mock.Anything).Return("v1.0.0", nil)
324335

336+
gitMock.EXPECT().CloneRepository(mock.Anything, "https://github.com/foo/bar", "", "my-branch", mock.Anything).Return(createTmpGitRepo(functions.Function{Name: "func-go"}), nil)
337+
},
338+
statusChecks: func(status *functionsdevv1alpha1.FunctionStatus) {
339+
Expect(status.Service.Ready).To(Equal("true"))
340+
Expect(status.Service.URL).To(Equal("http://example.com"))
341+
},
342+
}),
325343
Entry("should set ServiceReady condition to true when service is ready", reconcileTestCase{
326344
spec: defaultSpec,
327345
configureMocks: func(funcMock *funccli.MockManager, gitMock *git.MockManager) {

0 commit comments

Comments
 (0)