Skip to content

Commit 71d5769

Browse files
rosa: load identity dynamically
Instead of requiring users to provide their account IDs and ARNs in the spec of their hosted control planes, we can refer to AWS credentials like the other managed control plane controllers do in this provider. Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 1fd6d67 commit 71d5769

14 files changed

+177
-38
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ DOCKER_BUILDKIT=1
7676
export ACK_GINKGO_DEPRECATIONS := 1.16.4
7777

7878
# Set --output-base for conversion-gen if we are not within GOPATH
79-
ifneq ($(abspath $(REPO_ROOT)),$(shell go env GOPATH)/src/sigs.k8s.io/cluster-api-provider-aws)
79+
ifneq ($(abspath $(REPO_ROOT)),$(abspath $(shell go env GOPATH)/src/sigs.k8s.io/cluster-api-provider-aws))
8080
GEN_OUTPUT_BASE := --output-base=$(REPO_ROOT)
8181
else
8282
export GOPATH := $(shell go env GOPATH)
@@ -190,6 +190,7 @@ defaulters: $(DEFAULTER_GEN) ## Generate all Go types
190190
$(DEFAULTER_GEN) \
191191
--input-dirs=./api/v1beta2 \
192192
--input-dirs=./$(EXP_DIR)/api/v1beta2 \
193+
--input-dirs=./controlplane/rosa/api/v1beta2 \
193194
--input-dirs=./cmd/clusterawsadm/api/bootstrap/v1beta1 \
194195
--input-dirs=./cmd/clusterawsadm/api/bootstrap/v1alpha1 \
195196
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1beta1 \

config/crd/bases/controlplane.cluster.x-k8s.io_rosacontrolplanes.yaml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ spec:
4545
type: object
4646
spec:
4747
properties:
48-
accountID:
49-
description: 'TODO: these are to satisfy ocm sdk. Explore how to drop
50-
them.'
51-
type: string
5248
availabilityZones:
5349
description: AWS AvailabilityZones of the worker nodes should match
5450
the AvailabilityZones of the Subnets.
@@ -70,8 +66,6 @@ spec:
7066
- host
7167
- port
7268
type: object
73-
creatorARN:
74-
type: string
7569
credentialsSecretRef:
7670
description: 'CredentialsSecretRef references a secret with necessary
7771
credentials to connect to the OCM API. The secret should contain
@@ -84,7 +78,28 @@ spec:
8478
type: string
8579
type: object
8680
x-kubernetes-map-type: atomic
81+
identityRef:
82+
description: IdentityRef is a reference to an identity to be used
83+
when reconciling the managed control plane.
84+
properties:
85+
kind:
86+
description: Kind of the identity.
87+
enum:
88+
- AWSClusterControllerIdentity
89+
- AWSClusterRoleIdentity
90+
- AWSClusterStaticIdentity
91+
type: string
92+
name:
93+
description: Name of the identity.
94+
minLength: 1
95+
type: string
96+
required:
97+
- kind
98+
- name
99+
type: object
87100
installerRoleARN:
101+
description: 'TODO: these are to satisfy ocm sdk. Explore how to drop
102+
them.'
88103
type: string
89104
machineCIDR:
90105
description: Block of IP addresses used by OpenShift while installing
@@ -276,9 +291,7 @@ spec:
276291
workerRoleARN:
277292
type: string
278293
required:
279-
- accountID
280294
- availabilityZones
281-
- creatorARN
282295
- installerRoleARN
283296
- machineCIDR
284297
- oidcID

controllers/rosacluster_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
3636
rosacontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/rosa/api/v1beta2"
3737
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
38+
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
3839
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
3940
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
4041
"sigs.k8s.io/cluster-api/util"
@@ -48,6 +49,7 @@ type ROSAClusterReconciler struct {
4849
client.Client
4950
Recorder record.EventRecorder
5051
WatchFilterValue string
52+
Endpoints []scope.ServiceEndpoint
5153
}
5254

5355
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=rosaclusters,verbs=get;list;watch;update;patch;delete
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package v1beta2
2+
3+
import "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
4+
5+
// SetDefaults_RosaControlPlaneSpec is used by defaulter-gen.
6+
func SetDefaults_RosaControlPlaneSpec(s *RosaControlPlaneSpec) { //nolint:golint,stylecheck
7+
if s.IdentityRef == nil {
8+
s.IdentityRef = &v1beta2.AWSIdentityReference{
9+
Kind: v1beta2.ControllerIdentityKind,
10+
Name: v1beta2.AWSClusterControllerIdentityName,
11+
}
12+
}
13+
}

controlplane/rosa/api/v1beta2/rosacontrolplane_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222

23+
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2324
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2425
)
2526

@@ -64,8 +65,6 @@ type RosaControlPlaneSpec struct { //nolint: maligned
6465
OIDCID *string `json:"oidcID"`
6566

6667
// TODO: these are to satisfy ocm sdk. Explore how to drop them.
67-
AccountID *string `json:"accountID"`
68-
CreatorARN *string `json:"creatorARN"`
6968
InstallerRoleARN *string `json:"installerRoleARN"`
7069
SupportRoleARN *string `json:"supportRoleARN"`
7170
WorkerRoleARN *string `json:"workerRoleARN"`
@@ -76,6 +75,10 @@ type RosaControlPlaneSpec struct { //nolint: maligned
7675
// - ocmApiUrl: Optional, defaults to 'https://api.openshift.com'
7776
// +optional
7877
CredentialsSecretRef *corev1.LocalObjectReference `json:"credentialsSecretRef,omitempty"`
78+
79+
// IdentityRef is a reference to an identity to be used when reconciling the managed control plane.
80+
// +optional
81+
IdentityRef *infrav1.AWSIdentityReference `json:"identityRef,omitempty"`
7982
}
8083

8184
// AWSRolesRef contains references to various AWS IAM roles required for operators to make calls against the AWS API.
@@ -489,6 +492,7 @@ type RosaControlPlaneStatus struct {
489492
// +kubebuilder:subresource:status
490493
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this RosaControl belongs"
491494
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Control plane infrastructure is ready for worker nodes"
495+
// +k8s:defaulter-gen=true
492496

493497
type ROSAControlPlane struct {
494498
metav1.TypeMeta `json:",inline"`

controlplane/rosa/api/v1beta2/zz_generated.deepcopy.go

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/rosa/api/v1beta2/zz_generated.defaults.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/rosa/controllers/rosacontrolplane_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type ROSAControlPlaneReconciler struct {
6868
client.Client
6969
WatchFilterValue string
7070
WaitInfraPeriod time.Duration
71+
Endpoints []scope.ServiceEndpoint
7172
}
7273

7374
// SetupWithManager is used to setup the controller.
@@ -148,6 +149,7 @@ func (r *ROSAControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
148149
Cluster: cluster,
149150
ControlPlane: rosaControlPlane,
150151
ControllerName: strings.ToLower(rosaControlPlaneKind),
152+
Endpoints: r.Endpoints,
151153
Logger: log,
152154
})
153155
if err != nil {
@@ -344,8 +346,8 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
344346
stsBuilder.AutoMode(true)
345347

346348
awsBuilder := cmv1.NewAWS().
347-
AccountID(*rosaScope.ControlPlane.Spec.AccountID).
348-
BillingAccountID(*rosaScope.ControlPlane.Spec.AccountID).
349+
AccountID(*rosaScope.Identity.Account).
350+
BillingAccountID(*rosaScope.Identity.Account).
349351
SubnetIDs(rosaScope.ControlPlane.Spec.Subnets...).
350352
STS(stsBuilder)
351353
clusterBuilder = clusterBuilder.AWS(awsBuilder)
@@ -355,7 +357,7 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
355357
clusterBuilder = clusterBuilder.Nodes(clusterNodesBuilder)
356358

357359
clusterProperties := map[string]string{}
358-
clusterProperties[rosaCreatorArnProperty] = *rosaScope.ControlPlane.Spec.CreatorARN
360+
clusterProperties[rosaCreatorArnProperty] = *rosaScope.Identity.Arn
359361

360362
clusterBuilder = clusterBuilder.Properties(clusterProperties)
361363
clusterSpec, err := clusterBuilder.Build()

exp/controllers/rosamachinepool_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ROSAMachinePoolReconciler struct {
3737
client.Client
3838
Recorder record.EventRecorder
3939
WatchFilterValue string
40+
Endpoints []scope.ServiceEndpoint
4041
}
4142

4243
// SetupWithManager is used to setup the controller.

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func main() {
227227
Client: mgr.GetClient(),
228228
WatchFilterValue: watchFilterValue,
229229
WaitInfraPeriod: waitInfraPeriod,
230+
Endpoints: awsServiceEndpoints,
230231
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: awsClusterConcurrency, RecoverPanic: ptr.To[bool](true)}); err != nil {
231232
setupLog.Error(err, "unable to create controller", "controller", "ROSAControlPlane")
232233
os.Exit(1)
@@ -237,6 +238,7 @@ func main() {
237238
Client: mgr.GetClient(),
238239
Recorder: mgr.GetEventRecorderFor("rosacluster-controller"),
239240
WatchFilterValue: watchFilterValue,
241+
Endpoints: awsServiceEndpoints,
240242
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: awsClusterConcurrency, RecoverPanic: ptr.To[bool](true)}); err != nil {
241243
setupLog.Error(err, "unable to create controller", "controller", "ROSACluster")
242244
os.Exit(1)
@@ -247,6 +249,7 @@ func main() {
247249
Client: mgr.GetClient(),
248250
Recorder: mgr.GetEventRecorderFor("rosamachinepool-controller"),
249251
WatchFilterValue: watchFilterValue,
252+
Endpoints: awsServiceEndpoints,
250253
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: awsClusterConcurrency, RecoverPanic: ptr.To[bool](true)}); err != nil {
251254
setupLog.Error(err, "unable to create controller", "controller", "ROSAMachinePool")
252255
os.Exit(1)

0 commit comments

Comments
 (0)