-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Azure:master' into master
- Loading branch information
Showing
40 changed files
with
3,146 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package cluster | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
operatorv1 "github.com/openshift/api/operator/v1" | ||
samplesv1 "github.com/openshift/api/samples/v1" | ||
kerrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
|
||
"github.com/Azure/ARO-RP/pkg/api" | ||
mock_env "github.com/Azure/ARO-RP/pkg/util/mocks/env" | ||
mock_samples "github.com/Azure/ARO-RP/pkg/util/mocks/samples" | ||
mock_samplesclient "github.com/Azure/ARO-RP/pkg/util/mocks/samplesclient" | ||
utilerror "github.com/Azure/ARO-RP/test/util/error" | ||
) | ||
|
||
func Test_manager_disableSamples(t *testing.T) { | ||
ctx := context.Background() | ||
samplesConfig := &samplesv1.Config{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{}, | ||
Spec: samplesv1.ConfigSpec{}, | ||
Status: samplesv1.ConfigStatus{}, | ||
} | ||
tests := []struct { | ||
name string | ||
samplesConfig *samplesv1.Config | ||
samplesCRGetError error | ||
samplesCRUpdateError error | ||
expectedMinNumberOfGetCalls int | ||
expectedMaxNumberOfGetCalls int | ||
wantErr string | ||
}{ | ||
{ | ||
name: "samples cr is found and updated", | ||
samplesConfig: samplesConfig, | ||
expectedMinNumberOfGetCalls: 1, | ||
expectedMaxNumberOfGetCalls: 1, | ||
wantErr: "", | ||
}, | ||
{ | ||
name: "samples cr is not found and retried", | ||
samplesCRGetError: kerrors.NewNotFound(schema.GroupResource{}, "samples"), | ||
expectedMinNumberOfGetCalls: 2, | ||
expectedMaxNumberOfGetCalls: 15, | ||
wantErr: " \"samples\" not found", | ||
}, | ||
{ | ||
name: "samples cr update is conflicting and retried", | ||
samplesConfig: samplesConfig, | ||
expectedMinNumberOfGetCalls: 2, | ||
expectedMaxNumberOfGetCalls: 15, | ||
samplesCRUpdateError: kerrors.NewConflict(schema.GroupResource{}, "samples", errors.New("conflict")), | ||
wantErr: "Operation cannot be fulfilled on \"samples\": conflict", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
controller := gomock.NewController(t) | ||
defer controller.Finish() | ||
env := mock_env.NewMockInterface(controller) | ||
samplescli := mock_samplesclient.NewMockInterface(controller) | ||
samplesInterface := mock_samples.NewMockSamplesV1Interface(controller) | ||
configInterface := mock_samples.NewMockConfigInterface(controller) | ||
|
||
env.EXPECT().IsLocalDevelopmentMode().Return(false) | ||
samplescli.EXPECT().SamplesV1().AnyTimes().Return(samplesInterface) | ||
samplesInterface.EXPECT().Configs().AnyTimes().Return(configInterface) | ||
configInterface.EXPECT().Get(gomock.Any(), "cluster", metav1.GetOptions{}). | ||
MinTimes(tt.expectedMinNumberOfGetCalls). | ||
MaxTimes(tt.expectedMaxNumberOfGetCalls). | ||
Return(tt.samplesConfig, tt.samplesCRGetError) | ||
|
||
if tt.samplesConfig != nil { | ||
samplesConfig.Spec.ManagementState = operatorv1.Removed | ||
configInterface.EXPECT().Update(gomock.Any(), samplesConfig, metav1.UpdateOptions{}).AnyTimes().Return(samplesConfig, tt.samplesCRUpdateError) | ||
} | ||
|
||
m := &manager{ | ||
env: env, | ||
doc: &api.OpenShiftClusterDocument{ | ||
OpenShiftCluster: &api.OpenShiftCluster{ | ||
Properties: api.OpenShiftClusterProperties{ | ||
ClusterProfile: api.ClusterProfile{ | ||
ResourceGroupID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clusterRGName", | ||
}, | ||
}, | ||
}, | ||
}, | ||
samplescli: samplescli, | ||
} | ||
|
||
err := m.disableSamples(ctx) | ||
utilerror.AssertErrorMessage(t, err, tt.wantErr) | ||
}) | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
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" | ||
operatorclient "github.com/openshift/client-go/operator/clientset/versioned" | ||
"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" | ||
"github.com/Azure/ARO-RP/pkg/util/restconfig" | ||
) | ||
|
||
func (f *frontend) postAdminOpenShiftClusterEtcdRecovery(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
log := ctx.Value(middleware.ContextKeyLog).(*logrus.Entry) | ||
r.URL.Path = filepath.Dir(r.URL.Path) | ||
|
||
b, err := f._postAdminOpenShiftClusterEtcdRecovery(ctx, r, log) | ||
|
||
if err == nil { | ||
w.Header().Set("Content-Type", "text/plain") | ||
} | ||
|
||
adminReply(log, w, nil, b, err) | ||
} | ||
|
||
// TODO write integration test that skips f.fixEtcd | ||
func (f *frontend) _postAdminOpenShiftClusterEtcdRecovery(ctx context.Context, r *http.Request, log *logrus.Entry) ([]byte, error) { | ||
resType, resName, resGroupName := chi.URLParam(r, "resourceType"), chi.URLParam(r, "resourceName"), chi.URLParam(r, "resourceGroupName") | ||
resourceID := strings.TrimPrefix(r.URL.Path, "/admin") | ||
|
||
doc, err := f.dbOpenShiftClusters.Get(ctx, resourceID) | ||
switch { | ||
case cosmosdb.IsErrorStatusCode(err, http.StatusNotFound): | ||
return []byte{}, api.NewCloudError(http.StatusNotFound, api.CloudErrorCodeResourceNotFound, "", "The Resource '%s/%s' under resource group '%s' was not found.", resType, resName, resGroupName) | ||
case err != nil: | ||
return []byte{}, err | ||
} | ||
kubeActions, err := f.kubeActionsFactory(log, f.env, doc.OpenShiftCluster) | ||
if err != nil { | ||
return []byte{}, api.NewCloudError(http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", err.Error()) | ||
} | ||
|
||
gvr, err := kubeActions.ResolveGVR("Etcd") | ||
if err != nil { | ||
return []byte{}, api.NewCloudError(http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", err.Error()) | ||
} | ||
|
||
err = validateAdminKubernetesObjects(r.Method, gvr, namespaceEtcds, "cluster") | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
|
||
restConfig, err := restconfig.RestConfig(f.env, doc.OpenShiftCluster) | ||
if err != nil { | ||
return []byte{}, api.NewCloudError(http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", err.Error()) | ||
} | ||
|
||
operatorcli, err := operatorclient.NewForConfig(restConfig) | ||
if err != nil { | ||
return []byte{}, api.NewCloudError(http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", err.Error()) | ||
} | ||
|
||
return f.fixEtcd(ctx, log, f.env, doc, kubeActions, operatorcli.OperatorV1().Etcds()) | ||
} |
Oops, something went wrong.