Skip to content

Commit

Permalink
Implement Cluster and CRT creation in a designated namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Danil Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Nov 16, 2023
1 parent b14a296 commit 3a14fb8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ rules:
- get
- list
- watch
- create
- apiGroups:
- provisioning.cattle.io
resources:
Expand Down
1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ rules:
- get
- list
- watch
- create
- apiGroups:
- provisioning.cattle.io
resources:
Expand Down
20 changes: 12 additions & 8 deletions internal/controllers/import_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ const (
importLabelName = "cluster-api.cattle.io/rancher-auto-import"
ownedLabelName = "cluster-api.cattle.io/owned"

defaultRequeueDuration = 1 * time.Minute
clusterRegistrationTokenName = "default-token"
defaultRequeueDuration = 1 * time.Minute
)

// CAPIImportReconciler represents a reconciler for importing CAPI clusters in Rancher.
Expand Down Expand Up @@ -272,7 +271,7 @@ func (r *CAPIImportReconciler) reconcileNormal(ctx context.Context, capiCluster
}

// get the registration manifest
manifest, err := r.getClusterRegistrationManifest(ctx, rancherCluster.Status.ClusterName)
manifest, err := r.getClusterRegistrationManifest(ctx, rancherCluster.Status.ClusterName, capiCluster.Namespace)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -318,13 +317,18 @@ func (r *CAPIImportReconciler) reconcileDelete(ctx context.Context, capiCluster
return ctrl.Result{}, nil
}

func (r *CAPIImportReconciler) getClusterRegistrationManifest(ctx context.Context, clusterName string) (string, error) {
func (r *CAPIImportReconciler) getClusterRegistrationManifest(ctx context.Context, clusterName, namespace string) (string, error) {
log := log.FromContext(ctx)

token := &managementv3.ClusterRegistrationToken{ObjectMeta: metav1.ObjectMeta{
Name: clusterRegistrationTokenName,
Namespace: clusterName,
}}
token := &managementv3.ClusterRegistrationToken{
ObjectMeta: metav1.ObjectMeta{
Name: clusterName,
Namespace: namespace,
},
Spec: managementv3.ClusterRegistrationTokenSpec{
ClusterName: clusterName,
},
}
err := r.RancherClient.Get(ctx, client.ObjectKeyFromObject(token), token)

if client.IgnoreNotFound(err) != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/rancher/management/v3/clusterregistrationtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ type ClusterRegistrationToken struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ClusterRegistrationTokenSpec `json:"spec"`

Status ClusterRegistrationTokenStatus `json:"status,omitempty"`
}

// ClusterRegistrationTokenSpec is the struct representing the spec of a Rancher ClusterRegistrationToken.
type ClusterRegistrationTokenSpec struct {
ClusterName string `json:"clusterName"`
}

// ClusterRegistrationTokenStatus is the struct representing the status of a Rancher ClusterRegistrationToken.
type ClusterRegistrationTokenStatus struct {
ManifestURL string `json:"manifestUrl"`
Expand Down

0 comments on commit 3a14fb8

Please sign in to comment.