From 6fc46469619fe8b693e3d04fe933ab3886d71c80 Mon Sep 17 00:00:00 2001 From: Anya Krupp <18508181+cherchezlafemme@users.noreply.github.com> Date: Wed, 6 Sep 2023 03:04:39 -0700 Subject: [PATCH] Update nats to latest set up Signed-off-by: Anya Krupp <18508181+cherchezlafemme@users.noreply.github.com> --- .devcontainer/devcontainer.json | 1 + .devcontainer/scripts/nats_account.sh | 10 ++++++++ .devcontainer/scripts/nats_init.sh | 3 --- README.md | 1 + chart/location-api/templates/api-config.yaml | 11 +++++++-- chart/location-api/templates/deployment.yaml | 9 +++++++- chart/location-api/values.yaml | 24 ++++++++++++++++---- go.mod | 6 ++--- go.sum | 18 +++++---------- 9 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 .devcontainer/scripts/nats_account.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 03e8dc0..7b65702 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -27,6 +27,7 @@ ] } }, + "postCreateCommand": [".devcontainer/scripts/nats_account.sh"], "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {} } diff --git a/.devcontainer/scripts/nats_account.sh b/.devcontainer/scripts/nats_account.sh new file mode 100644 index 0000000..37ca2ce --- /dev/null +++ b/.devcontainer/scripts/nats_account.sh @@ -0,0 +1,10 @@ +#!/bin/bash + + +sudo chown -Rh vscode:vscode $WORKSPACE_ROOT/.devcontainer/nsc + +echo "Dumping NATS user creds file" +nsc --data-dir=$WORKSPACE_ROOT/.devcontainer/nsc/nats/nsc/stores generate creds -a LOC -n USER > /tmp/user.creds + +echo "Dumping NATS sys creds file" +nsc --data-dir=$WORKSPACE_ROOT/.devcontainer/nsc/nats/nsc/stores generate creds -a SYS -n sys > /tmp/sys.creds \ No newline at end of file diff --git a/.devcontainer/scripts/nats_init.sh b/.devcontainer/scripts/nats_init.sh index b5a0c5f..d743287 100755 --- a/.devcontainer/scripts/nats_init.sh +++ b/.devcontainer/scripts/nats_init.sh @@ -1,7 +1,4 @@ #!/bin/sh - -set -e - # script to bootstrap a nats operator environment if nsc describe operator; then diff --git a/README.md b/README.md index 3b52617..527dbcf 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Provides GraphQL APIs to manage locations - [Development Guide](docs/development.md) - [Contributing](https://infratographer.com/community/contributing/) +- [NATS](https://nats.io/) ### Getting Started diff --git a/chart/location-api/templates/api-config.yaml b/chart/location-api/templates/api-config.yaml index 27a1cdc..3d2f9b5 100644 --- a/chart/location-api/templates/api-config.yaml +++ b/chart/location-api/templates/api-config.yaml @@ -5,8 +5,15 @@ metadata: labels: {{- include "common.labels.standard" . | nindent 4 }} data: - LOCATIONAPI_EVENTS_PUBLISHER_PREFIX: "{{ .Values.api.events.topicPrefix }}" - LOCATIONAPI_EVENTS_PUBLISHER_URL: "{{ .Values.api.events.connectionURL }}" + LOCATIONAPI_EVENTS_NATS_URL: "{{ .Values.api.events.nats.url }}" + LOCATIONAPI_EVENTS_NATS_PUBLISHPREFIX: "{{ .Values.api.events.nats.publishPrefix }}" + LOCATIONAPI_EVENTS_NATS_QUEUEGROUP: "{{ .Values.api.events.nats.queueGroup }}" + LOCATIONAPI_EVENTS_NATS_SOURCE: "{{ .Values.api.events.nats.source }}" + LOCATIONAPI_EVENTS_NATS_CONNECTTIMEOUT: "{{ .Values.api.events.nats.connectTimeout }}" + LOCATIONAPI_EVENTS_NATS_SHUTDOWNTIMEOUT: "{{ .Values.api.events.nats.shutdownTimeout }}" +{{- if .Values.api.events.nats.credsSecretName }} + LOCATIONAPI_EVENTS_NATS_CREDSFILE: "{{ .Values.api.events.nats.credsFile }}" +{{- end }} LOCATIONAPI_OIDC_ENABLED: "{{ .Values.api.oidc.enabled }}" LOCATIONAPI_OIDC_AUDIENCE: "{{ .Values.api.oidc.audience }}" LOCATIONAPI_OIDC_ISSUER: "{{ .Values.api.oidc.issuer }}" diff --git a/chart/location-api/templates/deployment.yaml b/chart/location-api/templates/deployment.yaml index 9b052a3..52e9bd5 100644 --- a/chart/location-api/templates/deployment.yaml +++ b/chart/location-api/templates/deployment.yaml @@ -39,8 +39,15 @@ spec: {{- end }} containers: - name: {{ .Chart.Name }} - {{- if .Values.api.extraEnvVars }} env: + {{- if .Values.api.events.nats.tokenSecretName }} + - name: LOCATIONAPI_EVENTS_NATS_TOKEN + valueFrom: + secretKeyRef: + name: {{ .Values.api.events.nats.tokenSecretName }} + key: token + {{- end }} + {{- if .Values.api.extraEnvVars }} {{- range .Values.api.extraEnvVars }} - name: {{ .name }} value: {{ .value }} diff --git a/chart/location-api/values.yaml b/chart/location-api/values.yaml index 157340f..2f853ca 100644 --- a/chart/location-api/values.yaml +++ b/chart/location-api/values.yaml @@ -42,11 +42,25 @@ api: podSecurityContext: {} securityContext: {} events: - connectionURL: "nats://my-events-cluster.example.com:4222" - auth: - secretName: "" - credsPath: "/nats/creds" - topicPrefix: "com.infratographer" + nats: + # url is the event server connection url + url: "nats://my-events-cluster.example.com:4222" + # publishPrefix is the subscribe event prefix + publishPrefix: "com.infratographer" + # queueGroup defines the events queue group + queueGroup: "" + # source defines the source of the events (defaults to application name) + source: "" + # connectTimeout is event connection timeout + connectTimeout: "10s" + # shutdownTimeout is the shutdown grace period + shutdownTimeout: "5s" + # tokenSecretName is the secret to load the auth token + tokenSecretName: "" + # credsSecretName is the secret to load the creds auth file from + credsSecretName: "" + # credsFile is the location to read the creds file from + credsFile: "/nats/creds" db: uriSecret: "" certSecret: "" diff --git a/go.mod b/go.mod index f50ddae..a611a5c 100644 --- a/go.mod +++ b/go.mod @@ -97,9 +97,9 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/morikuni/aec v1.0.0 // indirect - github.com/nats-io/jwt/v2 v2.4.1 // indirect - github.com/nats-io/nats-server/v2 v2.9.17 // indirect - github.com/nats-io/nats.go v1.27.1 // indirect + github.com/nats-io/jwt/v2 v2.5.0 // indirect + github.com/nats-io/nats-server/v2 v2.9.21 // indirect + github.com/nats-io/nats.go v1.28.0 // indirect github.com/nats-io/nkeys v0.4.4 // indirect github.com/nats-io/nuid v1.0.1 // indirect github.com/oklog/ulid v1.3.1 // indirect diff --git a/go.sum b/go.sum index eda8bf0..127fdb9 100644 --- a/go.sum +++ b/go.sum @@ -112,7 +112,6 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= @@ -391,12 +390,12 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= -github.com/nats-io/jwt/v2 v2.4.1 h1:Y35W1dgbbz2SQUYDPCaclXcuqleVmpbRa7646Jf2EX4= -github.com/nats-io/jwt/v2 v2.4.1/go.mod h1:24BeQtRwxRV8ruvC4CojXlx/WQ/VjuwlYiH+vu/+ibI= -github.com/nats-io/nats-server/v2 v2.9.17 h1:gFpUQ3hqIDJrnqog+Bl5vaXg+RhhYEZIElasEuRn2tw= -github.com/nats-io/nats-server/v2 v2.9.17/go.mod h1:eQysm3xDZmIjfkjr7DuD9DjRFpnxQc2vKVxtEg0Dp6s= -github.com/nats-io/nats.go v1.27.1 h1:OuYnal9aKVSnOzLQIzf7554OXMCG7KbaTkCSBHRcSoo= -github.com/nats-io/nats.go v1.27.1/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc= +github.com/nats-io/jwt/v2 v2.5.0 h1:WQQ40AAlqqfx+f6ku+i0pOVm+ASirD4fUh+oQsiE9Ak= +github.com/nats-io/jwt/v2 v2.5.0/go.mod h1:24BeQtRwxRV8ruvC4CojXlx/WQ/VjuwlYiH+vu/+ibI= +github.com/nats-io/nats-server/v2 v2.9.21 h1:2TBTh0UDE74eNXQmV4HofsmRSCiVN0TH2Wgrp6BD6fk= +github.com/nats-io/nats-server/v2 v2.9.21/go.mod h1:ozqMZc2vTHcNcblOiXMWIXkf8+0lDGAi5wQcG+O1mHU= +github.com/nats-io/nats.go v1.28.0 h1:Th4G6zdsz2d0OqXdfzKLClo6bOfoI/b1kInhRtFIy5c= +github.com/nats-io/nats.go v1.28.0/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc= github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA= github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= @@ -435,8 +434,6 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= -github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sebdah/goldie/v2 v2.5.3 h1:9ES/mNN+HNUbNWpVAlrzuZ7jE+Nrczbj8uFRjM7624Y= @@ -487,8 +484,6 @@ github.com/testcontainers/testcontainers-go v0.21.0 h1:syePAxdeTzfkap+RrJaQZpJQ/ github.com/testcontainers/testcontainers-go v0.21.0/go.mod h1:c1ez3WVRHq7T/Aj+X3TIipFBwkBaNT5iNCY8+1b83Ng= github.com/testcontainers/testcontainers-go/modules/postgres v0.21.0 h1:rFPyTR7pPMiHcDktXwd5iZ+mA1cHH/WRa+knxBcY8wU= github.com/testcontainers/testcontainers-go/modules/postgres v0.21.0/go.mod h1:Uoia8PX1RewxkJTbeXGBK6vgMjlmRbnL/4n0EXH2Z54= -github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= -github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= @@ -504,7 +499,6 @@ github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vb github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/wundergraph/graphql-go-tools v1.63.0 h1:iOFIlKitbzXAdncPhQJ3xQUO1WBbI6w5r+Wktwh2/90= github.com/wundergraph/graphql-go-tools v1.63.0/go.mod h1:Lsg/b4nVfNQLyJE1mjPV73O/JuhhCxH5qmaWQjitVHM= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=