Upgrade test(LTS): use network area to federate cluster (#19934)

- Join areas
- wait for members alive and validate cross area service discovery
This commit is contained in:
cskh 2023-12-13 20:15:55 -05:00 committed by GitHub
parent 3443db7885
commit 33a90edfab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 9 deletions

View File

@ -171,7 +171,7 @@ node_prefix "" {
policy = "write" policy = "write"
} }
operator = "read" operator = "write"
` `
policy, _, err := acl.PolicyCreate( policy, _, err := acl.PolicyCreate(
&api.ACLPolicy{ &api.ACLPolicy{

View File

@ -12,6 +12,7 @@ import (
"strings" "strings"
"time" "time"
retry "github.com/avast/retry-go"
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
@ -146,6 +147,10 @@ func (s *Sprawl) launchType(firstTime bool, launchPhase LaunchPhase) (launchErr
return fmt.Errorf("waitForPeeringEstablishment: %w", err) return fmt.Errorf("waitForPeeringEstablishment: %w", err)
} }
if err := s.waitForNetworkAreaEstablishment(); err != nil {
return fmt.Errorf("waitForNetworkAreaEstablishment: %w", err)
}
cleanupFuncs = nil // reset cleanupFuncs = nil // reset
return nil return nil
@ -198,7 +203,7 @@ func (s *Sprawl) assignIPAddresses() error {
return fmt.Errorf("unknown network %q", addr.Network) return fmt.Errorf("unknown network %q", addr.Network)
} }
addr.IPAddress = net.IPByIndex(node.Index) addr.IPAddress = net.IPByIndex(node.Index)
s.logger.Info("assign addr", "node", node.Name, "addr", addr.IPAddress, "enabled", !node.Disabled) s.logger.Info("assign addr", "node", node.Name, "addr", addr.IPAddress, "type", addr.Type, "enabled", !node.Disabled)
} }
} }
} }
@ -315,9 +320,19 @@ func (s *Sprawl) createFirstTime() error {
return fmt.Errorf("generator[agents]: %w", err) return fmt.Errorf("generator[agents]: %w", err)
} }
for _, cluster := range s.topology.Clusters { for _, cluster := range s.topology.Clusters {
err := retry.Do(
func() error {
if err := s.waitForClientAntiEntropyOnce(cluster); err != nil { if err := s.waitForClientAntiEntropyOnce(cluster); err != nil {
return fmt.Errorf("create first time - waitForClientAntiEntropyOnce[%s]: %w", cluster.Name, err) return fmt.Errorf("create first time - waitForClientAntiEntropyOnce[%s]: %w", cluster.Name, err)
} }
return nil
},
retry.MaxDelay(5*time.Second),
retry.Attempts(15),
)
if err != nil {
return fmt.Errorf("create first time - waitForClientAntiEntropyOnce[%s]: %w", cluster.Name, err)
}
} }
// Ideally we start services WITH a token initially, so we pre-create them // Ideally we start services WITH a token initially, so we pre-create them
@ -344,6 +359,10 @@ func (s *Sprawl) createFirstTime() error {
if err := s.initPeerings(); err != nil { if err := s.initPeerings(); err != nil {
return fmt.Errorf("initPeerings: %w", err) return fmt.Errorf("initPeerings: %w", err)
} }
if err := s.initNetworkAreas(); err != nil {
return fmt.Errorf("initNetworkAreas: %w", err)
}
return nil return nil
} }

View File

@ -84,7 +84,9 @@ func (g *Generator) generateAgentHCL(node *topology.Node, enableV2, enableV2Tena
b.add("prometheus_retention_time", "168h") b.add("prometheus_retention_time", "168h")
}) })
if !cluster.DisableGossipEncryption {
b.add("encrypt", g.sec.ReadGeneric(node.Cluster, secrets.GossipKey)) b.add("encrypt", g.sec.ReadGeneric(node.Cluster, secrets.GossipKey))
}
{ {
var ( var (

View File

@ -0,0 +1,14 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build !consulent
package sprawl
func (s *Sprawl) initNetworkAreas() error {
return nil
}
func (s *Sprawl) waitForNetworkAreaEstablishment() error {
return nil
}

View File

@ -699,6 +699,7 @@ func compile(logger hclog.Logger, raw *Config, prev *Topology) (*Topology, error
Clusters: clusters, Clusters: clusters,
Images: images, Images: images,
Peerings: raw.Peerings, Peerings: raw.Peerings,
NetworkAreas: raw.NetworkAreas,
} }
if prev != nil { if prev != nil {

View File

@ -35,6 +35,10 @@ type Topology struct {
// Peerings defines the list of pairwise peerings that should be established // Peerings defines the list of pairwise peerings that should be established
// between clusters. // between clusters.
Peerings []*Peering `json:",omitempty"` Peerings []*Peering `json:",omitempty"`
// NetworkAreas defines the list of pairwise network area that should be established
// between clusters.
NetworkAreas []*NetworkArea `json:",omitempty"`
} }
func (t *Topology) DigestExposedProxyPort(netName string, proxyPort int) (bool, error) { func (t *Topology) DigestExposedProxyPort(netName string, proxyPort int) (bool, error) {
@ -100,6 +104,10 @@ type Config struct {
// Peerings defines the list of pairwise peerings that should be established // Peerings defines the list of pairwise peerings that should be established
// between clusters. // between clusters.
Peerings []*Peering Peerings []*Peering
// NetworkAreas defines the list of pairwise NetworkArea that should be established
// between clusters.
NetworkAreas []*NetworkArea
} }
func (c *Config) Cluster(name string) *Cluster { func (c *Config) Cluster(name string) *Cluster {
@ -293,6 +301,10 @@ type Cluster struct {
// Segments is a map of network segment name and the ports // Segments is a map of network segment name and the ports
Segments map[string]int Segments map[string]int
// DisableGossipEncryption disables gossip encryption on the cluster
// Default is false to enable gossip encryption
DisableGossipEncryption bool `json:",omitempty"`
} }
func (c *Cluster) inheritFromExisting(existing *Cluster) { func (c *Cluster) inheritFromExisting(existing *Cluster) {
@ -1055,6 +1067,13 @@ type Peering struct {
Accepting PeerCluster Accepting PeerCluster
} }
// NetworkArea - a pair of clusters that are peered together
// through network area. PeerCluster type is reused here.
type NetworkArea struct {
Primary PeerCluster
Secondary PeerCluster
}
type PeerCluster struct { type PeerCluster struct {
Name string Name string
Partition string Partition string