Skip to content

Commit

Permalink
working finalizers and gc logic, updated cue spec generation, server-…
Browse files Browse the repository at this point in the history
…side apply validation
  • Loading branch information
jlarfors committed Mar 6, 2024
1 parent bdbcd1a commit a8b3745
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 75 deletions.
43 changes: 32 additions & 11 deletions cmd/hzctl/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

type deleteCmdOptions struct {
filename string
key string
}

var deleteOpts deleteCmdOptions
Expand All @@ -39,18 +40,31 @@ to quickly create a Cobra application.`,
)
}

if deleteOpts.filename == "" {
return fmt.Errorf("filename is required")
}
clientDeleteOpts := []hz.HTTPDeleteOption{}
if deleteOpts.filename != "" {
yData, err := os.ReadFile(deleteOpts.filename)
if err != nil {
return fmt.Errorf("open file: %w", err)
}

yData, err := os.ReadFile(deleteOpts.filename)
if err != nil {
return fmt.Errorf("open file: %w", err)
jData, err := yaml.YAMLToJSONStrict(yData)
if err != nil {
return fmt.Errorf("convert yaml to json: %w", err)
}
clientDeleteOpts = append(
clientDeleteOpts,
hz.WithHTTPDeleteData(jData),
)
}

jData, err := yaml.YAMLToJSONStrict(yData)
if err != nil {
return fmt.Errorf("convert yaml to json: %w", err)
if deleteOpts.key != "" {
objKey, err := hz.ObjectKeyFromString(deleteOpts.key)
if err != nil {
return fmt.Errorf("parse key: %w", err)
}
clientDeleteOpts = append(
clientDeleteOpts,
hz.WithHTTPDeleteKey(objKey),
)
}

client := hz.HTTPClient{
Expand All @@ -60,7 +74,7 @@ to quickly create a Cobra application.`,
}

ctx := context.Background()
if err := client.Delete(ctx, hz.WithHTTPDeleteData(jData)); err != nil {
if err := client.Delete(ctx, clientDeleteOpts...); err != nil {
return fmt.Errorf("delete: %w", err)
}

Expand All @@ -79,4 +93,11 @@ func init() {
"",
"Filename to delete",
)
flags.StringVarP(
&deleteOpts.key,
"key",
"k",
"",
"Key to delete",
)
}
5 changes: 0 additions & 5 deletions cmd/hzctl/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/base64"
"fmt"
"os"

Expand Down Expand Up @@ -36,10 +35,6 @@ to quickly create a Cobra application.`,
if err != nil {
return err
}
creds := base64.StdEncoding.EncodeToString(
[]byte(resp.Credentials),
)
hCtx.Credentials = &creds
hCtx.Session = &resp.Session
config.Add(hCtx)
f, err := os.Create(configFile)
Expand Down
2 changes: 0 additions & 2 deletions examples/greetings/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import (
)

func main() {
// TODO: get NATS credentials and server information.
if err := run(); err != nil {
slog.Error("running", "error", err)
os.Exit(1)

}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/greetings/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestGreeting(t *testing.T) {

select {
case <-timeout:
t.Fatal("timed out waiting for account")
t.Fatal("timed out waiting for greeting")
case <-done:
}
}
2 changes: 1 addition & 1 deletion examples/greetings/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type PortalHandler struct {

func (h *PortalHandler) Router() *chi.Mux {
r := chi.NewRouter()
logger := httplog.NewLogger("horizon", httplog.Options{
logger := httplog.NewLogger("portal-greetings", httplog.Options{
JSON: false,
LogLevel: slog.LevelInfo,
Concise: true,
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ toolchain go1.21.6

require (
cuelang.org/go v0.7.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4 v4.2.1
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1
github.com/a-h/templ v0.2.543
github.com/charmbracelet/huh v0.3.0
github.com/charmbracelet/lipgloss v0.9.1
Expand All @@ -19,6 +23,8 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/gorilla/securecookie v1.1.2
github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5
github.com/microsoft/azure-devops-go-api/azuredevops/v7 v7.1.0
github.com/nats-io/jwt/v2 v2.5.5
github.com/nats-io/nats-server/v2 v2.10.11
github.com/nats-io/nats.go v1.33.1
Expand All @@ -44,6 +50,7 @@ require (
github.com/Antonboom/errname v0.1.12 // indirect
github.com/Antonboom/nilnil v0.1.7 // indirect
github.com/Antonboom/testifylint v1.1.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.2.0 // indirect
Expand Down Expand Up @@ -106,6 +113,7 @@ require (
github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 // indirect
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect
Expand Down Expand Up @@ -136,6 +144,7 @@ require (
github.com/klauspost/compress v1.17.7 // indirect
github.com/kulti/thelper v0.6.3 // indirect
github.com/kunwardeep/paralleltest v1.0.9 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/kyoh86/exportloopref v0.1.11 // indirect
github.com/ldez/gomoddirectives v0.2.3 // indirect
github.com/ldez/tagliatelle v0.5.0 // indirect
Expand Down Expand Up @@ -175,6 +184,7 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/polyfloyd/go-errorlint v1.4.8 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
Expand Down
29 changes: 29 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ github.com/Antonboom/nilnil v0.1.7 h1:ofgL+BA7vlA1K2wNQOsHzLJ2Pw5B5DpWRLdDAVvvTo
github.com/Antonboom/nilnil v0.1.7/go.mod h1:TP+ScQWVEq0eSIxqU8CbdT5DFWoHp0MbP+KMUO1BKYQ=
github.com/Antonboom/testifylint v1.1.2 h1:IdLRermiLRogxY5AumBL4sP0A+qKHQM/AP1Xd7XOTKc=
github.com/Antonboom/testifylint v1.1.2/go.mod h1:9PFi+vWa8zzl4/B/kqmFJcw85ZUv8ReyBzuQCd30+WI=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 h1:lGlwhPtrX6EVml1hO0ivjkUxsSyl4dsiw9qcA1k/3IQ=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1/go.mod h1:RKUqNu35KJYcVG/fqTRqmuXJZYNhYkBrnC/hX7yGbTA=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 h1:sO0/P7g68FrryJzljemN+6GTssUXdANk6aJ7T1ZxnsQ=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1/go.mod h1:h8hyGFDsU5HMivxiS2iYFZsgDbU9OnnJ163x5UGVKYo=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 h1:6oNBlSdi1QqM1PNW7FPA6xOGA5UNsXnkaYZz9vdPGhA=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4 v4.2.1 h1:UPeCRD+XY7QlaGQte2EVI2iOcWvUYA2XY8w5T/8v0NQ=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4 v4.2.1/go.mod h1:oGV6NlB0cvi1ZbYRR2UN44QHxWFyGk+iylgD0qaMXjA=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.0.0 h1:nBy98uKOIfun5z6wx6jwWLrULcM0+cjBalBFZlEZ7CA=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.0.0/go.mod h1:243D9iHbcQXoFUtgHJwL7gl2zx1aDuDMjvBZVGr2uW0=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s=
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 h1:DzHpqpoJVaCgOUdVHxE8QB52S6NiVdDQvGlny1qvPqA=
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
Expand Down Expand Up @@ -164,6 +180,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denis-tingaikin/go-header v0.4.3 h1:tEaZKAlqql6SKCY++utLmkPLd6K8IBM20Ha7UVm+mtU=
github.com/denis-tingaikin/go-header v0.4.3/go.mod h1:0wOCWuN71D5qIgE2nz9KrKmuYBAC2Mra5RassOIQ2/c=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/emicklei/proto v1.10.0 h1:pDGyFRVV5RvV+nkBK9iy3q67FBy9Xa7vwrOTE+g5aGw=
github.com/emicklei/proto v1.10.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -245,6 +263,8 @@ github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJA
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -328,6 +348,7 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
Expand Down Expand Up @@ -401,6 +422,8 @@ github.com/kulti/thelper v0.6.3 h1:ElhKf+AlItIu+xGnI990no4cE2+XaSu1ULymV2Yulxs=
github.com/kulti/thelper v0.6.3/go.mod h1:DsqKShOvP40epevkFrvIwkCMNYxMeTNjdWL4dqWHZ6I=
github.com/kunwardeep/paralleltest v1.0.9 h1:3Sr2IfFNcsMmlqPk1cjTUbJ4zofKPGyHxenwPebgTug=
github.com/kunwardeep/paralleltest v1.0.9/go.mod h1:2C7s65hONVqY7Q5Efj5aLzRCNLjw2h4eMc9EcypGjcY=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/kyoh86/exportloopref v0.1.11 h1:1Z0bcmTypkL3Q4k+IDHMWTcnCliEZcaPiIe0/ymEyhQ=
github.com/kyoh86/exportloopref v0.1.11/go.mod h1:qkV4UF1zGl6EkF1ox8L5t9SwyeBAZ3qLMd6up458uqA=
github.com/ldez/gomoddirectives v0.2.3 h1:y7MBaisZVDYmKvt9/l1mjNCiSA1BVn34U0ObUcJwlhA=
Expand Down Expand Up @@ -444,6 +467,10 @@ github.com/mbilski/exhaustivestruct v1.2.0 h1:wCBmUnSYufAHO6J4AVWY6ff+oxWxsVFrwg
github.com/mbilski/exhaustivestruct v1.2.0/go.mod h1:OeTBVxQWoEmB2J2JCHmXWPJ0aksxSUOUy+nvtVEfzXc=
github.com/mgechev/revive v1.3.7 h1:502QY0vQGe9KtYJ9FpxMz9rL+Fc/P13CI5POL4uHCcE=
github.com/mgechev/revive v1.3.7/go.mod h1:RJ16jUbF0OWC3co/+XTxmFNgEpUPwnnA0BRllX2aDNA=
github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5 h1:YH424zrwLTlyHSH/GzLMJeu5zhYVZSx5RQxGKm1h96s=
github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5/go.mod h1:PoGiBqKSQK1vIfQ+yVaFcGjDySHvym6FM1cNYnwzbrY=
github.com/microsoft/azure-devops-go-api/azuredevops/v7 v7.1.0 h1:mmJCWLe63QvybxhW1iBmQWEaCKdc4SKgALfTNZ+OphU=
github.com/microsoft/azure-devops-go-api/azuredevops/v7 v7.1.0/go.mod h1:mDunUZ1IUJdJIRHvFb+LPBUtxe3AYB5MI6BMXNg8194=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
Expand Down Expand Up @@ -516,6 +543,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
14 changes: 14 additions & 0 deletions pkg/gateway/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,23 @@ func (h *AccountsHandler) servePortal(
account: account,
}
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
// NOTE: this only handles errors returned from the proxy.
// I.e. if an HTTP response is received, then it is not considered
// an error.
w.WriteHeader(http.StatusOK)
_ = portalError(err).Render(r.Context(), w)
}
// This is one idea to handle errors returned from portals.
// Ideally portals should only return 2xx status codes, as per the
// HATEOS way of handling things.
// https://htmx.org/essays/hateoas/
// proxy.ModifyResponse = func(resp *http.Response) error {
// // Modify the response if the status code is not 2xx.
// if resp.StatusCode < 200 || resp.StatusCode >= 300 {
// // Modify the response here to be 2xx for HTMX to render it.
// }
// return nil
// }
proxy.ServeHTTP(w, r)
return
}
Expand Down
20 changes: 13 additions & 7 deletions pkg/gateway/gateway.templ
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gateway

import (
"fmt"
"strings"
"github.com/verifa/horizon/pkg/hz"
"github.com/verifa/horizon/pkg/auth"
)
Expand Down Expand Up @@ -78,12 +78,18 @@ templ nav(userInfo *auth.UserInfo) {
</div>
}

templ portalProxy(account string, actor string, subpath string) {
if subpath == "" {
<div hx-get={ fmt.Sprintf("/accounts/%s/%s", account, actor) } hx-headers='{"HZ-Portal-Load-Request": "true"}' hx-trigger="load" hx-swap="outerHTML"><span class="loading loading-infinity loading-lg"></span></div>
} else {
<div hx-get={ fmt.Sprintf("/accounts/%s/%s/%s", account, actor, subpath) } hx-headers='{"HZ-Portal-Load-Request": "true"}' hx-trigger="load" hx-swap="outerHTML"><span class="loading loading-infinity loading-lg"></span></div>
}
templ portalProxy(account string, portal string, subpath string) {
<div hx-ext="response-targets">
<div
hx-get={ string(templ.URL(strings.Join([]string{"/accounts", account, portal, subpath}, "/"))) }
hx-headers='{"HZ-Portal-Load-Request": "true"}'
hx-trigger="load"
hx-swap="outerHTML"
hx-target-error="this"
>
<span class="loading loading-infinity loading-lg"></span>
</div>
</div>
}

templ loggedOutPage() {
Expand Down
7 changes: 2 additions & 5 deletions pkg/hz/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ func (c *Controller) startReconciler(
return fmt.Errorf("create for consumer: %w", err)
}
cc, err := con.Consume(func(msg jetstream.Msg) {
slog.Info("consumer", "subject", msg.Subject())
kvop := opFromMsg(msg)
if kvop == jetstream.KeyValueDelete {
// If the operation is a KV delete, then the value has been
Expand Down Expand Up @@ -419,7 +418,6 @@ func (c *Controller) handleControlLoop(
msg jetstream.Msg,
ttl time.Duration,
) {
slog.Info("control loop", "key", key)
// Check that the message is the last message for the subject.
// If not, we don't care about it and want to avoid acquiring the lock.
isLast, err := isLastMsg(ctx, kv, msg)
Expand All @@ -441,7 +439,7 @@ func (c *Controller) handleControlLoop(
return
}
// Get the object key from the nats subject / kv key.
objKey, err := objectKeyFromKey(key)
objKey, err := ObjectKeyFromString(key)
if err != nil {
slog.Error("getting object key from key", "key", key, "error", err)
_ = msg.NakWithDelay(time.Second)
Expand Down Expand Up @@ -496,6 +494,7 @@ func (c *Controller) handleControlLoop(
defer cancel()
reconcileResult, reconcileErr = reconciler.Reconcile(ctx, req)
}
slog.Info("reconciling object", "key", key)
go reconcile()

// Setup an auto-ticker for the message, which keeps the message alive and
Expand Down Expand Up @@ -527,8 +526,6 @@ func (c *Controller) handleControlLoop(
}
slog.Error(
"reconcile",
"subject",
msg.Subject(),
"key",
req.Key,
"backoff",
Expand Down
5 changes: 4 additions & 1 deletion pkg/hz/cue.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/format"
"github.com/google/uuid"
"github.com/verifa/horizon/pkg/internal/managedfields"
)

Expand Down Expand Up @@ -155,7 +156,7 @@ func cueEncodeField(
// Handle special types.
iVal := reflect.New(fieldType).Elem().Interface()
switch iVal.(type) {
case time.Time:
case Time, time.Time:
// This was the best attempt at getting formatting for time, but it
// involves importing stuff and complicated things a lot right now.
// importTime := ast.NewImport(nil, "time")
Expand All @@ -168,6 +169,8 @@ func cueEncodeField(
case json.RawMessage:
// Use lattice type for raw message.
return cCtx.BuildExpr(ast.NewIdent("_")), nil
case uuid.UUID:
return cCtx.BuildExpr(ast.NewIdent("string")), nil
case managedfields.FieldsV1:
// Use lattice type for fieldsv1 because it is recursive.
// Would be nice to "solve" recursion in the future...
Expand Down
1 change: 1 addition & 0 deletions pkg/hz/cue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func TestCueDefinition(t *testing.T) {
account: string
name: string
}]
deletionTimestamp?: string
managedFields?: [...{
manager: =~"^[a-zA-Z0-9-_]+$"
fieldsType: =~"^FieldsV1$"
Expand Down
Loading

0 comments on commit a8b3745

Please sign in to comment.