Skip to content

Commit 0e81c50

Browse files
committed
MEDIUM: cluster: add PUT and DELETE methods for cluster
Added a DELETE method to handle removing the cluster settings and PUT method for setting the cluster logging.
1 parent 54257b4 commit 0e81c50

22 files changed

+1577
-83
lines changed

cmd/dataplaneapi/main.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/go-openapi/runtime/security"
3030
flags "github.com/jessevdk/go-flags"
3131

32+
"github.com/haproxytech/client-native/v2/models"
3233
"github.com/haproxytech/client-native/v2/storage"
3334
"github.com/haproxytech/dataplaneapi"
3435
"github.com/haproxytech/dataplaneapi/configuration"
@@ -172,7 +173,8 @@ func startServer(cfg *configuration.Configuration) (reload configuration.AtomicB
172173
}
173174
}
174175

175-
if err = log.InitWithConfiguration(cfg.LogTargets, cfg.Logging, cfg.Syslog); err != nil {
176+
clusterLogTargets := parseClusterLogTargets(cfg)
177+
if err = log.InitWithConfiguration(cfg.LogTargets, cfg.Logging, cfg.Syslog, clusterLogTargets, cfg.Cluster.ID.Load()); err != nil {
176178
fmt.Println(err)
177179
os.Exit(1)
178180
}
@@ -256,3 +258,10 @@ func startServer(cfg *configuration.Configuration) (reload configuration.AtomicB
256258

257259
return reload
258260
}
261+
262+
func parseClusterLogTargets(cfg *configuration.Configuration) []*models.ClusterLogTarget {
263+
if cfg.Mode.Load() == "cluster" && cfg.Cluster.ClusterLogTargets != nil && len(cfg.Cluster.ClusterLogTargets) > 0 {
264+
return cfg.Cluster.ClusterLogTargets
265+
}
266+
return []*models.ClusterLogTarget{}
267+
}

configuration/configuration.go

+22-14
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,22 @@ type APIConfiguration struct {
7676
}
7777

7878
type ClusterConfiguration struct {
79-
ID AtomicString `yaml:"id,omitempty" group:"cluster" save:"true"`
80-
BootstrapKey AtomicString `yaml:"bootstrap_key,omitempty" group:"cluster" save:"true"`
81-
ActiveBootstrapKey AtomicString `yaml:"active_bootstrap_key,omitempty" group:"cluster" save:"true"`
82-
Token AtomicString `yaml:"token,omitempty" group:"cluster" save:"true"`
83-
URL AtomicString `yaml:"url,omitempty" group:"cluster" save:"true"`
84-
Port AtomicInt `yaml:"port,omitempty" group:"cluster" save:"true"`
85-
APIBasePath AtomicString `yaml:"api_base_path,omitempty" group:"cluster" save:"true"`
86-
APINodesPath AtomicString `yaml:"api_nodes_path,omitempty" group:"cluster" save:"true"`
87-
APIRegisterPath AtomicString `yaml:"api_register_path,omitempty" group:"cluster" save:"true"`
88-
StorageDir AtomicString `yaml:"storage_dir,omitempty" group:"cluster" save:"true"`
89-
CertificateDir AtomicString `yaml:"cert_path,omitempty" group:"cluster" save:"true"`
90-
CertificateFetched AtomicBool `yaml:"cert_fetched,omitempty" group:"cluster" save:"true" example:"false"`
91-
Name AtomicString `yaml:"name,omitempty" group:"cluster" save:"true"`
92-
Description AtomicString `yaml:"description,omitempty" group:"cluster" save:"true"`
79+
ID AtomicString `yaml:"id,omitempty" group:"cluster" save:"true"`
80+
BootstrapKey AtomicString `yaml:"bootstrap_key,omitempty" group:"cluster" save:"true"`
81+
ActiveBootstrapKey AtomicString `yaml:"active_bootstrap_key,omitempty" group:"cluster" save:"true"`
82+
Token AtomicString `yaml:"token,omitempty" group:"cluster" save:"true"`
83+
URL AtomicString `yaml:"url,omitempty" group:"cluster" save:"true"`
84+
Port AtomicInt `yaml:"port,omitempty" group:"cluster" save:"true"`
85+
APIBasePath AtomicString `yaml:"api_base_path,omitempty" group:"cluster" save:"true"`
86+
APINodesPath AtomicString `yaml:"api_nodes_path,omitempty" group:"cluster" save:"true"`
87+
APIRegisterPath AtomicString `yaml:"api_register_path,omitempty" group:"cluster" save:"true"`
88+
StorageDir AtomicString `yaml:"storage_dir,omitempty" group:"cluster" save:"true"`
89+
CertificateDir AtomicString `yaml:"cert_path,omitempty" group:"cluster" save:"true"`
90+
CertificateFetched AtomicBool `yaml:"cert_fetched,omitempty" group:"cluster" save:"true" example:"false"`
91+
Name AtomicString `yaml:"name,omitempty" group:"cluster" save:"true"`
92+
Description AtomicString `yaml:"description,omitempty" group:"cluster" save:"true"`
93+
ClusterLogTargets []*models.ClusterLogTarget `yaml:"cluster_log_targets,omitempty" group:"cluster" save:"true"`
94+
ClusterID AtomicString `yaml:"cluster_id,omitempty" group:"cluster" save:"true"`
9395
}
9496

9597
func (c *ClusterConfiguration) Clear() {
@@ -103,6 +105,8 @@ func (c *ClusterConfiguration) Clear() {
103105
c.CertificateFetched.Store(false)
104106
c.Name.Store("")
105107
c.Description.Store("")
108+
c.ClusterID.Store("")
109+
c.ClusterLogTargets = nil
106110
}
107111

108112
type RuntimeData struct {
@@ -269,6 +273,10 @@ func (c *Configuration) Save() error {
269273
cfg := c.storage.Get()
270274
cfg.LogTargets = nil
271275
}
276+
if len(c.Cluster.ClusterLogTargets) == 0 {
277+
cfg := c.storage.Get()
278+
cfg.Cluster.ClusterLogTargets = nil
279+
}
272280
// clean storage data if we are not in cluster mode or preparing to go into that mode
273281
if cfg.Mode.Load() != "cluster" && cfg.Cluster.BootstrapKey.Load() == "" {
274282
storage := cfg.storage.Get()

configuration/configuration_storage.go

+36-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure_data_plane.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,10 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
510510
api.InformationGetInfoHandler = &handlers.GetInfoHandlerImpl{SystemInfo: haproxyOptions.ShowSystemInfo, BuildTime: BuildTime, Version: Version}
511511

512512
// setup cluster handlers
513-
api.DiscoveryGetClusterHandler = &handlers.GetClusterHandlerImpl{Config: cfg}
513+
api.ClusterGetClusterHandler = &handlers.GetClusterHandlerImpl{Config: cfg}
514514
api.ClusterPostClusterHandler = &handlers.CreateClusterHandlerImpl{Client: client, Config: cfg, ReloadAgent: ra}
515+
api.ClusterDeleteClusterHandler = &handlers.DeleteClusterHandlerImpl{Client: client, Config: cfg, ReloadAgent: ra}
516+
api.ClusterEditClusterHandler = &handlers.EditClusterHandlerImpl{Config: cfg}
515517
api.ClusterInitiateCertificateRefreshHandler = &handlers.ClusterInitiateCertificateRefreshHandlerImpl{Config: cfg}
516518

517519
clusterSync := dataplaneapi_config.ClusterSync{ReloadAgent: ra, Context: ctx}

0 commit comments

Comments
 (0)