Skip to content

Commit

Permalink
Merge pull request #399 from Dee-6777/add-domain-prefix
Browse files Browse the repository at this point in the history
OSD-21691 : Add domain prefix in place of cluster name for cluster namespace
  • Loading branch information
openshift-merge-bot[bot] authored Apr 19, 2024
2 parents ff1d882 + 4c053bd commit 3f1f834
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/ocm-backplane/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func runLogin(cmd *cobra.Command, argv []string) (err error) {
logger.WithField("Cluster ID", clusterID).Debugln("Finding managing cluster")
var isHostedControlPlane bool
targetClusterID := clusterID
targetClusterName := clusterName

clusterID, clusterName, isHostedControlPlane, err = ocm.DefaultOCMInterface.GetManagingCluster(clusterID)
if err != nil {
Expand All @@ -207,7 +206,7 @@ func runLogin(cmd *cobra.Command, argv []string) (err error) {
logger.Debugln("Finding K8s namespaces")
// Print the related namespace if login to manager cluster
var namespaces []string
namespaces, err = listNamespaces(targetClusterID, targetClusterName, isHostedControlPlane)
namespaces, err = listNamespaces(targetClusterID, isHostedControlPlane)
if err != nil {
return err
}
Expand Down Expand Up @@ -469,14 +468,19 @@ func doLogin(api, clusterID, accessToken string) (string, error) {
return api + *loginResp.JSON200.ProxyUri, nil
}

func listNamespaces(clusterID, clusterName string, isHostedControlPlane bool) ([]string, error) {
func listNamespaces(clusterID string, isHostedControlPlane bool) ([]string, error) {

env, err := ocm.DefaultOCMInterface.GetOCMEnvironment()
if err != nil {
return []string{}, err
}
envName := env.Name()

clusterInfo, err := ocm.DefaultOCMInterface.GetClusterInfoByID(clusterID)
if err != nil {
return []string{}, err
}

klusterletPrefix := "klusterlet-"
hivePrefix := fmt.Sprintf("uhc-%s-", envName)
hcpPrefix := fmt.Sprintf("ocm-%s-", envName)
Expand All @@ -487,7 +491,7 @@ func listNamespaces(clusterID, clusterName string, isHostedControlPlane bool) ([
nsList = []string{
klusterletPrefix + clusterID,
hcpPrefix + clusterID,
hcpPrefix + clusterID + "-" + clusterName,
hcpPrefix + clusterID + "-" + clusterInfo.DomainPrefix(),
}
} else {
nsList = []string{
Expand Down
1 change: 1 addition & 0 deletions cmd/ocm-backplane/login/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ var _ = Describe("Login command", func() {

It("should return the managing cluster if one is requested", func() {
globalOpts.Manager = true
mockOcmInterface.EXPECT().GetClusterInfoByID(gomock.Any()).Return(mockCluster, nil).AnyTimes()
mockOcmInterface.EXPECT().GetOCMEnvironment().Return(ocmEnv, nil).AnyTimes()
mockOcmInterface.EXPECT().GetTargetCluster(testClusterID).Return(trueClusterID, testClusterID, nil)
mockOcmInterface.EXPECT().GetManagingCluster(trueClusterID).Return(managingClusterID, managingClusterID, true, nil)
Expand Down

0 comments on commit 3f1f834

Please sign in to comment.