Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ The status will include:
- Git information (branch, commit, last checked time)
- Deployment details (image, runtime, build time, deployer)
- Middleware status (current and available versions, auto-update settings, pending rebuild status)
- Service status (URL and readiness)

## Advanced Use Cases

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

#### Status Conditions

Expand Down
17 changes: 12 additions & 5 deletions api/v1alpha1/function_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ type FunctionSpecRegistry struct {
type FunctionStatus struct {
Name string `json:"name"`

Conditions []metav1.Condition `json:"conditions,omitempty"`
Git FunctionStatusGit `json:"git,omitempty"`
Deployment FunctionStatusDeployment `json:"deployment,omitempty"`
Middleware FunctionStatusMiddleware `json:"middleware,omitempty"`
Service FunctionServiceStatus `json:"service,omitempty"`

History []FunctionStatusHistoryEntry `json:"history,omitempty"`

Git FunctionStatusGit `json:"git,omitempty"`
Deployment FunctionStatusDeployment `json:"deployment,omitempty"`
Middleware FunctionStatusMiddleware `json:"middleware,omitempty"`
History []FunctionStatusHistoryEntry `json:"history,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

type FunctionStatusHistoryEntry struct {
Expand Down Expand Up @@ -112,6 +114,11 @@ type FunctionStatusMiddleware struct {
LastRebuild metav1.Time `json:"lastRebuild,omitempty"`
}

type FunctionServiceStatus struct {
URL string `json:"url,omitempty"`
Ready string `json:"ready,omitempty"` // string, as it can be UNKNOWN too
}

type FunctionStatusMiddlewareAutoUpdate struct {
Enabled bool `json:"enabled"` // no omitempty to have it always shown
Source string `json:"source,omitempty"`
Expand Down
30 changes: 23 additions & 7 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/crd/bases/functions.dev_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ spec:
type: object
name:
type: string
service:
properties:
ready:
type: string
url:
type: string
type: object
required:
- name
type: object
Expand Down
10 changes: 10 additions & 0 deletions internal/controller/function_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ type middlewareUpToDate struct {
currentRevision string
serviceReady string
currentVersion string
serviceUrl string
autoUpdate autoUpdateStatus
}

Expand All @@ -266,6 +267,7 @@ type middlewareOutdated struct {
serviceReady string
currentVersion string
availableVersion string
serviceUrl string
autoUpdate autoUpdateStatus
}

Expand Down Expand Up @@ -297,6 +299,7 @@ func (r *FunctionReconciler) checkMiddlewareState(ctx context.Context, function
currentImage: desc.Image,
currentRevision: desc.Revision,
serviceReady: desc.Ready,
serviceUrl: desc.Route,
currentVersion: desc.Middleware.Version,
autoUpdate: autoUpdate,
}, nil
Expand All @@ -306,6 +309,7 @@ func (r *FunctionReconciler) checkMiddlewareState(ctx context.Context, function
currentImage: desc.Image,
currentRevision: desc.Revision,
serviceReady: desc.Ready,
serviceUrl: desc.Route,
currentVersion: desc.Middleware.Version,
availableVersion: latestVersion,
autoUpdate: autoUpdate,
Expand Down Expand Up @@ -339,6 +343,8 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
function.Status.Middleware.AutoUpdate.Enabled = check.autoUpdate.enabled
function.Status.Middleware.AutoUpdate.Source = check.autoUpdate.source
function.Status.Middleware.PendingRebuild = false
function.Status.Service.URL = check.serviceUrl
function.Status.Service.Ready = check.serviceReady
markServiceStatus(check.serviceReady, function)
function.MarkMiddlewareUpToDate()

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

if !check.autoUpdate.enabled {
Expand Down Expand Up @@ -379,6 +387,8 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
function.Status.Middleware.LastRebuild = metav1.Now()
function.Status.Deployment.ImageBuilt = metav1.Now()
function.Status.Middleware.Available = nil
function.Status.Service.URL = desc.Route
function.Status.Service.Ready = desc.Ready
markServiceStatus(desc.Ready, function)

function.RecordHistoryEvent(fmt.Sprintf("Middleware updated from %q to %q", check.currentVersion, check.availableVersion))
Expand Down
18 changes: 18 additions & 0 deletions internal/controller/function_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,25 @@ var _ = Describe("Function Controller", func() {
Expect(status.Middleware.Available).Should(BeNil())
},
}),
Entry("should populate Service information in the status", reconcileTestCase{
spec: defaultSpec,
configureMocks: func(funcMock *funccli.MockManager, gitMock *git.MockManager) {
funcMock.EXPECT().Describe(mock.Anything, functionName, resourceNamespace).Return(functions.Instance{
Middleware: functions.Middleware{
Version: "v1.0.0",
},
Ready: "true",
Route: "http://example.com",
}, nil)
funcMock.EXPECT().GetLatestMiddlewareVersion(mock.Anything, mock.Anything, mock.Anything).Return("v1.0.0", nil)

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