Skip to content

Commit

Permalink
core/config: remove version (#4653)
Browse files Browse the repository at this point in the history
* core/config: remove version

* lint

* fix
  • Loading branch information
calebdoxsey committed Nov 1, 2023
1 parent 6511440 commit 53573dc
Show file tree
Hide file tree
Showing 9 changed files with 761 additions and 800 deletions.
2 changes: 0 additions & 2 deletions config/config.go
Expand Up @@ -27,7 +27,6 @@ type Config struct {
Options *Options
AutoCertificates []tls.Certificate
EnvoyVersion string
Version int64

// DerivedCertificates are TLS certificates derived from the shared secret
DerivedCertificates []tls.Certificate
Expand Down Expand Up @@ -63,7 +62,6 @@ func (cfg *Config) Clone() *Config {
_ = copy(endpoints, cfg.MetricsScrapeEndpoints)

return &Config{
Version: cfg.Version,
Options: newOptions,
AutoCertificates: cfg.AutoCertificates,
EnvoyVersion: cfg.EnvoyVersion,
Expand Down
4 changes: 1 addition & 3 deletions config/config_source.go
Expand Up @@ -114,7 +114,6 @@ func NewFileOrEnvironmentSource(
cfg := &Config{
Options: options,
EnvoyVersion: envoyVersion,
Version: 1,
}

ports, err := netutil.AllocatePorts(6)
Expand Down Expand Up @@ -152,7 +151,6 @@ func (src *FileOrEnvironmentSource) check(ctx context.Context) {
options, err := newOptionsFromConfig(src.configFile)
if err == nil {
cfg = cfg.Clone()
cfg.Version++
cfg.Options = options
metrics.SetConfigInfo(ctx, cfg.Options.Services, "local", cfg.Checksum(), true)
} else {
Expand All @@ -162,7 +160,7 @@ func (src *FileOrEnvironmentSource) check(ctx context.Context) {
src.config = cfg
src.mu.Unlock()

log.Info(ctx).Int64("config-version", cfg.Version).Msg("config: loaded configuration")
log.Info(ctx).Msg("config: loaded configuration")

src.Trigger(ctx, cfg)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/controlplane/server.go
Expand Up @@ -255,7 +255,6 @@ func (srv *Server) Run(ctx context.Context) error {
err := srv.update(ctx, cfg)
if err != nil {
log.Error(ctx).Err(err).
Int64("config-version", cfg.Version).
Msg("controlplane: error updating server with new config")
}
}
Expand Down Expand Up @@ -303,7 +302,7 @@ func (srv *Server) update(ctx context.Context, cfg *config.Config) error {
if err != nil {
return err
}
srv.xdsmgr.Update(ctx, cfg.Version, res)
srv.xdsmgr.Update(ctx, res)
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions internal/controlplane/xds.go
Expand Up @@ -26,7 +26,7 @@ func (srv *Server) buildDiscoveryResources(ctx context.Context) (map[string][]*e

cfg := srv.currentConfig.Load()

log.Info(ctx).Int64("config-version", cfg.Version).Msg("controlplane: building discovery resources")
log.Info(ctx).Msg("controlplane: building discovery resources")

eg, ctx := errgroup.WithContext(ctx)

Expand Down Expand Up @@ -84,7 +84,6 @@ func (srv *Server) buildDiscoveryResources(ctx context.Context) (map[string][]*e
}

log.Info(ctx).
Int64("config-version", cfg.Version).
Int("cluster-count", len(clusterResources)).
Int("listener-count", len(listenerResources)).
Int("route-configuration-count", len(routeConfigurationResources)).
Expand Down
25 changes: 3 additions & 22 deletions internal/controlplane/xdsmgr/xdsmgr.go
Expand Up @@ -3,9 +3,6 @@ package xdsmgr

import (
"context"
"fmt"
"strconv"
"strings"
"sync"

envoy_service_discovery_v3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
Expand Down Expand Up @@ -40,7 +37,7 @@ func NewManager(resources map[string][]*envoy_service_discovery_v3.Resource) *Ma
return &Manager{
signal: signal.New(),

nonce: toNonce(0),
nonce: uuid.New().String(),
resources: resources,
}
}
Expand Down Expand Up @@ -112,7 +109,6 @@ func (mgr *Manager) DeltaAggregatedResources(
case req.GetErrorDetail() != nil:
log.Info(ctx).
Any("error-detail", req.GetErrorDetail()).
Int64("config-version", versionFromNonce(req.GetResponseNonce())).
Msg("xdsmgr: nack")
// a NACK
// - set the client resource versions to the current resource versions
Expand All @@ -122,7 +118,6 @@ func (mgr *Manager) DeltaAggregatedResources(
}
case req.GetResponseNonce() == mgr.nonce:
log.Info(ctx).
Int64("config-version", versionFromNonce(req.GetResponseNonce())).
Msg("xdsmgr: ack")
// an ACK for the last response
// - set the client resource versions to the current resource versions
Expand All @@ -133,7 +128,6 @@ func (mgr *Manager) DeltaAggregatedResources(
default:
// an ACK for a response that's not the last response
log.Info(ctx).
Int64("config-version", versionFromNonce(req.GetResponseNonce())).
Msg("xdsmgr: ack")
}

Expand Down Expand Up @@ -215,7 +209,6 @@ func (mgr *Manager) DeltaAggregatedResources(
return ctx.Err()
case res := <-outgoing:
log.Info(ctx).
Int64("config-version", versionFromNonce(res.GetNonce())).
Int("resource-count", len(res.GetResources())).
Int("removed-resource-count", len(res.GetRemovedResources())).
Msg("xdsmgr: sending resources")
Expand All @@ -238,8 +231,8 @@ func (mgr *Manager) StreamAggregatedResources(

// Update updates the state of resources. If any changes are made they will be pushed to any listening
// streams. For each TypeURL the list of resources should be the complete list of resources.
func (mgr *Manager) Update(ctx context.Context, version int64, resources map[string][]*envoy_service_discovery_v3.Resource) {
nonce := toNonce(version)
func (mgr *Manager) Update(ctx context.Context, resources map[string][]*envoy_service_discovery_v3.Resource) {
nonce := uuid.New().String()

mgr.mu.Lock()
mgr.nonce = nonce
Expand All @@ -248,15 +241,3 @@ func (mgr *Manager) Update(ctx context.Context, version int64, resources map[str

mgr.signal.Broadcast(ctx)
}

func toNonce(version int64) string {
return fmt.Sprintf("%d/%s", version, uuid.New().String())
}

// versionFromNonce parses the version out of the nonce. A missing or invalid version will be returned as 0.
func versionFromNonce(nonce string) (version int64) {
if idx := strings.Index(nonce, "/"); idx > 0 {
version, _ = strconv.ParseInt(nonce[:idx], 10, 64)
}
return version
}
4 changes: 2 additions & 2 deletions internal/controlplane/xdsmgr/xdsmgr_test.go
Expand Up @@ -94,7 +94,7 @@ func TestManager(t *testing.T) {
}, msg.GetResources())
ack(msg.Nonce)

mgr.Update(ctx, 1, map[string][]*envoy_service_discovery_v3.Resource{
mgr.Update(ctx, map[string][]*envoy_service_discovery_v3.Resource{
typeURL: {{Name: "r1", Version: "2"}},
})

Expand All @@ -105,7 +105,7 @@ func TestManager(t *testing.T) {
}, msg.GetResources())
ack(msg.Nonce)

mgr.Update(ctx, 1, map[string][]*envoy_service_discovery_v3.Resource{
mgr.Update(ctx, map[string][]*envoy_service_discovery_v3.Resource{
typeURL: nil,
})

Expand Down
5 changes: 1 addition & 4 deletions internal/databroker/config_source.go
Expand Up @@ -109,9 +109,6 @@ func (src *ConfigSource) rebuild(ctx context.Context, firstTime firstTime) {
// add all the config policies to the list
for _, id := range ids {
cfgpb := src.dbConfigs[id]
if cfgpb.GetVersion() > 0 {
cfg.Version = cfgpb.GetVersion()
}

cfg.Options.ApplySettings(ctx, certsIndex, cfgpb.Settings)
var errCount uint64
Expand Down Expand Up @@ -171,7 +168,7 @@ func (src *ConfigSource) rebuild(ctx context.Context, firstTime firstTime) {
// add the additional policies here since calling `Validate` will reset them.
cfg.Options.AdditionalPolicies = append(cfg.Options.AdditionalPolicies, additionalPolicies...)

log.Info(ctx).Int64("config-version", cfg.Version).Msg("databroker: built new config")
log.Info(ctx).Msg("databroker: built new config")

src.computedConfig = cfg
if !firstTime {
Expand Down

0 comments on commit 53573dc

Please sign in to comment.