Skip to content

Commit 08a1ecd

Browse files
committed
Fall back to cluster identityRef in absence of machine
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]>
1 parent 8a49b9f commit 08a1ecd

9 files changed

+21
-9
lines changed

api/v1alpha7/openstackmachine_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ type OpenStackMachineSpec struct {
8989
// The server group to assign the machine to
9090
ServerGroupID string `json:"serverGroupID,omitempty"`
9191

92-
// IdentityRef is a reference to a identity to be used when reconciling this cluster
92+
// IdentityRef is a reference to a identity to be used when reconciling this cluster.
93+
// If not specified, the identity ref of the cluster will be used instead.
9394
// +optional
9495
IdentityRef *OpenStackIdentityReference `json:"identityRef,omitempty"`
9596
}

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3849,7 +3849,8 @@ spec:
38493849
type: string
38503850
identityRef:
38513851
description: IdentityRef is a reference to a identity to be
3852-
used when reconciling this cluster
3852+
used when reconciling this cluster. If not specified, the
3853+
identity ref of the cluster will be used instead.
38533854
properties:
38543855
kind:
38553856
description: Kind of the identity. Must be supported by

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,9 @@ spec:
16951695
type: string
16961696
identityRef:
16971697
description: IdentityRef is a reference to a identity
1698-
to be used when reconciling this cluster
1698+
to be used when reconciling this cluster. If not
1699+
specified, the identity ref of the cluster will
1700+
be used instead.
16991701
properties:
17001702
kind:
17011703
description: Kind of the identity. Must be supported

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,8 @@ spec:
12281228
type: string
12291229
identityRef:
12301230
description: IdentityRef is a reference to a identity to be used when
1231-
reconciling this cluster
1231+
reconciling this cluster. If not specified, the identity ref of
1232+
the cluster will be used instead.
12321233
properties:
12331234
kind:
12341235
description: Kind of the identity. Must be supported by the infrastructure

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ spec:
10321032
type: string
10331033
identityRef:
10341034
description: IdentityRef is a reference to a identity to be
1035-
used when reconciling this cluster
1035+
used when reconciling this cluster. If not specified, the
1036+
identity ref of the cluster will be used instead.
10361037
properties:
10371038
kind:
10381039
description: Kind of the identity. Must be supported by

controllers/openstackmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (r *OpenStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Req
140140
}
141141
}()
142142

143-
scope, err := r.ScopeFactory.NewClientScopeFromMachine(ctx, r.Client, openStackMachine, r.CaCertificates, log)
143+
scope, err := r.ScopeFactory.NewClientScopeFromMachine(ctx, r.Client, openStackMachine, infraCluster, r.CaCertificates, log)
144144
if err != nil {
145145
return reconcile.Result{}, err
146146
}

pkg/scope/mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (f *MockScopeFactory) SetClientScopeCreateError(err error) {
6666
f.clientScopeCreateError = err
6767
}
6868

69-
func (f *MockScopeFactory) NewClientScopeFromMachine(_ context.Context, _ client.Client, _ *infrav1.OpenStackMachine, _ []byte, _ logr.Logger) (Scope, error) {
69+
func (f *MockScopeFactory) NewClientScopeFromMachine(_ context.Context, _ client.Client, _ *infrav1.OpenStackMachine, _ *infrav1.OpenStackCluster, _ []byte, _ logr.Logger) (Scope, error) {
7070
if f.clientScopeCreateError != nil {
7171
return nil, f.clientScopeCreateError
7272
}

pkg/scope/provider.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type providerScopeFactory struct {
5252
clientCache *cache.LRUExpireCache
5353
}
5454

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

@@ -62,6 +62,12 @@ func (f *providerScopeFactory) NewClientScopeFromMachine(ctx context.Context, ct
6262
if err != nil {
6363
return nil, err
6464
}
65+
} else if openStackCluster.Spec.IdentityRef != nil {
66+
var err error
67+
cloud, caCert, err = getCloudFromSecret(ctx, ctrlClient, openStackCluster.Namespace, openStackCluster.Spec.IdentityRef.Name, openStackCluster.Spec.CloudName)
68+
if err != nil {
69+
return nil, err
70+
}
6571
}
6672

6773
if caCert == nil {

pkg/scope/scope.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewFactory(maxCacheSize int) Factory {
4141

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

0 commit comments

Comments
 (0)