-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid AdminUpdate panic when Nodes are down (#1972)
* Skip ensureAROOperator and aroDeploymentReady when the IngressProfiles data is missing, esp after cluster VM restarts as part of the update call * Refactor Cluster Manager code to make ensureAROOperator code testable * Add unit test for ensureAROOperator code Co-authored-by: Ulrich Schlueter <[email protected]>
- Loading branch information
1 parent
02d429a
commit f4f2b72
Showing
7 changed files
with
312 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
package cluster | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/Azure/ARO-RP/pkg/api" | ||
mock_deploy "github.com/Azure/ARO-RP/pkg/util/mocks/operator/deploy" | ||
) | ||
|
||
func TestEnsureAROOperator(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
const ( | ||
key = "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/resourceGroup/providers/Microsoft.RedHatOpenShift/openShiftClusters/resourceName1" | ||
) | ||
|
||
for _, tt := range []struct { | ||
name string | ||
doc *api.OpenShiftClusterDocument | ||
mocks func(*mock_deploy.MockOperator) | ||
wantErr string | ||
}{ | ||
{ | ||
name: "create/update success", | ||
doc: &api.OpenShiftClusterDocument{ | ||
Key: strings.ToLower(key), | ||
OpenShiftCluster: &api.OpenShiftCluster{ | ||
ID: key, | ||
Properties: api.OpenShiftClusterProperties{ | ||
IngressProfiles: []api.IngressProfile{ | ||
{ | ||
Visibility: api.VisibilityPublic, | ||
Name: "default", | ||
}, | ||
}, | ||
ProvisioningState: api.ProvisioningStateAdminUpdating, | ||
ClusterProfile: api.ClusterProfile{ | ||
Version: "4.8.18", | ||
}, | ||
NetworkProfile: api.NetworkProfile{ | ||
APIServerPrivateEndpointIP: "1.2.3.4", | ||
}, | ||
}, | ||
}, | ||
}, | ||
mocks: func(dep *mock_deploy.MockOperator) { | ||
dep.EXPECT(). | ||
CreateOrUpdate(gomock.Any()). | ||
Return(nil) | ||
}, | ||
}, | ||
{ | ||
name: "create/update failure", | ||
doc: &api.OpenShiftClusterDocument{ | ||
Key: strings.ToLower(key), | ||
OpenShiftCluster: &api.OpenShiftCluster{ | ||
ID: key, | ||
Properties: api.OpenShiftClusterProperties{ | ||
IngressProfiles: []api.IngressProfile{ | ||
{ | ||
Visibility: api.VisibilityPublic, | ||
Name: "default", | ||
}, | ||
}, | ||
ProvisioningState: api.ProvisioningStateAdminUpdating, | ||
ClusterProfile: api.ClusterProfile{ | ||
Version: "4.8.18", | ||
}, | ||
NetworkProfile: api.NetworkProfile{ | ||
APIServerPrivateEndpointIP: "1.2.3.4", | ||
}, | ||
}, | ||
}, | ||
}, | ||
mocks: func(dep *mock_deploy.MockOperator) { | ||
dep.EXPECT(). | ||
CreateOrUpdate(gomock.Any()). | ||
Return(errors.New("Mock return: CreateFailed")) | ||
}, | ||
|
||
wantErr: "Mock return: CreateFailed", | ||
}, | ||
{ | ||
name: "enriched data not available - skip", | ||
|
||
doc: &api.OpenShiftClusterDocument{ | ||
Key: strings.ToLower(key), | ||
OpenShiftCluster: &api.OpenShiftCluster{ | ||
ID: key, | ||
Properties: api.OpenShiftClusterProperties{ | ||
IngressProfiles: nil, | ||
ProvisioningState: api.ProvisioningStateAdminUpdating, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
controller := gomock.NewController(t) | ||
defer controller.Finish() | ||
|
||
dep := mock_deploy.NewMockOperator(controller) | ||
if tt.mocks != nil { | ||
tt.mocks(dep) | ||
} | ||
|
||
m := &manager{ | ||
log: logrus.NewEntry(logrus.StandardLogger()), | ||
doc: tt.doc, | ||
|
||
aroOperatorDeployer: dep, | ||
} | ||
|
||
err := m.ensureAROOperator(ctx) | ||
if err != nil && err.Error() != tt.wantErr || | ||
err == nil && tt.wantErr != "" { | ||
t.Error(err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAroDeploymentReady(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
const ( | ||
key = "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/resourceGroup/providers/Microsoft.RedHatOpenShift/openShiftClusters/resourceName1" | ||
) | ||
|
||
for _, tt := range []struct { | ||
name string | ||
doc *api.OpenShiftClusterDocument | ||
mocks func(*mock_deploy.MockOperator) | ||
wantRes bool | ||
}{ | ||
{ | ||
name: "create/update success", | ||
doc: &api.OpenShiftClusterDocument{ | ||
Key: strings.ToLower(key), | ||
OpenShiftCluster: &api.OpenShiftCluster{ | ||
ID: key, | ||
Properties: api.OpenShiftClusterProperties{ | ||
IngressProfiles: []api.IngressProfile{ | ||
{ | ||
Visibility: api.VisibilityPublic, | ||
Name: "default", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
mocks: func(dep *mock_deploy.MockOperator) { | ||
dep.EXPECT(). | ||
IsReady(gomock.Any()). | ||
Return(true, nil) | ||
}, | ||
wantRes: true, | ||
}, | ||
{ | ||
name: "enriched data not available - skip", | ||
doc: &api.OpenShiftClusterDocument{ | ||
Key: strings.ToLower(key), | ||
OpenShiftCluster: &api.OpenShiftCluster{ | ||
ID: key, | ||
Properties: api.OpenShiftClusterProperties{ | ||
IngressProfiles: nil, | ||
}, | ||
}, | ||
}, | ||
wantRes: true, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
controller := gomock.NewController(t) | ||
defer controller.Finish() | ||
|
||
dep := mock_deploy.NewMockOperator(controller) | ||
if tt.mocks != nil { | ||
tt.mocks(dep) | ||
} | ||
|
||
m := &manager{ | ||
log: logrus.NewEntry(logrus.StandardLogger()), | ||
doc: tt.doc, | ||
aroOperatorDeployer: dep, | ||
} | ||
|
||
ok, err := m.aroDeploymentReady(ctx) | ||
if err != nil || ok != tt.wantRes { | ||
t.Error(err) | ||
} | ||
|
||
}) | ||
} | ||
} |
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,8 @@ | ||
package deploy | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
//go:generate rm -rf ../../util/mocks/operator/$GOPACKAGE | ||
//go:generate go run ../../../vendor/github.com/golang/mock/mockgen -destination=../../util/mocks/operator/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/operator/$GOPACKAGE Operator | ||
//go:generate go run ../../../vendor/golang.org/x/tools/cmd/goimports -local=github.com/Azure/ARO-RP -e -w ../../util/mocks/operator/$GOPACKAGE/$GOPACKAGE.go |
Oops, something went wrong.