Skip to content

Commit

Permalink
Merge pull request #40816 from thaJeztah/fix_api_version_handling
Browse files Browse the repository at this point in the history
swarm: fix API version detection
  • Loading branch information
tiborvass authored Apr 15, 2020
2 parents db669cd + a9d2091 commit f4b0673
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions api/server/router/swarm/cluster_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,13 @@ func (sr *swarmRouter) createService(ctx context.Context, w http.ResponseWriter,

// Get returns "" if the header does not exist
encodedAuth := r.Header.Get("X-Registry-Auth")
cliVersion := r.Header.Get("version")
queryRegistry := false
if cliVersion != "" {
if versions.LessThan(cliVersion, "1.30") {
if v := httputils.VersionFromContext(ctx); v != "" {
if versions.LessThan(v, "1.30") {
queryRegistry = true
}
adjustForAPIVersion(cliVersion, &service)
adjustForAPIVersion(v, &service)
}

resp, err := sr.backend.CreateService(service, encodedAuth, queryRegistry)
if err != nil {
logrus.Errorf("Error creating service %s: %v", service.Name, err)
Expand Down Expand Up @@ -265,13 +263,12 @@ func (sr *swarmRouter) updateService(ctx context.Context, w http.ResponseWriter,
flags.EncodedRegistryAuth = r.Header.Get("X-Registry-Auth")
flags.RegistryAuthFrom = r.URL.Query().Get("registryAuthFrom")
flags.Rollback = r.URL.Query().Get("rollback")
cliVersion := r.Header.Get("version")
queryRegistry := false
if cliVersion != "" {
if versions.LessThan(cliVersion, "1.30") {
if v := httputils.VersionFromContext(ctx); v != "" {
if versions.LessThan(v, "1.30") {
queryRegistry = true
}
adjustForAPIVersion(cliVersion, &service)
adjustForAPIVersion(v, &service)
}

resp, err := sr.backend.UpdateService(vars["id"], version, service, flags, queryRegistry)
Expand Down

0 comments on commit f4b0673

Please sign in to comment.