Skip to content

Commit

Permalink
Merge pull request #2093 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…1768-to-release-0.9

[release-0.9] 🐛 Fall back to cluster identityRef in absence of machine identityRef
  • Loading branch information
k8s-ci-robot authored May 17, 2024
2 parents b389ac5 + 71f7ea0 commit 05f8e3d
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 05f8e3d

Please sign in to comment.