github.com/minio/madmin-go/v2@v2.2.1/update-commands.go (about) 1 // 2 // Copyright (c) 2015-2022 MinIO, Inc. 3 // 4 // This file is part of MinIO Object Storage stack 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU Affero General Public License as 8 // published by the Free Software Foundation, either version 3 of the 9 // License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Affero General Public License for more details. 15 // 16 // You should have received a copy of the GNU Affero General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 package madmin 21 22 import ( 23 "context" 24 "encoding/json" 25 "net/http" 26 "net/url" 27 ) 28 29 // ServerUpdateStatus - contains the response of service update API 30 type ServerUpdateStatus struct { 31 CurrentVersion string `json:"currentVersion"` 32 UpdatedVersion string `json:"updatedVersion"` 33 } 34 35 // ServerUpdate - updates and restarts the MinIO cluster to latest version. 36 // optionally takes an input URL to specify a custom update binary link 37 func (adm *AdminClient) ServerUpdate(ctx context.Context, updateURL string) (us ServerUpdateStatus, err error) { 38 queryValues := url.Values{} 39 queryValues.Set("updateURL", updateURL) 40 41 // Request API to Restart server 42 resp, err := adm.executeMethod(ctx, 43 http.MethodPost, requestData{ 44 relPath: adminAPIPrefix + "/update", 45 queryValues: queryValues, 46 }, 47 ) 48 defer closeResponse(resp) 49 if err != nil { 50 return us, err 51 } 52 53 if resp.StatusCode != http.StatusOK { 54 return us, httpRespToErrorResponse(resp) 55 } 56 57 if err = json.NewDecoder(resp.Body).Decode(&us); err != nil { 58 return us, err 59 } 60 61 return us, nil 62 }