Skip to content

Commit

Permalink
Merge pull request openshift#1647 from abutcher/ocm-2.4-backport-HIVE…
Browse files Browse the repository at this point in the history
…-1465

OCM-2.4: Backport HIVE-1465
  • Loading branch information
openshift-merge-robot authored Jan 7, 2022
2 parents cce4cb9 + 3316487 commit 8c50440
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
15 changes: 5 additions & 10 deletions pkg/controller/clusterdeployment/clusterdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,9 @@ func (r *ReconcileClusterDeployment) reconcile(request reconcile.Request, cd *hi
return *result, err
}

// Sanity check the platform/cloud credentials.
validCreds, err := r.validatePlatformCreds(cd, cdLog)
if err != nil {
cdLog.WithError(err).Error("unable to validate platform credentials")
return reconcile.Result{}, err
}
// Make sure the condition is set properly.
_, err = r.setAuthenticationFailure(cd, validCreds, cdLog)
// Sanity check the platform/cloud credentials and set hivev1.AuthenticationFailureClusterDeploymentCondition
validCreds, authError := r.validatePlatformCreds(cd, cdLog)
_, err := r.setAuthenticationFailure(cd, validCreds, authError, cdLog)
if err != nil {
cdLog.WithError(err).Error("unable to update clusterdeployment")
return reconcile.Result{}, err
Expand Down Expand Up @@ -1062,7 +1057,7 @@ func (r *ReconcileClusterDeployment) setDNSNotReadyCondition(cd *hivev1.ClusterD
return r.Status().Update(context.TODO(), cd)
}

func (r *ReconcileClusterDeployment) setAuthenticationFailure(cd *hivev1.ClusterDeployment, authSuccessful bool, cdLog log.FieldLogger) (bool, error) {
func (r *ReconcileClusterDeployment) setAuthenticationFailure(cd *hivev1.ClusterDeployment, authSuccessful bool, authError error, cdLog log.FieldLogger) (bool, error) {

var status corev1.ConditionStatus
var reason, message string
Expand All @@ -1074,7 +1069,7 @@ func (r *ReconcileClusterDeployment) setAuthenticationFailure(cd *hivev1.Cluster
} else {
status = corev1.ConditionTrue
reason = platformAuthFailureReason
message = "Platform credentials failed authentication check"
message = fmt.Sprintf("Platform credentials failed authentication check: %s", authError)
}

conditions, changed := controllerutils.SetClusterDeploymentConditionWithChangeCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1883,14 +1884,24 @@ func TestClusterDeploymentReconcile(t *testing.T) {
testClusterDeploymentWithInitializedConditions(testClusterDeployment()),
},
platformCredentialsValidation: func(client.Client, *hivev1.ClusterDeployment, log.FieldLogger) (bool, error) {
return false, nil
return false, errors.New("Post \"https://xxx.xxx.xxx.xxx/sdk\": x509: cannot validate certificate for xxx.xxx.xxx.xxx because it doesn't contain any IP SANs")
},
expectErr: true,
validate: func(c client.Client, t *testing.T) {
cd := getCD(c)
require.NotNil(t, cd, "could not get ClusterDeployment")

testassert.AssertConditionStatus(t, cd, hivev1.AuthenticationFailureClusterDeploymentCondition, corev1.ConditionTrue)

// Preflight check happens before we declare provisioning
testassert.AssertConditions(t, cd, []hivev1.ClusterDeploymentCondition{
{
Type: hivev1.AuthenticationFailureClusterDeploymentCondition,
Status: corev1.ConditionTrue,
Reason: platformAuthFailureReason,
Message: "Platform credentials failed authentication check: Post \"https://xxx.xxx.xxx.xxx/sdk\": x509: cannot validate certificate for xxx.xxx.xxx.xxx because it doesn't contain any IP SANs",
},
})
},
},
{
Expand Down

0 comments on commit 8c50440

Please sign in to comment.