github.com/minio/madmin-go@v1.7.5/update-commands.go (about)

     1  //
     2  // MinIO Object Storage (c) 2021 MinIO, Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //      http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package madmin
    18  
    19  import (
    20  	"context"
    21  	"encoding/json"
    22  	"net/http"
    23  	"net/url"
    24  )
    25  
    26  // ServerUpdateStatus - contains the response of service update API
    27  type ServerUpdateStatus struct {
    28  	CurrentVersion string `json:"currentVersion"`
    29  	UpdatedVersion string `json:"updatedVersion"`
    30  }
    31  
    32  // ServerUpdate - updates and restarts the MinIO cluster to latest version.
    33  // optionally takes an input URL to specify a custom update binary link
    34  func (adm *AdminClient) ServerUpdate(ctx context.Context, updateURL string) (us ServerUpdateStatus, err error) {
    35  	queryValues := url.Values{}
    36  	queryValues.Set("updateURL", updateURL)
    37  
    38  	// Request API to Restart server
    39  	resp, err := adm.executeMethod(ctx,
    40  		http.MethodPost, requestData{
    41  			relPath:     adminAPIPrefix + "/update",
    42  			queryValues: queryValues,
    43  		},
    44  	)
    45  	defer closeResponse(resp)
    46  	if err != nil {
    47  		return us, err
    48  	}
    49  
    50  	if resp.StatusCode != http.StatusOK {
    51  		return us, httpRespToErrorResponse(resp)
    52  	}
    53  
    54  	if err = json.NewDecoder(resp.Body).Decode(&us); err != nil {
    55  		return us, err
    56  	}
    57  
    58  	return us, nil
    59  }