Skip to content

Commit 1eed677

Browse files
committed
BUILD/MEDIUM: specification: upgrade specification and client-native
Upgrade go-swagger to v0.32.3, and upgrade client-native
1 parent e36a7e4 commit 1eed677

19 files changed

+285
-113
lines changed

cmd/dataplaneapi/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func startServer(cfg *configuration.Configuration, cancelDebugServer context.Can
127127
fmt.Printf("HAProxy Data Plane API %s %s%s\n\n", GitTag, GitCommit, GitDirty)
128128
fmt.Printf("Build from: %s\n", GitRepo)
129129
fmt.Printf("Build date: %s\n\n", BuildTime)
130-
return
130+
return reload
131131
}
132132

133133
var loadMsg []string

configure_data_plane.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
api_errors "github.com/go-openapi/errors"
3737
"github.com/go-openapi/runtime"
3838
"github.com/go-openapi/runtime/middleware"
39-
"github.com/go-openapi/swag"
39+
"github.com/go-openapi/swag/cmdutils"
4040
client_native "github.com/haproxytech/client-native/v6"
4141
"github.com/haproxytech/client-native/v6/models"
4242
"github.com/haproxytech/client-native/v6/options"
@@ -57,7 +57,7 @@ import (
5757
"github.com/haproxytech/dataplaneapi/operations"
5858
"github.com/haproxytech/dataplaneapi/operations/discovery"
5959
"github.com/haproxytech/dataplaneapi/operations/specification"
60-
"github.com/haproxytech/dataplaneapi/operations/version3"
60+
"github.com/haproxytech/dataplaneapi/operations/specification_openapiv3"
6161
"github.com/haproxytech/dataplaneapi/rate"
6262
"github.com/haproxytech/dataplaneapi/resilient"
6363
socket_runtime "github.com/haproxytech/dataplaneapi/runtime"
@@ -89,25 +89,25 @@ func SetServerStartedCallback(callFunc func()) {
8989
func configureFlags(api *operations.DataPlaneAPI) {
9090
cfg := dataplaneapi_config.Get()
9191

92-
haproxyOptionsGroup := swag.CommandLineOptionsGroup{
92+
haproxyOptionsGroup := cmdutils.CommandLineOptionsGroup{
9393
ShortDescription: "HAProxy options",
9494
LongDescription: "Options for configuring haproxy locations.",
9595
Options: &cfg.HAProxy,
9696
}
9797

98-
loggingOptionsGroup := swag.CommandLineOptionsGroup{
98+
loggingOptionsGroup := cmdutils.CommandLineOptionsGroup{
9999
ShortDescription: "Logging options",
100100
LongDescription: "Options for configuring logging.",
101101
Options: &cfg.Logging,
102102
}
103103

104-
syslogOptionsGroup := swag.CommandLineOptionsGroup{
104+
syslogOptionsGroup := cmdutils.CommandLineOptionsGroup{
105105
ShortDescription: "Syslog options",
106106
LongDescription: "Options for configuring syslog logging.",
107107
Options: &cfg.Syslog,
108108
}
109109

110-
api.CommandLineOptionsGroups = make([]swag.CommandLineOptionsGroup, 0, 1)
110+
api.CommandLineOptionsGroups = make([]cmdutils.CommandLineOptionsGroup, 0, 1)
111111
api.CommandLineOptionsGroups = append(api.CommandLineOptionsGroups, haproxyOptionsGroup)
112112
api.CommandLineOptionsGroups = append(api.CommandLineOptionsGroups, loggingOptionsGroup)
113113
api.CommandLineOptionsGroups = append(api.CommandLineOptionsGroups, syslogOptionsGroup)
@@ -1010,7 +1010,7 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
10101010
api.StorageReplaceStorageGeneralFileHandler = &handlers.StorageReplaceStorageGeneralFileHandlerImpl{Client: client, ReloadAgent: ra}
10111011

10121012
// setup OpenAPI v3 specification handler
1013-
api.Version3GetOpenapiv3SpecificationHandler = version3.GetOpenapiv3SpecificationHandlerFunc(func(params version3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
1013+
api.SpecificationOpenapiv3GetOpenapiv3SpecificationHandler = specification_openapiv3.GetOpenapiv3SpecificationHandlerFunc(func(params specification_openapiv3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
10141014
v2 := openapi2.T{}
10151015
v2JSONString := string(SwaggerJSON)
10161016
v2JSONString = strings.ReplaceAll(v2JSONString, "#/definitions", "#/components/schemas")
@@ -1019,7 +1019,7 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
10191019
err = v2.UnmarshalJSON(curatedV2)
10201020
if err != nil {
10211021
e := misc.HandleError(err)
1022-
return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
1022+
return specification_openapiv3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
10231023
}
10241024

10251025
// if host is empty(dynamic hosts), server prop is empty,
@@ -1033,9 +1033,9 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
10331033
v3, err = openapi2conv.ToV3(&v2)
10341034
if err != nil {
10351035
e := misc.HandleError(err)
1036-
return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
1036+
return specification_openapiv3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
10371037
}
1038-
return version3.NewGetOpenapiv3SpecificationOK().WithPayload(v3)
1038+
return specification_openapiv3.NewGetOpenapiv3SpecificationOK().WithPayload(v3)
10391039
})
10401040

10411041
// TODO: do we need a ReloadAgent for SPOE

discovery/aws_service_discovery.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,23 @@ func (a awsServiceDiscovery) AddNode(id string, params ServiceDiscoveryParams) (
5050
var instance *awsInstance
5151
instance, err = newAWSRegionInstance(a.context, aParams, a.client, a.reloadAgent)
5252
if err != nil {
53-
return
53+
return err
5454
}
5555

5656
if err = a.services.Create(id, instance); err != nil {
57-
return
57+
return err
5858
}
5959

6060
if *aParams.Enabled {
6161
instance.start()
6262
}
63-
return
63+
return err
6464
}
6565

6666
func (a awsServiceDiscovery) GetNode(id string) (params ServiceDiscoveryParams, err error) {
6767
var i interface{}
6868
if i, err = a.services.Read(id); err != nil {
69-
return
69+
return params, err
7070
}
7171
return i.(*awsInstance).params, nil
7272
}
@@ -112,6 +112,6 @@ func (a awsServiceDiscovery) UpdateNode(id string, params ServiceDiscoveryParams
112112
ai.update <- struct{}{}
113113
}
114114

115-
return
115+
return err
116116
})
117117
}

discovery/aws_service_discovery_instance.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (a awsService) GetServers() (servers []configuration.ServiceServer) {
102102
Port: port,
103103
})
104104
}
105-
return
105+
return servers
106106
}
107107

108108
func newAWSRegionInstance(ctx context.Context, params *models.AwsRegion, client configuration.Configuration, reloadAgent haproxy.IReloadAgent) (*awsInstance, error) {
@@ -143,7 +143,7 @@ func (a *awsInstance) filterConverter(in []*models.AwsFilters) (out []types.Filt
143143
Values: []string{aws.ToString(l.Value)},
144144
}
145145
}
146-
return
146+
return out
147147
}
148148

149149
func (a *awsInstance) updateTimeout(timeoutSeconds int64) error {
@@ -252,7 +252,7 @@ func (a *awsInstance) updateServices(api *ec2.Client) (err error) {
252252
}, a.filterConverter(a.params.Allowlist)...),
253253
})
254254
if err != nil {
255-
return
255+
return err
256256
}
257257

258258
mapService := make(map[string]*awsService)
@@ -346,7 +346,7 @@ func (a *awsInstance) updateServices(api *ec2.Client) (err error) {
346346
id := aws.ToString(instance.InstanceId)
347347
hash[id] = aws.ToTime(instance.LaunchTime)
348348
}
349-
return
349+
return hash
350350
}(s.instances)
351351
}
352352

@@ -367,7 +367,7 @@ func (a *awsService) instancePortFromEC2(instance types.Instance) (port int, err
367367
return strconv.Atoi(*t.Value)
368368
}
369369
}
370-
return
370+
return port, err
371371
}
372372

373373
func (a *awsInstance) serviceNameFromEC2(instance types.Instance) (string, error) {

discovery/consul_service_discovery.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (c *consulServiceDiscovery) AddNode(id string, params ServiceDiscoveryParam
7474
}
7575

7676
if err = c.consulServices.Create(id, instance); err != nil {
77-
return
77+
return err
7878
}
7979

8080
instance.prevEnabled = *cParams.Enabled
@@ -88,10 +88,10 @@ func (c *consulServiceDiscovery) AddNode(id string, params ServiceDiscoveryParam
8888
func (c *consulServiceDiscovery) GetNode(id string) (p ServiceDiscoveryParams, err error) {
8989
var i interface{}
9090
if i, err = c.consulServices.Read(id); err != nil {
91-
return
91+
return p, err
9292
}
9393
p = i.(*consulInstance).params
94-
return
94+
return p, err
9595
}
9696

9797
func (c *consulServiceDiscovery) GetNodes() (ServiceDiscoveryParams, error) {

discovery/service_discovery_instance_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func createLaunchConfiguration(name *string, client *autoscaling.Client) (err er
191191
ImageId: aws.String(ami),
192192
InstanceType: aws.String("t2.micro"),
193193
})
194-
return
194+
return err
195195
}
196196

197197
func createAutoScalingGroup(instanceId *string, client *autoscaling.Client) (err error) {
@@ -220,7 +220,7 @@ func createAutoScalingGroup(instanceId *string, client *autoscaling.Client) (err
220220
},
221221
},
222222
})
223-
return
223+
return err
224224
}
225225

226226
func checkBackendServers(asgName *string, backendName string, asg *autoscaling.Client, ec2Client *ec2.Client, confClient *configuration.Client) (ok bool) {
@@ -280,7 +280,7 @@ func scaleAutoScalingGroup(asgName *string, desiredCapacity int32, asg *autoscal
280280
AutoScalingGroupName: asgName,
281281
DesiredCapacity: aws.Int32(desiredCapacity),
282282
})
283-
return
283+
return err
284284
}
285285

286286
func checkAutoScalingGroupCapacity(asgName *string, desiredCapacity int32, asg *autoscaling.Client) (err error) {
@@ -301,7 +301,7 @@ func checkAutoScalingGroupCapacity(asgName *string, desiredCapacity int32, asg *
301301
if len(out.AutoScalingGroups[0].Instances) != int(desiredCapacity) {
302302
continue
303303
}
304-
return
304+
return err
305305
}
306306
}
307307
}

discovery/store.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *instanceStore) Update(name string, mutateFn func(obj interface{}) error
4848
}
4949

5050
s.store[name] = o
51-
return
51+
return err
5252
}
5353

5454
func (s *instanceStore) List() (list []interface{}) {
@@ -58,7 +58,7 @@ func (s *instanceStore) List() (list []interface{}) {
5858
for _, i := range s.store {
5959
list = append(list, i)
6060
}
61-
return
61+
return list
6262
}
6363

6464
func NewInstanceStore() Store {
@@ -85,7 +85,7 @@ func (s *instanceStore) Delete(name string) (err error) {
8585
defer s.mu.Unlock()
8686

8787
if _, err = s.get(name); err != nil {
88-
return
88+
return err
8989
}
9090

9191
delete(s.store, name)
@@ -105,5 +105,5 @@ func (s *instanceStore) get(name string) (sd interface{}, err error) {
105105
if !ok {
106106
return nil, errors.New("instance not found")
107107
}
108-
return
108+
return sd, err
109109
}

0 commit comments

Comments
 (0)