Skip to content

Commit

Permalink
Fall back to cluster identityRef in absence of machine
Browse files Browse the repository at this point in the history
The 'identityRef' attribute is marked as optional but without it we have
no ability to talk to the cloud. In a future API version, we may wish to
make this a required attribute but for now, provide the ability to
retrieve credentials from the cluster in the absence of the machine.

Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin authored and k8s-infra-cherrypick-robot committed May 17, 2024
1 parent aa2296e commit 71f7ea0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion api/v1alpha7/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ type OpenStackMachineSpec struct {
// The server group to assign the machine to
ServerGroupID string `json:"serverGroupID,omitempty"`

// IdentityRef is a reference to a identity to be used when reconciling this cluster
// IdentityRef is a reference to a identity to be used when reconciling this cluster.
// If not specified, the identity ref of the cluster will be used instead.
// +optional
IdentityRef *OpenStackIdentityReference `json:"identityRef,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3849,7 +3849,8 @@ spec:
type: string
identityRef:
description: IdentityRef is a reference to a identity to be
used when reconciling this cluster
used when reconciling this cluster. If not specified, the
identity ref of the cluster will be used instead.
properties:
kind:
description: Kind of the identity. Must be supported by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,9 @@ spec:
type: string
identityRef:
description: IdentityRef is a reference to a identity
to be used when reconciling this cluster
to be used when reconciling this cluster. If not
specified, the identity ref of the cluster will
be used instead.
properties:
kind:
description: Kind of the identity. Must be supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,8 @@ spec:
type: string
identityRef:
description: IdentityRef is a reference to a identity to be used when
reconciling this cluster
reconciling this cluster. If not specified, the identity ref of
the cluster will be used instead.
properties:
kind:
description: Kind of the identity. Must be supported by the infrastructure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,8 @@ spec:
type: string
identityRef:
description: IdentityRef is a reference to a identity to be
used when reconciling this cluster
used when reconciling this cluster. If not specified, the
identity ref of the cluster will be used instead.
properties:
kind:
description: Kind of the identity. Must be supported by
Expand Down
2 changes: 1 addition & 1 deletion controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (r *OpenStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Req
}
}()

scope, err := r.ScopeFactory.NewClientScopeFromMachine(ctx, r.Client, openStackMachine, r.CaCertificates, log)
scope, err := r.ScopeFactory.NewClientScopeFromMachine(ctx, r.Client, openStackMachine, infraCluster, r.CaCertificates, log)
if err != nil {
return reconcile.Result{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scope/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (f *MockScopeFactory) SetClientScopeCreateError(err error) {
f.clientScopeCreateError = err
}

func (f *MockScopeFactory) NewClientScopeFromMachine(_ context.Context, _ client.Client, _ *infrav1.OpenStackMachine, _ []byte, _ logr.Logger) (Scope, error) {
func (f *MockScopeFactory) NewClientScopeFromMachine(_ context.Context, _ client.Client, _ *infrav1.OpenStackMachine, _ *infrav1.OpenStackCluster, _ []byte, _ logr.Logger) (Scope, error) {
if f.clientScopeCreateError != nil {
return nil, f.clientScopeCreateError
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/scope/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type providerScopeFactory struct {
clientCache *cache.LRUExpireCache
}

func (f *providerScopeFactory) NewClientScopeFromMachine(ctx context.Context, ctrlClient client.Client, openStackMachine *infrav1.OpenStackMachine, defaultCACert []byte, logger logr.Logger) (Scope, error) {
func (f *providerScopeFactory) NewClientScopeFromMachine(ctx context.Context, ctrlClient client.Client, openStackMachine *infrav1.OpenStackMachine, openStackCluster *infrav1.OpenStackCluster, defaultCACert []byte, logger logr.Logger) (Scope, error) {
var cloud clientconfig.Cloud
var caCert []byte

Expand All @@ -62,6 +62,12 @@ func (f *providerScopeFactory) NewClientScopeFromMachine(ctx context.Context, ct
if err != nil {
return nil, err
}
} else if openStackCluster.Spec.IdentityRef != nil {
var err error
cloud, caCert, err = getCloudFromSecret(ctx, ctrlClient, openStackCluster.Namespace, openStackCluster.Spec.IdentityRef.Name, openStackCluster.Spec.CloudName)
if err != nil {
return nil, err
}
}

if caCert == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/scope/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewFactory(maxCacheSize int) Factory {

// Factory instantiates a new Scope using credentials from either a cluster or a machine.
type Factory interface {
NewClientScopeFromMachine(ctx context.Context, ctrlClient client.Client, openStackMachine *infrav1.OpenStackMachine, defaultCACert []byte, logger logr.Logger) (Scope, error)
NewClientScopeFromMachine(ctx context.Context, ctrlClient client.Client, openStackMachine *infrav1.OpenStackMachine, openStackCluster *infrav1.OpenStackCluster, defaultCACert []byte, logger logr.Logger) (Scope, error)
NewClientScopeFromCluster(ctx context.Context, ctrlClient client.Client, openStackCluster *infrav1.OpenStackCluster, defaultCACert []byte, logger logr.Logger) (Scope, error)
}

Expand Down

0 comments on commit 71f7ea0

Please sign in to comment.