зеркало из https://github.com/Azure/ARO-RP.git
61 строка
1.8 KiB
Go
61 строка
1.8 KiB
Go
package frontend
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/Azure/ARO-RP/pkg/api"
|
|
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
|
|
"github.com/Azure/ARO-RP/pkg/frontend/middleware"
|
|
)
|
|
|
|
func (f *frontend) postAdminOpenShiftClusterDrainNode(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
log := ctx.Value(middleware.ContextKeyLog).(*logrus.Entry)
|
|
r.URL.Path = filepath.Dir(r.URL.Path)
|
|
|
|
err := f._postAdminOpenShiftClusterDrainNode(ctx, r, log)
|
|
|
|
adminReply(log, w, nil, nil, err)
|
|
}
|
|
|
|
func (f *frontend) _postAdminOpenShiftClusterDrainNode(ctx context.Context, r *http.Request, log *logrus.Entry) error {
|
|
resType, resName, resGroupName := chi.URLParam(r, "resourceType"), chi.URLParam(r, "resourceName"), chi.URLParam(r, "resourceGroupName")
|
|
|
|
vmName := r.URL.Query().Get("vmName")
|
|
err := validateAdminKubernetesObjects(r.Method, nodeResource, "", vmName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
resourceID := strings.TrimPrefix(r.URL.Path, "/admin")
|
|
|
|
dbOpenShiftClusters, err := f.dbGroup.OpenShiftClusters()
|
|
if err != nil {
|
|
return api.NewCloudError(http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", err.Error())
|
|
}
|
|
|
|
doc, err := dbOpenShiftClusters.Get(ctx, resourceID)
|
|
switch {
|
|
case cosmosdb.IsErrorStatusCode(err, http.StatusNotFound):
|
|
return api.NewCloudError(http.StatusNotFound, api.CloudErrorCodeResourceNotFound, "", "The Resource '%s/%s' under resource group '%s' was not found.", resType, resName, resGroupName)
|
|
case err != nil:
|
|
return err
|
|
}
|
|
|
|
k, err := f.kubeActionsFactory(log, f.env, doc.OpenShiftCluster)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return k.DrainNode(ctx, vmName)
|
|
}
|