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
6 changes: 4 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ datum-cloud/enhancements#943.
- Side effects are reconciled by the operator, not done in the request.
Every reconcile step must be idempotent and keyed on deterministic names.
- GitHub-derived fields live in `status` and are written only by
`feedback-sync`. The operator owns post `votes` and `delivery`; both use
server-side apply with their own field manager. Staff can only patch
`feedback-sync`. The operator owns post `votes`, `delivery` and
`conditions`; all use server-side apply with their own field manager.
Never apply two of them with the same manager: an apply drops fields its
manager applied before and left out. Staff can only patch
`spec.hidden` on posts.
- `Submission`, `SubmissionReview`, `SecurityReport` and
`SecurityReportTriage` are audited at `Metadata` only (a Milo audit policy
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ webhooks.

## Status

The CRDs are defined and the operator starts. Admission webhooks and
reconcilers are tracked as sub-issues of the epic.
The CRDs are defined. The operator sets owners and reviewers in admission,
and reconciles votes and follows. Submissions, security reports and
attachments are tracked as sub-issues of the epic.

| Resource | Who writes it | Who reads it |
| --- | --- | --- |
Expand Down Expand Up @@ -50,6 +51,13 @@ operator creates them for someone else, and the Security Team logs reports
for external reporters with no owner. The `reviewer` webhook records who
decided on a `SubmissionReview`.

## Votes

- **Admission** (`vote` webhook). A vote or follow needs a post that exists, isn't hidden and isn't merged. A vote also needs a verified email address.
- **`vote` reconciler.** It follows the post for each new voter, then sets `status.subscribed` so a follow the voter deletes isn't recreated. It records the voter's organizations and linked GitHub username in the vote's status; these Milo lookups are best effort. Votes on a deleted post are marked with `feedback.miloapis.com/orphaned-at` and deleted after 30 days unless the post returns.
- **`post-votes` reconciler.** It counts a post's votes from the cache (indexed by `spec.postRef.name`) and applies `status.votes.{total,datum,linked,trendingScore}` with server-side apply as `feedback-operator`. `github` and `githubReactions` belong to `feedback-sync`. `total = datum + github - linked`, where `linked` counts people whose 👍 comes from the GitHub account linked to their vote. Posts with a trending score are re-tallied hourly as votes age.
- **`merge` reconciler.** When `status.mergedInto` is set, it gives each voter and follower the same on the target post, unless they already have one, and deletes the old one.

## Roles

| Role | For |
Expand All @@ -67,7 +75,9 @@ client certificates and get Kubernetes RBAC in Milo (`config/milo/rbac`).

```
cmd/feedback/ operator and version commands
internal/controller/ reconcilers
internal/identity/ who a request comes from, from Milo's user info
internal/milo/ voter lookups in Milo
internal/webhook/ admission webhooks Milo calls
pkg/apis/feedback/ feedback.miloapis.com/v1alpha1 types (CRDs)
config/crd/ generated CRDs, installed in Milo
Expand Down
13 changes: 12 additions & 1 deletion cmd/feedback/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"

"go.miloapis.com/feedback/internal/controller"
"go.miloapis.com/feedback/internal/milo"
"go.miloapis.com/feedback/internal/version"
"go.miloapis.com/feedback/internal/webhook"
feedbackv1alpha1 "go.miloapis.com/feedback/pkg/apis/feedback/v1alpha1"
Expand Down Expand Up @@ -95,6 +97,15 @@ func runOperator(o operatorOptions) error {

webhook.Register(mgr)

users, err := milo.NewClient(miloConfig)
if err != nil {
return fmt.Errorf("creating Milo user client: %w", err)
}
ctx := ctrl.SetupSignalHandler()
if err := controller.Setup(ctx, mgr, controller.Options{Users: users}); err != nil {
return fmt.Errorf("setting up controllers: %w", err)
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
return err
}
Expand All @@ -103,7 +114,7 @@ func runOperator(o operatorOptions) error {
}

log.Info("Starting manager")
return mgr.Start(ctrl.SetupSignalHandler())
return mgr.Start(ctx)
}

// restConfig loads kubeconfig, or the in-cluster config when it is empty.
Expand Down
64 changes: 64 additions & 0 deletions config/crd/bases/feedback.miloapis.com_posts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,70 @@ spec:
type: string
type: array
x-kubernetes-list-type: set
conditions:
description: |-
Conditions are written by the operator. A merged post carries
VotesMoved: whether its votes and follows reached the post at the end
of its merge chain, and if not, why. Posts are public, so messages
never say a post is hidden.
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
delivery:
description: Delivery tracks the post from request to release.
properties:
Expand Down
8 changes: 8 additions & 0 deletions config/milo/rbac/feedback-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ rules:
- apiGroups: [feedback.miloapis.com]
resources: [submissions]
verbs: [delete]
# Voters' organizations and linked GitHub usernames, for staff analytics
# and so a 👍 from the same person isn't counted twice.
- apiGroups: [resourcemanager.miloapis.com]
resources: [organizationmemberships]
verbs: [list]
- apiGroups: [identity.miloapis.com]
resources: [useridentities]
verbs: [list]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
16 changes: 16 additions & 0 deletions config/milo/webhook/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ patches:
- op: replace
path: /webhooks/1/clientConfig/service/namespace
value: feedback-system
- target:
kind: ValidatingWebhookConfiguration
name: validating-webhook-configuration
patch: |-
- op: replace
path: /metadata/name
value: feedback.miloapis.com
- target:
kind: ValidatingWebhookConfiguration
patch: |-
- op: replace
path: /webhooks/0/clientConfig/service/name
value: feedback-operator-webhook
- op: replace
path: /webhooks/0/clientConfig/service/namespace
value: feedback-system
26 changes: 26 additions & 0 deletions config/milo/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,29 @@ webhooks:
resources:
- submissionreviews
sideEffects: None
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: validating-webhook-configuration
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-vote
failurePolicy: Fail
name: vote.feedback.miloapis.com
rules:
- apiGroups:
- feedback.miloapis.com
apiVersions:
- v1alpha1
operations:
- CREATE
resources:
- votes
- subscriptions
sideEffects: None
Loading
Loading