Skip to content

Commit 71f7ea0

Browse files
stephenfink8s-infra-cherrypick-robot
authored andcommitted
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 aa2296e commit 71f7ea0

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
@@ -93,7 +93,8 @@ type OpenStackMachineSpec struct {
9393
// The server group to assign the machine to
9494
ServerGroupID string `json:"serverGroupID,omitempty"`
9595

96-
// IdentityRef is a reference to a identity to be used when reconciling this cluster
96+
// IdentityRef is a reference to a identity to be used when reconciling this cluster.
97+
// If not specified, the identity ref of the cluster will be used instead.
9798
// +optional
9899
IdentityRef *OpenStackIdentityReference `json:"identityRef,omitempty"`
99100
}

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
@@ -1233,7 +1233,8 @@ spec:
12331233
type: string
12341234
identityRef:
12351235
description: IdentityRef is a reference to a identity to be used when
1236-
reconciling this cluster
1236+
reconciling this cluster. If not specified, the identity ref of
1237+
the cluster will be used instead.
12371238
properties:
12381239
kind:
12391240
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
@@ -1037,7 +1037,8 @@ spec:
10371037
type: string
10381038
identityRef:
10391039
description: IdentityRef is a reference to a identity to be
1040-
used when reconciling this cluster
1040+
used when reconciling this cluster. If not specified, the
1041+
identity ref of the cluster will be used instead.
10411042
properties:
10421043
kind:
10431044
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)