Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 14 additions & 1 deletion pkg/api/validate/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ type Subnet struct {
Path string
}

type ServicePrincipalValidator interface {
ValidateServicePrincipal(ctx context.Context, clientID, clientSecret, tenantID string) error
}

// Dynamic validate in the operator context.
type Dynamic interface {
ServicePrincipalValidator

ValidateVnet(ctx context.Context, location string, subnets []Subnet, additionalCIDRs ...string) error
ValidateSubnets(ctx context.Context, oc *api.OpenShiftCluster, subnets []Subnet) error
ValidateProviders(ctx context.Context) error
ValidateServicePrincipal(ctx context.Context, clientID, clientSecret, tenantID string) error
ValidateQuota(ctx context.Context, oc *api.OpenShiftCluster) error
ValidateDiskEncryptionSets(ctx context.Context, oc *api.OpenShiftCluster) error
ValidateEncryptionAtHost(ctx context.Context, oc *api.OpenShiftCluster) error
Expand Down Expand Up @@ -85,6 +90,14 @@ func NewValidator(log *logrus.Entry, env env.Interface, azEnv *azureclient.AROEn
}, nil
}

func NewServicePrincipalValidator(log *logrus.Entry, azEnv *azureclient.AROEnvironment, subscriptionID string, authorizerType AuthorizerType) (ServicePrincipalValidator, error) {
Copy link
Contributor

@troy0820 troy0820 Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func NewServicePrincipalValidator(log *logrus.Entry, azEnv *azureclient.AROEnvironment, subscriptionID string, authorizerType AuthorizerType) (ServicePrincipalValidator, error) {
func NewServicePrincipalValidator(log *logrus.Entry, azEnv *azureclient.AROEnvironment, authorizerType AuthorizerType) (ServicePrincipalValidator, error) {

We are not using the subscriptionID anywhere in this function. I don't think this is necessary for the constructor.

Is this missing the clients necessary to do the ValidateServicePrincipal check that it had when it was a full dynamic validator?

Copy link
Contributor

@troy0820 troy0820 Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, disregard.
Edit: See below comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, @troy0820, I think you were right. subscriptionID is not used anywhere. It is passed into the function and then it dies.

Copy link
Contributor

@troy0820 troy0820 Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nilsanderselde The subscriptionID is passed into this constructor to fulfill the functions that create the rest of the dynamic type, it's just not explicitly set because this happens with functions below on the dynamic struct fields.
Edit: I don't believe that it uses these clients, so the subscriptionID isn't necessary.

providers:          features.NewProvidersClient(azEnv, subscriptionID, authorizer),
spComputeUsage:     compute.NewUsageClient(azEnv, subscriptionID, authorizer),
spNetworkUsage:     network.NewUsageClient(azEnv, subscriptionID, authorizer),
permissions:        authorization.NewPermissionsClient(azEnv, subscriptionID, authorizer),
virtualNetworks:    newVirtualNetworksCache(network.NewVirtualNetworksClient(azEnv, subscriptionID, authorizer)),
diskEncryptionSets: compute.NewDiskEncryptionSetsClient(azEnv, subscriptionID, authorizer),

It doesn't need to be explicitly set because the subscriptionID is necessary for the above functions in the creation of this type.

return &dynamic{
log: log,
authorizerType: authorizerType,
azEnv: azEnv,
}, nil
}

func (dv *dynamic) ValidateVnet(ctx context.Context, location string, subnets []Subnet, additionalCIDRs ...string) error {
if len(subnets) == 0 {
return fmt.Errorf("no subnets provided")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *ServicePrincipalChecker) Check(ctx context.Context) error {
updateFailedCondition(cond, err)
}

spDynamic, err := dynamic.NewValidator(r.log, nil, &azEnv, resource.SubscriptionID, nil, dynamic.AuthorizerClusterServicePrincipal)
spDynamic, err := dynamic.NewServicePrincipalValidator(r.log, &azEnv, resource.SubscriptionID, dynamic.AuthorizerClusterServicePrincipal)
if err != nil {
return err
}
Expand Down