Skip to content

Commit

Permalink
feat: support creating management.catte.io/v3 cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Salas <[email protected]>
  • Loading branch information
salasberryfin committed Jan 9, 2024
1 parent f5ada58 commit 4275316
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,8 @@ rules:
resources:
- clusterregistrationtokens
- clusterregistrationtokens/status
- clusters
- clusters/status
verbs:
- get
- list
Expand Down
2 changes: 2 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ rules:
resources:
- clusterregistrationtokens
- clusterregistrationtokens/status
- clusters
- clusters/status
verbs:
- get
- list
Expand Down
10 changes: 10 additions & 0 deletions internal/controllers/import_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ func (r *CAPIImportReconciler) reconcileNormal(ctx context.Context, capiCluster
return ctrl.Result{}, nil
}

//log.Info("##### Creating management.cattle.io/v3 rancher cluster")
//if err := r.RancherClient.Create(ctx, &managementv3.Cluster{
// ObjectMeta: metav1.ObjectMeta{
// Name: turtlesnaming.Name(capiCluster.Name).ToRancherName(),
// Namespace: capiCluster.Namespace,
// },
//}); err != nil {
// return ctrl.Result{}, fmt.Errorf("error creating management.cattle.io/v3 rancher cluster: %w", err)
//}

if err := r.RancherClient.Create(ctx, &provisioningv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: turtlesnaming.Name(capiCluster.Name).ToRancherName(),
Expand Down
9 changes: 9 additions & 0 deletions internal/controllers/import_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
r *CAPIImportReconciler
capiCluster *clusterv1.Cluster
rancherCluster *provisioningv1.Cluster
rancherClusterV3 *managementv3.Cluster
clusterRegistrationToken *managementv3.ClusterRegistrationToken
capiKubeconfigSecret *corev1.Secret
clusterName = "generated-rancher-cluster"
Expand Down Expand Up @@ -78,6 +79,13 @@ var _ = Describe("reconcile CAPI Cluster", func() {
},
}

rancherClusterV3 = &managementv3.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: turtlesnaming.Name(capiCluster.Name).ToRancherName(),
Namespace: testNamespace,
},
}

clusterRegistrationToken = &managementv3.ClusterRegistrationToken{
ObjectMeta: metav1.ObjectMeta{
Name: clusterName,
Expand All @@ -101,6 +109,7 @@ var _ = Describe("reconcile CAPI Cluster", func() {
clientObjs := []client.Object{
capiCluster,
rancherCluster,
rancherClusterV3,
clusterRegistrationToken,
capiKubeconfigSecret,
}
Expand Down
57 changes: 57 additions & 0 deletions internal/rancher/management/v3/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright © 2023 - 2024 SUSE LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Check failure on line 7 in internal/rancher/management/v3/cluster.go

View workflow job for this annotation

GitHub Actions / lint

Actual: http://www.apache.org/licenses/LICENSE-2.0

Check failure on line 7 in internal/rancher/management/v3/cluster.go

View workflow job for this annotation

GitHub Actions / lint

Actual: http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v3

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Cluster is the struct representing a Rancher Cluster.
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ClusterSpec `json:"spec"`
Status ClusterStatus `json:"status,omitempty"`
}

// ClusterSpec is the struct representing the specification of a Rancher Cluster.
type ClusterSpec struct {
DisplayName string `json:"displayName,omitempty"`
Description string `json:"description,omitempty"`
}

// ClusterStatus is the struct representing the status of a Rancher Cluster.
type ClusterStatus struct {
ClusterName string `json:"clusterName,omitempty"`
AgentDeployed bool `json:"agentDeployed,omitempty"`
Ready bool `json:"ready,omitempty"`
}

// ClusterList contains a list of ClusterList.
// +kubebuilder:object:root=true
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cluster `json:"items"`
}

func init() {
SchemeBuilder.Register(&Cluster{}, &ClusterList{})
}
89 changes: 89 additions & 0 deletions internal/rancher/management/v3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4275316

Please sign in to comment.