зеркало из https://github.com/Azure/ARO-RP.git
remove postAdminOpenShiftClusterUpgrade geneva action
This commit is contained in:
Родитель
c351da74c6
Коммит
7771d6dc0d
|
@ -1,44 +0,0 @@
|
|||
package frontend
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"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) postAdminOpenShiftClusterUpgrade(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._postAdminOpenShiftClusterUpgrade(ctx, r, log)
|
||||
|
||||
adminReply(log, w, nil, nil, err)
|
||||
}
|
||||
|
||||
func (f *frontend) _postAdminOpenShiftClusterUpgrade(ctx context.Context, r *http.Request, log *logrus.Entry) error {
|
||||
vars := mux.Vars(r)
|
||||
|
||||
resourceID := strings.TrimPrefix(r.URL.Path, "/admin")
|
||||
|
||||
doc, err := f.db.OpenShiftClusters.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.", vars["resourceType"], vars["resourceName"], vars["resourceGroupName"])
|
||||
case err != nil:
|
||||
return err
|
||||
}
|
||||
|
||||
return f.kubeActionsFactory(log, f.env).ClusterUpgrade(ctx, doc.OpenShiftCluster)
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
package frontend
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
"github.com/Azure/ARO-RP/pkg/database"
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
"github.com/Azure/ARO-RP/pkg/frontend/kubeactions"
|
||||
"github.com/Azure/ARO-RP/pkg/metrics/noop"
|
||||
"github.com/Azure/ARO-RP/pkg/util/clientauthorizer"
|
||||
mock_database "github.com/Azure/ARO-RP/pkg/util/mocks/database"
|
||||
mock_kubeactions "github.com/Azure/ARO-RP/pkg/util/mocks/kubeactions"
|
||||
utiltls "github.com/Azure/ARO-RP/pkg/util/tls"
|
||||
"github.com/Azure/ARO-RP/test/util/listener"
|
||||
)
|
||||
|
||||
func TestAdminUpdate(t *testing.T) {
|
||||
mockSubID := "00000000-0000-0000-0000-000000000000"
|
||||
ctx := context.Background()
|
||||
|
||||
clientkey, clientcerts, err := utiltls.GenerateKeyAndCertificate("client", nil, nil, false, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
serverkey, servercerts, err := utiltls.GenerateKeyAndCertificate("server", nil, nil, false, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pool := x509.NewCertPool()
|
||||
pool.AddCert(servercerts[0])
|
||||
|
||||
cli := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
RootCAs: pool,
|
||||
Certificates: []tls.Certificate{
|
||||
{
|
||||
Certificate: [][]byte{clientcerts[0].Raw},
|
||||
PrivateKey: clientkey,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
type test struct {
|
||||
name string
|
||||
resourceID string
|
||||
mocks func(*test, *mock_database.MockOpenShiftClusters, *mock_kubeactions.MockInterface)
|
||||
wantStatusCode int
|
||||
wantError string
|
||||
}
|
||||
|
||||
for _, tt := range []*test{
|
||||
{
|
||||
name: "basic coverage test",
|
||||
resourceID: fmt.Sprintf("/subscriptions/%s/resourcegroups/resourceGroup/providers/Microsoft.RedHatOpenShift/openShiftClusters/resourceName", mockSubID),
|
||||
mocks: func(tt *test, openshiftClusters *mock_database.MockOpenShiftClusters, kactions *mock_kubeactions.MockInterface) {
|
||||
clusterDoc := &api.OpenShiftClusterDocument{
|
||||
OpenShiftCluster: &api.OpenShiftCluster{
|
||||
ID: "fakeClusterID",
|
||||
Name: "resourceName",
|
||||
Type: "Microsoft.RedHatOpenShift/openshiftClusters",
|
||||
Properties: api.OpenShiftClusterProperties{
|
||||
AROServiceKubeconfig: api.SecureBytes(""),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
openshiftClusters.EXPECT().Get(gomock.Any(), strings.ToLower(tt.resourceID)).Return(clusterDoc, nil)
|
||||
kactions.EXPECT().ClusterUpgrade(gomock.Any(), clusterDoc.OpenShiftCluster).Return(nil)
|
||||
},
|
||||
wantStatusCode: http.StatusOK,
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
defer cli.CloseIdleConnections()
|
||||
|
||||
l := listener.NewListener()
|
||||
defer l.Close()
|
||||
_env := &env.Test{
|
||||
L: l,
|
||||
TestLocation: "eastus",
|
||||
TLSKey: serverkey,
|
||||
TLSCerts: servercerts,
|
||||
}
|
||||
_env.SetAdminClientAuthorizer(clientauthorizer.NewOne(clientcerts[0].Raw))
|
||||
cli.Transport.(*http.Transport).Dial = l.Dial
|
||||
|
||||
controller := gomock.NewController(t)
|
||||
defer controller.Finish()
|
||||
|
||||
kactions := mock_kubeactions.NewMockInterface(controller)
|
||||
openshiftClusters := mock_database.NewMockOpenShiftClusters(controller)
|
||||
tt.mocks(tt, openshiftClusters, kactions)
|
||||
|
||||
f, err := NewFrontend(ctx, logrus.NewEntry(logrus.StandardLogger()), _env, &database.Database{
|
||||
OpenShiftClusters: openshiftClusters,
|
||||
}, api.APIs, &noop.Noop{}, nil, func(*logrus.Entry, env.Interface) kubeactions.Interface {
|
||||
return kactions
|
||||
}, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
go f.Run(ctx, nil, nil)
|
||||
|
||||
url := fmt.Sprintf("https://server/admin%s/upgrade", tt.resourceID)
|
||||
req, err := http.NewRequest(http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header = http.Header{
|
||||
"Content-Type": []string{"application/json"},
|
||||
}
|
||||
resp, err := cli.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != tt.wantStatusCode {
|
||||
t.Error(resp.StatusCode)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if tt.wantError != "" {
|
||||
cloudErr := &api.CloudError{StatusCode: resp.StatusCode}
|
||||
err = json.Unmarshal(b, &cloudErr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if cloudErr.Error() != tt.wantError {
|
||||
t.Error(cloudErr)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -197,12 +197,6 @@ func (f *frontend) authenticatedRoutes(r *mux.Router) {
|
|||
s.Methods(http.MethodPost).HandlerFunc(f.postAdminKubernetesObjects).Name("postAdminKubernetesObjects")
|
||||
s.Methods(http.MethodDelete).HandlerFunc(f.deleteAdminKubernetesObjects).Name("deleteAdminKubernetesObjects")
|
||||
|
||||
s = r.
|
||||
Path("/admin/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}/upgrade").
|
||||
Subrouter()
|
||||
|
||||
s.Methods(http.MethodPost).HandlerFunc(f.postAdminOpenShiftClusterUpgrade).Name("postAdminOpenShiftClusterUpgrade")
|
||||
|
||||
s = r.
|
||||
Path("/admin/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}/resources").
|
||||
Subrouter()
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
configv1 "github.com/openshift/api/config/v1"
|
||||
configclient "github.com/openshift/client-go/config/clientset/versioned"
|
||||
"github.com/sirupsen/logrus"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -18,12 +16,10 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/discovery"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/util/retry"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
"github.com/Azure/ARO-RP/pkg/env"
|
||||
"github.com/Azure/ARO-RP/pkg/util/restconfig"
|
||||
"github.com/Azure/ARO-RP/pkg/util/version"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
|
@ -31,7 +27,6 @@ type Interface interface {
|
|||
List(ctx context.Context, oc *api.OpenShiftCluster, groupKind, namespace string) ([]byte, error)
|
||||
CreateOrUpdate(ctx context.Context, oc *api.OpenShiftCluster, obj *unstructured.Unstructured) error
|
||||
Delete(ctx context.Context, oc *api.OpenShiftCluster, groupKind, namespace, name string) error
|
||||
ClusterUpgrade(ctx context.Context, oc *api.OpenShiftCluster) error
|
||||
MustGather(ctx context.Context, oc *api.OpenShiftCluster, w io.Writer) error
|
||||
}
|
||||
|
||||
|
@ -204,32 +199,3 @@ func (ka *kubeactions) Delete(ctx context.Context, oc *api.OpenShiftCluster, gro
|
|||
|
||||
return dyn.Resource(*gvr).Namespace(namespace).Delete(name, &metav1.DeleteOptions{})
|
||||
}
|
||||
|
||||
// ClusterUpgrade posts the new version and image to the cluster-version-operator
|
||||
// which will effect the upgrade.
|
||||
func (ka *kubeactions) ClusterUpgrade(ctx context.Context, oc *api.OpenShiftCluster) error {
|
||||
restconfig, err := restconfig.RestConfig(ka.env, oc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configcli, err := configclient.NewForConfig(restconfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
||||
cv, err := configcli.ConfigV1().ClusterVersions().Get("version", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cv.Spec.DesiredUpdate = &configv1.Update{
|
||||
Version: version.OpenShiftVersion,
|
||||
Image: version.OpenShiftPullSpec,
|
||||
}
|
||||
|
||||
_, err = configcli.ConfigV1().ClusterVersions().Update(cv)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
|
@ -38,20 +38,6 @@ func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder {
|
|||
return m.recorder
|
||||
}
|
||||
|
||||
// ClusterUpgrade mocks base method
|
||||
func (m *MockInterface) ClusterUpgrade(arg0 context.Context, arg1 *api.OpenShiftCluster) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ClusterUpgrade", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ClusterUpgrade indicates an expected call of ClusterUpgrade
|
||||
func (mr *MockInterfaceMockRecorder) ClusterUpgrade(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClusterUpgrade", reflect.TypeOf((*MockInterface)(nil).ClusterUpgrade), arg0, arg1)
|
||||
}
|
||||
|
||||
// CreateOrUpdate mocks base method
|
||||
func (m *MockInterface) CreateOrUpdate(arg0 context.Context, arg1 *api.OpenShiftCluster, arg2 *unstructured.Unstructured) error {
|
||||
m.ctrl.T.Helper()
|
||||
|
|
Загрузка…
Ссылка в новой задаче