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

🐛 Fall back to cluster identityRef in absence of machine identityRef #1768

Merged
merged 1 commit into from
Jan 10, 2024
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
3 changes: 2 additions & 1 deletion api/v1alpha7/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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 @@ -1228,7 +1228,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 @@ -1032,7 +1032,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