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: 9 additions & 5 deletions internal/bminventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3462,10 +3462,14 @@ func (b *bareMetalInventory) GetCredentialsInternal(ctx context.Context, params
log.WithError(err).Errorf("failed to find cluster %s", params.ClusterID)
return nil, err
}
if !b.clusterApi.IsOperatorAvailable(&cluster, operators.OperatorConsole.Name) {
err := errors.New("console-url isn't available yet, it will be once console operator is ready as part of cluster finalizing stage")
log.WithError(err)
return nil, common.NewApiError(http.StatusConflict, err)
var consoleURL string
if b.clusterApi.IsOperatorMonitored(&cluster, operators.OperatorConsole.Name) {
if !b.clusterApi.IsOperatorAvailable(&cluster, operators.OperatorConsole.Name) {
err := errors.New("console-url isn't available yet, it will be once console operator is ready as part of cluster finalizing stage")
log.WithError(err)
return nil, common.NewApiError(http.StatusConflict, err)
}
consoleURL = common.GetConsoleUrl(cluster.Name, cluster.BaseDNSDomain)
}
objectName := fmt.Sprintf("%s/%s", params.ClusterID, "kubeadmin-password")
r, _, err := b.objectHandler.Download(ctx, objectName)
Expand All @@ -3482,7 +3486,7 @@ func (b *bareMetalInventory) GetCredentialsInternal(ctx context.Context, params
return &models.Credentials{
Username: DefaultUser,
Password: string(password),
ConsoleURL: common.GetConsoleUrl(cluster.Name, cluster.BaseDNSDomain),
ConsoleURL: consoleURL,
}, nil
}

Expand Down
42 changes: 39 additions & 3 deletions internal/bminventory/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
Expand All @@ -22,6 +23,7 @@ import (

"github.com/cavaliercoder/go-cpio"
ign_3_1 "github.com/coreos/ignition/v2/config/v3_1"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
Expand Down Expand Up @@ -13889,7 +13891,9 @@ var _ = Describe("GetCredentials", func() {
clusterID := strfmt.UUID(uuid.New().String())
c = common.Cluster{
Cluster: models.Cluster{
ID: &clusterID,
ID: &clusterID,
Name: "my-cluster",
BaseDNSDomain: "my-domain",
},
}
Expect(db.Create(&c).Error).ShouldNot(HaveOccurred())
Expand All @@ -13901,7 +13905,7 @@ var _ = Describe("GetCredentials", func() {
})

It("Console operator available", func() {

mockClusterApi.EXPECT().IsOperatorMonitored(gomock.Any(), operators.OperatorConsole.Name).Return(true)
mockClusterApi.EXPECT().IsOperatorAvailable(gomock.Any(), operators.OperatorConsole.Name).Return(true)
objectName := fmt.Sprintf("%s/%s", *c.ID, "kubeadmin-password")
mockS3Client.EXPECT().Download(ctx, objectName).Return(ioutil.NopCloser(strings.NewReader("my_password")), int64(0), nil)
Expand All @@ -13911,12 +13915,44 @@ var _ = Describe("GetCredentials", func() {
})

It("Console operator not available", func() {

mockClusterApi.EXPECT().IsOperatorMonitored(gomock.Any(), operators.OperatorConsole.Name).Return(true)
mockClusterApi.EXPECT().IsOperatorAvailable(gomock.Any(), operators.OperatorConsole.Name).Return(false)

reply := bm.V2GetCredentials(ctx, installer.V2GetCredentialsParams{ClusterID: *c.ID})
verifyApiError(reply, http.StatusConflict)
})

It("Returns credentials and no console URL if the console capability is disabled", func() {
mockClusterApi.EXPECT().IsOperatorMonitored(gomock.Any(), operators.OperatorConsole.Name).Return(false)
objectName := fmt.Sprintf("%s/%s", *c.ID, "kubeadmin-password")
mockS3Client.EXPECT().Download(ctx, objectName).Return(io.NopCloser(strings.NewReader("my_password")), int64(0), nil)

reply := bm.V2GetCredentials(ctx, installer.V2GetCredentialsParams{ClusterID: *c.ID})
recorder := httptest.NewRecorder()
reply.WriteResponse(recorder, runtime.JSONProducer())
Expect(recorder.Code).To(Equal(http.StatusOK))
Expect(recorder.Body).To(MatchJSON(`{
"password": "my_password",
"username": "kubeadmin"
}`))
})

It("Returns credentials and console URL if the console capability is enabled", func() {
mockClusterApi.EXPECT().IsOperatorMonitored(gomock.Any(), operators.OperatorConsole.Name).Return(true)
mockClusterApi.EXPECT().IsOperatorAvailable(gomock.Any(), operators.OperatorConsole.Name).Return(true)
objectName := fmt.Sprintf("%s/%s", *c.ID, "kubeadmin-password")
mockS3Client.EXPECT().Download(ctx, objectName).Return(io.NopCloser(strings.NewReader("my_password")), int64(0), nil)

reply := bm.V2GetCredentials(ctx, installer.V2GetCredentialsParams{ClusterID: *c.ID})
recorder := httptest.NewRecorder()
reply.WriteResponse(recorder, runtime.JSONProducer())
Expect(recorder.Code).To(Equal(http.StatusOK))
Expect(recorder.Body).To(MatchJSON(`{
"password": "my_password",
"username": "kubeadmin",
"console_url": "https://console-openshift-console.apps.my-cluster.my-domain"
}`))
})
})

var _ = Describe("AddReleaseImage", func() {
Expand Down
10 changes: 10 additions & 0 deletions internal/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type API interface {
// Refresh state in case of hosts update
RefreshStatus(ctx context.Context, c *common.Cluster, db *gorm.DB) (*common.Cluster, error)
ClusterMonitoring()
IsOperatorMonitored(c *common.Cluster, operatorName string) bool
IsOperatorAvailable(c *common.Cluster, operatorName string) bool
UploadIngressCert(c *common.Cluster) (err error)
VerifyClusterUpdatability(c *common.Cluster) (err error)
Expand Down Expand Up @@ -626,6 +627,15 @@ func CanDownloadKubeconfig(c *common.Cluster) (err error) {
return err
}

func (m *Manager) IsOperatorMonitored(c *common.Cluster, operatorName string) bool {
for _, o := range c.MonitoredOperators {
if o.Name == operatorName {
return true
}
}
return false
}

func (m *Manager) IsOperatorAvailable(c *common.Cluster, operatorName string) bool {
// TODO: MGMT-4458
// Backward-compatible solution for clusters that don't have monitored operators data
Expand Down
14 changes: 14 additions & 0 deletions internal/cluster/mock_cluster_api.go

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