Skip to content

Commit

Permalink
clean up names
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamero committed Oct 20, 2023
1 parent 5d5ece7 commit 532dddc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
18 changes: 12 additions & 6 deletions testing/e2e/clients/aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"golang.org/x/sync/errgroup"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/Azure/aks-app-routing-operator/testing/e2e/infra"
"github.com/Azure/aks-app-routing-operator/testing/e2e/logger"
"github.com/Azure/aks-app-routing-operator/testing/e2e/manifests"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
Expand All @@ -40,6 +39,13 @@ type aks struct {
options map[string]struct{}
}

type AKSAuthType string

const (
AKSAuthTypeManagedIdentity AKSAuthType = "" // MSI is the default
AKSAuthTypeServicePrincipal AKSAuthType = "servicePrincipal"
)

// ServicePrincipal represents all the information needed to use a service principal including
// a fresh set of credentials and the associated application and service principal object ids.
// This representation is intended as read-only as in most cases only one ID is needed to retrieve
Expand Down Expand Up @@ -109,7 +115,7 @@ func LoadAks(id azure.Resource, dnsServiceIp, location, principalId, clientId st

// NewAks creates a new AKS cluster
// spOpts is optional, if nil then the cluster will use MSI
func NewAks(ctx context.Context, subscriptionId, resourceGroup, name, location string, sp ServicePrincipal, authType infra.AuthType, mcOpts ...McOpt) (*aks, error) {
func NewAks(ctx context.Context, subscriptionId, resourceGroup, name, location string, sp ServicePrincipal, authType AKSAuthType, mcOpts ...McOpt) (*aks, error) {
lgr := logger.FromContext(ctx).With("name", name, "resourceGroup", resourceGroup, "location", location)
ctx = logger.WithContext(ctx, lgr)
lgr.Info("starting to create aks")
Expand Down Expand Up @@ -151,12 +157,12 @@ func NewAks(ctx context.Context, subscriptionId, resourceGroup, name, location s

// apply service principal
switch authType {
case infra.AuthTypeServicePrincipal:
case AKSAuthTypeServicePrincipal:
mc.Properties.ServicePrincipalProfile = &armcontainerservice.ManagedClusterServicePrincipalProfile{
ClientID: to.Ptr(sp.ApplicationClientID),
Secret: to.Ptr(sp.ServicePrincipalCredPassword),
}
case infra.AuthTypeManagedIdentity:
case AKSAuthTypeManagedIdentity:
mc.Identity = &armcontainerservice.ManagedClusterIdentity{
Type: to.Ptr(armcontainerservice.ResourceIdentityTypeSystemAssigned),
}
Expand Down Expand Up @@ -206,9 +212,9 @@ func NewAks(ctx context.Context, subscriptionId, resourceGroup, name, location s
var identity *armcontainerservice.UserAssignedIdentity
var principalID, clientID string
switch authType {
case infra.AuthTypeServicePrincipal:
case AKSAuthTypeServicePrincipal:
principalID = sp.ServicePrincipalObjectID
case infra.AuthTypeManagedIdentity:
case AKSAuthTypeManagedIdentity:
ok := false // avoid shadowing
identity, ok = result.Properties.IdentityProfile["kubeletidentity"]
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion testing/e2e/infra/infras.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var Infras = infras{
Location: location,
Suffix: uuid.New().String(),
McOpts: []clients.McOpt{},
AuthType: AuthTypeServicePrincipal,
AuthType: clients.AKSAuthTypeServicePrincipal,
},
}

Expand Down
2 changes: 1 addition & 1 deletion testing/e2e/infra/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (i *infra) Provision(ctx context.Context, tenantId, subscriptionId, applica
AuthType: i.AuthType,
}

if i.AuthType == AuthTypeServicePrincipal {
if i.AuthType == clients.AKSAuthTypeServicePrincipal {
if applicationObjectId == "" {
return ret, logger.Error(lgr, fmt.Errorf("application object id must be provided when provisioning infrastructure with service principal options"))
}
Expand Down
13 changes: 3 additions & 10 deletions testing/e2e/infra/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import (
"github.com/Azure/go-autorest/autorest/azure"
)

type AuthType string

const (
AuthTypeManagedIdentity AuthType = "" // MSI is the default
AuthTypeServicePrincipal AuthType = "servicePrincipal"
)

type infras []infra

type infra struct {
Expand All @@ -30,7 +23,7 @@ type infra struct {
// for resources to be provisioned inside
ResourceGroup, Location string
McOpts []clients.McOpt
AuthType AuthType
AuthType clients.AKSAuthType
ServicePrincipal clients.ServicePrincipal
}

Expand Down Expand Up @@ -102,7 +95,7 @@ type Provisioned struct {
E2eImage string
OperatorImage string
ServicePrincipal clients.ServicePrincipal
AuthType AuthType
AuthType clients.AKSAuthType
}

type LoadableZone struct {
Expand All @@ -129,5 +122,5 @@ type LoadableProvisioned struct {
E2eImage string
OperatorImage string
ServicePrincipal clients.ServicePrincipal
AuthType AuthType
AuthType clients.AKSAuthType
}

0 comments on commit 532dddc

Please sign in to comment.