From aa816dc2a82f4a7ccdc3d30f926227df826a700f Mon Sep 17 00:00:00 2001 From: Caleb Doxsey Date: Tue, 10 Sep 2024 11:31:45 -0600 Subject: [PATCH] core/zero: add organization id and cluster id to bootstrap config (#5275) --- config/config.go | 5 +++++ internal/zero/bootstrap/source.go | 18 ++++++++++-------- .../zero/bootstrap/writers/k8s/secret_test.go | 2 +- pkg/zero/cluster/models.gen.go | 3 +++ pkg/zero/cluster/openapi.yaml | 6 ++++++ 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/config/config.go b/config/config.go index 2fe623fc7..7d23d3e18 100644 --- a/config/config.go +++ b/config/config.go @@ -49,6 +49,11 @@ type Config struct { // MetricsScrapeEndpoints additional metrics endpoints to scrape and provide part of metrics MetricsScrapeEndpoints []MetricsScrapeEndpoint + + // ZeroClusterID is the zero cluster id, only set when in zero mode. + ZeroClusterID string + // ZeroOrganizationID is the zero organization id, only set when in zero mode. + ZeroOrganizationID string } // Clone creates a clone of the config. diff --git a/internal/zero/bootstrap/source.go b/internal/zero/bootstrap/source.go index 2186f622c..ad1bfe657 100644 --- a/internal/zero/bootstrap/source.go +++ b/internal/zero/bootstrap/source.go @@ -55,9 +55,9 @@ func (src *source) OnConfigChange(_ context.Context, l config.ChangeListener) { func (src *source) UpdateBootstrap(ctx context.Context, cfg cluster_api.BootstrapConfig) bool { current := src.cfg.Load() incoming := current.Clone() - applyBootstrapConfig(incoming.Options, &cfg) + applyBootstrapConfig(incoming, &cfg) - if cmp.Equal(incoming.Options, current.Options, cmpOpts...) { + if cmp.Equal(incoming, current, cmpOpts...) { return false } @@ -81,13 +81,15 @@ func (src *source) notifyListeners(ctx context.Context, cfg *config.Config) { } } -func applyBootstrapConfig(dst *config.Options, src *cluster_api.BootstrapConfig) { - dst.SharedKey = base64.StdEncoding.EncodeToString(src.SharedSecret) +func applyBootstrapConfig(dst *config.Config, src *cluster_api.BootstrapConfig) { + dst.Options.SharedKey = base64.StdEncoding.EncodeToString(src.SharedSecret) if src.DatabrokerStorageConnection != nil { - dst.DataBrokerStorageType = config.StoragePostgresName - dst.DataBrokerStorageConnectionString = *src.DatabrokerStorageConnection + dst.Options.DataBrokerStorageType = config.StoragePostgresName + dst.Options.DataBrokerStorageConnectionString = *src.DatabrokerStorageConnection } else { - dst.DataBrokerStorageType = config.StorageInMemoryName - dst.DataBrokerStorageConnectionString = "" + dst.Options.DataBrokerStorageType = config.StorageInMemoryName + dst.Options.DataBrokerStorageConnectionString = "" } + dst.ZeroClusterID = src.ClusterId + dst.ZeroOrganizationID = src.OrganizationId } diff --git a/internal/zero/bootstrap/writers/k8s/secret_test.go b/internal/zero/bootstrap/writers/k8s/secret_test.go index 25c66e522..9b82875ae 100644 --- a/internal/zero/bootstrap/writers/k8s/secret_test.go +++ b/internal/zero/bootstrap/writers/k8s/secret_test.go @@ -95,7 +95,7 @@ func TestSecretWriter(t *testing.T) { "namespace": "pomerium", }, "data": map[string]any{ - "bootstrap.dat": `{"databrokerStorageConnection":"test","sharedSecret":null}`, + "bootstrap.dat": `{"clusterId":"","databrokerStorageConnection":"test","organizationId":"","sharedSecret":null}`, }, }, unstructured) }) diff --git a/pkg/zero/cluster/models.gen.go b/pkg/zero/cluster/models.gen.go index b3716332c..ac33f9099 100644 --- a/pkg/zero/cluster/models.gen.go +++ b/pkg/zero/cluster/models.gen.go @@ -18,8 +18,11 @@ const ( // BootstrapConfig defines model for BootstrapConfig. type BootstrapConfig struct { + ClusterId string `json:"clusterId"` + // DatabrokerStorageConnection databroker storage connection string DatabrokerStorageConnection *string `json:"databrokerStorageConnection,omitempty"` + OrganizationId string `json:"organizationId"` // SharedSecret shared secret SharedSecret []byte `json:"sharedSecret"` diff --git a/pkg/zero/cluster/openapi.yaml b/pkg/zero/cluster/openapi.yaml index e9c43bf71..df1c2d466 100644 --- a/pkg/zero/cluster/openapi.yaml +++ b/pkg/zero/cluster/openapi.yaml @@ -163,14 +163,20 @@ components: BootstrapConfig: type: object properties: + clusterId: + type: string databrokerStorageConnection: type: string description: databroker storage connection string + organizationId: + type: string sharedSecret: type: string format: byte description: shared secret required: + - clusterId + - organizationId - sharedSecret Bundle: