Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/clusteraccess/clusteraccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,16 @@ func (m *managerImpl) WithLogger(log *logging.Logger) Manager {
return m
}

func (m *managerImpl) CreateAndWaitForCluster(ctx context.Context, clusterName, purpose string,
// CreateAndWaitForCluster creates a new ClusterRequest and AccessRequest, waits for it to be ready, and returns the created Cluster.
// The name of the ClusterRequest and AccessRequest is derived from the controller name and the given localName.
// For example, if a provider needs access to the onboarding cluster, it could use the localName "onboarding" (or "onboarding-init").
// The resulting ClusterRequest and AccessRequest would then be named "<controllerName>--onboarding" (or "<controllerName>--onboarding-init").
func (m *managerImpl) CreateAndWaitForCluster(ctx context.Context, localName, purpose string,
scheme *runtime.Scheme, permissions []clustersv1alpha1.PermissionsRequest) (*clusters.Cluster, error) {

cr := &clustersv1alpha1.ClusterRequest{
ObjectMeta: metav1.ObjectMeta{
Name: clusterName,
Name: StableRequestNameFromLocalName(m.controllerName, localName),
Namespace: m.controllerNamespace,
},
}
Expand Down Expand Up @@ -742,6 +746,10 @@ func (m *accessRequestMutator) Mutate(accessRequest *clustersv1alpha1.AccessRequ
// StableRequestName generates a stable name for a Cluster- or AccessRequest related to an MCP.
// This basically results in '<lowercase_controller_name>--<request_name>'.
func StableRequestName(controllerName string, request reconcile.Request) string {
return StableRequestNameFromLocalName(controllerName, request.Name)
}

func StableRequestNameFromLocalName(controllerName, localName string) string {
controllerName = strings.ToLower(controllerName)
return fmt.Sprintf("%s--%s", controllerName, request.Name)
return fmt.Sprintf("%s--%s", controllerName, localName)
}
6 changes: 4 additions & 2 deletions lib/clusteraccess/clusteraccess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,18 @@ var _ = Describe("ClusterAccessManager", func() {
interval = 20 * time.Millisecond
)

requestName := clusteraccess.StableRequestNameFromLocalName(controllerName, clusterName)

clusterRequest := &clustersv1alpha1.ClusterRequest{
ObjectMeta: metav1.ObjectMeta{
Name: clusterName,
Name: requestName,
Namespace: controllerNamespace,
},
}

accessRequest := &clustersv1alpha1.AccessRequest{
ObjectMeta: metav1.ObjectMeta{
Name: clusterName,
Name: requestName,
Namespace: controllerNamespace,
},
}
Expand Down