Skip to content

Commit

Permalink
Cluster MSI follow-up (#3864)
Browse files Browse the repository at this point in the history
* Generate mocks for Azure clients added in cluster MSI PR

* Add other small changes in response to previous PR feedback:

- Get subscription ID from subscription doc instead of a platform MI
- Remove an unused mock controller
  • Loading branch information
kimorris27 authored Sep 26, 2024
1 parent e985b50 commit 7e77b10
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 11 deletions.
10 changes: 2 additions & 8 deletions pkg/cluster/clustermsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/msi-dataplane/pkg/dataplane"
"github.com/Azure/msi-dataplane/pkg/store"

Expand Down Expand Up @@ -116,13 +115,8 @@ func (m *manager) initializeClusterMsiClients(ctx context.Context) error {
return err
}

// Note that we are assuming that all of the platform MIs are in the same subscription.
pwiResourceId, err := arm.ParseResourceID(m.doc.OpenShiftCluster.Properties.PlatformWorkloadIdentityProfile.PlatformWorkloadIdentities[0].ResourceID)
if err != nil {
return err
}

subId := pwiResourceId.SubscriptionID
// Note that we are assuming that all of the platform MIs are in the same subscription as the ARO resource.
subId := m.subscriptionDoc.ID
clientOptions := m.env.Environment().ArmClientOptions()
clusterMsiFederatedIdentityCredentials, err := armmsi.NewFederatedIdentityCredentialsClient(subId, azureCred, clientOptions)
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions pkg/cluster/clustermsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@ func TestClusterMsiSecretName(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
controller := gomock.NewController(t)
defer controller.Finish()

m := manager{
log: logrus.NewEntry(logrus.StandardLogger()),
doc: tt.doc,
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/azureclient/azuresdk/armmsi/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package armmsi

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

// Use source mode to prevent some issues related to generics being present in the interface.
//go:generate rm -rf ../../../../../pkg/util/mocks/azureclient/azuresdk/$GOPACKAGE
//go:generate mockgen -source ./federated_identity_credentials.go -destination=../../../mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE FederatedIdentityCredentialsClient
//go:generate goimports -local=github.com/Azure/ARO-RP -e -w ../../../mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go
9 changes: 9 additions & 0 deletions pkg/util/azureclient/azuresdk/azsecrets/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package azsecrets

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

// Use source mode to prevent some issues related to generics being present in the interface.
//go:generate rm -rf ../../../../../pkg/util/mocks/azureclient/azuresdk/$GOPACKAGE
//go:generate mockgen -source ./client.go -destination=../../../mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE Client
//go:generate goimports -local=github.com/Azure/ARO-RP -e -w ../../../mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go
101 changes: 101 additions & 0 deletions pkg/util/mocks/azureclient/azuresdk/armmsi/armmsi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 130 additions & 0 deletions pkg/util/mocks/azureclient/azuresdk/azsecrets/azsecrets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e77b10

Please sign in to comment.