Skip to content

Commit bf5f312

Browse files
authored
Add service information in status (#101)
1 parent 91e9cec commit bf5f312

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
@@ -255,6 +255,7 @@ type middlewareUpToDate struct {
255255
currentRevision string
256256
serviceReady string
257257
currentVersion string
258+
serviceUrl string
258259
autoUpdate autoUpdateStatus
259260
}
260261

@@ -266,6 +267,7 @@ type middlewareOutdated struct {
266267
serviceReady string
267268
currentVersion string
268269
availableVersion string
270+
serviceUrl string
269271
autoUpdate autoUpdateStatus
270272
}
271273

@@ -297,6 +299,7 @@ func (r *FunctionReconciler) checkMiddlewareState(ctx context.Context, function
297299
currentImage: desc.Image,
298300
currentRevision: desc.Revision,
299301
serviceReady: desc.Ready,
302+
serviceUrl: desc.Route,
300303
currentVersion: desc.Middleware.Version,
301304
autoUpdate: autoUpdate,
302305
}, nil
@@ -306,6 +309,7 @@ func (r *FunctionReconciler) checkMiddlewareState(ctx context.Context, function
306309
currentImage: desc.Image,
307310
currentRevision: desc.Revision,
308311
serviceReady: desc.Ready,
312+
serviceUrl: desc.Route,
309313
currentVersion: desc.Middleware.Version,
310314
availableVersion: latestVersion,
311315
autoUpdate: autoUpdate,
@@ -339,6 +343,8 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
339343
function.Status.Middleware.AutoUpdate.Enabled = check.autoUpdate.enabled
340344
function.Status.Middleware.AutoUpdate.Source = check.autoUpdate.source
341345
function.Status.Middleware.PendingRebuild = false
346+
function.Status.Service.URL = check.serviceUrl
347+
function.Status.Service.Ready = check.serviceReady
342348
markServiceStatus(check.serviceReady, function)
343349
function.MarkMiddlewareUpToDate()
344350

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

355363
if !check.autoUpdate.enabled {
@@ -379,6 +387,8 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
379387
function.Status.Middleware.LastRebuild = metav1.Now()
380388
function.Status.Deployment.ImageBuilt = metav1.Now()
381389
function.Status.Middleware.Available = nil
390+
function.Status.Service.URL = desc.Route
391+
function.Status.Service.Ready = desc.Ready
382392
markServiceStatus(desc.Ready, function)
383393

384394
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)