Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shared utility function to check if a cluster is workload identity #3683

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/cluster/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/Azure/ARO-RP/pkg/util/azureclient"
"github.com/Azure/ARO-RP/pkg/util/azureerrors"
"github.com/Azure/ARO-RP/pkg/util/dns"
"github.com/Azure/ARO-RP/pkg/util/iswimi"
"github.com/Azure/ARO-RP/pkg/util/oidcbuilder"
"github.com/Azure/ARO-RP/pkg/util/rbac"
"github.com/Azure/ARO-RP/pkg/util/stringutils"
Expand Down Expand Up @@ -443,7 +444,7 @@ func (m *manager) Delete(ctx context.Context) error {
return err
}

if m.doc.OpenShiftCluster.Properties.ServicePrincipalProfile == nil && m.doc.OpenShiftCluster.Properties.PlatformWorkloadIdentityProfile != nil {
if iswimi.IsWimi(m.doc.OpenShiftCluster.Properties) {
m.log.Printf("deleting OIDC configuration")
blobContainerURL := oidcbuilder.GenerateBlobContainerURL(m.env)
azBlobClient, err := m.rpBlob.GetAZBlobClient(blobContainerURL, &azblob.ClientOptions{})
Expand Down
3 changes: 2 additions & 1 deletion pkg/cluster/deploybaseresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
apisubnet "github.com/Azure/ARO-RP/pkg/api/util/subnet"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/util/arm"
"github.com/Azure/ARO-RP/pkg/util/iswimi"
"github.com/Azure/ARO-RP/pkg/util/oidcbuilder"
"github.com/Azure/ARO-RP/pkg/util/pointerutils"
"github.com/Azure/ARO-RP/pkg/util/stringutils"
Expand All @@ -39,7 +40,7 @@ func (m *manager) createDNS(ctx context.Context) error {
}

func (m *manager) createOIDC(ctx context.Context) error {
if m.doc.OpenShiftCluster.Properties.ServicePrincipalProfile != nil || m.doc.OpenShiftCluster.Properties.PlatformWorkloadIdentityProfile == nil {
if !iswimi.IsWimi(m.doc.OpenShiftCluster.Properties) {
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/frontend/openshiftcluster_putorpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/frontend/middleware"
"github.com/Azure/ARO-RP/pkg/operator"
"github.com/Azure/ARO-RP/pkg/util/iswimi"
"github.com/Azure/ARO-RP/pkg/util/version"
)

Expand Down Expand Up @@ -136,7 +137,7 @@ func (f *frontend) _putOrPatchOpenShiftCluster(ctx context.Context, log *logrus.
// Persist identity URL and tenant ID only for managed/workload identity cluster create
// We don't support updating cluster managed identity after cluster creation
// TODO - use a common function to check if the cluster is a managed/workload identity cluster
kimorris27 marked this conversation as resolved.
Show resolved Hide resolved
if !(doc.OpenShiftCluster.Properties.ServicePrincipalProfile != nil || doc.OpenShiftCluster.Identity == nil) {
if iswimi.IsWimi(doc.OpenShiftCluster.Properties) {
if err := validateIdentityUrl(doc.OpenShiftCluster, putOrPatchClusterParameters.identityURL); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
"github.com/Azure/ARO-RP/pkg/operator/controllers/genevalogging"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
"github.com/Azure/ARO-RP/pkg/util/iswimi"
utilkubernetes "github.com/Azure/ARO-RP/pkg/util/kubernetes"
utilpem "github.com/Azure/ARO-RP/pkg/util/pem"
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
Expand Down Expand Up @@ -468,8 +469,7 @@ func (o *operator) RenewMDSDCertificate(ctx context.Context) error {
}

func (o *operator) EnsureUpgradeAnnotation(ctx context.Context) error {
if o.oc.Properties.PlatformWorkloadIdentityProfile == nil ||
o.oc.Properties.ServicePrincipalProfile != nil {
if !iswimi.IsWimi(o.oc.Properties) {
return nil
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/util/iswimi/iswimi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package iswimi
bitoku marked this conversation as resolved.
Show resolved Hide resolved

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

import "github.com/Azure/ARO-RP/pkg/api"

// IsWimi checks whether a cluster is Workload Identity or classic
kimorris27 marked this conversation as resolved.
Show resolved Hide resolved
func IsWimi(cluster api.OpenShiftClusterProperties) bool {
bitoku marked this conversation as resolved.
Show resolved Hide resolved
if cluster.PlatformWorkloadIdentityProfile == nil || cluster.ServicePrincipalProfile != nil {
slawande2 marked this conversation as resolved.
Show resolved Hide resolved
return false
}
return true
}
45 changes: 45 additions & 0 deletions pkg/util/iswimi/iswimi_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package iswimi

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

import (
"fmt"
"testing"

"github.com/Azure/ARO-RP/pkg/api"
)

func TestIswimi(t *testing.T) {
tests := []struct {
name string
cluster api.OpenShiftClusterProperties
want bool
}{
{
name: "Cluster is Workload Identity",
cluster: api.OpenShiftClusterProperties{
PlatformWorkloadIdentityProfile: &api.PlatformWorkloadIdentityProfile{},
ServicePrincipalProfile: nil,
},
want: true,
},
{
name: "Cluster is Classic",
kimorris27 marked this conversation as resolved.
Show resolved Hide resolved
cluster: api.OpenShiftClusterProperties{
PlatformWorkloadIdentityProfile: nil,
ServicePrincipalProfile: &api.ServicePrincipalProfile{},
},
want: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := IsWimi(test.cluster)
if got != test.want {
t.Error(fmt.Errorf("got != want: %v != %v", got, test.want))
}
})
}
}
Loading