Skip to content

Commit 7a3e2c0

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

19 files changed

+291
-97
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
"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"
@@ -88,25 +88,25 @@ func SetServerStartedCallback(callFunc func()) {
8888
func configureFlags(api *operations.DataPlaneAPI) {
8989
cfg := dataplaneapi_config.Get()
9090

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

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

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

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

951951
// setup OpenAPI v3 specification handler
952-
api.Version3GetOpenapiv3SpecificationHandler = version3.GetOpenapiv3SpecificationHandlerFunc(func(params version3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
952+
api.SpecificationOpenapiv3GetOpenapiv3SpecificationHandler = specification_openapiv3.GetOpenapiv3SpecificationHandlerFunc(func(params specification_openapiv3.GetOpenapiv3SpecificationParams, principal interface{}) middleware.Responder {
953953
v2 := openapi2.T{}
954954
v2JSONString := string(SwaggerJSON)
955955
v2JSONString = strings.ReplaceAll(v2JSONString, "#/definitions", "#/components/schemas")
@@ -958,7 +958,7 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
958958
err = v2.UnmarshalJSON(curatedV2)
959959
if err != nil {
960960
e := misc.HandleError(err)
961-
return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
961+
return specification_openapiv3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
962962
}
963963

964964
// if host is empty(dynamic hosts), server prop is empty,
@@ -972,9 +972,9 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
972972
v3, err = openapi2conv.ToV3(&v2)
973973
if err != nil {
974974
e := misc.HandleError(err)
975-
return version3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
975+
return specification_openapiv3.NewGetOpenapiv3SpecificationDefault(int(*e.Code)).WithPayload(e)
976976
}
977-
return version3.NewGetOpenapiv3SpecificationOK().WithPayload(v3)
977+
return specification_openapiv3.NewGetOpenapiv3SpecificationOK().WithPayload(v3)
978978
})
979979

980980
// 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
@@ -95,7 +95,7 @@ func (a awsService) GetServers() (servers []configuration.ServiceServer) {
9595
Port: port,
9696
})
9797
}
98-
return
98+
return servers
9999
}
100100

101101
func newAWSRegionInstance(ctx context.Context, params *models.AwsRegion, client configuration.Configuration, reloadAgent haproxy.IReloadAgent) (*awsInstance, error) {
@@ -136,7 +136,7 @@ func (a *awsInstance) filterConverter(in []*models.AwsFilters) (out []types.Filt
136136
Values: []string{aws.ToString(l.Value)},
137137
}
138138
}
139-
return
139+
return out
140140
}
141141

142142
func (a *awsInstance) updateTimeout(timeoutSeconds int64) error {
@@ -245,7 +245,7 @@ func (a *awsInstance) updateServices(api *ec2.Client) (err error) {
245245
}, a.filterConverter(a.params.Allowlist)...),
246246
})
247247
if err != nil {
248-
return
248+
return err
249249
}
250250

251251
mapService := make(map[string]*awsService)
@@ -339,7 +339,7 @@ func (a *awsInstance) updateServices(api *ec2.Client) (err error) {
339339
id := aws.ToString(instance.InstanceId)
340340
hash[id] = aws.ToTime(instance.LaunchTime)
341341
}
342-
return
342+
return hash
343343
}(s.instances)
344344
}
345345

@@ -360,7 +360,7 @@ func (a *awsService) instancePortFromEC2(instance types.Instance) (port int, err
360360
return strconv.Atoi(*t.Value)
361361
}
362362
}
363-
return
363+
return port, err
364364
}
365365

366366
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)